2 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
50 #include <rdma/ib_addr.h>
52 #include <libcxgb_cm.h>
56 static char *states[] = {
73 module_param(nocong, int, 0644);
74 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
76 static int enable_ecn;
77 module_param(enable_ecn, int, 0644);
78 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
80 static int dack_mode = 1;
81 module_param(dack_mode, int, 0644);
82 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
84 uint c4iw_max_read_depth = 32;
85 module_param(c4iw_max_read_depth, int, 0644);
86 MODULE_PARM_DESC(c4iw_max_read_depth,
87 "Per-connection max ORD/IRD (default=32)");
89 static int enable_tcp_timestamps;
90 module_param(enable_tcp_timestamps, int, 0644);
91 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
93 static int enable_tcp_sack;
94 module_param(enable_tcp_sack, int, 0644);
95 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
97 static int enable_tcp_window_scaling = 1;
98 module_param(enable_tcp_window_scaling, int, 0644);
99 MODULE_PARM_DESC(enable_tcp_window_scaling,
100 "Enable tcp window scaling (default=1)");
102 static int peer2peer = 1;
103 module_param(peer2peer, int, 0644);
104 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
106 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
107 module_param(p2p_type, int, 0644);
108 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
109 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
111 static int ep_timeout_secs = 60;
112 module_param(ep_timeout_secs, int, 0644);
113 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
114 "in seconds (default=60)");
116 static int mpa_rev = 2;
117 module_param(mpa_rev, int, 0644);
118 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
119 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
120 " compliant (default=2)");
122 static int markers_enabled;
123 module_param(markers_enabled, int, 0644);
124 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
126 static int crc_enabled = 1;
127 module_param(crc_enabled, int, 0644);
128 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
130 static int rcv_win = 256 * 1024;
131 module_param(rcv_win, int, 0644);
132 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
134 static int snd_win = 128 * 1024;
135 module_param(snd_win, int, 0644);
136 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
138 static struct workqueue_struct *workq;
140 static struct sk_buff_head rxq;
142 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
143 static void ep_timeout(struct timer_list *t);
144 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
145 static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
147 static LIST_HEAD(timeout_list);
148 static spinlock_t timeout_lock;
150 static void deref_cm_id(struct c4iw_ep_common *epc)
152 epc->cm_id->rem_ref(epc->cm_id);
154 set_bit(CM_ID_DEREFED, &epc->history);
157 static void ref_cm_id(struct c4iw_ep_common *epc)
159 set_bit(CM_ID_REFED, &epc->history);
160 epc->cm_id->add_ref(epc->cm_id);
163 static void deref_qp(struct c4iw_ep *ep)
165 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
166 clear_bit(QP_REFERENCED, &ep->com.flags);
167 set_bit(QP_DEREFED, &ep->com.history);
170 static void ref_qp(struct c4iw_ep *ep)
172 set_bit(QP_REFERENCED, &ep->com.flags);
173 set_bit(QP_REFED, &ep->com.history);
174 c4iw_qp_add_ref(&ep->com.qp->ibqp);
177 static void start_ep_timer(struct c4iw_ep *ep)
179 pr_debug("ep %p\n", ep);
180 if (timer_pending(&ep->timer)) {
181 pr_err("%s timer already started! ep %p\n",
185 clear_bit(TIMEOUT, &ep->com.flags);
186 c4iw_get_ep(&ep->com);
187 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
188 add_timer(&ep->timer);
191 static int stop_ep_timer(struct c4iw_ep *ep)
193 pr_debug("ep %p stopping\n", ep);
194 del_timer_sync(&ep->timer);
195 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
196 c4iw_put_ep(&ep->com);
202 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
203 struct l2t_entry *l2e)
207 if (c4iw_fatal_error(rdev)) {
209 pr_err("%s - device in error state - dropping\n", __func__);
212 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
215 else if (error == NET_XMIT_DROP)
217 return error < 0 ? error : 0;
220 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
224 if (c4iw_fatal_error(rdev)) {
226 pr_err("%s - device in error state - dropping\n", __func__);
229 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
232 return error < 0 ? error : 0;
235 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
237 u32 len = roundup(sizeof(struct cpl_tid_release), 16);
239 skb = get_skb(skb, len, GFP_KERNEL);
243 cxgb_mk_tid_release(skb, len, hwtid, 0);
244 c4iw_ofld_send(rdev, skb);
248 static void set_emss(struct c4iw_ep *ep, u16 opt)
250 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
251 ((AF_INET == ep->com.remote_addr.ss_family) ?
252 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
253 sizeof(struct tcphdr);
255 if (TCPOPT_TSTAMP_G(opt))
256 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
260 pr_debug("Warning: misaligned mtu idx %u mss %u emss=%u\n",
261 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
262 pr_debug("mss_idx %u mss %u emss=%u\n", TCPOPT_MSS_G(opt), ep->mss,
266 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
268 enum c4iw_ep_state state;
270 mutex_lock(&epc->mutex);
272 mutex_unlock(&epc->mutex);
276 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
281 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
283 mutex_lock(&epc->mutex);
284 pr_debug("%s -> %s\n", states[epc->state], states[new]);
285 __state_set(epc, new);
286 mutex_unlock(&epc->mutex);
290 static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
296 len = roundup(sizeof(union cpl_wr_size), 16);
297 for (i = 0; i < size; i++) {
298 skb = alloc_skb(len, GFP_KERNEL);
301 skb_queue_tail(ep_skb_list, skb);
305 skb_queue_purge(ep_skb_list);
309 static void *alloc_ep(int size, gfp_t gfp)
311 struct c4iw_ep_common *epc;
313 epc = kzalloc(size, gfp);
315 epc->wr_waitp = c4iw_alloc_wr_wait(gfp);
316 if (!epc->wr_waitp) {
321 kref_init(&epc->kref);
322 mutex_init(&epc->mutex);
323 c4iw_init_wr_wait(epc->wr_waitp);
325 pr_debug("alloc ep %p\n", epc);
330 static void remove_ep_tid(struct c4iw_ep *ep)
334 spin_lock_irqsave(&ep->com.dev->lock, flags);
335 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
336 if (idr_is_empty(&ep->com.dev->hwtid_idr))
337 wake_up(&ep->com.dev->wait);
338 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
341 static void insert_ep_tid(struct c4iw_ep *ep)
345 spin_lock_irqsave(&ep->com.dev->lock, flags);
346 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
347 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
351 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
353 static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
358 spin_lock_irqsave(&dev->lock, flags);
359 ep = idr_find(&dev->hwtid_idr, tid);
361 c4iw_get_ep(&ep->com);
362 spin_unlock_irqrestore(&dev->lock, flags);
367 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
369 static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
372 struct c4iw_listen_ep *ep;
375 spin_lock_irqsave(&dev->lock, flags);
376 ep = idr_find(&dev->stid_idr, stid);
378 c4iw_get_ep(&ep->com);
379 spin_unlock_irqrestore(&dev->lock, flags);
383 void _c4iw_free_ep(struct kref *kref)
387 ep = container_of(kref, struct c4iw_ep, com.kref);
388 pr_debug("ep %p state %s\n", ep, states[ep->com.state]);
389 if (test_bit(QP_REFERENCED, &ep->com.flags))
391 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
392 if (ep->com.remote_addr.ss_family == AF_INET6) {
393 struct sockaddr_in6 *sin6 =
394 (struct sockaddr_in6 *)
398 ep->com.dev->rdev.lldi.ports[0],
399 (const u32 *)&sin6->sin6_addr.s6_addr,
402 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
403 ep->com.local_addr.ss_family);
404 dst_release(ep->dst);
405 cxgb4_l2t_release(ep->l2t);
406 kfree_skb(ep->mpa_skb);
408 if (!skb_queue_empty(&ep->com.ep_skb_list))
409 skb_queue_purge(&ep->com.ep_skb_list);
410 c4iw_put_wr_wait(ep->com.wr_waitp);
414 static void release_ep_resources(struct c4iw_ep *ep)
416 set_bit(RELEASE_RESOURCES, &ep->com.flags);
419 * If we have a hwtid, then remove it from the idr table
420 * so lookups will no longer find this endpoint. Otherwise
421 * we have a race where one thread finds the ep ptr just
422 * before the other thread is freeing the ep memory.
426 c4iw_put_ep(&ep->com);
429 static int status2errno(int status)
434 case CPL_ERR_CONN_RESET:
436 case CPL_ERR_ARP_MISS:
437 return -EHOSTUNREACH;
438 case CPL_ERR_CONN_TIMEDOUT:
440 case CPL_ERR_TCAM_FULL:
442 case CPL_ERR_CONN_EXIST:
450 * Try and reuse skbs already allocated...
452 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
454 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
457 skb_reset_transport_header(skb);
459 skb = alloc_skb(len, gfp);
461 t4_set_arp_err_handler(skb, NULL, NULL);
465 static struct net_device *get_real_dev(struct net_device *egress_dev)
467 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
470 static void arp_failure_discard(void *handle, struct sk_buff *skb)
472 pr_err("ARP failure\n");
476 static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
478 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
483 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
484 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
487 static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
491 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
492 release_ep_resources(ep);
497 static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
501 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
502 c4iw_put_ep(&ep->parent_ep->com);
503 release_ep_resources(ep);
509 * Fake up a special CPL opcode and call sched() so process_work() will call
510 * _put_ep_safe() in a safe context to free the ep resources. This is needed
511 * because ARP error handlers are called in an ATOMIC context, and
512 * _c4iw_free_ep() needs to block.
514 static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
517 struct cpl_act_establish *rpl = cplhdr(skb);
519 /* Set our special ARP_FAILURE opcode */
520 rpl->ot.opcode = cpl;
523 * Save ep in the skb->cb area, after where sched() will save the dev
526 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
527 sched(ep->com.dev, skb);
530 /* Handle an ARP failure for an accept */
531 static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
533 struct c4iw_ep *ep = handle;
535 pr_err("ARP failure during accept - tid %u - dropping connection\n",
538 __state_set(&ep->com, DEAD);
539 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
543 * Handle an ARP failure for an active open.
545 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
547 struct c4iw_ep *ep = handle;
549 pr_err("ARP failure during connect\n");
550 connect_reply_upcall(ep, -EHOSTUNREACH);
551 __state_set(&ep->com, DEAD);
552 if (ep->com.remote_addr.ss_family == AF_INET6) {
553 struct sockaddr_in6 *sin6 =
554 (struct sockaddr_in6 *)&ep->com.local_addr;
555 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
556 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
558 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
559 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
560 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
564 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
567 static void abort_arp_failure(void *handle, struct sk_buff *skb)
570 struct c4iw_ep *ep = handle;
571 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
572 struct cpl_abort_req *req = cplhdr(skb);
574 pr_debug("rdev %p\n", rdev);
575 req->cmd = CPL_ABORT_NO_RST;
577 ret = c4iw_ofld_send(rdev, skb);
579 __state_set(&ep->com, DEAD);
580 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
585 static int send_flowc(struct c4iw_ep *ep)
587 struct fw_flowc_wr *flowc;
588 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
589 u16 vlan = ep->l2t->vlan;
591 int flowclen, flowclen16;
596 if (vlan == CPL_L2T_VLAN_NONE)
601 flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
602 flowclen16 = DIV_ROUND_UP(flowclen, 16);
603 flowclen = flowclen16 * 16;
605 flowc = __skb_put(skb, flowclen);
606 memset(flowc, 0, flowclen);
608 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
609 FW_FLOWC_WR_NPARAMS_V(nparams));
610 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(flowclen16) |
611 FW_WR_FLOWID_V(ep->hwtid));
613 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
614 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
615 (ep->com.dev->rdev.lldi.pf));
616 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
617 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
618 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
619 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
620 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
621 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
622 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
623 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
624 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
625 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
626 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
627 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
628 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
629 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
630 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_RCV_SCALE;
631 flowc->mnemval[8].val = cpu_to_be32(ep->snd_wscale);
634 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
635 flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
636 flowc->mnemval[9].val = cpu_to_be32(pri);
639 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
640 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
643 static int send_halfclose(struct c4iw_ep *ep)
645 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
646 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
648 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
652 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
653 NULL, arp_failure_discard);
655 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
658 static void read_tcb(struct c4iw_ep *ep)
661 struct cpl_get_tcb *req;
662 int wrlen = roundup(sizeof(*req), 16);
664 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
668 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
669 req = (struct cpl_get_tcb *) skb_put(skb, wrlen);
670 memset(req, 0, wrlen);
671 INIT_TP_WR(req, ep->hwtid);
672 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_GET_TCB, ep->hwtid));
673 req->reply_ctrl = htons(REPLY_CHAN_V(0) | QUEUENO_V(ep->rss_qid));
676 * keep a ref on the ep so the tcb is not unlocked before this
677 * cpl completes. The ref is released in read_tcb_rpl().
679 c4iw_get_ep(&ep->com);
680 if (WARN_ON(c4iw_ofld_send(&ep->com.dev->rdev, skb)))
681 c4iw_put_ep(&ep->com);
684 static int send_abort_req(struct c4iw_ep *ep)
686 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
687 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
689 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
690 if (WARN_ON(!req_skb))
693 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
694 ep, abort_arp_failure);
696 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
699 static int send_abort(struct c4iw_ep *ep)
701 if (!ep->com.qp || !ep->com.qp->srq) {
705 set_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags);
710 static int send_connect(struct c4iw_ep *ep)
712 struct cpl_act_open_req *req = NULL;
713 struct cpl_t5_act_open_req *t5req = NULL;
714 struct cpl_t6_act_open_req *t6req = NULL;
715 struct cpl_act_open_req6 *req6 = NULL;
716 struct cpl_t5_act_open_req6 *t5req6 = NULL;
717 struct cpl_t6_act_open_req6 *t6req6 = NULL;
721 unsigned int mtu_idx;
723 int win, sizev4, sizev6, wrlen;
724 struct sockaddr_in *la = (struct sockaddr_in *)
726 struct sockaddr_in *ra = (struct sockaddr_in *)
727 &ep->com.remote_addr;
728 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
730 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
731 &ep->com.remote_addr;
733 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
734 u32 isn = (prandom_u32() & ~7UL) - 1;
735 struct net_device *netdev;
738 netdev = ep->com.dev->rdev.lldi.ports[0];
740 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
742 sizev4 = sizeof(struct cpl_act_open_req);
743 sizev6 = sizeof(struct cpl_act_open_req6);
746 sizev4 = sizeof(struct cpl_t5_act_open_req);
747 sizev6 = sizeof(struct cpl_t5_act_open_req6);
750 sizev4 = sizeof(struct cpl_t6_act_open_req);
751 sizev6 = sizeof(struct cpl_t6_act_open_req6);
754 pr_err("T%d Chip is not supported\n",
755 CHELSIO_CHIP_VERSION(adapter_type));
759 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
760 roundup(sizev4, 16) :
763 pr_debug("ep %p atid %u\n", ep, ep->atid);
765 skb = get_skb(NULL, wrlen, GFP_KERNEL);
767 pr_err("%s - failed to alloc skb\n", __func__);
770 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
772 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
773 enable_tcp_timestamps,
774 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
775 wscale = cxgb_compute_wscale(rcv_win);
778 * Specify the largest window that will fit in opt0. The
779 * remainder will be specified in the rx_data_ack.
781 win = ep->rcv_win >> 10;
782 if (win > RCV_BUFSIZ_M)
785 opt0 = (nocong ? NO_CONG_F : 0) |
788 WND_SCALE_V(wscale) |
790 L2T_IDX_V(ep->l2t->idx) |
791 TX_CHAN_V(ep->tx_chan) |
792 SMAC_SEL_V(ep->smac_idx) |
793 DSCP_V(ep->tos >> 2) |
794 ULP_MODE_V(ULP_MODE_TCPDDP) |
796 opt2 = RX_CHANNEL_V(0) |
797 CCTRL_ECN_V(enable_ecn) |
798 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
799 if (enable_tcp_timestamps)
800 opt2 |= TSTAMPS_EN_F;
803 if (wscale && enable_tcp_window_scaling)
804 opt2 |= WND_SCALE_EN_F;
805 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
809 opt2 |= T5_OPT_2_VALID_F;
810 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
814 params = cxgb4_select_ntuple(netdev, ep->l2t);
816 if (ep->com.remote_addr.ss_family == AF_INET6)
817 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
818 (const u32 *)&la6->sin6_addr.s6_addr, 1);
820 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
822 if (ep->com.remote_addr.ss_family == AF_INET) {
823 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
825 req = skb_put(skb, wrlen);
829 t5req = skb_put(skb, wrlen);
830 INIT_TP_WR(t5req, 0);
831 req = (struct cpl_act_open_req *)t5req;
834 t6req = skb_put(skb, wrlen);
835 INIT_TP_WR(t6req, 0);
836 req = (struct cpl_act_open_req *)t6req;
837 t5req = (struct cpl_t5_act_open_req *)t6req;
840 pr_err("T%d Chip is not supported\n",
841 CHELSIO_CHIP_VERSION(adapter_type));
846 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
847 ((ep->rss_qid<<14) | ep->atid)));
848 req->local_port = la->sin_port;
849 req->peer_port = ra->sin_port;
850 req->local_ip = la->sin_addr.s_addr;
851 req->peer_ip = ra->sin_addr.s_addr;
852 req->opt0 = cpu_to_be64(opt0);
854 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
855 req->params = cpu_to_be32(params);
856 req->opt2 = cpu_to_be32(opt2);
858 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
860 cpu_to_be64(FILTER_TUPLE_V(params));
861 t5req->rsvd = cpu_to_be32(isn);
862 pr_debug("snd_isn %u\n", t5req->rsvd);
863 t5req->opt2 = cpu_to_be32(opt2);
866 cpu_to_be64(FILTER_TUPLE_V(params));
867 t6req->rsvd = cpu_to_be32(isn);
868 pr_debug("snd_isn %u\n", t6req->rsvd);
869 t6req->opt2 = cpu_to_be32(opt2);
873 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
875 req6 = skb_put(skb, wrlen);
879 t5req6 = skb_put(skb, wrlen);
880 INIT_TP_WR(t5req6, 0);
881 req6 = (struct cpl_act_open_req6 *)t5req6;
884 t6req6 = skb_put(skb, wrlen);
885 INIT_TP_WR(t6req6, 0);
886 req6 = (struct cpl_act_open_req6 *)t6req6;
887 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
890 pr_err("T%d Chip is not supported\n",
891 CHELSIO_CHIP_VERSION(adapter_type));
896 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
897 ((ep->rss_qid<<14)|ep->atid)));
898 req6->local_port = la6->sin6_port;
899 req6->peer_port = ra6->sin6_port;
900 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
901 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
902 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
903 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
904 req6->opt0 = cpu_to_be64(opt0);
906 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
907 req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
909 req6->opt2 = cpu_to_be32(opt2);
911 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
913 cpu_to_be64(FILTER_TUPLE_V(params));
914 t5req6->rsvd = cpu_to_be32(isn);
915 pr_debug("snd_isn %u\n", t5req6->rsvd);
916 t5req6->opt2 = cpu_to_be32(opt2);
919 cpu_to_be64(FILTER_TUPLE_V(params));
920 t6req6->rsvd = cpu_to_be32(isn);
921 pr_debug("snd_isn %u\n", t6req6->rsvd);
922 t6req6->opt2 = cpu_to_be32(opt2);
928 set_bit(ACT_OPEN_REQ, &ep->com.history);
929 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
931 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
932 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
933 (const u32 *)&la6->sin6_addr.s6_addr, 1);
937 static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
940 int mpalen, wrlen, ret;
941 struct fw_ofld_tx_data_wr *req;
942 struct mpa_message *mpa;
943 struct mpa_v2_conn_params mpa_v2_params;
945 pr_debug("ep %p tid %u pd_len %d\n",
946 ep, ep->hwtid, ep->plen);
948 mpalen = sizeof(*mpa) + ep->plen;
949 if (mpa_rev_to_use == 2)
950 mpalen += sizeof(struct mpa_v2_conn_params);
951 wrlen = roundup(mpalen + sizeof *req, 16);
952 skb = get_skb(skb, wrlen, GFP_KERNEL);
954 connect_reply_upcall(ep, -ENOMEM);
957 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
959 req = skb_put_zero(skb, wrlen);
960 req->op_to_immdlen = cpu_to_be32(
961 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
963 FW_WR_IMMDLEN_V(mpalen));
964 req->flowid_len16 = cpu_to_be32(
965 FW_WR_FLOWID_V(ep->hwtid) |
966 FW_WR_LEN16_V(wrlen >> 4));
967 req->plen = cpu_to_be32(mpalen);
968 req->tunnel_to_proxy = cpu_to_be32(
969 FW_OFLD_TX_DATA_WR_FLUSH_F |
970 FW_OFLD_TX_DATA_WR_SHOVE_F);
972 mpa = (struct mpa_message *)(req + 1);
973 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
977 mpa->flags |= MPA_CRC;
978 if (markers_enabled) {
979 mpa->flags |= MPA_MARKERS;
980 ep->mpa_attr.recv_marker_enabled = 1;
982 ep->mpa_attr.recv_marker_enabled = 0;
984 if (mpa_rev_to_use == 2)
985 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
987 mpa->private_data_size = htons(ep->plen);
988 mpa->revision = mpa_rev_to_use;
989 if (mpa_rev_to_use == 1) {
990 ep->tried_with_mpa_v1 = 1;
991 ep->retry_with_mpa_v1 = 0;
994 if (mpa_rev_to_use == 2) {
995 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
996 sizeof (struct mpa_v2_conn_params));
997 pr_debug("initiator ird %u ord %u\n", ep->ird,
999 mpa_v2_params.ird = htons((u16)ep->ird);
1000 mpa_v2_params.ord = htons((u16)ep->ord);
1003 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1004 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1005 mpa_v2_params.ord |=
1006 htons(MPA_V2_RDMA_WRITE_RTR);
1007 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1008 mpa_v2_params.ord |=
1009 htons(MPA_V2_RDMA_READ_RTR);
1011 memcpy(mpa->private_data, &mpa_v2_params,
1012 sizeof(struct mpa_v2_conn_params));
1015 memcpy(mpa->private_data +
1016 sizeof(struct mpa_v2_conn_params),
1017 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1020 memcpy(mpa->private_data,
1021 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1024 * Reference the mpa skb. This ensures the data area
1025 * will remain in memory until the hw acks the tx.
1026 * Function fw4_ack() will deref it.
1029 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1031 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1035 __state_set(&ep->com, MPA_REQ_SENT);
1036 ep->mpa_attr.initiator = 1;
1037 ep->snd_seq += mpalen;
1041 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1044 struct fw_ofld_tx_data_wr *req;
1045 struct mpa_message *mpa;
1046 struct sk_buff *skb;
1047 struct mpa_v2_conn_params mpa_v2_params;
1049 pr_debug("ep %p tid %u pd_len %d\n",
1050 ep, ep->hwtid, ep->plen);
1052 mpalen = sizeof(*mpa) + plen;
1053 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1054 mpalen += sizeof(struct mpa_v2_conn_params);
1055 wrlen = roundup(mpalen + sizeof *req, 16);
1057 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1059 pr_err("%s - cannot alloc skb!\n", __func__);
1062 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1064 req = skb_put_zero(skb, wrlen);
1065 req->op_to_immdlen = cpu_to_be32(
1066 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1068 FW_WR_IMMDLEN_V(mpalen));
1069 req->flowid_len16 = cpu_to_be32(
1070 FW_WR_FLOWID_V(ep->hwtid) |
1071 FW_WR_LEN16_V(wrlen >> 4));
1072 req->plen = cpu_to_be32(mpalen);
1073 req->tunnel_to_proxy = cpu_to_be32(
1074 FW_OFLD_TX_DATA_WR_FLUSH_F |
1075 FW_OFLD_TX_DATA_WR_SHOVE_F);
1077 mpa = (struct mpa_message *)(req + 1);
1078 memset(mpa, 0, sizeof(*mpa));
1079 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1080 mpa->flags = MPA_REJECT;
1081 mpa->revision = ep->mpa_attr.version;
1082 mpa->private_data_size = htons(plen);
1084 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1085 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1086 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1087 sizeof (struct mpa_v2_conn_params));
1088 mpa_v2_params.ird = htons(((u16)ep->ird) |
1089 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1091 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1093 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1094 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1095 FW_RI_INIT_P2PTYPE_READ_REQ ?
1096 MPA_V2_RDMA_READ_RTR : 0) : 0));
1097 memcpy(mpa->private_data, &mpa_v2_params,
1098 sizeof(struct mpa_v2_conn_params));
1101 memcpy(mpa->private_data +
1102 sizeof(struct mpa_v2_conn_params), pdata, plen);
1105 memcpy(mpa->private_data, pdata, plen);
1108 * Reference the mpa skb again. This ensures the data area
1109 * will remain in memory until the hw acks the tx.
1110 * Function fw4_ack() will deref it.
1113 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1114 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1116 ep->snd_seq += mpalen;
1117 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1120 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1123 struct fw_ofld_tx_data_wr *req;
1124 struct mpa_message *mpa;
1125 struct sk_buff *skb;
1126 struct mpa_v2_conn_params mpa_v2_params;
1128 pr_debug("ep %p tid %u pd_len %d\n",
1129 ep, ep->hwtid, ep->plen);
1131 mpalen = sizeof(*mpa) + plen;
1132 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1133 mpalen += sizeof(struct mpa_v2_conn_params);
1134 wrlen = roundup(mpalen + sizeof *req, 16);
1136 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1138 pr_err("%s - cannot alloc skb!\n", __func__);
1141 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1143 req = skb_put_zero(skb, wrlen);
1144 req->op_to_immdlen = cpu_to_be32(
1145 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1147 FW_WR_IMMDLEN_V(mpalen));
1148 req->flowid_len16 = cpu_to_be32(
1149 FW_WR_FLOWID_V(ep->hwtid) |
1150 FW_WR_LEN16_V(wrlen >> 4));
1151 req->plen = cpu_to_be32(mpalen);
1152 req->tunnel_to_proxy = cpu_to_be32(
1153 FW_OFLD_TX_DATA_WR_FLUSH_F |
1154 FW_OFLD_TX_DATA_WR_SHOVE_F);
1156 mpa = (struct mpa_message *)(req + 1);
1157 memset(mpa, 0, sizeof(*mpa));
1158 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1160 if (ep->mpa_attr.crc_enabled)
1161 mpa->flags |= MPA_CRC;
1162 if (ep->mpa_attr.recv_marker_enabled)
1163 mpa->flags |= MPA_MARKERS;
1164 mpa->revision = ep->mpa_attr.version;
1165 mpa->private_data_size = htons(plen);
1167 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1168 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1169 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1170 sizeof (struct mpa_v2_conn_params));
1171 mpa_v2_params.ird = htons((u16)ep->ird);
1172 mpa_v2_params.ord = htons((u16)ep->ord);
1173 if (peer2peer && (ep->mpa_attr.p2p_type !=
1174 FW_RI_INIT_P2PTYPE_DISABLED)) {
1175 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1177 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1178 mpa_v2_params.ord |=
1179 htons(MPA_V2_RDMA_WRITE_RTR);
1180 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1181 mpa_v2_params.ord |=
1182 htons(MPA_V2_RDMA_READ_RTR);
1185 memcpy(mpa->private_data, &mpa_v2_params,
1186 sizeof(struct mpa_v2_conn_params));
1189 memcpy(mpa->private_data +
1190 sizeof(struct mpa_v2_conn_params), pdata, plen);
1193 memcpy(mpa->private_data, pdata, plen);
1196 * Reference the mpa skb. This ensures the data area
1197 * will remain in memory until the hw acks the tx.
1198 * Function fw4_ack() will deref it.
1201 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1203 __state_set(&ep->com, MPA_REP_SENT);
1204 ep->snd_seq += mpalen;
1205 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1208 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1211 struct cpl_act_establish *req = cplhdr(skb);
1212 unsigned short tcp_opt = ntohs(req->tcp_opt);
1213 unsigned int tid = GET_TID(req);
1214 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
1215 struct tid_info *t = dev->rdev.lldi.tids;
1218 ep = lookup_atid(t, atid);
1220 pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep, tid,
1221 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1223 mutex_lock(&ep->com.mutex);
1224 dst_confirm(ep->dst);
1226 /* setup the hwtid for this connection */
1228 cxgb4_insert_tid(t, ep, tid, ep->com.local_addr.ss_family);
1231 ep->snd_seq = be32_to_cpu(req->snd_isn);
1232 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1233 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
1235 set_emss(ep, tcp_opt);
1237 /* dealloc the atid */
1238 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1239 cxgb4_free_atid(t, atid);
1240 set_bit(ACT_ESTAB, &ep->com.history);
1242 /* start MPA negotiation */
1243 ret = send_flowc(ep);
1246 if (ep->retry_with_mpa_v1)
1247 ret = send_mpa_req(ep, skb, 1);
1249 ret = send_mpa_req(ep, skb, mpa_rev);
1252 mutex_unlock(&ep->com.mutex);
1255 mutex_unlock(&ep->com.mutex);
1256 connect_reply_upcall(ep, -ENOMEM);
1257 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1261 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1263 struct iw_cm_event event;
1265 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1266 memset(&event, 0, sizeof(event));
1267 event.event = IW_CM_EVENT_CLOSE;
1268 event.status = status;
1269 if (ep->com.cm_id) {
1270 pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
1271 ep, ep->com.cm_id, ep->hwtid);
1272 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1273 deref_cm_id(&ep->com);
1274 set_bit(CLOSE_UPCALL, &ep->com.history);
1278 static void peer_close_upcall(struct c4iw_ep *ep)
1280 struct iw_cm_event event;
1282 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1283 memset(&event, 0, sizeof(event));
1284 event.event = IW_CM_EVENT_DISCONNECT;
1285 if (ep->com.cm_id) {
1286 pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
1287 ep, ep->com.cm_id, ep->hwtid);
1288 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1289 set_bit(DISCONN_UPCALL, &ep->com.history);
1293 static void peer_abort_upcall(struct c4iw_ep *ep)
1295 struct iw_cm_event event;
1297 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1298 memset(&event, 0, sizeof(event));
1299 event.event = IW_CM_EVENT_CLOSE;
1300 event.status = -ECONNRESET;
1301 if (ep->com.cm_id) {
1302 pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep,
1303 ep->com.cm_id, ep->hwtid);
1304 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1305 deref_cm_id(&ep->com);
1306 set_bit(ABORT_UPCALL, &ep->com.history);
1310 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1312 struct iw_cm_event event;
1314 pr_debug("ep %p tid %u status %d\n",
1315 ep, ep->hwtid, status);
1316 memset(&event, 0, sizeof(event));
1317 event.event = IW_CM_EVENT_CONNECT_REPLY;
1318 event.status = status;
1319 memcpy(&event.local_addr, &ep->com.local_addr,
1320 sizeof(ep->com.local_addr));
1321 memcpy(&event.remote_addr, &ep->com.remote_addr,
1322 sizeof(ep->com.remote_addr));
1324 if ((status == 0) || (status == -ECONNREFUSED)) {
1325 if (!ep->tried_with_mpa_v1) {
1326 /* this means MPA_v2 is used */
1327 event.ord = ep->ird;
1328 event.ird = ep->ord;
1329 event.private_data_len = ep->plen -
1330 sizeof(struct mpa_v2_conn_params);
1331 event.private_data = ep->mpa_pkt +
1332 sizeof(struct mpa_message) +
1333 sizeof(struct mpa_v2_conn_params);
1335 /* this means MPA_v1 is used */
1336 event.ord = cur_max_read_depth(ep->com.dev);
1337 event.ird = cur_max_read_depth(ep->com.dev);
1338 event.private_data_len = ep->plen;
1339 event.private_data = ep->mpa_pkt +
1340 sizeof(struct mpa_message);
1344 pr_debug("ep %p tid %u status %d\n", ep,
1346 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1347 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1350 deref_cm_id(&ep->com);
1353 static int connect_request_upcall(struct c4iw_ep *ep)
1355 struct iw_cm_event event;
1358 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1359 memset(&event, 0, sizeof(event));
1360 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1361 memcpy(&event.local_addr, &ep->com.local_addr,
1362 sizeof(ep->com.local_addr));
1363 memcpy(&event.remote_addr, &ep->com.remote_addr,
1364 sizeof(ep->com.remote_addr));
1365 event.provider_data = ep;
1366 if (!ep->tried_with_mpa_v1) {
1367 /* this means MPA_v2 is used */
1368 event.ord = ep->ord;
1369 event.ird = ep->ird;
1370 event.private_data_len = ep->plen -
1371 sizeof(struct mpa_v2_conn_params);
1372 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1373 sizeof(struct mpa_v2_conn_params);
1375 /* this means MPA_v1 is used. Send max supported */
1376 event.ord = cur_max_read_depth(ep->com.dev);
1377 event.ird = cur_max_read_depth(ep->com.dev);
1378 event.private_data_len = ep->plen;
1379 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1381 c4iw_get_ep(&ep->com);
1382 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1385 c4iw_put_ep(&ep->com);
1386 set_bit(CONNREQ_UPCALL, &ep->com.history);
1387 c4iw_put_ep(&ep->parent_ep->com);
1391 static void established_upcall(struct c4iw_ep *ep)
1393 struct iw_cm_event event;
1395 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1396 memset(&event, 0, sizeof(event));
1397 event.event = IW_CM_EVENT_ESTABLISHED;
1398 event.ird = ep->ord;
1399 event.ord = ep->ird;
1400 if (ep->com.cm_id) {
1401 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1402 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1403 set_bit(ESTAB_UPCALL, &ep->com.history);
1407 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1409 struct sk_buff *skb;
1410 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1413 pr_debug("ep %p tid %u credits %u\n",
1414 ep, ep->hwtid, credits);
1415 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1417 pr_err("update_rx_credits - cannot alloc skb!\n");
1422 * If we couldn't specify the entire rcv window at connection setup
1423 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1424 * then add the overage in to the credits returned.
1426 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1427 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
1429 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1430 RX_DACK_MODE_V(dack_mode);
1432 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1435 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1439 #define RELAXED_IRD_NEGOTIATION 1
1442 * process_mpa_reply - process streaming mode MPA reply
1446 * 0 upon success indicating a connect request was delivered to the ULP
1447 * or the mpa request is incomplete but valid so far.
1449 * 1 if a failure requires the caller to close the connection.
1451 * 2 if a failure requires the caller to abort the connection.
1453 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1455 struct mpa_message *mpa;
1456 struct mpa_v2_conn_params *mpa_v2_params;
1458 u16 resp_ird, resp_ord;
1459 u8 rtr_mismatch = 0, insuff_ird = 0;
1460 struct c4iw_qp_attributes attrs;
1461 enum c4iw_qp_attr_mask mask;
1465 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1468 * If we get more than the supported amount of private data
1469 * then we must fail this connection.
1471 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1473 goto err_stop_timer;
1477 * copy the new data into our accumulation buffer.
1479 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1481 ep->mpa_pkt_len += skb->len;
1484 * if we don't even have the mpa message, then bail.
1486 if (ep->mpa_pkt_len < sizeof(*mpa))
1488 mpa = (struct mpa_message *) ep->mpa_pkt;
1490 /* Validate MPA header. */
1491 if (mpa->revision > mpa_rev) {
1492 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1493 __func__, mpa_rev, mpa->revision);
1495 goto err_stop_timer;
1497 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1499 goto err_stop_timer;
1502 plen = ntohs(mpa->private_data_size);
1505 * Fail if there's too much private data.
1507 if (plen > MPA_MAX_PRIVATE_DATA) {
1509 goto err_stop_timer;
1513 * If plen does not account for pkt size
1515 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1517 goto err_stop_timer;
1520 ep->plen = (u8) plen;
1523 * If we don't have all the pdata yet, then bail.
1524 * We'll continue process when more data arrives.
1526 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1529 if (mpa->flags & MPA_REJECT) {
1530 err = -ECONNREFUSED;
1531 goto err_stop_timer;
1535 * Stop mpa timer. If it expired, then
1536 * we ignore the MPA reply. process_timeout()
1537 * will abort the connection.
1539 if (stop_ep_timer(ep))
1543 * If we get here we have accumulated the entire mpa
1544 * start reply message including private data. And
1545 * the MPA header is valid.
1547 __state_set(&ep->com, FPDU_MODE);
1548 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1549 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1550 ep->mpa_attr.version = mpa->revision;
1551 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1553 if (mpa->revision == 2) {
1554 ep->mpa_attr.enhanced_rdma_conn =
1555 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1556 if (ep->mpa_attr.enhanced_rdma_conn) {
1557 mpa_v2_params = (struct mpa_v2_conn_params *)
1558 (ep->mpa_pkt + sizeof(*mpa));
1559 resp_ird = ntohs(mpa_v2_params->ird) &
1560 MPA_V2_IRD_ORD_MASK;
1561 resp_ord = ntohs(mpa_v2_params->ord) &
1562 MPA_V2_IRD_ORD_MASK;
1563 pr_debug("responder ird %u ord %u ep ird %u ord %u\n",
1564 resp_ird, resp_ord, ep->ird, ep->ord);
1567 * This is a double-check. Ideally, below checks are
1568 * not required since ird/ord stuff has been taken
1569 * care of in c4iw_accept_cr
1571 if (ep->ird < resp_ord) {
1572 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1573 ep->com.dev->rdev.lldi.max_ordird_qp)
1577 } else if (ep->ird > resp_ord) {
1580 if (ep->ord > resp_ird) {
1581 if (RELAXED_IRD_NEGOTIATION)
1592 if (ntohs(mpa_v2_params->ird) &
1593 MPA_V2_PEER2PEER_MODEL) {
1594 if (ntohs(mpa_v2_params->ord) &
1595 MPA_V2_RDMA_WRITE_RTR)
1596 ep->mpa_attr.p2p_type =
1597 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1598 else if (ntohs(mpa_v2_params->ord) &
1599 MPA_V2_RDMA_READ_RTR)
1600 ep->mpa_attr.p2p_type =
1601 FW_RI_INIT_P2PTYPE_READ_REQ;
1604 } else if (mpa->revision == 1)
1606 ep->mpa_attr.p2p_type = p2p_type;
1608 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
1609 ep->mpa_attr.crc_enabled,
1610 ep->mpa_attr.recv_marker_enabled,
1611 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1612 ep->mpa_attr.p2p_type, p2p_type);
1615 * If responder's RTR does not match with that of initiator, assign
1616 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1617 * generated when moving QP to RTS state.
1618 * A TERM message will be sent after QP has moved to RTS state
1620 if ((ep->mpa_attr.version == 2) && peer2peer &&
1621 (ep->mpa_attr.p2p_type != p2p_type)) {
1622 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1626 attrs.mpa_attr = ep->mpa_attr;
1627 attrs.max_ird = ep->ird;
1628 attrs.max_ord = ep->ord;
1629 attrs.llp_stream_handle = ep;
1630 attrs.next_state = C4IW_QP_STATE_RTS;
1632 mask = C4IW_QP_ATTR_NEXT_STATE |
1633 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1634 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1636 /* bind QP and TID with INIT_WR */
1637 err = c4iw_modify_qp(ep->com.qp->rhp,
1638 ep->com.qp, mask, &attrs, 1);
1643 * If responder's RTR requirement did not match with what initiator
1644 * supports, generate TERM message
1647 pr_err("%s: RTR mismatch, sending TERM\n", __func__);
1648 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1649 attrs.ecode = MPA_NOMATCH_RTR;
1650 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1651 attrs.send_term = 1;
1652 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1653 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1660 * Generate TERM if initiator IRD is not sufficient for responder
1661 * provided ORD. Currently, we do the same behaviour even when
1662 * responder provided IRD is also not sufficient as regards to
1666 pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
1667 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1668 attrs.ecode = MPA_INSUFF_IRD;
1669 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1670 attrs.send_term = 1;
1671 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1672 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1683 connect_reply_upcall(ep, err);
1688 * process_mpa_request - process streaming mode MPA request
1692 * 0 upon success indicating a connect request was delivered to the ULP
1693 * or the mpa request is incomplete but valid so far.
1695 * 1 if a failure requires the caller to close the connection.
1697 * 2 if a failure requires the caller to abort the connection.
1699 static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1701 struct mpa_message *mpa;
1702 struct mpa_v2_conn_params *mpa_v2_params;
1705 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1708 * If we get more than the supported amount of private data
1709 * then we must fail this connection.
1711 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1712 goto err_stop_timer;
1714 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1717 * Copy the new data into our accumulation buffer.
1719 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1721 ep->mpa_pkt_len += skb->len;
1724 * If we don't even have the mpa message, then bail.
1725 * We'll continue process when more data arrives.
1727 if (ep->mpa_pkt_len < sizeof(*mpa))
1730 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1731 mpa = (struct mpa_message *) ep->mpa_pkt;
1734 * Validate MPA Header.
1736 if (mpa->revision > mpa_rev) {
1737 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1738 __func__, mpa_rev, mpa->revision);
1739 goto err_stop_timer;
1742 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1743 goto err_stop_timer;
1745 plen = ntohs(mpa->private_data_size);
1748 * Fail if there's too much private data.
1750 if (plen > MPA_MAX_PRIVATE_DATA)
1751 goto err_stop_timer;
1754 * If plen does not account for pkt size
1756 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1757 goto err_stop_timer;
1758 ep->plen = (u8) plen;
1761 * If we don't have all the pdata yet, then bail.
1763 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1767 * If we get here we have accumulated the entire mpa
1768 * start reply message including private data.
1770 ep->mpa_attr.initiator = 0;
1771 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1772 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1773 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1774 ep->mpa_attr.version = mpa->revision;
1775 if (mpa->revision == 1)
1776 ep->tried_with_mpa_v1 = 1;
1777 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1779 if (mpa->revision == 2) {
1780 ep->mpa_attr.enhanced_rdma_conn =
1781 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1782 if (ep->mpa_attr.enhanced_rdma_conn) {
1783 mpa_v2_params = (struct mpa_v2_conn_params *)
1784 (ep->mpa_pkt + sizeof(*mpa));
1785 ep->ird = ntohs(mpa_v2_params->ird) &
1786 MPA_V2_IRD_ORD_MASK;
1787 ep->ird = min_t(u32, ep->ird,
1788 cur_max_read_depth(ep->com.dev));
1789 ep->ord = ntohs(mpa_v2_params->ord) &
1790 MPA_V2_IRD_ORD_MASK;
1791 ep->ord = min_t(u32, ep->ord,
1792 cur_max_read_depth(ep->com.dev));
1793 pr_debug("initiator ird %u ord %u\n",
1795 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1797 if (ntohs(mpa_v2_params->ord) &
1798 MPA_V2_RDMA_WRITE_RTR)
1799 ep->mpa_attr.p2p_type =
1800 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1801 else if (ntohs(mpa_v2_params->ord) &
1802 MPA_V2_RDMA_READ_RTR)
1803 ep->mpa_attr.p2p_type =
1804 FW_RI_INIT_P2PTYPE_READ_REQ;
1807 } else if (mpa->revision == 1)
1809 ep->mpa_attr.p2p_type = p2p_type;
1811 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
1812 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1813 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1814 ep->mpa_attr.p2p_type);
1816 __state_set(&ep->com, MPA_REQ_RCVD);
1819 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1820 if (ep->parent_ep->com.state != DEAD) {
1821 if (connect_request_upcall(ep))
1822 goto err_unlock_parent;
1824 goto err_unlock_parent;
1826 mutex_unlock(&ep->parent_ep->com.mutex);
1830 mutex_unlock(&ep->parent_ep->com.mutex);
1833 (void)stop_ep_timer(ep);
1838 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1841 struct cpl_rx_data *hdr = cplhdr(skb);
1842 unsigned int dlen = ntohs(hdr->len);
1843 unsigned int tid = GET_TID(hdr);
1844 __u8 status = hdr->status;
1847 ep = get_ep_from_tid(dev, tid);
1850 pr_debug("ep %p tid %u dlen %u\n", ep, ep->hwtid, dlen);
1851 skb_pull(skb, sizeof(*hdr));
1852 skb_trim(skb, dlen);
1853 mutex_lock(&ep->com.mutex);
1855 switch (ep->com.state) {
1857 update_rx_credits(ep, dlen);
1858 ep->rcv_seq += dlen;
1859 disconnect = process_mpa_reply(ep, skb);
1862 update_rx_credits(ep, dlen);
1863 ep->rcv_seq += dlen;
1864 disconnect = process_mpa_request(ep, skb);
1867 struct c4iw_qp_attributes attrs;
1869 update_rx_credits(ep, dlen);
1871 pr_err("%s Unexpected streaming data." \
1872 " qpid %u ep %p state %d tid %u status %d\n",
1873 __func__, ep->com.qp->wq.sq.qid, ep,
1874 ep->com.state, ep->hwtid, status);
1875 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1876 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1877 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1884 mutex_unlock(&ep->com.mutex);
1886 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
1887 c4iw_put_ep(&ep->com);
1891 static void complete_cached_srq_buffers(struct c4iw_ep *ep, u32 srqidx)
1893 enum chip_type adapter_type;
1895 adapter_type = ep->com.dev->rdev.lldi.adapter_type;
1898 * If this TCB had a srq buffer cached, then we must complete
1899 * it. For user mode, that means saving the srqidx in the
1900 * user/kernel status page for this qp. For kernel mode, just
1901 * synthesize the CQE now.
1903 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T5 && srqidx) {
1904 if (ep->com.qp->ibqp.uobject)
1905 t4_set_wq_in_error(&ep->com.qp->wq, srqidx);
1907 c4iw_flush_srqidx(ep->com.qp, srqidx);
1911 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1915 struct cpl_abort_rpl_rss6 *rpl = cplhdr(skb);
1917 unsigned int tid = GET_TID(rpl);
1919 ep = get_ep_from_tid(dev, tid);
1921 pr_warn("Abort rpl to freed endpoint\n");
1925 if (ep->com.qp && ep->com.qp->srq) {
1926 srqidx = ABORT_RSS_SRQIDX_G(be32_to_cpu(rpl->srqidx_status));
1927 complete_cached_srq_buffers(ep, srqidx ? srqidx : ep->srqe_idx);
1930 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1931 mutex_lock(&ep->com.mutex);
1932 switch (ep->com.state) {
1934 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
1935 __state_set(&ep->com, DEAD);
1939 pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
1942 mutex_unlock(&ep->com.mutex);
1945 close_complete_upcall(ep, -ECONNRESET);
1946 release_ep_resources(ep);
1948 c4iw_put_ep(&ep->com);
1952 static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1954 struct sk_buff *skb;
1955 struct fw_ofld_connection_wr *req;
1956 unsigned int mtu_idx;
1958 struct sockaddr_in *sin;
1961 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1962 req = __skb_put_zero(skb, sizeof(*req));
1963 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
1964 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
1965 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1966 ep->com.dev->rdev.lldi.ports[0],
1968 sin = (struct sockaddr_in *)&ep->com.local_addr;
1969 req->le.lport = sin->sin_port;
1970 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1971 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1972 req->le.pport = sin->sin_port;
1973 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1974 req->tcb.t_state_to_astid =
1975 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1976 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
1977 req->tcb.cplrxdataack_cplpassacceptrpl =
1978 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
1979 req->tcb.tx_max = (__force __be32) jiffies;
1980 req->tcb.rcv_adv = htons(1);
1981 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1982 enable_tcp_timestamps,
1983 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
1984 wscale = cxgb_compute_wscale(rcv_win);
1987 * Specify the largest window that will fit in opt0. The
1988 * remainder will be specified in the rx_data_ack.
1990 win = ep->rcv_win >> 10;
1991 if (win > RCV_BUFSIZ_M)
1994 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1995 (nocong ? NO_CONG_F : 0) |
1998 WND_SCALE_V(wscale) |
1999 MSS_IDX_V(mtu_idx) |
2000 L2T_IDX_V(ep->l2t->idx) |
2001 TX_CHAN_V(ep->tx_chan) |
2002 SMAC_SEL_V(ep->smac_idx) |
2003 DSCP_V(ep->tos >> 2) |
2004 ULP_MODE_V(ULP_MODE_TCPDDP) |
2006 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
2007 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
2009 CCTRL_ECN_V(enable_ecn) |
2010 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
2011 if (enable_tcp_timestamps)
2012 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
2013 if (enable_tcp_sack)
2014 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
2015 if (wscale && enable_tcp_window_scaling)
2016 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
2017 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2018 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
2019 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2020 set_bit(ACT_OFLD_CONN, &ep->com.history);
2021 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2025 * Some of the error codes above implicitly indicate that there is no TID
2026 * allocated with the result of an ACT_OPEN. We use this predicate to make
2029 static inline int act_open_has_tid(int status)
2031 return (status != CPL_ERR_TCAM_PARITY &&
2032 status != CPL_ERR_TCAM_MISS &&
2033 status != CPL_ERR_TCAM_FULL &&
2034 status != CPL_ERR_CONN_EXIST_SYNRECV &&
2035 status != CPL_ERR_CONN_EXIST);
2038 static char *neg_adv_str(unsigned int status)
2041 case CPL_ERR_RTX_NEG_ADVICE:
2042 return "Retransmit timeout";
2043 case CPL_ERR_PERSIST_NEG_ADVICE:
2044 return "Persist timeout";
2045 case CPL_ERR_KEEPALV_NEG_ADVICE:
2046 return "Keepalive timeout";
2052 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2054 ep->snd_win = snd_win;
2055 ep->rcv_win = rcv_win;
2056 pr_debug("snd_win %d rcv_win %d\n",
2057 ep->snd_win, ep->rcv_win);
2060 #define ACT_OPEN_RETRY_COUNT 2
2062 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2063 struct dst_entry *dst, struct c4iw_dev *cdev,
2064 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
2066 struct neighbour *n;
2068 struct net_device *pdev;
2070 n = dst_neigh_lookup(dst, peer_ip);
2076 if (n->dev->flags & IFF_LOOPBACK) {
2078 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2079 else if (IS_ENABLED(CONFIG_IPV6))
2080 for_each_netdev(&init_net, pdev) {
2081 if (ipv6_chk_addr(&init_net,
2082 (struct in6_addr *)peer_ip,
2093 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2094 n, pdev, rt_tos2priority(tos));
2099 ep->mtu = pdev->mtu;
2100 ep->tx_chan = cxgb4_port_chan(pdev);
2101 ep->smac_idx = ((struct port_info *)netdev_priv(pdev))->smt_idx;
2102 step = cdev->rdev.lldi.ntxq /
2103 cdev->rdev.lldi.nchan;
2104 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2105 step = cdev->rdev.lldi.nrxq /
2106 cdev->rdev.lldi.nchan;
2107 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2108 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2109 cxgb4_port_idx(pdev) * step];
2110 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2113 pdev = get_real_dev(n->dev);
2114 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2115 n, pdev, rt_tos2priority(tos));
2118 ep->mtu = dst_mtu(dst);
2119 ep->tx_chan = cxgb4_port_chan(pdev);
2120 ep->smac_idx = ((struct port_info *)netdev_priv(pdev))->smt_idx;
2121 step = cdev->rdev.lldi.ntxq /
2122 cdev->rdev.lldi.nchan;
2123 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2124 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2125 step = cdev->rdev.lldi.nrxq /
2126 cdev->rdev.lldi.nchan;
2127 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2128 cxgb4_port_idx(pdev) * step];
2129 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2132 ep->retry_with_mpa_v1 = 0;
2133 ep->tried_with_mpa_v1 = 0;
2145 static int c4iw_reconnect(struct c4iw_ep *ep)
2149 struct sockaddr_in *laddr = (struct sockaddr_in *)
2150 &ep->com.cm_id->m_local_addr;
2151 struct sockaddr_in *raddr = (struct sockaddr_in *)
2152 &ep->com.cm_id->m_remote_addr;
2153 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2154 &ep->com.cm_id->m_local_addr;
2155 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2156 &ep->com.cm_id->m_remote_addr;
2160 pr_debug("qp %p cm_id %p\n", ep->com.qp, ep->com.cm_id);
2161 c4iw_init_wr_wait(ep->com.wr_waitp);
2163 /* When MPA revision is different on nodes, the node with MPA_rev=2
2164 * tries to reconnect with MPA_rev 1 for the same EP through
2165 * c4iw_reconnect(), where the same EP is assigned with new tid for
2166 * further connection establishment. As we are using the same EP pointer
2167 * for reconnect, few skbs are used during the previous c4iw_connect(),
2168 * which leaves the EP with inadequate skbs for further
2169 * c4iw_reconnect(), Further causing a crash due to an empty
2170 * skb_list() during peer_abort(). Allocate skbs which is already used.
2172 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2173 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2179 * Allocate an active TID to initiate a TCP connection.
2181 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2182 if (ep->atid == -1) {
2183 pr_err("%s - cannot alloc atid\n", __func__);
2187 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2190 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
2191 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2192 laddr->sin_addr.s_addr,
2193 raddr->sin_addr.s_addr,
2195 raddr->sin_port, ep->com.cm_id->tos);
2197 ra = (__u8 *)&raddr->sin_addr;
2199 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2201 laddr6->sin6_addr.s6_addr,
2202 raddr6->sin6_addr.s6_addr,
2206 raddr6->sin6_scope_id);
2208 ra = (__u8 *)&raddr6->sin6_addr;
2211 pr_err("%s - cannot find route\n", __func__);
2212 err = -EHOSTUNREACH;
2215 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2216 ep->com.dev->rdev.lldi.adapter_type,
2217 ep->com.cm_id->tos);
2219 pr_err("%s - cannot alloc l2e\n", __func__);
2223 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2224 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2227 state_set(&ep->com, CONNECTING);
2228 ep->tos = ep->com.cm_id->tos;
2230 /* send connect request to rnic */
2231 err = send_connect(ep);
2235 cxgb4_l2t_release(ep->l2t);
2237 dst_release(ep->dst);
2239 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2240 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2243 * remember to send notification to upper layer.
2244 * We are in here so the upper layer is not aware that this is
2245 * re-connect attempt and so, upper layer is still waiting for
2246 * response of 1st connect request.
2248 connect_reply_upcall(ep, -ECONNRESET);
2250 c4iw_put_ep(&ep->com);
2255 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2258 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2259 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2260 ntohl(rpl->atid_status)));
2261 struct tid_info *t = dev->rdev.lldi.tids;
2262 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
2263 struct sockaddr_in *la;
2264 struct sockaddr_in *ra;
2265 struct sockaddr_in6 *la6;
2266 struct sockaddr_in6 *ra6;
2269 ep = lookup_atid(t, atid);
2270 la = (struct sockaddr_in *)&ep->com.local_addr;
2271 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2272 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2273 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
2275 pr_debug("ep %p atid %u status %u errno %d\n", ep, atid,
2276 status, status2errno(status));
2278 if (cxgb_is_neg_adv(status)) {
2279 pr_debug("Connection problems for atid %u status %u (%s)\n",
2280 atid, status, neg_adv_str(status));
2281 ep->stats.connect_neg_adv++;
2282 mutex_lock(&dev->rdev.stats.lock);
2283 dev->rdev.stats.neg_adv++;
2284 mutex_unlock(&dev->rdev.stats.lock);
2288 set_bit(ACT_OPEN_RPL, &ep->com.history);
2291 * Log interesting failures.
2294 case CPL_ERR_CONN_RESET:
2295 case CPL_ERR_CONN_TIMEDOUT:
2297 case CPL_ERR_TCAM_FULL:
2298 mutex_lock(&dev->rdev.stats.lock);
2299 dev->rdev.stats.tcam_full++;
2300 mutex_unlock(&dev->rdev.stats.lock);
2301 if (ep->com.local_addr.ss_family == AF_INET &&
2302 dev->rdev.lldi.enable_fw_ofld_conn) {
2303 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2304 ntohl(rpl->atid_status))));
2310 case CPL_ERR_CONN_EXIST:
2311 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2312 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2313 if (ep->com.remote_addr.ss_family == AF_INET6) {
2314 struct sockaddr_in6 *sin6 =
2315 (struct sockaddr_in6 *)
2316 &ep->com.local_addr;
2318 ep->com.dev->rdev.lldi.ports[0],
2320 &sin6->sin6_addr.s6_addr, 1);
2322 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2324 cxgb4_free_atid(t, atid);
2325 dst_release(ep->dst);
2326 cxgb4_l2t_release(ep->l2t);
2332 if (ep->com.local_addr.ss_family == AF_INET) {
2333 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2334 atid, status, status2errno(status),
2335 &la->sin_addr.s_addr, ntohs(la->sin_port),
2336 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2338 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2339 atid, status, status2errno(status),
2340 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2341 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2347 connect_reply_upcall(ep, status2errno(status));
2348 state_set(&ep->com, DEAD);
2350 if (ep->com.remote_addr.ss_family == AF_INET6) {
2351 struct sockaddr_in6 *sin6 =
2352 (struct sockaddr_in6 *)&ep->com.local_addr;
2353 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2354 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2356 if (status && act_open_has_tid(status))
2357 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl),
2358 ep->com.local_addr.ss_family);
2360 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2361 cxgb4_free_atid(t, atid);
2362 dst_release(ep->dst);
2363 cxgb4_l2t_release(ep->l2t);
2364 c4iw_put_ep(&ep->com);
2369 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2371 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2372 unsigned int stid = GET_TID(rpl);
2373 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2376 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2379 pr_debug("ep %p status %d error %d\n", ep,
2380 rpl->status, status2errno(rpl->status));
2381 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2382 c4iw_put_ep(&ep->com);
2387 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2389 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2390 unsigned int stid = GET_TID(rpl);
2391 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2394 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2397 pr_debug("ep %p\n", ep);
2398 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2399 c4iw_put_ep(&ep->com);
2404 static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2405 struct cpl_pass_accept_req *req)
2407 struct cpl_pass_accept_rpl *rpl;
2408 unsigned int mtu_idx;
2412 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2414 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
2416 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2420 if (!is_t4(adapter_type)) {
2421 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2423 INIT_TP_WR(rpl5, ep->hwtid);
2425 skb_trim(skb, sizeof(*rpl));
2426 INIT_TP_WR(rpl, ep->hwtid);
2428 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2431 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2432 enable_tcp_timestamps && req->tcpopt.tstamp,
2433 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
2434 wscale = cxgb_compute_wscale(rcv_win);
2437 * Specify the largest window that will fit in opt0. The
2438 * remainder will be specified in the rx_data_ack.
2440 win = ep->rcv_win >> 10;
2441 if (win > RCV_BUFSIZ_M)
2443 opt0 = (nocong ? NO_CONG_F : 0) |
2446 WND_SCALE_V(wscale) |
2447 MSS_IDX_V(mtu_idx) |
2448 L2T_IDX_V(ep->l2t->idx) |
2449 TX_CHAN_V(ep->tx_chan) |
2450 SMAC_SEL_V(ep->smac_idx) |
2451 DSCP_V(ep->tos >> 2) |
2452 ULP_MODE_V(ULP_MODE_TCPDDP) |
2454 opt2 = RX_CHANNEL_V(0) |
2455 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
2457 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2458 opt2 |= TSTAMPS_EN_F;
2459 if (enable_tcp_sack && req->tcpopt.sack)
2461 if (wscale && enable_tcp_window_scaling)
2462 opt2 |= WND_SCALE_EN_F;
2464 const struct tcphdr *tcph;
2465 u32 hlen = ntohl(req->hdr_len);
2467 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2468 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2471 tcph = (const void *)(req + 1) +
2472 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
2473 if (tcph->ece && tcph->cwr)
2474 opt2 |= CCTRL_ECN_V(1);
2476 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
2477 u32 isn = (prandom_u32() & ~7UL) - 1;
2478 opt2 |= T5_OPT_2_VALID_F;
2479 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2482 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2485 rpl5->iss = cpu_to_be32(isn);
2486 pr_debug("iss %u\n", be32_to_cpu(rpl5->iss));
2489 rpl->opt0 = cpu_to_be64(opt0);
2490 rpl->opt2 = cpu_to_be32(opt2);
2491 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2492 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
2494 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2497 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2499 pr_debug("c4iw_dev %p tid %u\n", dev, hwtid);
2500 skb_trim(skb, sizeof(struct cpl_tid_release));
2501 release_tid(&dev->rdev, hwtid, skb);
2505 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2507 struct c4iw_ep *child_ep = NULL, *parent_ep;
2508 struct cpl_pass_accept_req *req = cplhdr(skb);
2509 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
2510 struct tid_info *t = dev->rdev.lldi.tids;
2511 unsigned int hwtid = GET_TID(req);
2512 struct dst_entry *dst;
2513 __u8 local_ip[16], peer_ip[16];
2514 __be16 local_port, peer_port;
2515 struct sockaddr_in6 *sin6;
2517 u16 peer_mss = ntohs(req->tcpopt.mss);
2519 unsigned short hdrs;
2522 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
2524 pr_err("%s connect request on invalid stid %d\n",
2529 if (state_read(&parent_ep->com) != LISTEN) {
2530 pr_err("%s - listening ep not in LISTEN\n", __func__);
2534 if (parent_ep->com.cm_id->tos_set)
2535 tos = parent_ep->com.cm_id->tos;
2537 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
2539 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2540 &iptype, local_ip, peer_ip, &local_port, &peer_port);
2542 /* Find output route */
2544 pr_debug("parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2546 local_ip, peer_ip, ntohs(local_port),
2547 ntohs(peer_port), peer_mss);
2548 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2549 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2550 local_port, peer_port, tos);
2552 pr_debug("parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2554 local_ip, peer_ip, ntohs(local_port),
2555 ntohs(peer_port), peer_mss);
2556 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2557 local_ip, peer_ip, local_port, peer_port,
2559 ((struct sockaddr_in6 *)
2560 &parent_ep->com.local_addr)->sin6_scope_id);
2563 pr_err("%s - failed to find dst entry!\n", __func__);
2567 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2569 pr_err("%s - failed to allocate ep entry!\n", __func__);
2574 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2575 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
2577 pr_err("%s - failed to allocate l2t entry!\n", __func__);
2583 hdrs = ((iptype == 4) ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)) +
2584 sizeof(struct tcphdr) +
2585 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2586 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2587 child_ep->mtu = peer_mss + hdrs;
2589 skb_queue_head_init(&child_ep->com.ep_skb_list);
2590 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2593 state_set(&child_ep->com, CONNECTING);
2594 child_ep->com.dev = dev;
2595 child_ep->com.cm_id = NULL;
2598 struct sockaddr_in *sin = (struct sockaddr_in *)
2599 &child_ep->com.local_addr;
2601 sin->sin_family = AF_INET;
2602 sin->sin_port = local_port;
2603 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2605 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2606 sin->sin_family = AF_INET;
2607 sin->sin_port = ((struct sockaddr_in *)
2608 &parent_ep->com.local_addr)->sin_port;
2609 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2611 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2612 sin->sin_family = AF_INET;
2613 sin->sin_port = peer_port;
2614 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2616 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2617 sin6->sin6_family = PF_INET6;
2618 sin6->sin6_port = local_port;
2619 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2621 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2622 sin6->sin6_family = PF_INET6;
2623 sin6->sin6_port = ((struct sockaddr_in6 *)
2624 &parent_ep->com.local_addr)->sin6_port;
2625 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2627 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2628 sin6->sin6_family = PF_INET6;
2629 sin6->sin6_port = peer_port;
2630 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2633 c4iw_get_ep(&parent_ep->com);
2634 child_ep->parent_ep = parent_ep;
2635 child_ep->tos = tos;
2636 child_ep->dst = dst;
2637 child_ep->hwtid = hwtid;
2639 pr_debug("tx_chan %u smac_idx %u rss_qid %u\n",
2640 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2642 timer_setup(&child_ep->timer, ep_timeout, 0);
2643 cxgb4_insert_tid(t, child_ep, hwtid,
2644 child_ep->com.local_addr.ss_family);
2645 insert_ep_tid(child_ep);
2646 if (accept_cr(child_ep, skb, req)) {
2647 c4iw_put_ep(&parent_ep->com);
2648 release_ep_resources(child_ep);
2650 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2653 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2654 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2655 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2659 c4iw_put_ep(&child_ep->com);
2661 reject_cr(dev, hwtid, skb);
2664 c4iw_put_ep(&parent_ep->com);
2668 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2671 struct cpl_pass_establish *req = cplhdr(skb);
2672 unsigned int tid = GET_TID(req);
2674 u16 tcp_opt = ntohs(req->tcp_opt);
2676 ep = get_ep_from_tid(dev, tid);
2677 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2678 ep->snd_seq = be32_to_cpu(req->snd_isn);
2679 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2680 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
2682 pr_debug("ep %p hwtid %u tcp_opt 0x%02x\n", ep, tid, tcp_opt);
2684 set_emss(ep, tcp_opt);
2686 dst_confirm(ep->dst);
2687 mutex_lock(&ep->com.mutex);
2688 ep->com.state = MPA_REQ_WAIT;
2690 set_bit(PASS_ESTAB, &ep->com.history);
2691 ret = send_flowc(ep);
2692 mutex_unlock(&ep->com.mutex);
2694 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
2695 c4iw_put_ep(&ep->com);
2700 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2702 struct cpl_peer_close *hdr = cplhdr(skb);
2704 struct c4iw_qp_attributes attrs;
2707 unsigned int tid = GET_TID(hdr);
2710 ep = get_ep_from_tid(dev, tid);
2714 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2715 dst_confirm(ep->dst);
2717 set_bit(PEER_CLOSE, &ep->com.history);
2718 mutex_lock(&ep->com.mutex);
2719 switch (ep->com.state) {
2721 __state_set(&ep->com, CLOSING);
2724 __state_set(&ep->com, CLOSING);
2725 connect_reply_upcall(ep, -ECONNRESET);
2730 * We're gonna mark this puppy DEAD, but keep
2731 * the reference on it until the ULP accepts or
2732 * rejects the CR. Also wake up anyone waiting
2733 * in rdma connection migration (see c4iw_accept_cr()).
2735 __state_set(&ep->com, CLOSING);
2736 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2737 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2740 __state_set(&ep->com, CLOSING);
2741 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2742 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2746 __state_set(&ep->com, CLOSING);
2747 attrs.next_state = C4IW_QP_STATE_CLOSING;
2748 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2749 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2750 if (ret != -ECONNRESET) {
2751 peer_close_upcall(ep);
2759 __state_set(&ep->com, MORIBUND);
2763 (void)stop_ep_timer(ep);
2764 if (ep->com.cm_id && ep->com.qp) {
2765 attrs.next_state = C4IW_QP_STATE_IDLE;
2766 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2767 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2769 close_complete_upcall(ep, 0);
2770 __state_set(&ep->com, DEAD);
2778 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2780 mutex_unlock(&ep->com.mutex);
2782 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2784 release_ep_resources(ep);
2785 c4iw_put_ep(&ep->com);
2789 static void finish_peer_abort(struct c4iw_dev *dev, struct c4iw_ep *ep)
2791 complete_cached_srq_buffers(ep, ep->srqe_idx);
2792 if (ep->com.cm_id && ep->com.qp) {
2793 struct c4iw_qp_attributes attrs;
2795 attrs.next_state = C4IW_QP_STATE_ERROR;
2796 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2797 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2799 peer_abort_upcall(ep);
2800 release_ep_resources(ep);
2801 c4iw_put_ep(&ep->com);
2804 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2806 struct cpl_abort_req_rss6 *req = cplhdr(skb);
2808 struct sk_buff *rpl_skb;
2809 struct c4iw_qp_attributes attrs;
2812 unsigned int tid = GET_TID(req);
2816 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
2818 ep = get_ep_from_tid(dev, tid);
2822 status = ABORT_RSS_STATUS_G(be32_to_cpu(req->srqidx_status));
2824 if (cxgb_is_neg_adv(status)) {
2825 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
2826 ep->hwtid, status, neg_adv_str(status));
2827 ep->stats.abort_neg_adv++;
2828 mutex_lock(&dev->rdev.stats.lock);
2829 dev->rdev.stats.neg_adv++;
2830 mutex_unlock(&dev->rdev.stats.lock);
2834 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid,
2836 set_bit(PEER_ABORT, &ep->com.history);
2839 * Wake up any threads in rdma_init() or rdma_fini().
2840 * However, this is not needed if com state is just
2843 if (ep->com.state != MPA_REQ_SENT)
2844 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2846 mutex_lock(&ep->com.mutex);
2847 switch (ep->com.state) {
2849 c4iw_put_ep(&ep->parent_ep->com);
2852 (void)stop_ep_timer(ep);
2855 (void)stop_ep_timer(ep);
2856 if (status != CPL_ERR_CONN_RESET || mpa_rev == 1 ||
2857 (mpa_rev == 2 && ep->tried_with_mpa_v1))
2858 connect_reply_upcall(ep, -ECONNRESET);
2861 * we just don't send notification upwards because we
2862 * want to retry with mpa_v1 without upper layers even
2865 * do some housekeeping so as to re-initiate the
2868 pr_info("%s: mpa_rev=%d. Retrying with mpav1\n",
2870 ep->retry_with_mpa_v1 = 1;
2882 if (ep->com.qp && ep->com.qp->srq) {
2883 srqidx = ABORT_RSS_SRQIDX_G(
2884 be32_to_cpu(req->srqidx_status));
2886 complete_cached_srq_buffers(ep,
2887 req->srqidx_status);
2889 /* Hold ep ref until finish_peer_abort() */
2890 c4iw_get_ep(&ep->com);
2891 __state_set(&ep->com, ABORTING);
2892 set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags);
2899 if (ep->com.cm_id && ep->com.qp) {
2900 attrs.next_state = C4IW_QP_STATE_ERROR;
2901 ret = c4iw_modify_qp(ep->com.qp->rhp,
2902 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2905 pr_err("%s - qp <- error failed!\n", __func__);
2907 peer_abort_upcall(ep);
2912 pr_warn("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2913 mutex_unlock(&ep->com.mutex);
2916 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2919 dst_confirm(ep->dst);
2920 if (ep->com.state != ABORTING) {
2921 __state_set(&ep->com, DEAD);
2922 /* we don't release if we want to retry with mpa_v1 */
2923 if (!ep->retry_with_mpa_v1)
2926 mutex_unlock(&ep->com.mutex);
2928 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2929 if (WARN_ON(!rpl_skb)) {
2934 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2936 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2939 release_ep_resources(ep);
2940 else if (ep->retry_with_mpa_v1) {
2941 if (ep->com.remote_addr.ss_family == AF_INET6) {
2942 struct sockaddr_in6 *sin6 =
2943 (struct sockaddr_in6 *)
2944 &ep->com.local_addr;
2946 ep->com.dev->rdev.lldi.ports[0],
2947 (const u32 *)&sin6->sin6_addr.s6_addr,
2950 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2951 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
2952 ep->com.local_addr.ss_family);
2953 dst_release(ep->dst);
2954 cxgb4_l2t_release(ep->l2t);
2959 c4iw_put_ep(&ep->com);
2960 /* Dereferencing ep, referenced in peer_abort_intr() */
2961 c4iw_put_ep(&ep->com);
2965 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2968 struct c4iw_qp_attributes attrs;
2969 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2971 unsigned int tid = GET_TID(rpl);
2973 ep = get_ep_from_tid(dev, tid);
2977 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2979 /* The cm_id may be null if we failed to connect */
2980 mutex_lock(&ep->com.mutex);
2981 set_bit(CLOSE_CON_RPL, &ep->com.history);
2982 switch (ep->com.state) {
2984 __state_set(&ep->com, MORIBUND);
2987 (void)stop_ep_timer(ep);
2988 if ((ep->com.cm_id) && (ep->com.qp)) {
2989 attrs.next_state = C4IW_QP_STATE_IDLE;
2990 c4iw_modify_qp(ep->com.qp->rhp,
2992 C4IW_QP_ATTR_NEXT_STATE,
2995 close_complete_upcall(ep, 0);
2996 __state_set(&ep->com, DEAD);
3003 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
3006 mutex_unlock(&ep->com.mutex);
3008 release_ep_resources(ep);
3009 c4iw_put_ep(&ep->com);
3013 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
3015 struct cpl_rdma_terminate *rpl = cplhdr(skb);
3016 unsigned int tid = GET_TID(rpl);
3018 struct c4iw_qp_attributes attrs;
3020 ep = get_ep_from_tid(dev, tid);
3024 pr_warn("TERM received tid %u qpid %u\n", tid,
3025 ep->com.qp->wq.sq.qid);
3026 attrs.next_state = C4IW_QP_STATE_TERMINATE;
3027 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
3028 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
3031 c4iw_put_ep(&ep->com);
3033 pr_warn("TERM received tid %u no ep/qp\n", tid);
3039 * Upcall from the adapter indicating data has been transmitted.
3040 * For us its just the single MPA request or reply. We can now free
3041 * the skb holding the mpa message.
3043 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
3046 struct cpl_fw4_ack *hdr = cplhdr(skb);
3047 u8 credits = hdr->credits;
3048 unsigned int tid = GET_TID(hdr);
3051 ep = get_ep_from_tid(dev, tid);
3054 pr_debug("ep %p tid %u credits %u\n",
3055 ep, ep->hwtid, credits);
3057 pr_debug("0 credit ack ep %p tid %u state %u\n",
3058 ep, ep->hwtid, state_read(&ep->com));
3062 dst_confirm(ep->dst);
3064 pr_debug("last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
3065 ep, ep->hwtid, state_read(&ep->com),
3066 ep->mpa_attr.initiator ? 1 : 0);
3067 mutex_lock(&ep->com.mutex);
3068 kfree_skb(ep->mpa_skb);
3070 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3072 mutex_unlock(&ep->com.mutex);
3075 c4iw_put_ep(&ep->com);
3079 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3082 struct c4iw_ep *ep = to_ep(cm_id);
3084 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3086 mutex_lock(&ep->com.mutex);
3087 if (ep->com.state != MPA_REQ_RCVD) {
3088 mutex_unlock(&ep->com.mutex);
3089 c4iw_put_ep(&ep->com);
3092 set_bit(ULP_REJECT, &ep->com.history);
3096 abort = send_mpa_reject(ep, pdata, pdata_len);
3097 mutex_unlock(&ep->com.mutex);
3100 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
3101 c4iw_put_ep(&ep->com);
3105 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3108 struct c4iw_qp_attributes attrs;
3109 enum c4iw_qp_attr_mask mask;
3110 struct c4iw_ep *ep = to_ep(cm_id);
3111 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3112 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
3115 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3117 mutex_lock(&ep->com.mutex);
3118 if (ep->com.state != MPA_REQ_RCVD) {
3128 set_bit(ULP_ACCEPT, &ep->com.history);
3129 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3130 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
3135 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3136 if (conn_param->ord > ep->ird) {
3137 if (RELAXED_IRD_NEGOTIATION) {
3138 conn_param->ord = ep->ird;
3140 ep->ird = conn_param->ird;
3141 ep->ord = conn_param->ord;
3142 send_mpa_reject(ep, conn_param->private_data,
3143 conn_param->private_data_len);
3148 if (conn_param->ird < ep->ord) {
3149 if (RELAXED_IRD_NEGOTIATION &&
3150 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3151 conn_param->ird = ep->ord;
3158 ep->ird = conn_param->ird;
3159 ep->ord = conn_param->ord;
3161 if (ep->mpa_attr.version == 1) {
3162 if (peer2peer && ep->ird == 0)
3166 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
3167 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
3171 pr_debug("ird %d ord %d\n", ep->ird, ep->ord);
3173 ep->com.cm_id = cm_id;
3174 ref_cm_id(&ep->com);
3178 /* bind QP to EP and move to RTS */
3179 attrs.mpa_attr = ep->mpa_attr;
3180 attrs.max_ird = ep->ird;
3181 attrs.max_ord = ep->ord;
3182 attrs.llp_stream_handle = ep;
3183 attrs.next_state = C4IW_QP_STATE_RTS;
3185 /* bind QP and TID with INIT_WR */
3186 mask = C4IW_QP_ATTR_NEXT_STATE |
3187 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3188 C4IW_QP_ATTR_MPA_ATTR |
3189 C4IW_QP_ATTR_MAX_IRD |
3190 C4IW_QP_ATTR_MAX_ORD;
3192 err = c4iw_modify_qp(ep->com.qp->rhp,
3193 ep->com.qp, mask, &attrs, 1);
3195 goto err_deref_cm_id;
3197 set_bit(STOP_MPA_TIMER, &ep->com.flags);
3198 err = send_mpa_reply(ep, conn_param->private_data,
3199 conn_param->private_data_len);
3201 goto err_deref_cm_id;
3203 __state_set(&ep->com, FPDU_MODE);
3204 established_upcall(ep);
3205 mutex_unlock(&ep->com.mutex);
3206 c4iw_put_ep(&ep->com);
3209 deref_cm_id(&ep->com);
3213 mutex_unlock(&ep->com.mutex);
3215 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
3216 c4iw_put_ep(&ep->com);
3220 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3222 struct in_device *ind;
3224 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3225 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
3227 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3229 return -EADDRNOTAVAIL;
3230 for_primary_ifa(ind) {
3231 laddr->sin_addr.s_addr = ifa->ifa_address;
3232 raddr->sin_addr.s_addr = ifa->ifa_address;
3238 return found ? 0 : -EADDRNOTAVAIL;
3241 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3242 unsigned char banned_flags)
3244 struct inet6_dev *idev;
3245 int err = -EADDRNOTAVAIL;
3248 idev = __in6_dev_get(dev);
3250 struct inet6_ifaddr *ifp;
3252 read_lock_bh(&idev->lock);
3253 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3254 if (ifp->scope == IFA_LINK &&
3255 !(ifp->flags & banned_flags)) {
3256 memcpy(addr, &ifp->addr, 16);
3261 read_unlock_bh(&idev->lock);
3267 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3269 struct in6_addr uninitialized_var(addr);
3270 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3271 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
3273 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
3274 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3275 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3278 return -EADDRNOTAVAIL;
3281 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3283 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3286 struct sockaddr_in *laddr;
3287 struct sockaddr_in *raddr;
3288 struct sockaddr_in6 *laddr6;
3289 struct sockaddr_in6 *raddr6;
3293 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3294 (conn_param->ird > cur_max_read_depth(dev))) {
3298 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3300 pr_err("%s - cannot alloc ep\n", __func__);
3305 skb_queue_head_init(&ep->com.ep_skb_list);
3306 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3311 timer_setup(&ep->timer, ep_timeout, 0);
3312 ep->plen = conn_param->private_data_len;
3314 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3315 conn_param->private_data, ep->plen);
3316 ep->ird = conn_param->ird;
3317 ep->ord = conn_param->ord;
3319 if (peer2peer && ep->ord == 0)
3322 ep->com.cm_id = cm_id;
3323 ref_cm_id(&ep->com);
3324 cm_id->provider_data = ep;
3326 ep->com.qp = get_qhp(dev, conn_param->qpn);
3328 pr_warn("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3333 pr_debug("qpn 0x%x qp %p cm_id %p\n", conn_param->qpn,
3337 * Allocate an active TID to initiate a TCP connection.
3339 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3340 if (ep->atid == -1) {
3341 pr_err("%s - cannot alloc atid\n", __func__);
3345 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
3347 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3348 sizeof(ep->com.local_addr));
3349 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
3350 sizeof(ep->com.remote_addr));
3352 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3353 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3354 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3355 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
3357 if (cm_id->m_remote_addr.ss_family == AF_INET) {
3359 ra = (__u8 *)&raddr->sin_addr;
3362 * Handle loopback requests to INADDR_ANY.
3364 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
3365 err = pick_local_ipaddrs(dev, cm_id);
3371 pr_debug("saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3372 &laddr->sin_addr, ntohs(laddr->sin_port),
3373 ra, ntohs(raddr->sin_port));
3374 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3375 laddr->sin_addr.s_addr,
3376 raddr->sin_addr.s_addr,
3378 raddr->sin_port, cm_id->tos);
3381 ra = (__u8 *)&raddr6->sin6_addr;
3384 * Handle loopback requests to INADDR_ANY.
3386 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3387 err = pick_local_ip6addrs(dev, cm_id);
3393 pr_debug("saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3394 laddr6->sin6_addr.s6_addr,
3395 ntohs(laddr6->sin6_port),
3396 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3397 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3398 laddr6->sin6_addr.s6_addr,
3399 raddr6->sin6_addr.s6_addr,
3401 raddr6->sin6_port, cm_id->tos,
3402 raddr6->sin6_scope_id);
3405 pr_err("%s - cannot find route\n", __func__);
3406 err = -EHOSTUNREACH;
3410 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3411 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
3413 pr_err("%s - cannot alloc l2e\n", __func__);
3417 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3418 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3421 state_set(&ep->com, CONNECTING);
3422 ep->tos = cm_id->tos;
3424 /* send connect request to rnic */
3425 err = send_connect(ep);
3429 cxgb4_l2t_release(ep->l2t);
3431 dst_release(ep->dst);
3433 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3434 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3436 skb_queue_purge(&ep->com.ep_skb_list);
3437 deref_cm_id(&ep->com);
3439 c4iw_put_ep(&ep->com);
3444 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3447 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3448 &ep->com.local_addr;
3450 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3451 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3452 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3456 c4iw_init_wr_wait(ep->com.wr_waitp);
3457 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3458 ep->stid, &sin6->sin6_addr,
3460 ep->com.dev->rdev.lldi.rxq_ids[0]);
3462 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3466 err = net_xmit_errno(err);
3468 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3469 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3470 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3472 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3477 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3480 struct sockaddr_in *sin = (struct sockaddr_in *)
3481 &ep->com.local_addr;
3483 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3485 err = cxgb4_create_server_filter(
3486 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3487 sin->sin_addr.s_addr, sin->sin_port, 0,
3488 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3489 if (err == -EBUSY) {
3490 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3494 set_current_state(TASK_UNINTERRUPTIBLE);
3495 schedule_timeout(usecs_to_jiffies(100));
3497 } while (err == -EBUSY);
3499 c4iw_init_wr_wait(ep->com.wr_waitp);
3500 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3501 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3502 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3504 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3508 err = net_xmit_errno(err);
3511 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3513 &sin->sin_addr, ntohs(sin->sin_port));
3517 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3520 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3521 struct c4iw_listen_ep *ep;
3525 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3527 pr_err("%s - cannot alloc ep\n", __func__);
3531 skb_queue_head_init(&ep->com.ep_skb_list);
3532 pr_debug("ep %p\n", ep);
3533 ep->com.cm_id = cm_id;
3534 ref_cm_id(&ep->com);
3536 ep->backlog = backlog;
3537 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3538 sizeof(ep->com.local_addr));
3541 * Allocate a server TID.
3543 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3544 ep->com.local_addr.ss_family == AF_INET)
3545 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3546 cm_id->m_local_addr.ss_family, ep);
3548 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3549 cm_id->m_local_addr.ss_family, ep);
3551 if (ep->stid == -1) {
3552 pr_err("%s - cannot alloc stid\n", __func__);
3556 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3558 state_set(&ep->com, LISTEN);
3559 if (ep->com.local_addr.ss_family == AF_INET)
3560 err = create_server4(dev, ep);
3562 err = create_server6(dev, ep);
3564 cm_id->provider_data = ep;
3567 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3568 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3569 ep->com.local_addr.ss_family);
3571 deref_cm_id(&ep->com);
3572 c4iw_put_ep(&ep->com);
3578 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3581 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3583 pr_debug("ep %p\n", ep);
3586 state_set(&ep->com, DEAD);
3587 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3588 ep->com.local_addr.ss_family == AF_INET) {
3589 err = cxgb4_remove_server_filter(
3590 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3591 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3593 struct sockaddr_in6 *sin6;
3594 c4iw_init_wr_wait(ep->com.wr_waitp);
3595 err = cxgb4_remove_server(
3596 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3597 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3600 err = c4iw_wait_for_reply(&ep->com.dev->rdev, ep->com.wr_waitp,
3602 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3603 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3604 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3606 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3607 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3608 ep->com.local_addr.ss_family);
3610 deref_cm_id(&ep->com);
3611 c4iw_put_ep(&ep->com);
3615 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3620 struct c4iw_rdev *rdev;
3622 mutex_lock(&ep->com.mutex);
3624 pr_debug("ep %p state %s, abrupt %d\n", ep,
3625 states[ep->com.state], abrupt);
3628 * Ref the ep here in case we have fatal errors causing the
3629 * ep to be released and freed.
3631 c4iw_get_ep(&ep->com);
3633 rdev = &ep->com.dev->rdev;
3634 if (c4iw_fatal_error(rdev)) {
3636 close_complete_upcall(ep, -EIO);
3637 ep->com.state = DEAD;
3639 switch (ep->com.state) {
3648 ep->com.state = ABORTING;
3650 ep->com.state = CLOSING;
3653 * if we close before we see the fw4_ack() then we fix
3654 * up the timer state since we're reusing it.
3657 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3658 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3663 set_bit(CLOSE_SENT, &ep->com.flags);
3666 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3669 (void)stop_ep_timer(ep);
3670 ep->com.state = ABORTING;
3672 ep->com.state = MORIBUND;
3678 pr_debug("ignoring disconnect ep %p state %u\n",
3682 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
3688 set_bit(EP_DISC_ABORT, &ep->com.history);
3689 ret = send_abort(ep);
3691 set_bit(EP_DISC_CLOSE, &ep->com.history);
3692 ret = send_halfclose(ep);
3695 set_bit(EP_DISC_FAIL, &ep->com.history);
3698 close_complete_upcall(ep, -EIO);
3701 struct c4iw_qp_attributes attrs;
3703 attrs.next_state = C4IW_QP_STATE_ERROR;
3704 ret = c4iw_modify_qp(ep->com.qp->rhp,
3706 C4IW_QP_ATTR_NEXT_STATE,
3709 pr_err("%s - qp <- error failed!\n",
3715 mutex_unlock(&ep->com.mutex);
3716 c4iw_put_ep(&ep->com);
3718 release_ep_resources(ep);
3722 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3723 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3726 int atid = be32_to_cpu(req->tid);
3728 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3729 (__force u32) req->tid);
3733 switch (req->retval) {
3735 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3736 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3737 send_fw_act_open_req(ep, atid);
3742 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3743 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3744 send_fw_act_open_req(ep, atid);
3749 pr_info("%s unexpected ofld conn wr retval %d\n",
3750 __func__, req->retval);
3753 pr_err("active ofld_connect_wr failure %d atid %d\n",
3755 mutex_lock(&dev->rdev.stats.lock);
3756 dev->rdev.stats.act_ofld_conn_fails++;
3757 mutex_unlock(&dev->rdev.stats.lock);
3758 connect_reply_upcall(ep, status2errno(req->retval));
3759 state_set(&ep->com, DEAD);
3760 if (ep->com.remote_addr.ss_family == AF_INET6) {
3761 struct sockaddr_in6 *sin6 =
3762 (struct sockaddr_in6 *)&ep->com.local_addr;
3763 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3764 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3766 remove_handle(dev, &dev->atid_idr, atid);
3767 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3768 dst_release(ep->dst);
3769 cxgb4_l2t_release(ep->l2t);
3770 c4iw_put_ep(&ep->com);
3773 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3774 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3776 struct sk_buff *rpl_skb;
3777 struct cpl_pass_accept_req *cpl;
3780 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3782 pr_err("%s passive open failure %d\n", __func__, req->retval);
3783 mutex_lock(&dev->rdev.stats.lock);
3784 dev->rdev.stats.pas_ofld_conn_fails++;
3785 mutex_unlock(&dev->rdev.stats.lock);
3788 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3789 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3790 (__force u32) htonl(
3791 (__force u32) req->tid)));
3792 ret = pass_accept_req(dev, rpl_skb);
3799 static inline u64 t4_tcb_get_field64(__be64 *tcb, u16 word)
3801 u64 tlo = be64_to_cpu(tcb[((31 - word) / 2)]);
3802 u64 thi = be64_to_cpu(tcb[((31 - word) / 2) - 1]);
3806 t = (thi << shift) | (tlo >> shift);
3811 static inline u32 t4_tcb_get_field32(__be64 *tcb, u16 word, u32 mask, u32 shift)
3814 u64 t = be64_to_cpu(tcb[(31 - word) / 2]);
3818 v = (t >> shift) & mask;
3822 static int read_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3824 struct cpl_get_tcb_rpl *rpl = cplhdr(skb);
3825 __be64 *tcb = (__be64 *)(rpl + 1);
3826 unsigned int tid = GET_TID(rpl);
3831 ep = get_ep_from_tid(dev, tid);
3834 /* Examine the TF_RX_PDU_OUT (bit 49 of the t_flags) in order to
3835 * determine if there's a rx PDU feedback event pending.
3837 * If that bit is set, it means we'll need to re-read the TCB's
3838 * rq_start value. The final value is the one present in a TCB
3839 * with the TF_RX_PDU_OUT bit cleared.
3842 t_flags_64 = t4_tcb_get_field64(tcb, TCB_T_FLAGS_W);
3843 rx_pdu_out = (t_flags_64 & TF_RX_PDU_OUT_V(1)) >> TF_RX_PDU_OUT_S;
3845 c4iw_put_ep(&ep->com); /* from get_ep_from_tid() */
3846 c4iw_put_ep(&ep->com); /* from read_tcb() */
3848 /* If TF_RX_PDU_OUT bit is set, re-read the TCB */
3850 if (++ep->rx_pdu_out_cnt >= 2) {
3851 WARN_ONCE(1, "tcb re-read() reached the guard limit, finishing the cleanup\n");
3858 ep->srqe_idx = t4_tcb_get_field32(tcb, TCB_RQ_START_W, TCB_RQ_START_W,
3861 pr_debug("ep %p tid %u %016x\n", ep, ep->hwtid, ep->srqe_idx);
3863 if (test_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags))
3864 finish_peer_abort(dev, ep);
3865 else if (test_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags))
3868 WARN_ONCE(1, "unexpected state!");
3873 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3875 struct cpl_fw6_msg *rpl = cplhdr(skb);
3876 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3878 switch (rpl->type) {
3880 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3882 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3883 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3884 switch (req->t_state) {
3886 active_ofld_conn_reply(dev, skb, req);
3889 passive_ofld_conn_reply(dev, skb, req);
3892 pr_err("%s unexpected ofld conn wr state %d\n",
3893 __func__, req->t_state);
3901 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3904 __be16 hdr_len, vlantag, len;
3906 int tcp_hdr_len, ip_hdr_len;
3908 struct cpl_rx_pkt *cpl = cplhdr(skb);
3909 struct cpl_pass_accept_req *req;
3910 struct tcp_options_received tmp_opt;
3911 struct c4iw_dev *dev;
3912 enum chip_type type;
3914 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3915 /* Store values from cpl_rx_pkt in temporary location. */
3916 vlantag = cpl->vlan;
3918 l2info = cpl->l2info;
3919 hdr_len = cpl->hdr_len;
3922 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3925 * We need to parse the TCP options from SYN packet.
3926 * to generate cpl_pass_accept_req.
3928 memset(&tmp_opt, 0, sizeof(tmp_opt));
3929 tcp_clear_options(&tmp_opt);
3930 tcp_parse_options(&init_net, skb, &tmp_opt, 0, NULL);
3932 req = __skb_push(skb, sizeof(*req));
3933 memset(req, 0, sizeof(*req));
3934 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3935 SYN_MAC_IDX_V(RX_MACIDX_G(
3936 be32_to_cpu(l2info))) |
3938 type = dev->rdev.lldi.adapter_type;
3939 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3940 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3942 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3943 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3944 eth_hdr_len = is_t4(type) ?
3945 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3946 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3947 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3948 IP_HDR_LEN_V(ip_hdr_len) |
3949 ETH_HDR_LEN_V(eth_hdr_len));
3950 } else { /* T6 and later */
3951 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3952 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3953 T6_IP_HDR_LEN_V(ip_hdr_len) |
3954 T6_ETH_HDR_LEN_V(eth_hdr_len));
3956 req->vlan = vlantag;
3958 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3959 PASS_OPEN_TOS_V(tos));
3960 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3961 if (tmp_opt.wscale_ok)
3962 req->tcpopt.wsf = tmp_opt.snd_wscale;
3963 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3964 if (tmp_opt.sack_ok)
3965 req->tcpopt.sack = 1;
3966 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3970 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3971 __be32 laddr, __be16 lport,
3972 __be32 raddr, __be16 rport,
3973 u32 rcv_isn, u32 filter, u16 window,
3974 u32 rss_qid, u8 port_id)
3976 struct sk_buff *req_skb;
3977 struct fw_ofld_connection_wr *req;
3978 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3981 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3984 req = __skb_put_zero(req_skb, sizeof(*req));
3985 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
3986 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
3987 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
3988 req->le.filter = (__force __be32) filter;
3989 req->le.lport = lport;
3990 req->le.pport = rport;
3991 req->le.u.ipv4.lip = laddr;
3992 req->le.u.ipv4.pip = raddr;
3993 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3994 req->tcb.rcv_adv = htons(window);
3995 req->tcb.t_state_to_astid =
3996 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3997 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3998 FW_OFLD_CONNECTION_WR_ASTID_V(
3999 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
4002 * We store the qid in opt2 which will be used by the firmware
4003 * to send us the wr response.
4005 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
4008 * We initialize the MSS index in TCB to 0xF.
4009 * So that when driver sends cpl_pass_accept_rpl
4010 * TCB picks up the correct value. If this was 0
4011 * TP will ignore any value > 0 for MSS index.
4013 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
4014 req->cookie = (uintptr_t)skb;
4016 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
4017 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
4019 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
4027 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
4028 * messages when a filter is being used instead of server to
4029 * redirect a syn packet. When packets hit filter they are redirected
4030 * to the offload queue and driver tries to establish the connection
4031 * using firmware work request.
4033 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
4036 unsigned int filter;
4037 struct ethhdr *eh = NULL;
4038 struct vlan_ethhdr *vlan_eh = NULL;
4040 struct tcphdr *tcph;
4041 struct rss_header *rss = (void *)skb->data;
4042 struct cpl_rx_pkt *cpl = (void *)skb->data;
4043 struct cpl_pass_accept_req *req = (void *)(rss + 1);
4044 struct l2t_entry *e;
4045 struct dst_entry *dst;
4046 struct c4iw_ep *lep = NULL;
4048 struct port_info *pi;
4049 struct net_device *pdev;
4050 u16 rss_qid, eth_hdr_len;
4052 struct neighbour *neigh;
4054 /* Drop all non-SYN packets */
4055 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
4059 * Drop all packets which did not hit the filter.
4060 * Unlikely to happen.
4062 if (!(rss->filter_hit && rss->filter_tid))
4066 * Calculate the server tid from filter hit index from cpl_rx_pkt.
4068 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
4070 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
4072 pr_warn("%s connect request on invalid stid %d\n",
4077 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
4079 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4082 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4085 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4088 pr_err("T%d Chip is not supported\n",
4089 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
4093 if (eth_hdr_len == ETH_HLEN) {
4094 eh = (struct ethhdr *)(req + 1);
4095 iph = (struct iphdr *)(eh + 1);
4097 vlan_eh = (struct vlan_ethhdr *)(req + 1);
4098 iph = (struct iphdr *)(vlan_eh + 1);
4099 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cpl->vlan));
4102 if (iph->version != 0x4)
4105 tcph = (struct tcphdr *)(iph + 1);
4106 skb_set_network_header(skb, (void *)iph - (void *)rss);
4107 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
4110 pr_debug("lip 0x%x lport %u pip 0x%x pport %u tos %d\n",
4111 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
4112 ntohs(tcph->source), iph->tos);
4114 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
4115 iph->daddr, iph->saddr, tcph->dest,
4116 tcph->source, iph->tos);
4118 pr_err("%s - failed to find dst entry!\n", __func__);
4121 neigh = dst_neigh_lookup_skb(dst, skb);
4124 pr_err("%s - failed to allocate neigh!\n", __func__);
4128 if (neigh->dev->flags & IFF_LOOPBACK) {
4129 pdev = ip_dev_find(&init_net, iph->daddr);
4130 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
4132 pi = (struct port_info *)netdev_priv(pdev);
4135 pdev = get_real_dev(neigh->dev);
4136 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
4138 pi = (struct port_info *)netdev_priv(pdev);
4140 neigh_release(neigh);
4142 pr_err("%s - failed to allocate l2t entry!\n",
4147 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4148 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
4149 window = (__force u16) htons((__force u16)tcph->window);
4151 /* Calcuate filter portion for LE region. */
4152 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4153 dev->rdev.lldi.ports[0],
4157 * Synthesize the cpl_pass_accept_req. We have everything except the
4158 * TID. Once firmware sends a reply with TID we update the TID field
4159 * in cpl and pass it through the regular cpl_pass_accept_req path.
4161 build_cpl_pass_accept_req(skb, stid, iph->tos);
4162 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4163 tcph->source, ntohl(tcph->seq), filter, window,
4164 rss_qid, pi->port_id);
4165 cxgb4_l2t_release(e);
4170 c4iw_put_ep(&lep->com);
4175 * These are the real handlers that are called from a
4178 static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
4179 [CPL_ACT_ESTABLISH] = act_establish,
4180 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4181 [CPL_RX_DATA] = rx_data,
4182 [CPL_ABORT_RPL_RSS] = abort_rpl,
4183 [CPL_ABORT_RPL] = abort_rpl,
4184 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4185 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4186 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4187 [CPL_PASS_ESTABLISH] = pass_establish,
4188 [CPL_PEER_CLOSE] = peer_close,
4189 [CPL_ABORT_REQ_RSS] = peer_abort,
4190 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4191 [CPL_RDMA_TERMINATE] = terminate,
4192 [CPL_FW4_ACK] = fw4_ack,
4193 [CPL_GET_TCB_RPL] = read_tcb_rpl,
4194 [CPL_FW6_MSG] = deferred_fw6_msg,
4195 [CPL_RX_PKT] = rx_pkt,
4196 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4197 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
4200 static void process_timeout(struct c4iw_ep *ep)
4202 struct c4iw_qp_attributes attrs;
4205 mutex_lock(&ep->com.mutex);
4206 pr_debug("ep %p tid %u state %d\n", ep, ep->hwtid, ep->com.state);
4207 set_bit(TIMEDOUT, &ep->com.history);
4208 switch (ep->com.state) {
4210 connect_reply_upcall(ep, -ETIMEDOUT);
4219 if (ep->com.cm_id && ep->com.qp) {
4220 attrs.next_state = C4IW_QP_STATE_ERROR;
4221 c4iw_modify_qp(ep->com.qp->rhp,
4222 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4225 close_complete_upcall(ep, -ETIMEDOUT);
4231 * These states are expected if the ep timed out at the same
4232 * time as another thread was calling stop_ep_timer().
4233 * So we silently do nothing for these states.
4238 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
4239 __func__, ep, ep->hwtid, ep->com.state);
4242 mutex_unlock(&ep->com.mutex);
4244 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
4245 c4iw_put_ep(&ep->com);
4248 static void process_timedout_eps(void)
4252 spin_lock_irq(&timeout_lock);
4253 while (!list_empty(&timeout_list)) {
4254 struct list_head *tmp;
4256 tmp = timeout_list.next;
4260 spin_unlock_irq(&timeout_lock);
4261 ep = list_entry(tmp, struct c4iw_ep, entry);
4262 process_timeout(ep);
4263 spin_lock_irq(&timeout_lock);
4265 spin_unlock_irq(&timeout_lock);
4268 static void process_work(struct work_struct *work)
4270 struct sk_buff *skb = NULL;
4271 struct c4iw_dev *dev;
4272 struct cpl_act_establish *rpl;
4273 unsigned int opcode;
4276 process_timedout_eps();
4277 while ((skb = skb_dequeue(&rxq))) {
4279 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4280 opcode = rpl->ot.opcode;
4282 if (opcode >= ARRAY_SIZE(work_handlers) ||
4283 !work_handlers[opcode]) {
4284 pr_err("No handler for opcode 0x%x.\n", opcode);
4287 ret = work_handlers[opcode](dev, skb);
4291 process_timedout_eps();
4295 static DECLARE_WORK(skb_work, process_work);
4297 static void ep_timeout(struct timer_list *t)
4299 struct c4iw_ep *ep = from_timer(ep, t, timer);
4302 spin_lock(&timeout_lock);
4303 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
4305 * Only insert if it is not already on the list.
4307 if (!ep->entry.next) {
4308 list_add_tail(&ep->entry, &timeout_list);
4312 spin_unlock(&timeout_lock);
4314 queue_work(workq, &skb_work);
4318 * All the CM events are handled on a work queue to have a safe context.
4320 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4324 * Save dev in the skb->cb area.
4326 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4329 * Queue the skb and schedule the worker thread.
4331 skb_queue_tail(&rxq, skb);
4332 queue_work(workq, &skb_work);
4336 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4338 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4340 if (rpl->status != CPL_ERR_NONE) {
4341 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4342 rpl->status, GET_TID(rpl));
4348 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4350 struct cpl_fw6_msg *rpl = cplhdr(skb);
4351 struct c4iw_wr_wait *wr_waitp;
4354 pr_debug("type %u\n", rpl->type);
4356 switch (rpl->type) {
4357 case FW6_TYPE_WR_RPL:
4358 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
4359 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
4360 pr_debug("wr_waitp %p ret %u\n", wr_waitp, ret);
4362 c4iw_wake_up_deref(wr_waitp, ret ? -ret : 0);
4366 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
4370 pr_err("%s unexpected fw6 msg type %u\n",
4371 __func__, rpl->type);
4378 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4380 struct cpl_abort_req_rss *req = cplhdr(skb);
4382 unsigned int tid = GET_TID(req);
4384 ep = get_ep_from_tid(dev, tid);
4385 /* This EP will be dereferenced in peer_abort() */
4387 pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
4391 if (cxgb_is_neg_adv(req->status)) {
4392 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
4393 ep->hwtid, req->status,
4394 neg_adv_str(req->status));
4397 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid, ep->com.state);
4399 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
4406 * Most upcalls from the T4 Core go to sched() to
4407 * schedule the processing on a work queue.
4409 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4410 [CPL_ACT_ESTABLISH] = sched,
4411 [CPL_ACT_OPEN_RPL] = sched,
4412 [CPL_RX_DATA] = sched,
4413 [CPL_ABORT_RPL_RSS] = sched,
4414 [CPL_ABORT_RPL] = sched,
4415 [CPL_PASS_OPEN_RPL] = sched,
4416 [CPL_CLOSE_LISTSRV_RPL] = sched,
4417 [CPL_PASS_ACCEPT_REQ] = sched,
4418 [CPL_PASS_ESTABLISH] = sched,
4419 [CPL_PEER_CLOSE] = sched,
4420 [CPL_CLOSE_CON_RPL] = sched,
4421 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
4422 [CPL_RDMA_TERMINATE] = sched,
4423 [CPL_FW4_ACK] = sched,
4424 [CPL_SET_TCB_RPL] = set_tcb_rpl,
4425 [CPL_GET_TCB_RPL] = sched,
4426 [CPL_FW6_MSG] = fw6_msg,
4427 [CPL_RX_PKT] = sched
4430 int __init c4iw_cm_init(void)
4432 spin_lock_init(&timeout_lock);
4433 skb_queue_head_init(&rxq);
4435 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
4442 void c4iw_cm_term(void)
4444 WARN_ON(!list_empty(&timeout_list));
4445 flush_workqueue(workq);
4446 destroy_workqueue(workq);