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);
407 kfree_skb(ep->mpa_skb);
409 if (!skb_queue_empty(&ep->com.ep_skb_list))
410 skb_queue_purge(&ep->com.ep_skb_list);
411 c4iw_put_wr_wait(ep->com.wr_waitp);
415 static void release_ep_resources(struct c4iw_ep *ep)
417 set_bit(RELEASE_RESOURCES, &ep->com.flags);
420 * If we have a hwtid, then remove it from the idr table
421 * so lookups will no longer find this endpoint. Otherwise
422 * we have a race where one thread finds the ep ptr just
423 * before the other thread is freeing the ep memory.
427 c4iw_put_ep(&ep->com);
430 static int status2errno(int status)
435 case CPL_ERR_CONN_RESET:
437 case CPL_ERR_ARP_MISS:
438 return -EHOSTUNREACH;
439 case CPL_ERR_CONN_TIMEDOUT:
441 case CPL_ERR_TCAM_FULL:
443 case CPL_ERR_CONN_EXIST:
451 * Try and reuse skbs already allocated...
453 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
455 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
458 skb_reset_transport_header(skb);
460 skb = alloc_skb(len, gfp);
464 t4_set_arp_err_handler(skb, NULL, NULL);
468 static struct net_device *get_real_dev(struct net_device *egress_dev)
470 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
473 static void arp_failure_discard(void *handle, struct sk_buff *skb)
475 pr_err("ARP failure\n");
479 static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
481 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
486 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
487 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
490 static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
494 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
495 release_ep_resources(ep);
499 static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
503 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
504 c4iw_put_ep(&ep->parent_ep->com);
505 release_ep_resources(ep);
510 * Fake up a special CPL opcode and call sched() so process_work() will call
511 * _put_ep_safe() in a safe context to free the ep resources. This is needed
512 * because ARP error handlers are called in an ATOMIC context, and
513 * _c4iw_free_ep() needs to block.
515 static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
518 struct cpl_act_establish *rpl = cplhdr(skb);
520 /* Set our special ARP_FAILURE opcode */
521 rpl->ot.opcode = cpl;
524 * Save ep in the skb->cb area, after where sched() will save the dev
527 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
528 sched(ep->com.dev, skb);
531 /* Handle an ARP failure for an accept */
532 static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
534 struct c4iw_ep *ep = handle;
536 pr_err("ARP failure during accept - tid %u - dropping connection\n",
539 __state_set(&ep->com, DEAD);
540 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
544 * Handle an ARP failure for an active open.
546 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
548 struct c4iw_ep *ep = handle;
550 pr_err("ARP failure during connect\n");
551 connect_reply_upcall(ep, -EHOSTUNREACH);
552 __state_set(&ep->com, DEAD);
553 if (ep->com.remote_addr.ss_family == AF_INET6) {
554 struct sockaddr_in6 *sin6 =
555 (struct sockaddr_in6 *)&ep->com.local_addr;
556 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
557 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
559 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
560 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
561 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
565 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
568 static void abort_arp_failure(void *handle, struct sk_buff *skb)
571 struct c4iw_ep *ep = handle;
572 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
573 struct cpl_abort_req *req = cplhdr(skb);
575 pr_debug("rdev %p\n", rdev);
576 req->cmd = CPL_ABORT_NO_RST;
578 ret = c4iw_ofld_send(rdev, skb);
580 __state_set(&ep->com, DEAD);
581 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
586 static int send_flowc(struct c4iw_ep *ep)
588 struct fw_flowc_wr *flowc;
589 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
590 u16 vlan = ep->l2t->vlan;
592 int flowclen, flowclen16;
597 if (vlan == CPL_L2T_VLAN_NONE)
602 flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
603 flowclen16 = DIV_ROUND_UP(flowclen, 16);
604 flowclen = flowclen16 * 16;
606 flowc = __skb_put(skb, flowclen);
607 memset(flowc, 0, flowclen);
609 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
610 FW_FLOWC_WR_NPARAMS_V(nparams));
611 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(flowclen16) |
612 FW_WR_FLOWID_V(ep->hwtid));
614 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
615 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
616 (ep->com.dev->rdev.lldi.pf));
617 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
618 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
619 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
620 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
621 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
622 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
623 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
624 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
625 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
626 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
627 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
628 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
629 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
630 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
631 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_RCV_SCALE;
632 flowc->mnemval[8].val = cpu_to_be32(ep->snd_wscale);
635 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
636 flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
637 flowc->mnemval[9].val = cpu_to_be32(pri);
640 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
641 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
644 static int send_halfclose(struct c4iw_ep *ep)
646 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
647 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
649 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
653 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
654 NULL, arp_failure_discard);
656 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
659 static int send_abort(struct c4iw_ep *ep)
661 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
662 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
664 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
665 if (WARN_ON(!req_skb))
668 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
669 ep, abort_arp_failure);
671 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
674 static int send_connect(struct c4iw_ep *ep)
676 struct cpl_act_open_req *req = NULL;
677 struct cpl_t5_act_open_req *t5req = NULL;
678 struct cpl_t6_act_open_req *t6req = NULL;
679 struct cpl_act_open_req6 *req6 = NULL;
680 struct cpl_t5_act_open_req6 *t5req6 = NULL;
681 struct cpl_t6_act_open_req6 *t6req6 = NULL;
685 unsigned int mtu_idx;
687 int win, sizev4, sizev6, wrlen;
688 struct sockaddr_in *la = (struct sockaddr_in *)
690 struct sockaddr_in *ra = (struct sockaddr_in *)
691 &ep->com.remote_addr;
692 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
694 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
695 &ep->com.remote_addr;
697 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
698 u32 isn = (prandom_u32() & ~7UL) - 1;
699 struct net_device *netdev;
702 netdev = ep->com.dev->rdev.lldi.ports[0];
704 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
706 sizev4 = sizeof(struct cpl_act_open_req);
707 sizev6 = sizeof(struct cpl_act_open_req6);
710 sizev4 = sizeof(struct cpl_t5_act_open_req);
711 sizev6 = sizeof(struct cpl_t5_act_open_req6);
714 sizev4 = sizeof(struct cpl_t6_act_open_req);
715 sizev6 = sizeof(struct cpl_t6_act_open_req6);
718 pr_err("T%d Chip is not supported\n",
719 CHELSIO_CHIP_VERSION(adapter_type));
723 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
724 roundup(sizev4, 16) :
727 pr_debug("ep %p atid %u\n", ep, ep->atid);
729 skb = get_skb(NULL, wrlen, GFP_KERNEL);
731 pr_err("%s - failed to alloc skb\n", __func__);
734 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
736 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
737 enable_tcp_timestamps,
738 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
739 wscale = cxgb_compute_wscale(rcv_win);
742 * Specify the largest window that will fit in opt0. The
743 * remainder will be specified in the rx_data_ack.
745 win = ep->rcv_win >> 10;
746 if (win > RCV_BUFSIZ_M)
749 opt0 = (nocong ? NO_CONG_F : 0) |
752 WND_SCALE_V(wscale) |
754 L2T_IDX_V(ep->l2t->idx) |
755 TX_CHAN_V(ep->tx_chan) |
756 SMAC_SEL_V(ep->smac_idx) |
757 DSCP_V(ep->tos >> 2) |
758 ULP_MODE_V(ULP_MODE_TCPDDP) |
760 opt2 = RX_CHANNEL_V(0) |
761 CCTRL_ECN_V(enable_ecn) |
762 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
763 if (enable_tcp_timestamps)
764 opt2 |= TSTAMPS_EN_F;
767 if (wscale && enable_tcp_window_scaling)
768 opt2 |= WND_SCALE_EN_F;
769 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
773 opt2 |= T5_OPT_2_VALID_F;
774 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
778 params = cxgb4_select_ntuple(netdev, ep->l2t);
780 if (ep->com.remote_addr.ss_family == AF_INET6)
781 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
782 (const u32 *)&la6->sin6_addr.s6_addr, 1);
784 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
786 if (ep->com.remote_addr.ss_family == AF_INET) {
787 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
789 req = skb_put(skb, wrlen);
793 t5req = skb_put(skb, wrlen);
794 INIT_TP_WR(t5req, 0);
795 req = (struct cpl_act_open_req *)t5req;
798 t6req = skb_put(skb, wrlen);
799 INIT_TP_WR(t6req, 0);
800 req = (struct cpl_act_open_req *)t6req;
801 t5req = (struct cpl_t5_act_open_req *)t6req;
804 pr_err("T%d Chip is not supported\n",
805 CHELSIO_CHIP_VERSION(adapter_type));
810 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
811 ((ep->rss_qid<<14) | ep->atid)));
812 req->local_port = la->sin_port;
813 req->peer_port = ra->sin_port;
814 req->local_ip = la->sin_addr.s_addr;
815 req->peer_ip = ra->sin_addr.s_addr;
816 req->opt0 = cpu_to_be64(opt0);
818 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
819 req->params = cpu_to_be32(params);
820 req->opt2 = cpu_to_be32(opt2);
822 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
824 cpu_to_be64(FILTER_TUPLE_V(params));
825 t5req->rsvd = cpu_to_be32(isn);
826 pr_debug("snd_isn %u\n", t5req->rsvd);
827 t5req->opt2 = cpu_to_be32(opt2);
830 cpu_to_be64(FILTER_TUPLE_V(params));
831 t6req->rsvd = cpu_to_be32(isn);
832 pr_debug("snd_isn %u\n", t6req->rsvd);
833 t6req->opt2 = cpu_to_be32(opt2);
837 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
839 req6 = skb_put(skb, wrlen);
843 t5req6 = skb_put(skb, wrlen);
844 INIT_TP_WR(t5req6, 0);
845 req6 = (struct cpl_act_open_req6 *)t5req6;
848 t6req6 = skb_put(skb, wrlen);
849 INIT_TP_WR(t6req6, 0);
850 req6 = (struct cpl_act_open_req6 *)t6req6;
851 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
854 pr_err("T%d Chip is not supported\n",
855 CHELSIO_CHIP_VERSION(adapter_type));
860 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
861 ((ep->rss_qid<<14)|ep->atid)));
862 req6->local_port = la6->sin6_port;
863 req6->peer_port = ra6->sin6_port;
864 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
865 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
866 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
867 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
868 req6->opt0 = cpu_to_be64(opt0);
870 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
871 req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
873 req6->opt2 = cpu_to_be32(opt2);
875 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
877 cpu_to_be64(FILTER_TUPLE_V(params));
878 t5req6->rsvd = cpu_to_be32(isn);
879 pr_debug("snd_isn %u\n", t5req6->rsvd);
880 t5req6->opt2 = cpu_to_be32(opt2);
883 cpu_to_be64(FILTER_TUPLE_V(params));
884 t6req6->rsvd = cpu_to_be32(isn);
885 pr_debug("snd_isn %u\n", t6req6->rsvd);
886 t6req6->opt2 = cpu_to_be32(opt2);
892 set_bit(ACT_OPEN_REQ, &ep->com.history);
893 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
895 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
896 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
897 (const u32 *)&la6->sin6_addr.s6_addr, 1);
901 static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
904 int mpalen, wrlen, ret;
905 struct fw_ofld_tx_data_wr *req;
906 struct mpa_message *mpa;
907 struct mpa_v2_conn_params mpa_v2_params;
909 pr_debug("ep %p tid %u pd_len %d\n",
910 ep, ep->hwtid, ep->plen);
912 mpalen = sizeof(*mpa) + ep->plen;
913 if (mpa_rev_to_use == 2)
914 mpalen += sizeof(struct mpa_v2_conn_params);
915 wrlen = roundup(mpalen + sizeof *req, 16);
916 skb = get_skb(skb, wrlen, GFP_KERNEL);
918 connect_reply_upcall(ep, -ENOMEM);
921 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
923 req = skb_put_zero(skb, wrlen);
924 req->op_to_immdlen = cpu_to_be32(
925 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
927 FW_WR_IMMDLEN_V(mpalen));
928 req->flowid_len16 = cpu_to_be32(
929 FW_WR_FLOWID_V(ep->hwtid) |
930 FW_WR_LEN16_V(wrlen >> 4));
931 req->plen = cpu_to_be32(mpalen);
932 req->tunnel_to_proxy = cpu_to_be32(
933 FW_OFLD_TX_DATA_WR_FLUSH_F |
934 FW_OFLD_TX_DATA_WR_SHOVE_F);
936 mpa = (struct mpa_message *)(req + 1);
937 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
941 mpa->flags |= MPA_CRC;
942 if (markers_enabled) {
943 mpa->flags |= MPA_MARKERS;
944 ep->mpa_attr.recv_marker_enabled = 1;
946 ep->mpa_attr.recv_marker_enabled = 0;
948 if (mpa_rev_to_use == 2)
949 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
951 mpa->private_data_size = htons(ep->plen);
952 mpa->revision = mpa_rev_to_use;
953 if (mpa_rev_to_use == 1) {
954 ep->tried_with_mpa_v1 = 1;
955 ep->retry_with_mpa_v1 = 0;
958 if (mpa_rev_to_use == 2) {
959 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
960 sizeof (struct mpa_v2_conn_params));
961 pr_debug("initiator ird %u ord %u\n", ep->ird,
963 mpa_v2_params.ird = htons((u16)ep->ird);
964 mpa_v2_params.ord = htons((u16)ep->ord);
967 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
968 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
970 htons(MPA_V2_RDMA_WRITE_RTR);
971 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
973 htons(MPA_V2_RDMA_READ_RTR);
975 memcpy(mpa->private_data, &mpa_v2_params,
976 sizeof(struct mpa_v2_conn_params));
979 memcpy(mpa->private_data +
980 sizeof(struct mpa_v2_conn_params),
981 ep->mpa_pkt + sizeof(*mpa), ep->plen);
984 memcpy(mpa->private_data,
985 ep->mpa_pkt + sizeof(*mpa), ep->plen);
988 * Reference the mpa skb. This ensures the data area
989 * will remain in memory until the hw acks the tx.
990 * Function fw4_ack() will deref it.
993 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
995 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
999 __state_set(&ep->com, MPA_REQ_SENT);
1000 ep->mpa_attr.initiator = 1;
1001 ep->snd_seq += mpalen;
1005 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1008 struct fw_ofld_tx_data_wr *req;
1009 struct mpa_message *mpa;
1010 struct sk_buff *skb;
1011 struct mpa_v2_conn_params mpa_v2_params;
1013 pr_debug("ep %p tid %u pd_len %d\n",
1014 ep, ep->hwtid, ep->plen);
1016 mpalen = sizeof(*mpa) + plen;
1017 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1018 mpalen += sizeof(struct mpa_v2_conn_params);
1019 wrlen = roundup(mpalen + sizeof *req, 16);
1021 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1023 pr_err("%s - cannot alloc skb!\n", __func__);
1026 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1028 req = skb_put_zero(skb, wrlen);
1029 req->op_to_immdlen = cpu_to_be32(
1030 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1032 FW_WR_IMMDLEN_V(mpalen));
1033 req->flowid_len16 = cpu_to_be32(
1034 FW_WR_FLOWID_V(ep->hwtid) |
1035 FW_WR_LEN16_V(wrlen >> 4));
1036 req->plen = cpu_to_be32(mpalen);
1037 req->tunnel_to_proxy = cpu_to_be32(
1038 FW_OFLD_TX_DATA_WR_FLUSH_F |
1039 FW_OFLD_TX_DATA_WR_SHOVE_F);
1041 mpa = (struct mpa_message *)(req + 1);
1042 memset(mpa, 0, sizeof(*mpa));
1043 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1044 mpa->flags = MPA_REJECT;
1045 mpa->revision = ep->mpa_attr.version;
1046 mpa->private_data_size = htons(plen);
1048 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1049 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1050 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1051 sizeof (struct mpa_v2_conn_params));
1052 mpa_v2_params.ird = htons(((u16)ep->ird) |
1053 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1055 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1057 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1058 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1059 FW_RI_INIT_P2PTYPE_READ_REQ ?
1060 MPA_V2_RDMA_READ_RTR : 0) : 0));
1061 memcpy(mpa->private_data, &mpa_v2_params,
1062 sizeof(struct mpa_v2_conn_params));
1065 memcpy(mpa->private_data +
1066 sizeof(struct mpa_v2_conn_params), pdata, plen);
1069 memcpy(mpa->private_data, pdata, plen);
1072 * Reference the mpa skb again. This ensures the data area
1073 * will remain in memory until the hw acks the tx.
1074 * Function fw4_ack() will deref it.
1077 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1078 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1080 ep->snd_seq += mpalen;
1081 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1084 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1087 struct fw_ofld_tx_data_wr *req;
1088 struct mpa_message *mpa;
1089 struct sk_buff *skb;
1090 struct mpa_v2_conn_params mpa_v2_params;
1092 pr_debug("ep %p tid %u pd_len %d\n",
1093 ep, ep->hwtid, ep->plen);
1095 mpalen = sizeof(*mpa) + plen;
1096 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1097 mpalen += sizeof(struct mpa_v2_conn_params);
1098 wrlen = roundup(mpalen + sizeof *req, 16);
1100 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1102 pr_err("%s - cannot alloc skb!\n", __func__);
1105 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1107 req = skb_put_zero(skb, wrlen);
1108 req->op_to_immdlen = cpu_to_be32(
1109 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1111 FW_WR_IMMDLEN_V(mpalen));
1112 req->flowid_len16 = cpu_to_be32(
1113 FW_WR_FLOWID_V(ep->hwtid) |
1114 FW_WR_LEN16_V(wrlen >> 4));
1115 req->plen = cpu_to_be32(mpalen);
1116 req->tunnel_to_proxy = cpu_to_be32(
1117 FW_OFLD_TX_DATA_WR_FLUSH_F |
1118 FW_OFLD_TX_DATA_WR_SHOVE_F);
1120 mpa = (struct mpa_message *)(req + 1);
1121 memset(mpa, 0, sizeof(*mpa));
1122 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1124 if (ep->mpa_attr.crc_enabled)
1125 mpa->flags |= MPA_CRC;
1126 if (ep->mpa_attr.recv_marker_enabled)
1127 mpa->flags |= MPA_MARKERS;
1128 mpa->revision = ep->mpa_attr.version;
1129 mpa->private_data_size = htons(plen);
1131 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1132 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1133 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1134 sizeof (struct mpa_v2_conn_params));
1135 mpa_v2_params.ird = htons((u16)ep->ird);
1136 mpa_v2_params.ord = htons((u16)ep->ord);
1137 if (peer2peer && (ep->mpa_attr.p2p_type !=
1138 FW_RI_INIT_P2PTYPE_DISABLED)) {
1139 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1141 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1142 mpa_v2_params.ord |=
1143 htons(MPA_V2_RDMA_WRITE_RTR);
1144 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1145 mpa_v2_params.ord |=
1146 htons(MPA_V2_RDMA_READ_RTR);
1149 memcpy(mpa->private_data, &mpa_v2_params,
1150 sizeof(struct mpa_v2_conn_params));
1153 memcpy(mpa->private_data +
1154 sizeof(struct mpa_v2_conn_params), pdata, plen);
1157 memcpy(mpa->private_data, pdata, plen);
1160 * Reference the mpa skb. This ensures the data area
1161 * will remain in memory until the hw acks the tx.
1162 * Function fw4_ack() will deref it.
1165 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1167 __state_set(&ep->com, MPA_REP_SENT);
1168 ep->snd_seq += mpalen;
1169 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1172 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1175 struct cpl_act_establish *req = cplhdr(skb);
1176 unsigned short tcp_opt = ntohs(req->tcp_opt);
1177 unsigned int tid = GET_TID(req);
1178 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
1179 struct tid_info *t = dev->rdev.lldi.tids;
1182 ep = lookup_atid(t, atid);
1184 pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep, tid,
1185 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1187 mutex_lock(&ep->com.mutex);
1188 dst_confirm(ep->dst);
1190 /* setup the hwtid for this connection */
1192 cxgb4_insert_tid(t, ep, tid, ep->com.local_addr.ss_family);
1195 ep->snd_seq = be32_to_cpu(req->snd_isn);
1196 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1197 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
1199 set_emss(ep, tcp_opt);
1201 /* dealloc the atid */
1202 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1203 cxgb4_free_atid(t, atid);
1204 set_bit(ACT_ESTAB, &ep->com.history);
1206 /* start MPA negotiation */
1207 ret = send_flowc(ep);
1210 if (ep->retry_with_mpa_v1)
1211 ret = send_mpa_req(ep, skb, 1);
1213 ret = send_mpa_req(ep, skb, mpa_rev);
1216 mutex_unlock(&ep->com.mutex);
1219 mutex_unlock(&ep->com.mutex);
1220 connect_reply_upcall(ep, -ENOMEM);
1221 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1225 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1227 struct iw_cm_event event;
1229 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1230 memset(&event, 0, sizeof(event));
1231 event.event = IW_CM_EVENT_CLOSE;
1232 event.status = status;
1233 if (ep->com.cm_id) {
1234 pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
1235 ep, ep->com.cm_id, ep->hwtid);
1236 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1237 deref_cm_id(&ep->com);
1238 set_bit(CLOSE_UPCALL, &ep->com.history);
1242 static void peer_close_upcall(struct c4iw_ep *ep)
1244 struct iw_cm_event event;
1246 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1247 memset(&event, 0, sizeof(event));
1248 event.event = IW_CM_EVENT_DISCONNECT;
1249 if (ep->com.cm_id) {
1250 pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
1251 ep, ep->com.cm_id, ep->hwtid);
1252 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1253 set_bit(DISCONN_UPCALL, &ep->com.history);
1257 static void peer_abort_upcall(struct c4iw_ep *ep)
1259 struct iw_cm_event event;
1261 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1262 memset(&event, 0, sizeof(event));
1263 event.event = IW_CM_EVENT_CLOSE;
1264 event.status = -ECONNRESET;
1265 if (ep->com.cm_id) {
1266 pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep,
1267 ep->com.cm_id, ep->hwtid);
1268 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1269 deref_cm_id(&ep->com);
1270 set_bit(ABORT_UPCALL, &ep->com.history);
1274 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1276 struct iw_cm_event event;
1278 pr_debug("ep %p tid %u status %d\n",
1279 ep, ep->hwtid, status);
1280 memset(&event, 0, sizeof(event));
1281 event.event = IW_CM_EVENT_CONNECT_REPLY;
1282 event.status = status;
1283 memcpy(&event.local_addr, &ep->com.local_addr,
1284 sizeof(ep->com.local_addr));
1285 memcpy(&event.remote_addr, &ep->com.remote_addr,
1286 sizeof(ep->com.remote_addr));
1288 if ((status == 0) || (status == -ECONNREFUSED)) {
1289 if (!ep->tried_with_mpa_v1) {
1290 /* this means MPA_v2 is used */
1291 event.ord = ep->ird;
1292 event.ird = ep->ord;
1293 event.private_data_len = ep->plen -
1294 sizeof(struct mpa_v2_conn_params);
1295 event.private_data = ep->mpa_pkt +
1296 sizeof(struct mpa_message) +
1297 sizeof(struct mpa_v2_conn_params);
1299 /* this means MPA_v1 is used */
1300 event.ord = cur_max_read_depth(ep->com.dev);
1301 event.ird = cur_max_read_depth(ep->com.dev);
1302 event.private_data_len = ep->plen;
1303 event.private_data = ep->mpa_pkt +
1304 sizeof(struct mpa_message);
1308 pr_debug("ep %p tid %u status %d\n", ep,
1310 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1311 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1314 deref_cm_id(&ep->com);
1317 static int connect_request_upcall(struct c4iw_ep *ep)
1319 struct iw_cm_event event;
1322 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1323 memset(&event, 0, sizeof(event));
1324 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1325 memcpy(&event.local_addr, &ep->com.local_addr,
1326 sizeof(ep->com.local_addr));
1327 memcpy(&event.remote_addr, &ep->com.remote_addr,
1328 sizeof(ep->com.remote_addr));
1329 event.provider_data = ep;
1330 if (!ep->tried_with_mpa_v1) {
1331 /* this means MPA_v2 is used */
1332 event.ord = ep->ord;
1333 event.ird = ep->ird;
1334 event.private_data_len = ep->plen -
1335 sizeof(struct mpa_v2_conn_params);
1336 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1337 sizeof(struct mpa_v2_conn_params);
1339 /* this means MPA_v1 is used. Send max supported */
1340 event.ord = cur_max_read_depth(ep->com.dev);
1341 event.ird = cur_max_read_depth(ep->com.dev);
1342 event.private_data_len = ep->plen;
1343 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1345 c4iw_get_ep(&ep->com);
1346 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1349 c4iw_put_ep(&ep->com);
1350 set_bit(CONNREQ_UPCALL, &ep->com.history);
1351 c4iw_put_ep(&ep->parent_ep->com);
1355 static void established_upcall(struct c4iw_ep *ep)
1357 struct iw_cm_event event;
1359 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1360 memset(&event, 0, sizeof(event));
1361 event.event = IW_CM_EVENT_ESTABLISHED;
1362 event.ird = ep->ord;
1363 event.ord = ep->ird;
1364 if (ep->com.cm_id) {
1365 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1366 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1367 set_bit(ESTAB_UPCALL, &ep->com.history);
1371 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1373 struct sk_buff *skb;
1374 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1377 pr_debug("ep %p tid %u credits %u\n",
1378 ep, ep->hwtid, credits);
1379 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1381 pr_err("update_rx_credits - cannot alloc skb!\n");
1386 * If we couldn't specify the entire rcv window at connection setup
1387 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1388 * then add the overage in to the credits returned.
1390 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1391 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
1393 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1394 RX_DACK_MODE_V(dack_mode);
1396 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1399 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1403 #define RELAXED_IRD_NEGOTIATION 1
1406 * process_mpa_reply - process streaming mode MPA reply
1410 * 0 upon success indicating a connect request was delivered to the ULP
1411 * or the mpa request is incomplete but valid so far.
1413 * 1 if a failure requires the caller to close the connection.
1415 * 2 if a failure requires the caller to abort the connection.
1417 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1419 struct mpa_message *mpa;
1420 struct mpa_v2_conn_params *mpa_v2_params;
1422 u16 resp_ird, resp_ord;
1423 u8 rtr_mismatch = 0, insuff_ird = 0;
1424 struct c4iw_qp_attributes attrs;
1425 enum c4iw_qp_attr_mask mask;
1429 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1432 * If we get more than the supported amount of private data
1433 * then we must fail this connection.
1435 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1437 goto err_stop_timer;
1441 * copy the new data into our accumulation buffer.
1443 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1445 ep->mpa_pkt_len += skb->len;
1448 * if we don't even have the mpa message, then bail.
1450 if (ep->mpa_pkt_len < sizeof(*mpa))
1452 mpa = (struct mpa_message *) ep->mpa_pkt;
1454 /* Validate MPA header. */
1455 if (mpa->revision > mpa_rev) {
1456 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1457 __func__, mpa_rev, mpa->revision);
1459 goto err_stop_timer;
1461 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1463 goto err_stop_timer;
1466 plen = ntohs(mpa->private_data_size);
1469 * Fail if there's too much private data.
1471 if (plen > MPA_MAX_PRIVATE_DATA) {
1473 goto err_stop_timer;
1477 * If plen does not account for pkt size
1479 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1481 goto err_stop_timer;
1484 ep->plen = (u8) plen;
1487 * If we don't have all the pdata yet, then bail.
1488 * We'll continue process when more data arrives.
1490 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1493 if (mpa->flags & MPA_REJECT) {
1494 err = -ECONNREFUSED;
1495 goto err_stop_timer;
1499 * Stop mpa timer. If it expired, then
1500 * we ignore the MPA reply. process_timeout()
1501 * will abort the connection.
1503 if (stop_ep_timer(ep))
1507 * If we get here we have accumulated the entire mpa
1508 * start reply message including private data. And
1509 * the MPA header is valid.
1511 __state_set(&ep->com, FPDU_MODE);
1512 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1513 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1514 ep->mpa_attr.version = mpa->revision;
1515 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1517 if (mpa->revision == 2) {
1518 ep->mpa_attr.enhanced_rdma_conn =
1519 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1520 if (ep->mpa_attr.enhanced_rdma_conn) {
1521 mpa_v2_params = (struct mpa_v2_conn_params *)
1522 (ep->mpa_pkt + sizeof(*mpa));
1523 resp_ird = ntohs(mpa_v2_params->ird) &
1524 MPA_V2_IRD_ORD_MASK;
1525 resp_ord = ntohs(mpa_v2_params->ord) &
1526 MPA_V2_IRD_ORD_MASK;
1527 pr_debug("responder ird %u ord %u ep ird %u ord %u\n",
1528 resp_ird, resp_ord, ep->ird, ep->ord);
1531 * This is a double-check. Ideally, below checks are
1532 * not required since ird/ord stuff has been taken
1533 * care of in c4iw_accept_cr
1535 if (ep->ird < resp_ord) {
1536 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1537 ep->com.dev->rdev.lldi.max_ordird_qp)
1541 } else if (ep->ird > resp_ord) {
1544 if (ep->ord > resp_ird) {
1545 if (RELAXED_IRD_NEGOTIATION)
1556 if (ntohs(mpa_v2_params->ird) &
1557 MPA_V2_PEER2PEER_MODEL) {
1558 if (ntohs(mpa_v2_params->ord) &
1559 MPA_V2_RDMA_WRITE_RTR)
1560 ep->mpa_attr.p2p_type =
1561 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1562 else if (ntohs(mpa_v2_params->ord) &
1563 MPA_V2_RDMA_READ_RTR)
1564 ep->mpa_attr.p2p_type =
1565 FW_RI_INIT_P2PTYPE_READ_REQ;
1568 } else if (mpa->revision == 1)
1570 ep->mpa_attr.p2p_type = p2p_type;
1572 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
1573 ep->mpa_attr.crc_enabled,
1574 ep->mpa_attr.recv_marker_enabled,
1575 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1576 ep->mpa_attr.p2p_type, p2p_type);
1579 * If responder's RTR does not match with that of initiator, assign
1580 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1581 * generated when moving QP to RTS state.
1582 * A TERM message will be sent after QP has moved to RTS state
1584 if ((ep->mpa_attr.version == 2) && peer2peer &&
1585 (ep->mpa_attr.p2p_type != p2p_type)) {
1586 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1590 attrs.mpa_attr = ep->mpa_attr;
1591 attrs.max_ird = ep->ird;
1592 attrs.max_ord = ep->ord;
1593 attrs.llp_stream_handle = ep;
1594 attrs.next_state = C4IW_QP_STATE_RTS;
1596 mask = C4IW_QP_ATTR_NEXT_STATE |
1597 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1598 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1600 /* bind QP and TID with INIT_WR */
1601 err = c4iw_modify_qp(ep->com.qp->rhp,
1602 ep->com.qp, mask, &attrs, 1);
1607 * If responder's RTR requirement did not match with what initiator
1608 * supports, generate TERM message
1611 pr_err("%s: RTR mismatch, sending TERM\n", __func__);
1612 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1613 attrs.ecode = MPA_NOMATCH_RTR;
1614 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1615 attrs.send_term = 1;
1616 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1617 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1624 * Generate TERM if initiator IRD is not sufficient for responder
1625 * provided ORD. Currently, we do the same behaviour even when
1626 * responder provided IRD is also not sufficient as regards to
1630 pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
1631 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1632 attrs.ecode = MPA_INSUFF_IRD;
1633 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1634 attrs.send_term = 1;
1635 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1636 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1647 connect_reply_upcall(ep, err);
1652 * process_mpa_request - process streaming mode MPA request
1656 * 0 upon success indicating a connect request was delivered to the ULP
1657 * or the mpa request is incomplete but valid so far.
1659 * 1 if a failure requires the caller to close the connection.
1661 * 2 if a failure requires the caller to abort the connection.
1663 static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1665 struct mpa_message *mpa;
1666 struct mpa_v2_conn_params *mpa_v2_params;
1669 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1672 * If we get more than the supported amount of private data
1673 * then we must fail this connection.
1675 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1676 goto err_stop_timer;
1678 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1681 * Copy the new data into our accumulation buffer.
1683 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1685 ep->mpa_pkt_len += skb->len;
1688 * If we don't even have the mpa message, then bail.
1689 * We'll continue process when more data arrives.
1691 if (ep->mpa_pkt_len < sizeof(*mpa))
1694 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1695 mpa = (struct mpa_message *) ep->mpa_pkt;
1698 * Validate MPA Header.
1700 if (mpa->revision > mpa_rev) {
1701 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1702 __func__, mpa_rev, mpa->revision);
1703 goto err_stop_timer;
1706 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1707 goto err_stop_timer;
1709 plen = ntohs(mpa->private_data_size);
1712 * Fail if there's too much private data.
1714 if (plen > MPA_MAX_PRIVATE_DATA)
1715 goto err_stop_timer;
1718 * If plen does not account for pkt size
1720 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1721 goto err_stop_timer;
1722 ep->plen = (u8) plen;
1725 * If we don't have all the pdata yet, then bail.
1727 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1731 * If we get here we have accumulated the entire mpa
1732 * start reply message including private data.
1734 ep->mpa_attr.initiator = 0;
1735 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1736 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1737 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1738 ep->mpa_attr.version = mpa->revision;
1739 if (mpa->revision == 1)
1740 ep->tried_with_mpa_v1 = 1;
1741 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1743 if (mpa->revision == 2) {
1744 ep->mpa_attr.enhanced_rdma_conn =
1745 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1746 if (ep->mpa_attr.enhanced_rdma_conn) {
1747 mpa_v2_params = (struct mpa_v2_conn_params *)
1748 (ep->mpa_pkt + sizeof(*mpa));
1749 ep->ird = ntohs(mpa_v2_params->ird) &
1750 MPA_V2_IRD_ORD_MASK;
1751 ep->ird = min_t(u32, ep->ird,
1752 cur_max_read_depth(ep->com.dev));
1753 ep->ord = ntohs(mpa_v2_params->ord) &
1754 MPA_V2_IRD_ORD_MASK;
1755 ep->ord = min_t(u32, ep->ord,
1756 cur_max_read_depth(ep->com.dev));
1757 pr_debug("initiator ird %u ord %u\n",
1759 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1761 if (ntohs(mpa_v2_params->ord) &
1762 MPA_V2_RDMA_WRITE_RTR)
1763 ep->mpa_attr.p2p_type =
1764 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1765 else if (ntohs(mpa_v2_params->ord) &
1766 MPA_V2_RDMA_READ_RTR)
1767 ep->mpa_attr.p2p_type =
1768 FW_RI_INIT_P2PTYPE_READ_REQ;
1771 } else if (mpa->revision == 1)
1773 ep->mpa_attr.p2p_type = p2p_type;
1775 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
1776 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1777 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1778 ep->mpa_attr.p2p_type);
1780 __state_set(&ep->com, MPA_REQ_RCVD);
1783 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1784 if (ep->parent_ep->com.state != DEAD) {
1785 if (connect_request_upcall(ep))
1786 goto err_unlock_parent;
1788 goto err_unlock_parent;
1790 mutex_unlock(&ep->parent_ep->com.mutex);
1794 mutex_unlock(&ep->parent_ep->com.mutex);
1797 (void)stop_ep_timer(ep);
1802 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1805 struct cpl_rx_data *hdr = cplhdr(skb);
1806 unsigned int dlen = ntohs(hdr->len);
1807 unsigned int tid = GET_TID(hdr);
1808 __u8 status = hdr->status;
1811 ep = get_ep_from_tid(dev, tid);
1814 pr_debug("ep %p tid %u dlen %u\n", ep, ep->hwtid, dlen);
1815 skb_pull(skb, sizeof(*hdr));
1816 skb_trim(skb, dlen);
1817 mutex_lock(&ep->com.mutex);
1819 switch (ep->com.state) {
1821 update_rx_credits(ep, dlen);
1822 ep->rcv_seq += dlen;
1823 disconnect = process_mpa_reply(ep, skb);
1826 update_rx_credits(ep, dlen);
1827 ep->rcv_seq += dlen;
1828 disconnect = process_mpa_request(ep, skb);
1831 struct c4iw_qp_attributes attrs;
1833 update_rx_credits(ep, dlen);
1835 pr_err("%s Unexpected streaming data." \
1836 " qpid %u ep %p state %d tid %u status %d\n",
1837 __func__, ep->com.qp->wq.sq.qid, ep,
1838 ep->com.state, ep->hwtid, status);
1839 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1840 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1841 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1848 mutex_unlock(&ep->com.mutex);
1850 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
1851 c4iw_put_ep(&ep->com);
1855 static void complete_cached_srq_buffers(struct c4iw_ep *ep,
1856 __be32 srqidx_status)
1858 enum chip_type adapter_type;
1861 adapter_type = ep->com.dev->rdev.lldi.adapter_type;
1862 srqidx = ABORT_RSS_SRQIDX_G(be32_to_cpu(srqidx_status));
1865 * If this TCB had a srq buffer cached, then we must complete
1866 * it. For user mode, that means saving the srqidx in the
1867 * user/kernel status page for this qp. For kernel mode, just
1868 * synthesize the CQE now.
1870 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T5 && srqidx) {
1871 if (ep->com.qp->ibqp.uobject)
1872 t4_set_wq_in_error(&ep->com.qp->wq, srqidx);
1874 c4iw_flush_srqidx(ep->com.qp, srqidx);
1878 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1881 struct cpl_abort_rpl_rss6 *rpl = cplhdr(skb);
1883 unsigned int tid = GET_TID(rpl);
1885 ep = get_ep_from_tid(dev, tid);
1887 pr_warn("Abort rpl to freed endpoint\n");
1891 complete_cached_srq_buffers(ep, rpl->srqidx_status);
1893 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1894 mutex_lock(&ep->com.mutex);
1895 switch (ep->com.state) {
1897 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
1898 __state_set(&ep->com, DEAD);
1902 pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
1905 mutex_unlock(&ep->com.mutex);
1908 close_complete_upcall(ep, -ECONNRESET);
1909 release_ep_resources(ep);
1911 c4iw_put_ep(&ep->com);
1915 static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1917 struct sk_buff *skb;
1918 struct fw_ofld_connection_wr *req;
1919 unsigned int mtu_idx;
1921 struct sockaddr_in *sin;
1924 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1925 req = __skb_put_zero(skb, sizeof(*req));
1926 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
1927 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
1928 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1929 ep->com.dev->rdev.lldi.ports[0],
1931 sin = (struct sockaddr_in *)&ep->com.local_addr;
1932 req->le.lport = sin->sin_port;
1933 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1934 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1935 req->le.pport = sin->sin_port;
1936 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1937 req->tcb.t_state_to_astid =
1938 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1939 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
1940 req->tcb.cplrxdataack_cplpassacceptrpl =
1941 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
1942 req->tcb.tx_max = (__force __be32) jiffies;
1943 req->tcb.rcv_adv = htons(1);
1944 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1945 enable_tcp_timestamps,
1946 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
1947 wscale = cxgb_compute_wscale(rcv_win);
1950 * Specify the largest window that will fit in opt0. The
1951 * remainder will be specified in the rx_data_ack.
1953 win = ep->rcv_win >> 10;
1954 if (win > RCV_BUFSIZ_M)
1957 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1958 (nocong ? NO_CONG_F : 0) |
1961 WND_SCALE_V(wscale) |
1962 MSS_IDX_V(mtu_idx) |
1963 L2T_IDX_V(ep->l2t->idx) |
1964 TX_CHAN_V(ep->tx_chan) |
1965 SMAC_SEL_V(ep->smac_idx) |
1966 DSCP_V(ep->tos >> 2) |
1967 ULP_MODE_V(ULP_MODE_TCPDDP) |
1969 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1970 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1972 CCTRL_ECN_V(enable_ecn) |
1973 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
1974 if (enable_tcp_timestamps)
1975 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
1976 if (enable_tcp_sack)
1977 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
1978 if (wscale && enable_tcp_window_scaling)
1979 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1980 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1981 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
1982 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1983 set_bit(ACT_OFLD_CONN, &ep->com.history);
1984 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1988 * Some of the error codes above implicitly indicate that there is no TID
1989 * allocated with the result of an ACT_OPEN. We use this predicate to make
1992 static inline int act_open_has_tid(int status)
1994 return (status != CPL_ERR_TCAM_PARITY &&
1995 status != CPL_ERR_TCAM_MISS &&
1996 status != CPL_ERR_TCAM_FULL &&
1997 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1998 status != CPL_ERR_CONN_EXIST);
2001 static char *neg_adv_str(unsigned int status)
2004 case CPL_ERR_RTX_NEG_ADVICE:
2005 return "Retransmit timeout";
2006 case CPL_ERR_PERSIST_NEG_ADVICE:
2007 return "Persist timeout";
2008 case CPL_ERR_KEEPALV_NEG_ADVICE:
2009 return "Keepalive timeout";
2015 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2017 ep->snd_win = snd_win;
2018 ep->rcv_win = rcv_win;
2019 pr_debug("snd_win %d rcv_win %d\n",
2020 ep->snd_win, ep->rcv_win);
2023 #define ACT_OPEN_RETRY_COUNT 2
2025 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2026 struct dst_entry *dst, struct c4iw_dev *cdev,
2027 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
2029 struct neighbour *n;
2031 struct net_device *pdev;
2033 n = dst_neigh_lookup(dst, peer_ip);
2039 if (n->dev->flags & IFF_LOOPBACK) {
2041 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2042 else if (IS_ENABLED(CONFIG_IPV6))
2043 for_each_netdev(&init_net, pdev) {
2044 if (ipv6_chk_addr(&init_net,
2045 (struct in6_addr *)peer_ip,
2056 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2057 n, pdev, rt_tos2priority(tos));
2062 ep->mtu = pdev->mtu;
2063 ep->tx_chan = cxgb4_port_chan(pdev);
2064 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2065 cxgb4_port_viid(pdev));
2066 step = cdev->rdev.lldi.ntxq /
2067 cdev->rdev.lldi.nchan;
2068 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2069 step = cdev->rdev.lldi.nrxq /
2070 cdev->rdev.lldi.nchan;
2071 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2072 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2073 cxgb4_port_idx(pdev) * step];
2074 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2077 pdev = get_real_dev(n->dev);
2078 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2079 n, pdev, rt_tos2priority(tos));
2082 ep->mtu = dst_mtu(dst);
2083 ep->tx_chan = cxgb4_port_chan(pdev);
2084 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2085 cxgb4_port_viid(pdev));
2086 step = cdev->rdev.lldi.ntxq /
2087 cdev->rdev.lldi.nchan;
2088 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2089 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2090 step = cdev->rdev.lldi.nrxq /
2091 cdev->rdev.lldi.nchan;
2092 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2093 cxgb4_port_idx(pdev) * step];
2094 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2097 ep->retry_with_mpa_v1 = 0;
2098 ep->tried_with_mpa_v1 = 0;
2110 static int c4iw_reconnect(struct c4iw_ep *ep)
2114 struct sockaddr_in *laddr = (struct sockaddr_in *)
2115 &ep->com.cm_id->m_local_addr;
2116 struct sockaddr_in *raddr = (struct sockaddr_in *)
2117 &ep->com.cm_id->m_remote_addr;
2118 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2119 &ep->com.cm_id->m_local_addr;
2120 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2121 &ep->com.cm_id->m_remote_addr;
2125 pr_debug("qp %p cm_id %p\n", ep->com.qp, ep->com.cm_id);
2126 c4iw_init_wr_wait(ep->com.wr_waitp);
2128 /* When MPA revision is different on nodes, the node with MPA_rev=2
2129 * tries to reconnect with MPA_rev 1 for the same EP through
2130 * c4iw_reconnect(), where the same EP is assigned with new tid for
2131 * further connection establishment. As we are using the same EP pointer
2132 * for reconnect, few skbs are used during the previous c4iw_connect(),
2133 * which leaves the EP with inadequate skbs for further
2134 * c4iw_reconnect(), Further causing a crash due to an empty
2135 * skb_list() during peer_abort(). Allocate skbs which is already used.
2137 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2138 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2144 * Allocate an active TID to initiate a TCP connection.
2146 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2147 if (ep->atid == -1) {
2148 pr_err("%s - cannot alloc atid\n", __func__);
2152 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2155 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
2156 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2157 laddr->sin_addr.s_addr,
2158 raddr->sin_addr.s_addr,
2160 raddr->sin_port, ep->com.cm_id->tos);
2162 ra = (__u8 *)&raddr->sin_addr;
2164 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2166 laddr6->sin6_addr.s6_addr,
2167 raddr6->sin6_addr.s6_addr,
2171 raddr6->sin6_scope_id);
2173 ra = (__u8 *)&raddr6->sin6_addr;
2176 pr_err("%s - cannot find route\n", __func__);
2177 err = -EHOSTUNREACH;
2180 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2181 ep->com.dev->rdev.lldi.adapter_type,
2182 ep->com.cm_id->tos);
2184 pr_err("%s - cannot alloc l2e\n", __func__);
2188 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2189 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2192 state_set(&ep->com, CONNECTING);
2193 ep->tos = ep->com.cm_id->tos;
2195 /* send connect request to rnic */
2196 err = send_connect(ep);
2200 cxgb4_l2t_release(ep->l2t);
2202 dst_release(ep->dst);
2204 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2205 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2208 * remember to send notification to upper layer.
2209 * We are in here so the upper layer is not aware that this is
2210 * re-connect attempt and so, upper layer is still waiting for
2211 * response of 1st connect request.
2213 connect_reply_upcall(ep, -ECONNRESET);
2215 c4iw_put_ep(&ep->com);
2220 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2223 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2224 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2225 ntohl(rpl->atid_status)));
2226 struct tid_info *t = dev->rdev.lldi.tids;
2227 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
2228 struct sockaddr_in *la;
2229 struct sockaddr_in *ra;
2230 struct sockaddr_in6 *la6;
2231 struct sockaddr_in6 *ra6;
2234 ep = lookup_atid(t, atid);
2235 la = (struct sockaddr_in *)&ep->com.local_addr;
2236 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2237 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2238 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
2240 pr_debug("ep %p atid %u status %u errno %d\n", ep, atid,
2241 status, status2errno(status));
2243 if (cxgb_is_neg_adv(status)) {
2244 pr_debug("Connection problems for atid %u status %u (%s)\n",
2245 atid, status, neg_adv_str(status));
2246 ep->stats.connect_neg_adv++;
2247 mutex_lock(&dev->rdev.stats.lock);
2248 dev->rdev.stats.neg_adv++;
2249 mutex_unlock(&dev->rdev.stats.lock);
2253 set_bit(ACT_OPEN_RPL, &ep->com.history);
2256 * Log interesting failures.
2259 case CPL_ERR_CONN_RESET:
2260 case CPL_ERR_CONN_TIMEDOUT:
2262 case CPL_ERR_TCAM_FULL:
2263 mutex_lock(&dev->rdev.stats.lock);
2264 dev->rdev.stats.tcam_full++;
2265 mutex_unlock(&dev->rdev.stats.lock);
2266 if (ep->com.local_addr.ss_family == AF_INET &&
2267 dev->rdev.lldi.enable_fw_ofld_conn) {
2268 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2269 ntohl(rpl->atid_status))));
2275 case CPL_ERR_CONN_EXIST:
2276 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2277 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2278 if (ep->com.remote_addr.ss_family == AF_INET6) {
2279 struct sockaddr_in6 *sin6 =
2280 (struct sockaddr_in6 *)
2281 &ep->com.local_addr;
2283 ep->com.dev->rdev.lldi.ports[0],
2285 &sin6->sin6_addr.s6_addr, 1);
2287 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2289 cxgb4_free_atid(t, atid);
2290 dst_release(ep->dst);
2291 cxgb4_l2t_release(ep->l2t);
2297 if (ep->com.local_addr.ss_family == AF_INET) {
2298 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2299 atid, status, status2errno(status),
2300 &la->sin_addr.s_addr, ntohs(la->sin_port),
2301 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2303 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2304 atid, status, status2errno(status),
2305 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2306 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2312 connect_reply_upcall(ep, status2errno(status));
2313 state_set(&ep->com, DEAD);
2315 if (ep->com.remote_addr.ss_family == AF_INET6) {
2316 struct sockaddr_in6 *sin6 =
2317 (struct sockaddr_in6 *)&ep->com.local_addr;
2318 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2319 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2321 if (status && act_open_has_tid(status))
2322 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl),
2323 ep->com.local_addr.ss_family);
2325 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2326 cxgb4_free_atid(t, atid);
2327 dst_release(ep->dst);
2328 cxgb4_l2t_release(ep->l2t);
2329 c4iw_put_ep(&ep->com);
2334 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2336 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2337 unsigned int stid = GET_TID(rpl);
2338 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2341 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2344 pr_debug("ep %p status %d error %d\n", ep,
2345 rpl->status, status2errno(rpl->status));
2346 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2347 c4iw_put_ep(&ep->com);
2352 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2354 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2355 unsigned int stid = GET_TID(rpl);
2356 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2359 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2362 pr_debug("ep %p\n", ep);
2363 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2364 c4iw_put_ep(&ep->com);
2369 static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2370 struct cpl_pass_accept_req *req)
2372 struct cpl_pass_accept_rpl *rpl;
2373 unsigned int mtu_idx;
2377 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2379 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
2381 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2382 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2383 enable_tcp_timestamps && req->tcpopt.tstamp,
2384 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
2385 wscale = cxgb_compute_wscale(rcv_win);
2388 * Specify the largest window that will fit in opt0. The
2389 * remainder will be specified in the rx_data_ack.
2391 win = ep->rcv_win >> 10;
2392 if (win > RCV_BUFSIZ_M)
2394 opt0 = (nocong ? NO_CONG_F : 0) |
2397 WND_SCALE_V(wscale) |
2398 MSS_IDX_V(mtu_idx) |
2399 L2T_IDX_V(ep->l2t->idx) |
2400 TX_CHAN_V(ep->tx_chan) |
2401 SMAC_SEL_V(ep->smac_idx) |
2402 DSCP_V(ep->tos >> 2) |
2403 ULP_MODE_V(ULP_MODE_TCPDDP) |
2405 opt2 = RX_CHANNEL_V(0) |
2406 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
2408 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2409 opt2 |= TSTAMPS_EN_F;
2410 if (enable_tcp_sack && req->tcpopt.sack)
2412 if (wscale && enable_tcp_window_scaling)
2413 opt2 |= WND_SCALE_EN_F;
2415 const struct tcphdr *tcph;
2416 u32 hlen = ntohl(req->hdr_len);
2418 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2419 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2422 tcph = (const void *)(req + 1) +
2423 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
2424 if (tcph->ece && tcph->cwr)
2425 opt2 |= CCTRL_ECN_V(1);
2430 if (!is_t4(adapter_type)) {
2431 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2433 INIT_TP_WR(rpl5, ep->hwtid);
2435 skb_trim(skb, sizeof(*rpl));
2436 INIT_TP_WR(rpl, ep->hwtid);
2438 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2441 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
2442 u32 isn = (prandom_u32() & ~7UL) - 1;
2443 opt2 |= T5_OPT_2_VALID_F;
2444 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2447 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2450 rpl5->iss = cpu_to_be32(isn);
2451 pr_debug("iss %u\n", be32_to_cpu(rpl5->iss));
2454 rpl->opt0 = cpu_to_be64(opt0);
2455 rpl->opt2 = cpu_to_be32(opt2);
2456 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2457 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
2459 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2462 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2464 pr_debug("c4iw_dev %p tid %u\n", dev, hwtid);
2465 skb_trim(skb, sizeof(struct cpl_tid_release));
2466 release_tid(&dev->rdev, hwtid, skb);
2470 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2472 struct c4iw_ep *child_ep = NULL, *parent_ep;
2473 struct cpl_pass_accept_req *req = cplhdr(skb);
2474 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
2475 struct tid_info *t = dev->rdev.lldi.tids;
2476 unsigned int hwtid = GET_TID(req);
2477 struct dst_entry *dst;
2478 __u8 local_ip[16], peer_ip[16];
2479 __be16 local_port, peer_port;
2480 struct sockaddr_in6 *sin6;
2482 u16 peer_mss = ntohs(req->tcpopt.mss);
2484 unsigned short hdrs;
2485 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
2487 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
2489 pr_err("%s connect request on invalid stid %d\n",
2494 if (state_read(&parent_ep->com) != LISTEN) {
2495 pr_err("%s - listening ep not in LISTEN\n", __func__);
2499 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2500 &iptype, local_ip, peer_ip, &local_port, &peer_port);
2502 /* Find output route */
2504 pr_debug("parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2506 local_ip, peer_ip, ntohs(local_port),
2507 ntohs(peer_port), peer_mss);
2508 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2509 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2510 local_port, peer_port, tos);
2512 pr_debug("parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2514 local_ip, peer_ip, ntohs(local_port),
2515 ntohs(peer_port), peer_mss);
2516 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2517 local_ip, peer_ip, local_port, peer_port,
2518 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2519 ((struct sockaddr_in6 *)
2520 &parent_ep->com.local_addr)->sin6_scope_id);
2523 pr_err("%s - failed to find dst entry!\n", __func__);
2527 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2529 pr_err("%s - failed to allocate ep entry!\n", __func__);
2534 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2535 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
2537 pr_err("%s - failed to allocate l2t entry!\n", __func__);
2543 hdrs = ((iptype == 4) ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)) +
2544 sizeof(struct tcphdr) +
2545 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2546 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2547 child_ep->mtu = peer_mss + hdrs;
2549 skb_queue_head_init(&child_ep->com.ep_skb_list);
2550 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2553 state_set(&child_ep->com, CONNECTING);
2554 child_ep->com.dev = dev;
2555 child_ep->com.cm_id = NULL;
2558 struct sockaddr_in *sin = (struct sockaddr_in *)
2559 &child_ep->com.local_addr;
2561 sin->sin_family = AF_INET;
2562 sin->sin_port = local_port;
2563 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2565 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2566 sin->sin_family = AF_INET;
2567 sin->sin_port = ((struct sockaddr_in *)
2568 &parent_ep->com.local_addr)->sin_port;
2569 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2571 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2572 sin->sin_family = AF_INET;
2573 sin->sin_port = peer_port;
2574 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2576 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2577 sin6->sin6_family = PF_INET6;
2578 sin6->sin6_port = local_port;
2579 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2581 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2582 sin6->sin6_family = PF_INET6;
2583 sin6->sin6_port = ((struct sockaddr_in6 *)
2584 &parent_ep->com.local_addr)->sin6_port;
2585 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2587 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2588 sin6->sin6_family = PF_INET6;
2589 sin6->sin6_port = peer_port;
2590 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2593 c4iw_get_ep(&parent_ep->com);
2594 child_ep->parent_ep = parent_ep;
2595 child_ep->tos = tos;
2596 child_ep->dst = dst;
2597 child_ep->hwtid = hwtid;
2599 pr_debug("tx_chan %u smac_idx %u rss_qid %u\n",
2600 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2602 timer_setup(&child_ep->timer, ep_timeout, 0);
2603 cxgb4_insert_tid(t, child_ep, hwtid,
2604 child_ep->com.local_addr.ss_family);
2605 insert_ep_tid(child_ep);
2606 if (accept_cr(child_ep, skb, req)) {
2607 c4iw_put_ep(&parent_ep->com);
2608 release_ep_resources(child_ep);
2610 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2613 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2614 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2615 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2619 c4iw_put_ep(&child_ep->com);
2621 reject_cr(dev, hwtid, skb);
2624 c4iw_put_ep(&parent_ep->com);
2628 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2631 struct cpl_pass_establish *req = cplhdr(skb);
2632 unsigned int tid = GET_TID(req);
2634 u16 tcp_opt = ntohs(req->tcp_opt);
2636 ep = get_ep_from_tid(dev, tid);
2637 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2638 ep->snd_seq = be32_to_cpu(req->snd_isn);
2639 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2640 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
2642 pr_debug("ep %p hwtid %u tcp_opt 0x%02x\n", ep, tid, tcp_opt);
2644 set_emss(ep, tcp_opt);
2646 dst_confirm(ep->dst);
2647 mutex_lock(&ep->com.mutex);
2648 ep->com.state = MPA_REQ_WAIT;
2650 set_bit(PASS_ESTAB, &ep->com.history);
2651 ret = send_flowc(ep);
2652 mutex_unlock(&ep->com.mutex);
2654 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
2655 c4iw_put_ep(&ep->com);
2660 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2662 struct cpl_peer_close *hdr = cplhdr(skb);
2664 struct c4iw_qp_attributes attrs;
2667 unsigned int tid = GET_TID(hdr);
2670 ep = get_ep_from_tid(dev, tid);
2674 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2675 dst_confirm(ep->dst);
2677 set_bit(PEER_CLOSE, &ep->com.history);
2678 mutex_lock(&ep->com.mutex);
2679 switch (ep->com.state) {
2681 __state_set(&ep->com, CLOSING);
2684 __state_set(&ep->com, CLOSING);
2685 connect_reply_upcall(ep, -ECONNRESET);
2690 * We're gonna mark this puppy DEAD, but keep
2691 * the reference on it until the ULP accepts or
2692 * rejects the CR. Also wake up anyone waiting
2693 * in rdma connection migration (see c4iw_accept_cr()).
2695 __state_set(&ep->com, CLOSING);
2696 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2697 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2700 __state_set(&ep->com, CLOSING);
2701 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2702 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2706 __state_set(&ep->com, CLOSING);
2707 attrs.next_state = C4IW_QP_STATE_CLOSING;
2708 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2709 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2710 if (ret != -ECONNRESET) {
2711 peer_close_upcall(ep);
2719 __state_set(&ep->com, MORIBUND);
2723 (void)stop_ep_timer(ep);
2724 if (ep->com.cm_id && ep->com.qp) {
2725 attrs.next_state = C4IW_QP_STATE_IDLE;
2726 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2727 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2729 close_complete_upcall(ep, 0);
2730 __state_set(&ep->com, DEAD);
2738 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2740 mutex_unlock(&ep->com.mutex);
2742 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2744 release_ep_resources(ep);
2745 c4iw_put_ep(&ep->com);
2749 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2751 struct cpl_abort_req_rss6 *req = cplhdr(skb);
2753 struct sk_buff *rpl_skb;
2754 struct c4iw_qp_attributes attrs;
2757 unsigned int tid = GET_TID(req);
2760 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
2762 ep = get_ep_from_tid(dev, tid);
2766 status = ABORT_RSS_STATUS_G(be32_to_cpu(req->srqidx_status));
2768 if (cxgb_is_neg_adv(status)) {
2769 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
2770 ep->hwtid, status, neg_adv_str(status));
2771 ep->stats.abort_neg_adv++;
2772 mutex_lock(&dev->rdev.stats.lock);
2773 dev->rdev.stats.neg_adv++;
2774 mutex_unlock(&dev->rdev.stats.lock);
2778 complete_cached_srq_buffers(ep, req->srqidx_status);
2780 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid,
2782 set_bit(PEER_ABORT, &ep->com.history);
2785 * Wake up any threads in rdma_init() or rdma_fini().
2786 * However, this is not needed if com state is just
2789 if (ep->com.state != MPA_REQ_SENT)
2790 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2792 mutex_lock(&ep->com.mutex);
2793 switch (ep->com.state) {
2795 c4iw_put_ep(&ep->parent_ep->com);
2798 (void)stop_ep_timer(ep);
2801 (void)stop_ep_timer(ep);
2802 if (status != CPL_ERR_CONN_RESET || mpa_rev == 1 ||
2803 (mpa_rev == 2 && ep->tried_with_mpa_v1))
2804 connect_reply_upcall(ep, -ECONNRESET);
2807 * we just don't send notification upwards because we
2808 * want to retry with mpa_v1 without upper layers even
2811 * do some housekeeping so as to re-initiate the
2814 pr_info("%s: mpa_rev=%d. Retrying with mpav1\n",
2816 ep->retry_with_mpa_v1 = 1;
2828 if (ep->com.cm_id && ep->com.qp) {
2829 attrs.next_state = C4IW_QP_STATE_ERROR;
2830 ret = c4iw_modify_qp(ep->com.qp->rhp,
2831 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2834 pr_err("%s - qp <- error failed!\n", __func__);
2836 peer_abort_upcall(ep);
2841 pr_warn("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2842 mutex_unlock(&ep->com.mutex);
2845 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2848 dst_confirm(ep->dst);
2849 if (ep->com.state != ABORTING) {
2850 __state_set(&ep->com, DEAD);
2851 /* we don't release if we want to retry with mpa_v1 */
2852 if (!ep->retry_with_mpa_v1)
2855 mutex_unlock(&ep->com.mutex);
2857 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2858 if (WARN_ON(!rpl_skb)) {
2863 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2865 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2868 release_ep_resources(ep);
2869 else if (ep->retry_with_mpa_v1) {
2870 if (ep->com.remote_addr.ss_family == AF_INET6) {
2871 struct sockaddr_in6 *sin6 =
2872 (struct sockaddr_in6 *)
2873 &ep->com.local_addr;
2875 ep->com.dev->rdev.lldi.ports[0],
2876 (const u32 *)&sin6->sin6_addr.s6_addr,
2879 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2880 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
2881 ep->com.local_addr.ss_family);
2882 dst_release(ep->dst);
2883 cxgb4_l2t_release(ep->l2t);
2888 c4iw_put_ep(&ep->com);
2889 /* Dereferencing ep, referenced in peer_abort_intr() */
2890 c4iw_put_ep(&ep->com);
2894 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2897 struct c4iw_qp_attributes attrs;
2898 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2900 unsigned int tid = GET_TID(rpl);
2902 ep = get_ep_from_tid(dev, tid);
2906 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2908 /* The cm_id may be null if we failed to connect */
2909 mutex_lock(&ep->com.mutex);
2910 set_bit(CLOSE_CON_RPL, &ep->com.history);
2911 switch (ep->com.state) {
2913 __state_set(&ep->com, MORIBUND);
2916 (void)stop_ep_timer(ep);
2917 if ((ep->com.cm_id) && (ep->com.qp)) {
2918 attrs.next_state = C4IW_QP_STATE_IDLE;
2919 c4iw_modify_qp(ep->com.qp->rhp,
2921 C4IW_QP_ATTR_NEXT_STATE,
2924 close_complete_upcall(ep, 0);
2925 __state_set(&ep->com, DEAD);
2932 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2935 mutex_unlock(&ep->com.mutex);
2937 release_ep_resources(ep);
2938 c4iw_put_ep(&ep->com);
2942 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2944 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2945 unsigned int tid = GET_TID(rpl);
2947 struct c4iw_qp_attributes attrs;
2949 ep = get_ep_from_tid(dev, tid);
2953 pr_warn("TERM received tid %u qpid %u\n", tid,
2954 ep->com.qp->wq.sq.qid);
2955 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2956 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2957 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2960 c4iw_put_ep(&ep->com);
2962 pr_warn("TERM received tid %u no ep/qp\n", tid);
2968 * Upcall from the adapter indicating data has been transmitted.
2969 * For us its just the single MPA request or reply. We can now free
2970 * the skb holding the mpa message.
2972 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2975 struct cpl_fw4_ack *hdr = cplhdr(skb);
2976 u8 credits = hdr->credits;
2977 unsigned int tid = GET_TID(hdr);
2980 ep = get_ep_from_tid(dev, tid);
2983 pr_debug("ep %p tid %u credits %u\n",
2984 ep, ep->hwtid, credits);
2986 pr_debug("0 credit ack ep %p tid %u state %u\n",
2987 ep, ep->hwtid, state_read(&ep->com));
2991 dst_confirm(ep->dst);
2993 pr_debug("last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
2994 ep, ep->hwtid, state_read(&ep->com),
2995 ep->mpa_attr.initiator ? 1 : 0);
2996 mutex_lock(&ep->com.mutex);
2997 kfree_skb(ep->mpa_skb);
2999 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3001 mutex_unlock(&ep->com.mutex);
3004 c4iw_put_ep(&ep->com);
3008 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3011 struct c4iw_ep *ep = to_ep(cm_id);
3013 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3015 mutex_lock(&ep->com.mutex);
3016 if (ep->com.state != MPA_REQ_RCVD) {
3017 mutex_unlock(&ep->com.mutex);
3018 c4iw_put_ep(&ep->com);
3021 set_bit(ULP_REJECT, &ep->com.history);
3025 abort = send_mpa_reject(ep, pdata, pdata_len);
3026 mutex_unlock(&ep->com.mutex);
3029 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
3030 c4iw_put_ep(&ep->com);
3034 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3037 struct c4iw_qp_attributes attrs;
3038 enum c4iw_qp_attr_mask mask;
3039 struct c4iw_ep *ep = to_ep(cm_id);
3040 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3041 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
3044 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3046 mutex_lock(&ep->com.mutex);
3047 if (ep->com.state != MPA_REQ_RCVD) {
3057 set_bit(ULP_ACCEPT, &ep->com.history);
3058 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3059 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
3064 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3065 if (conn_param->ord > ep->ird) {
3066 if (RELAXED_IRD_NEGOTIATION) {
3067 conn_param->ord = ep->ird;
3069 ep->ird = conn_param->ird;
3070 ep->ord = conn_param->ord;
3071 send_mpa_reject(ep, conn_param->private_data,
3072 conn_param->private_data_len);
3077 if (conn_param->ird < ep->ord) {
3078 if (RELAXED_IRD_NEGOTIATION &&
3079 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3080 conn_param->ird = ep->ord;
3087 ep->ird = conn_param->ird;
3088 ep->ord = conn_param->ord;
3090 if (ep->mpa_attr.version == 1) {
3091 if (peer2peer && ep->ird == 0)
3095 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
3096 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
3100 pr_debug("ird %d ord %d\n", ep->ird, ep->ord);
3102 ep->com.cm_id = cm_id;
3103 ref_cm_id(&ep->com);
3107 /* bind QP to EP and move to RTS */
3108 attrs.mpa_attr = ep->mpa_attr;
3109 attrs.max_ird = ep->ird;
3110 attrs.max_ord = ep->ord;
3111 attrs.llp_stream_handle = ep;
3112 attrs.next_state = C4IW_QP_STATE_RTS;
3114 /* bind QP and TID with INIT_WR */
3115 mask = C4IW_QP_ATTR_NEXT_STATE |
3116 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3117 C4IW_QP_ATTR_MPA_ATTR |
3118 C4IW_QP_ATTR_MAX_IRD |
3119 C4IW_QP_ATTR_MAX_ORD;
3121 err = c4iw_modify_qp(ep->com.qp->rhp,
3122 ep->com.qp, mask, &attrs, 1);
3124 goto err_deref_cm_id;
3126 set_bit(STOP_MPA_TIMER, &ep->com.flags);
3127 err = send_mpa_reply(ep, conn_param->private_data,
3128 conn_param->private_data_len);
3130 goto err_deref_cm_id;
3132 __state_set(&ep->com, FPDU_MODE);
3133 established_upcall(ep);
3134 mutex_unlock(&ep->com.mutex);
3135 c4iw_put_ep(&ep->com);
3138 deref_cm_id(&ep->com);
3142 mutex_unlock(&ep->com.mutex);
3144 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
3145 c4iw_put_ep(&ep->com);
3149 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3151 struct in_device *ind;
3153 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3154 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
3156 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3158 return -EADDRNOTAVAIL;
3159 for_primary_ifa(ind) {
3160 laddr->sin_addr.s_addr = ifa->ifa_address;
3161 raddr->sin_addr.s_addr = ifa->ifa_address;
3167 return found ? 0 : -EADDRNOTAVAIL;
3170 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3171 unsigned char banned_flags)
3173 struct inet6_dev *idev;
3174 int err = -EADDRNOTAVAIL;
3177 idev = __in6_dev_get(dev);
3179 struct inet6_ifaddr *ifp;
3181 read_lock_bh(&idev->lock);
3182 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3183 if (ifp->scope == IFA_LINK &&
3184 !(ifp->flags & banned_flags)) {
3185 memcpy(addr, &ifp->addr, 16);
3190 read_unlock_bh(&idev->lock);
3196 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3198 struct in6_addr uninitialized_var(addr);
3199 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3200 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
3202 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
3203 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3204 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3207 return -EADDRNOTAVAIL;
3210 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3212 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3215 struct sockaddr_in *laddr;
3216 struct sockaddr_in *raddr;
3217 struct sockaddr_in6 *laddr6;
3218 struct sockaddr_in6 *raddr6;
3222 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3223 (conn_param->ird > cur_max_read_depth(dev))) {
3227 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3229 pr_err("%s - cannot alloc ep\n", __func__);
3234 skb_queue_head_init(&ep->com.ep_skb_list);
3235 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3240 timer_setup(&ep->timer, ep_timeout, 0);
3241 ep->plen = conn_param->private_data_len;
3243 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3244 conn_param->private_data, ep->plen);
3245 ep->ird = conn_param->ird;
3246 ep->ord = conn_param->ord;
3248 if (peer2peer && ep->ord == 0)
3251 ep->com.cm_id = cm_id;
3252 ref_cm_id(&ep->com);
3253 cm_id->provider_data = ep;
3255 ep->com.qp = get_qhp(dev, conn_param->qpn);
3257 pr_warn("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3262 pr_debug("qpn 0x%x qp %p cm_id %p\n", conn_param->qpn,
3266 * Allocate an active TID to initiate a TCP connection.
3268 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3269 if (ep->atid == -1) {
3270 pr_err("%s - cannot alloc atid\n", __func__);
3274 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
3276 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3277 sizeof(ep->com.local_addr));
3278 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
3279 sizeof(ep->com.remote_addr));
3281 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3282 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3283 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3284 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
3286 if (cm_id->m_remote_addr.ss_family == AF_INET) {
3288 ra = (__u8 *)&raddr->sin_addr;
3291 * Handle loopback requests to INADDR_ANY.
3293 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
3294 err = pick_local_ipaddrs(dev, cm_id);
3300 pr_debug("saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3301 &laddr->sin_addr, ntohs(laddr->sin_port),
3302 ra, ntohs(raddr->sin_port));
3303 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3304 laddr->sin_addr.s_addr,
3305 raddr->sin_addr.s_addr,
3307 raddr->sin_port, cm_id->tos);
3310 ra = (__u8 *)&raddr6->sin6_addr;
3313 * Handle loopback requests to INADDR_ANY.
3315 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3316 err = pick_local_ip6addrs(dev, cm_id);
3322 pr_debug("saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3323 laddr6->sin6_addr.s6_addr,
3324 ntohs(laddr6->sin6_port),
3325 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3326 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3327 laddr6->sin6_addr.s6_addr,
3328 raddr6->sin6_addr.s6_addr,
3330 raddr6->sin6_port, cm_id->tos,
3331 raddr6->sin6_scope_id);
3334 pr_err("%s - cannot find route\n", __func__);
3335 err = -EHOSTUNREACH;
3339 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3340 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
3342 pr_err("%s - cannot alloc l2e\n", __func__);
3346 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3347 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3350 state_set(&ep->com, CONNECTING);
3351 ep->tos = cm_id->tos;
3353 /* send connect request to rnic */
3354 err = send_connect(ep);
3358 cxgb4_l2t_release(ep->l2t);
3360 dst_release(ep->dst);
3362 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3363 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3365 skb_queue_purge(&ep->com.ep_skb_list);
3366 deref_cm_id(&ep->com);
3368 c4iw_put_ep(&ep->com);
3373 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3376 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3377 &ep->com.local_addr;
3379 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3380 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3381 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3385 c4iw_init_wr_wait(ep->com.wr_waitp);
3386 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3387 ep->stid, &sin6->sin6_addr,
3389 ep->com.dev->rdev.lldi.rxq_ids[0]);
3391 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3395 err = net_xmit_errno(err);
3397 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3398 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3399 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3401 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3406 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3409 struct sockaddr_in *sin = (struct sockaddr_in *)
3410 &ep->com.local_addr;
3412 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3414 err = cxgb4_create_server_filter(
3415 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3416 sin->sin_addr.s_addr, sin->sin_port, 0,
3417 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3418 if (err == -EBUSY) {
3419 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3423 set_current_state(TASK_UNINTERRUPTIBLE);
3424 schedule_timeout(usecs_to_jiffies(100));
3426 } while (err == -EBUSY);
3428 c4iw_init_wr_wait(ep->com.wr_waitp);
3429 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3430 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3431 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3433 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3437 err = net_xmit_errno(err);
3440 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3442 &sin->sin_addr, ntohs(sin->sin_port));
3446 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3449 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3450 struct c4iw_listen_ep *ep;
3454 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3456 pr_err("%s - cannot alloc ep\n", __func__);
3460 skb_queue_head_init(&ep->com.ep_skb_list);
3461 pr_debug("ep %p\n", ep);
3462 ep->com.cm_id = cm_id;
3463 ref_cm_id(&ep->com);
3465 ep->backlog = backlog;
3466 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3467 sizeof(ep->com.local_addr));
3470 * Allocate a server TID.
3472 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3473 ep->com.local_addr.ss_family == AF_INET)
3474 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3475 cm_id->m_local_addr.ss_family, ep);
3477 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3478 cm_id->m_local_addr.ss_family, ep);
3480 if (ep->stid == -1) {
3481 pr_err("%s - cannot alloc stid\n", __func__);
3485 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3487 state_set(&ep->com, LISTEN);
3488 if (ep->com.local_addr.ss_family == AF_INET)
3489 err = create_server4(dev, ep);
3491 err = create_server6(dev, ep);
3493 cm_id->provider_data = ep;
3496 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3497 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3498 ep->com.local_addr.ss_family);
3500 deref_cm_id(&ep->com);
3501 c4iw_put_ep(&ep->com);
3507 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3510 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3512 pr_debug("ep %p\n", ep);
3515 state_set(&ep->com, DEAD);
3516 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3517 ep->com.local_addr.ss_family == AF_INET) {
3518 err = cxgb4_remove_server_filter(
3519 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3520 ep->com.dev->rdev.lldi.rxq_ids[0], false);
3522 struct sockaddr_in6 *sin6;
3523 c4iw_init_wr_wait(ep->com.wr_waitp);
3524 err = cxgb4_remove_server(
3525 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3526 ep->com.dev->rdev.lldi.rxq_ids[0],
3527 ep->com.local_addr.ss_family == AF_INET6);
3530 err = c4iw_wait_for_reply(&ep->com.dev->rdev, ep->com.wr_waitp,
3532 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3533 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3534 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3536 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3537 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3538 ep->com.local_addr.ss_family);
3540 deref_cm_id(&ep->com);
3541 c4iw_put_ep(&ep->com);
3545 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3550 struct c4iw_rdev *rdev;
3552 mutex_lock(&ep->com.mutex);
3554 pr_debug("ep %p state %s, abrupt %d\n", ep,
3555 states[ep->com.state], abrupt);
3558 * Ref the ep here in case we have fatal errors causing the
3559 * ep to be released and freed.
3561 c4iw_get_ep(&ep->com);
3563 rdev = &ep->com.dev->rdev;
3564 if (c4iw_fatal_error(rdev)) {
3566 close_complete_upcall(ep, -EIO);
3567 ep->com.state = DEAD;
3569 switch (ep->com.state) {
3578 ep->com.state = ABORTING;
3580 ep->com.state = CLOSING;
3583 * if we close before we see the fw4_ack() then we fix
3584 * up the timer state since we're reusing it.
3587 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3588 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3593 set_bit(CLOSE_SENT, &ep->com.flags);
3596 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3599 (void)stop_ep_timer(ep);
3600 ep->com.state = ABORTING;
3602 ep->com.state = MORIBUND;
3608 pr_debug("ignoring disconnect ep %p state %u\n",
3612 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
3618 set_bit(EP_DISC_ABORT, &ep->com.history);
3619 ret = send_abort(ep);
3621 set_bit(EP_DISC_CLOSE, &ep->com.history);
3622 ret = send_halfclose(ep);
3625 set_bit(EP_DISC_FAIL, &ep->com.history);
3628 close_complete_upcall(ep, -EIO);
3631 struct c4iw_qp_attributes attrs;
3633 attrs.next_state = C4IW_QP_STATE_ERROR;
3634 ret = c4iw_modify_qp(ep->com.qp->rhp,
3636 C4IW_QP_ATTR_NEXT_STATE,
3639 pr_err("%s - qp <- error failed!\n",
3645 mutex_unlock(&ep->com.mutex);
3646 c4iw_put_ep(&ep->com);
3648 release_ep_resources(ep);
3652 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3653 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3656 int atid = be32_to_cpu(req->tid);
3658 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3659 (__force u32) req->tid);
3663 switch (req->retval) {
3665 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3666 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3667 send_fw_act_open_req(ep, atid);
3672 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3673 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3674 send_fw_act_open_req(ep, atid);
3679 pr_info("%s unexpected ofld conn wr retval %d\n",
3680 __func__, req->retval);
3683 pr_err("active ofld_connect_wr failure %d atid %d\n",
3685 mutex_lock(&dev->rdev.stats.lock);
3686 dev->rdev.stats.act_ofld_conn_fails++;
3687 mutex_unlock(&dev->rdev.stats.lock);
3688 connect_reply_upcall(ep, status2errno(req->retval));
3689 state_set(&ep->com, DEAD);
3690 if (ep->com.remote_addr.ss_family == AF_INET6) {
3691 struct sockaddr_in6 *sin6 =
3692 (struct sockaddr_in6 *)&ep->com.local_addr;
3693 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3694 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3696 remove_handle(dev, &dev->atid_idr, atid);
3697 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3698 dst_release(ep->dst);
3699 cxgb4_l2t_release(ep->l2t);
3700 c4iw_put_ep(&ep->com);
3703 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3704 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3706 struct sk_buff *rpl_skb;
3707 struct cpl_pass_accept_req *cpl;
3710 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3712 pr_err("%s passive open failure %d\n", __func__, req->retval);
3713 mutex_lock(&dev->rdev.stats.lock);
3714 dev->rdev.stats.pas_ofld_conn_fails++;
3715 mutex_unlock(&dev->rdev.stats.lock);
3718 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3719 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3720 (__force u32) htonl(
3721 (__force u32) req->tid)));
3722 ret = pass_accept_req(dev, rpl_skb);
3729 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3731 struct cpl_fw6_msg *rpl = cplhdr(skb);
3732 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3734 switch (rpl->type) {
3736 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3738 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3739 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3740 switch (req->t_state) {
3742 active_ofld_conn_reply(dev, skb, req);
3745 passive_ofld_conn_reply(dev, skb, req);
3748 pr_err("%s unexpected ofld conn wr state %d\n",
3749 __func__, req->t_state);
3757 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3760 __be16 hdr_len, vlantag, len;
3762 int tcp_hdr_len, ip_hdr_len;
3764 struct cpl_rx_pkt *cpl = cplhdr(skb);
3765 struct cpl_pass_accept_req *req;
3766 struct tcp_options_received tmp_opt;
3767 struct c4iw_dev *dev;
3768 enum chip_type type;
3770 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3771 /* Store values from cpl_rx_pkt in temporary location. */
3772 vlantag = cpl->vlan;
3774 l2info = cpl->l2info;
3775 hdr_len = cpl->hdr_len;
3778 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3781 * We need to parse the TCP options from SYN packet.
3782 * to generate cpl_pass_accept_req.
3784 memset(&tmp_opt, 0, sizeof(tmp_opt));
3785 tcp_clear_options(&tmp_opt);
3786 tcp_parse_options(&init_net, skb, &tmp_opt, 0, NULL);
3788 req = __skb_push(skb, sizeof(*req));
3789 memset(req, 0, sizeof(*req));
3790 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3791 SYN_MAC_IDX_V(RX_MACIDX_G(
3792 be32_to_cpu(l2info))) |
3794 type = dev->rdev.lldi.adapter_type;
3795 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3796 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3798 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3799 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3800 eth_hdr_len = is_t4(type) ?
3801 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3802 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3803 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3804 IP_HDR_LEN_V(ip_hdr_len) |
3805 ETH_HDR_LEN_V(eth_hdr_len));
3806 } else { /* T6 and later */
3807 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3808 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3809 T6_IP_HDR_LEN_V(ip_hdr_len) |
3810 T6_ETH_HDR_LEN_V(eth_hdr_len));
3812 req->vlan = vlantag;
3814 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3815 PASS_OPEN_TOS_V(tos));
3816 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3817 if (tmp_opt.wscale_ok)
3818 req->tcpopt.wsf = tmp_opt.snd_wscale;
3819 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3820 if (tmp_opt.sack_ok)
3821 req->tcpopt.sack = 1;
3822 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3826 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3827 __be32 laddr, __be16 lport,
3828 __be32 raddr, __be16 rport,
3829 u32 rcv_isn, u32 filter, u16 window,
3830 u32 rss_qid, u8 port_id)
3832 struct sk_buff *req_skb;
3833 struct fw_ofld_connection_wr *req;
3834 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3837 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3840 req = __skb_put_zero(req_skb, sizeof(*req));
3841 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
3842 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
3843 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
3844 req->le.filter = (__force __be32) filter;
3845 req->le.lport = lport;
3846 req->le.pport = rport;
3847 req->le.u.ipv4.lip = laddr;
3848 req->le.u.ipv4.pip = raddr;
3849 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3850 req->tcb.rcv_adv = htons(window);
3851 req->tcb.t_state_to_astid =
3852 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3853 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3854 FW_OFLD_CONNECTION_WR_ASTID_V(
3855 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
3858 * We store the qid in opt2 which will be used by the firmware
3859 * to send us the wr response.
3861 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
3864 * We initialize the MSS index in TCB to 0xF.
3865 * So that when driver sends cpl_pass_accept_rpl
3866 * TCB picks up the correct value. If this was 0
3867 * TP will ignore any value > 0 for MSS index.
3869 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
3870 req->cookie = (uintptr_t)skb;
3872 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3873 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3875 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3883 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3884 * messages when a filter is being used instead of server to
3885 * redirect a syn packet. When packets hit filter they are redirected
3886 * to the offload queue and driver tries to establish the connection
3887 * using firmware work request.
3889 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3892 unsigned int filter;
3893 struct ethhdr *eh = NULL;
3894 struct vlan_ethhdr *vlan_eh = NULL;
3896 struct tcphdr *tcph;
3897 struct rss_header *rss = (void *)skb->data;
3898 struct cpl_rx_pkt *cpl = (void *)skb->data;
3899 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3900 struct l2t_entry *e;
3901 struct dst_entry *dst;
3902 struct c4iw_ep *lep = NULL;
3904 struct port_info *pi;
3905 struct net_device *pdev;
3906 u16 rss_qid, eth_hdr_len;
3908 struct neighbour *neigh;
3910 /* Drop all non-SYN packets */
3911 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
3915 * Drop all packets which did not hit the filter.
3916 * Unlikely to happen.
3918 if (!(rss->filter_hit && rss->filter_tid))
3922 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3924 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3926 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
3928 pr_warn("%s connect request on invalid stid %d\n",
3933 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3935 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3938 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3941 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3944 pr_err("T%d Chip is not supported\n",
3945 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3949 if (eth_hdr_len == ETH_HLEN) {
3950 eh = (struct ethhdr *)(req + 1);
3951 iph = (struct iphdr *)(eh + 1);
3953 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3954 iph = (struct iphdr *)(vlan_eh + 1);
3955 skb->vlan_tci = ntohs(cpl->vlan);
3958 if (iph->version != 0x4)
3961 tcph = (struct tcphdr *)(iph + 1);
3962 skb_set_network_header(skb, (void *)iph - (void *)rss);
3963 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3966 pr_debug("lip 0x%x lport %u pip 0x%x pport %u tos %d\n",
3967 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3968 ntohs(tcph->source), iph->tos);
3970 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3971 iph->daddr, iph->saddr, tcph->dest,
3972 tcph->source, iph->tos);
3974 pr_err("%s - failed to find dst entry!\n", __func__);
3977 neigh = dst_neigh_lookup_skb(dst, skb);
3980 pr_err("%s - failed to allocate neigh!\n", __func__);
3984 if (neigh->dev->flags & IFF_LOOPBACK) {
3985 pdev = ip_dev_find(&init_net, iph->daddr);
3986 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3988 pi = (struct port_info *)netdev_priv(pdev);
3991 pdev = get_real_dev(neigh->dev);
3992 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3994 pi = (struct port_info *)netdev_priv(pdev);
3996 neigh_release(neigh);
3998 pr_err("%s - failed to allocate l2t entry!\n",
4003 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4004 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
4005 window = (__force u16) htons((__force u16)tcph->window);
4007 /* Calcuate filter portion for LE region. */
4008 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4009 dev->rdev.lldi.ports[0],
4013 * Synthesize the cpl_pass_accept_req. We have everything except the
4014 * TID. Once firmware sends a reply with TID we update the TID field
4015 * in cpl and pass it through the regular cpl_pass_accept_req path.
4017 build_cpl_pass_accept_req(skb, stid, iph->tos);
4018 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4019 tcph->source, ntohl(tcph->seq), filter, window,
4020 rss_qid, pi->port_id);
4021 cxgb4_l2t_release(e);
4026 c4iw_put_ep(&lep->com);
4031 * These are the real handlers that are called from a
4034 static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
4035 [CPL_ACT_ESTABLISH] = act_establish,
4036 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4037 [CPL_RX_DATA] = rx_data,
4038 [CPL_ABORT_RPL_RSS] = abort_rpl,
4039 [CPL_ABORT_RPL] = abort_rpl,
4040 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4041 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4042 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4043 [CPL_PASS_ESTABLISH] = pass_establish,
4044 [CPL_PEER_CLOSE] = peer_close,
4045 [CPL_ABORT_REQ_RSS] = peer_abort,
4046 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4047 [CPL_RDMA_TERMINATE] = terminate,
4048 [CPL_FW4_ACK] = fw4_ack,
4049 [CPL_FW6_MSG] = deferred_fw6_msg,
4050 [CPL_RX_PKT] = rx_pkt,
4051 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4052 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
4055 static void process_timeout(struct c4iw_ep *ep)
4057 struct c4iw_qp_attributes attrs;
4060 mutex_lock(&ep->com.mutex);
4061 pr_debug("ep %p tid %u state %d\n", ep, ep->hwtid, ep->com.state);
4062 set_bit(TIMEDOUT, &ep->com.history);
4063 switch (ep->com.state) {
4065 connect_reply_upcall(ep, -ETIMEDOUT);
4074 if (ep->com.cm_id && ep->com.qp) {
4075 attrs.next_state = C4IW_QP_STATE_ERROR;
4076 c4iw_modify_qp(ep->com.qp->rhp,
4077 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4080 close_complete_upcall(ep, -ETIMEDOUT);
4086 * These states are expected if the ep timed out at the same
4087 * time as another thread was calling stop_ep_timer().
4088 * So we silently do nothing for these states.
4093 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
4094 __func__, ep, ep->hwtid, ep->com.state);
4097 mutex_unlock(&ep->com.mutex);
4099 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
4100 c4iw_put_ep(&ep->com);
4103 static void process_timedout_eps(void)
4107 spin_lock_irq(&timeout_lock);
4108 while (!list_empty(&timeout_list)) {
4109 struct list_head *tmp;
4111 tmp = timeout_list.next;
4115 spin_unlock_irq(&timeout_lock);
4116 ep = list_entry(tmp, struct c4iw_ep, entry);
4117 process_timeout(ep);
4118 spin_lock_irq(&timeout_lock);
4120 spin_unlock_irq(&timeout_lock);
4123 static void process_work(struct work_struct *work)
4125 struct sk_buff *skb = NULL;
4126 struct c4iw_dev *dev;
4127 struct cpl_act_establish *rpl;
4128 unsigned int opcode;
4131 process_timedout_eps();
4132 while ((skb = skb_dequeue(&rxq))) {
4134 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4135 opcode = rpl->ot.opcode;
4137 if (opcode >= ARRAY_SIZE(work_handlers) ||
4138 !work_handlers[opcode]) {
4139 pr_err("No handler for opcode 0x%x.\n", opcode);
4142 ret = work_handlers[opcode](dev, skb);
4146 process_timedout_eps();
4150 static DECLARE_WORK(skb_work, process_work);
4152 static void ep_timeout(struct timer_list *t)
4154 struct c4iw_ep *ep = from_timer(ep, t, timer);
4157 spin_lock(&timeout_lock);
4158 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
4160 * Only insert if it is not already on the list.
4162 if (!ep->entry.next) {
4163 list_add_tail(&ep->entry, &timeout_list);
4167 spin_unlock(&timeout_lock);
4169 queue_work(workq, &skb_work);
4173 * All the CM events are handled on a work queue to have a safe context.
4175 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4179 * Save dev in the skb->cb area.
4181 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4184 * Queue the skb and schedule the worker thread.
4186 skb_queue_tail(&rxq, skb);
4187 queue_work(workq, &skb_work);
4191 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4193 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4195 if (rpl->status != CPL_ERR_NONE) {
4196 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4197 rpl->status, GET_TID(rpl));
4203 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4205 struct cpl_fw6_msg *rpl = cplhdr(skb);
4206 struct c4iw_wr_wait *wr_waitp;
4209 pr_debug("type %u\n", rpl->type);
4211 switch (rpl->type) {
4212 case FW6_TYPE_WR_RPL:
4213 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
4214 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
4215 pr_debug("wr_waitp %p ret %u\n", wr_waitp, ret);
4217 c4iw_wake_up_deref(wr_waitp, ret ? -ret : 0);
4221 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
4225 pr_err("%s unexpected fw6 msg type %u\n",
4226 __func__, rpl->type);
4233 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4235 struct cpl_abort_req_rss *req = cplhdr(skb);
4237 unsigned int tid = GET_TID(req);
4239 ep = get_ep_from_tid(dev, tid);
4240 /* This EP will be dereferenced in peer_abort() */
4242 pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
4246 if (cxgb_is_neg_adv(req->status)) {
4247 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
4248 ep->hwtid, req->status,
4249 neg_adv_str(req->status));
4252 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid, ep->com.state);
4254 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
4261 * Most upcalls from the T4 Core go to sched() to
4262 * schedule the processing on a work queue.
4264 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4265 [CPL_ACT_ESTABLISH] = sched,
4266 [CPL_ACT_OPEN_RPL] = sched,
4267 [CPL_RX_DATA] = sched,
4268 [CPL_ABORT_RPL_RSS] = sched,
4269 [CPL_ABORT_RPL] = sched,
4270 [CPL_PASS_OPEN_RPL] = sched,
4271 [CPL_CLOSE_LISTSRV_RPL] = sched,
4272 [CPL_PASS_ACCEPT_REQ] = sched,
4273 [CPL_PASS_ESTABLISH] = sched,
4274 [CPL_PEER_CLOSE] = sched,
4275 [CPL_CLOSE_CON_RPL] = sched,
4276 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
4277 [CPL_RDMA_TERMINATE] = sched,
4278 [CPL_FW4_ACK] = sched,
4279 [CPL_SET_TCB_RPL] = set_tcb_rpl,
4280 [CPL_FW6_MSG] = fw6_msg,
4281 [CPL_RX_PKT] = sched
4284 int __init c4iw_cm_init(void)
4286 spin_lock_init(&timeout_lock);
4287 skb_queue_head_init(&rxq);
4289 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
4296 void c4iw_cm_term(void)
4298 WARN_ON(!list_empty(&timeout_list));
4299 flush_workqueue(workq);
4300 destroy_workqueue(workq);