2 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
50 #include <rdma/ib_addr.h>
52 #include <libcxgb_cm.h>
56 static char *states[] = {
73 module_param(nocong, int, 0644);
74 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
76 static int enable_ecn;
77 module_param(enable_ecn, int, 0644);
78 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
80 static int dack_mode = 1;
81 module_param(dack_mode, int, 0644);
82 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
84 uint c4iw_max_read_depth = 32;
85 module_param(c4iw_max_read_depth, int, 0644);
86 MODULE_PARM_DESC(c4iw_max_read_depth,
87 "Per-connection max ORD/IRD (default=32)");
89 static int enable_tcp_timestamps;
90 module_param(enable_tcp_timestamps, int, 0644);
91 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
93 static int enable_tcp_sack;
94 module_param(enable_tcp_sack, int, 0644);
95 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
97 static int enable_tcp_window_scaling = 1;
98 module_param(enable_tcp_window_scaling, int, 0644);
99 MODULE_PARM_DESC(enable_tcp_window_scaling,
100 "Enable tcp window scaling (default=1)");
102 static int peer2peer = 1;
103 module_param(peer2peer, int, 0644);
104 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
106 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
107 module_param(p2p_type, int, 0644);
108 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
109 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
111 static int ep_timeout_secs = 60;
112 module_param(ep_timeout_secs, int, 0644);
113 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
114 "in seconds (default=60)");
116 static int mpa_rev = 2;
117 module_param(mpa_rev, int, 0644);
118 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
119 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
120 " compliant (default=2)");
122 static int markers_enabled;
123 module_param(markers_enabled, int, 0644);
124 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
126 static int crc_enabled = 1;
127 module_param(crc_enabled, int, 0644);
128 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
130 static int rcv_win = 256 * 1024;
131 module_param(rcv_win, int, 0644);
132 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
134 static int snd_win = 128 * 1024;
135 module_param(snd_win, int, 0644);
136 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
138 static struct workqueue_struct *workq;
140 static struct sk_buff_head rxq;
142 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
143 static void ep_timeout(struct timer_list *t);
144 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
145 static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
147 static LIST_HEAD(timeout_list);
148 static spinlock_t timeout_lock;
150 static void deref_cm_id(struct c4iw_ep_common *epc)
152 epc->cm_id->rem_ref(epc->cm_id);
154 set_bit(CM_ID_DEREFED, &epc->history);
157 static void ref_cm_id(struct c4iw_ep_common *epc)
159 set_bit(CM_ID_REFED, &epc->history);
160 epc->cm_id->add_ref(epc->cm_id);
163 static void deref_qp(struct c4iw_ep *ep)
165 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
166 clear_bit(QP_REFERENCED, &ep->com.flags);
167 set_bit(QP_DEREFED, &ep->com.history);
170 static void ref_qp(struct c4iw_ep *ep)
172 set_bit(QP_REFERENCED, &ep->com.flags);
173 set_bit(QP_REFED, &ep->com.history);
174 c4iw_qp_add_ref(&ep->com.qp->ibqp);
177 static void start_ep_timer(struct c4iw_ep *ep)
179 pr_debug("ep %p\n", ep);
180 if (timer_pending(&ep->timer)) {
181 pr_err("%s timer already started! ep %p\n",
185 clear_bit(TIMEOUT, &ep->com.flags);
186 c4iw_get_ep(&ep->com);
187 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
188 add_timer(&ep->timer);
191 static int stop_ep_timer(struct c4iw_ep *ep)
193 pr_debug("ep %p stopping\n", ep);
194 del_timer_sync(&ep->timer);
195 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
196 c4iw_put_ep(&ep->com);
202 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
203 struct l2t_entry *l2e)
207 if (c4iw_fatal_error(rdev)) {
209 pr_err("%s - device in error state - dropping\n", __func__);
212 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
215 else if (error == NET_XMIT_DROP)
217 return error < 0 ? error : 0;
220 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
224 if (c4iw_fatal_error(rdev)) {
226 pr_err("%s - device in error state - dropping\n", __func__);
229 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
232 return error < 0 ? error : 0;
235 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
237 u32 len = roundup(sizeof(struct cpl_tid_release), 16);
239 skb = get_skb(skb, len, GFP_KERNEL);
243 cxgb_mk_tid_release(skb, len, hwtid, 0);
244 c4iw_ofld_send(rdev, skb);
248 static void set_emss(struct c4iw_ep *ep, u16 opt)
250 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
251 ((AF_INET == ep->com.remote_addr.ss_family) ?
252 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
253 sizeof(struct tcphdr);
255 if (TCPOPT_TSTAMP_G(opt))
256 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
260 pr_debug("Warning: misaligned mtu idx %u mss %u emss=%u\n",
261 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
262 pr_debug("mss_idx %u mss %u emss=%u\n", TCPOPT_MSS_G(opt), ep->mss,
266 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
268 enum c4iw_ep_state state;
270 mutex_lock(&epc->mutex);
272 mutex_unlock(&epc->mutex);
276 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
281 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
283 mutex_lock(&epc->mutex);
284 pr_debug("%s -> %s\n", states[epc->state], states[new]);
285 __state_set(epc, new);
286 mutex_unlock(&epc->mutex);
290 static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
296 len = roundup(sizeof(union cpl_wr_size), 16);
297 for (i = 0; i < size; i++) {
298 skb = alloc_skb(len, GFP_KERNEL);
301 skb_queue_tail(ep_skb_list, skb);
305 skb_queue_purge(ep_skb_list);
309 static void *alloc_ep(int size, gfp_t gfp)
311 struct c4iw_ep_common *epc;
313 epc = kzalloc(size, gfp);
315 epc->wr_waitp = c4iw_alloc_wr_wait(gfp);
316 if (!epc->wr_waitp) {
321 kref_init(&epc->kref);
322 mutex_init(&epc->mutex);
323 c4iw_init_wr_wait(epc->wr_waitp);
325 pr_debug("alloc ep %p\n", epc);
330 static void remove_ep_tid(struct c4iw_ep *ep)
334 spin_lock_irqsave(&ep->com.dev->lock, flags);
335 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
336 if (idr_is_empty(&ep->com.dev->hwtid_idr))
337 wake_up(&ep->com.dev->wait);
338 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
341 static void insert_ep_tid(struct c4iw_ep *ep)
345 spin_lock_irqsave(&ep->com.dev->lock, flags);
346 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
347 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
351 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
353 static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
358 spin_lock_irqsave(&dev->lock, flags);
359 ep = idr_find(&dev->hwtid_idr, tid);
361 c4iw_get_ep(&ep->com);
362 spin_unlock_irqrestore(&dev->lock, flags);
367 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
369 static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
372 struct c4iw_listen_ep *ep;
375 spin_lock_irqsave(&dev->lock, flags);
376 ep = idr_find(&dev->stid_idr, stid);
378 c4iw_get_ep(&ep->com);
379 spin_unlock_irqrestore(&dev->lock, flags);
383 void _c4iw_free_ep(struct kref *kref)
387 ep = container_of(kref, struct c4iw_ep, com.kref);
388 pr_debug("ep %p state %s\n", ep, states[ep->com.state]);
389 if (test_bit(QP_REFERENCED, &ep->com.flags))
391 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
392 if (ep->com.remote_addr.ss_family == AF_INET6) {
393 struct sockaddr_in6 *sin6 =
394 (struct sockaddr_in6 *)
398 ep->com.dev->rdev.lldi.ports[0],
399 (const u32 *)&sin6->sin6_addr.s6_addr,
402 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
403 ep->com.local_addr.ss_family);
404 dst_release(ep->dst);
405 cxgb4_l2t_release(ep->l2t);
406 kfree_skb(ep->mpa_skb);
408 if (!skb_queue_empty(&ep->com.ep_skb_list))
409 skb_queue_purge(&ep->com.ep_skb_list);
410 c4iw_put_wr_wait(ep->com.wr_waitp);
414 static void release_ep_resources(struct c4iw_ep *ep)
416 set_bit(RELEASE_RESOURCES, &ep->com.flags);
419 * If we have a hwtid, then remove it from the idr table
420 * so lookups will no longer find this endpoint. Otherwise
421 * we have a race where one thread finds the ep ptr just
422 * before the other thread is freeing the ep memory.
426 c4iw_put_ep(&ep->com);
429 static int status2errno(int status)
434 case CPL_ERR_CONN_RESET:
436 case CPL_ERR_ARP_MISS:
437 return -EHOSTUNREACH;
438 case CPL_ERR_CONN_TIMEDOUT:
440 case CPL_ERR_TCAM_FULL:
442 case CPL_ERR_CONN_EXIST:
450 * Try and reuse skbs already allocated...
452 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
454 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
457 skb_reset_transport_header(skb);
459 skb = alloc_skb(len, gfp);
461 t4_set_arp_err_handler(skb, NULL, NULL);
465 static struct net_device *get_real_dev(struct net_device *egress_dev)
467 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
470 static void arp_failure_discard(void *handle, struct sk_buff *skb)
472 pr_err("ARP failure\n");
476 static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
478 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
483 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
484 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
487 static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
491 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
492 release_ep_resources(ep);
497 static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
501 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
502 c4iw_put_ep(&ep->parent_ep->com);
503 release_ep_resources(ep);
509 * Fake up a special CPL opcode and call sched() so process_work() will call
510 * _put_ep_safe() in a safe context to free the ep resources. This is needed
511 * because ARP error handlers are called in an ATOMIC context, and
512 * _c4iw_free_ep() needs to block.
514 static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
517 struct cpl_act_establish *rpl = cplhdr(skb);
519 /* Set our special ARP_FAILURE opcode */
520 rpl->ot.opcode = cpl;
523 * Save ep in the skb->cb area, after where sched() will save the dev
526 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
527 sched(ep->com.dev, skb);
530 /* Handle an ARP failure for an accept */
531 static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
533 struct c4iw_ep *ep = handle;
535 pr_err("ARP failure during accept - tid %u - dropping connection\n",
538 __state_set(&ep->com, DEAD);
539 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
543 * Handle an ARP failure for an active open.
545 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
547 struct c4iw_ep *ep = handle;
549 pr_err("ARP failure during connect\n");
550 connect_reply_upcall(ep, -EHOSTUNREACH);
551 __state_set(&ep->com, DEAD);
552 if (ep->com.remote_addr.ss_family == AF_INET6) {
553 struct sockaddr_in6 *sin6 =
554 (struct sockaddr_in6 *)&ep->com.local_addr;
555 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
556 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
558 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
559 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
560 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
564 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
567 static void abort_arp_failure(void *handle, struct sk_buff *skb)
570 struct c4iw_ep *ep = handle;
571 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
572 struct cpl_abort_req *req = cplhdr(skb);
574 pr_debug("rdev %p\n", rdev);
575 req->cmd = CPL_ABORT_NO_RST;
577 ret = c4iw_ofld_send(rdev, skb);
579 __state_set(&ep->com, DEAD);
580 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
585 static int send_flowc(struct c4iw_ep *ep)
587 struct fw_flowc_wr *flowc;
588 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
589 u16 vlan = ep->l2t->vlan;
591 int flowclen, flowclen16;
596 if (vlan == CPL_L2T_VLAN_NONE)
601 flowclen = offsetof(struct fw_flowc_wr, mnemval[nparams]);
602 flowclen16 = DIV_ROUND_UP(flowclen, 16);
603 flowclen = flowclen16 * 16;
605 flowc = __skb_put(skb, flowclen);
606 memset(flowc, 0, flowclen);
608 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
609 FW_FLOWC_WR_NPARAMS_V(nparams));
610 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(flowclen16) |
611 FW_WR_FLOWID_V(ep->hwtid));
613 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
614 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
615 (ep->com.dev->rdev.lldi.pf));
616 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
617 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
618 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
619 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
620 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
621 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
622 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
623 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
624 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
625 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
626 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
627 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
628 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
629 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
630 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_RCV_SCALE;
631 flowc->mnemval[8].val = cpu_to_be32(ep->snd_wscale);
634 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
635 flowc->mnemval[9].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
636 flowc->mnemval[9].val = cpu_to_be32(pri);
639 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
640 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
643 static int send_halfclose(struct c4iw_ep *ep)
645 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
646 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
648 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
652 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
653 NULL, arp_failure_discard);
655 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
658 static int send_abort(struct c4iw_ep *ep)
660 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
661 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
663 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
664 if (WARN_ON(!req_skb))
667 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
668 ep, abort_arp_failure);
670 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
673 static int send_connect(struct c4iw_ep *ep)
675 struct cpl_act_open_req *req = NULL;
676 struct cpl_t5_act_open_req *t5req = NULL;
677 struct cpl_t6_act_open_req *t6req = NULL;
678 struct cpl_act_open_req6 *req6 = NULL;
679 struct cpl_t5_act_open_req6 *t5req6 = NULL;
680 struct cpl_t6_act_open_req6 *t6req6 = NULL;
684 unsigned int mtu_idx;
686 int win, sizev4, sizev6, wrlen;
687 struct sockaddr_in *la = (struct sockaddr_in *)
689 struct sockaddr_in *ra = (struct sockaddr_in *)
690 &ep->com.remote_addr;
691 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
693 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
694 &ep->com.remote_addr;
696 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
697 u32 isn = (prandom_u32() & ~7UL) - 1;
698 struct net_device *netdev;
701 netdev = ep->com.dev->rdev.lldi.ports[0];
703 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
705 sizev4 = sizeof(struct cpl_act_open_req);
706 sizev6 = sizeof(struct cpl_act_open_req6);
709 sizev4 = sizeof(struct cpl_t5_act_open_req);
710 sizev6 = sizeof(struct cpl_t5_act_open_req6);
713 sizev4 = sizeof(struct cpl_t6_act_open_req);
714 sizev6 = sizeof(struct cpl_t6_act_open_req6);
717 pr_err("T%d Chip is not supported\n",
718 CHELSIO_CHIP_VERSION(adapter_type));
722 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
723 roundup(sizev4, 16) :
726 pr_debug("ep %p atid %u\n", ep, ep->atid);
728 skb = get_skb(NULL, wrlen, GFP_KERNEL);
730 pr_err("%s - failed to alloc skb\n", __func__);
733 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
735 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
736 enable_tcp_timestamps,
737 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
738 wscale = cxgb_compute_wscale(rcv_win);
741 * Specify the largest window that will fit in opt0. The
742 * remainder will be specified in the rx_data_ack.
744 win = ep->rcv_win >> 10;
745 if (win > RCV_BUFSIZ_M)
748 opt0 = (nocong ? NO_CONG_F : 0) |
751 WND_SCALE_V(wscale) |
753 L2T_IDX_V(ep->l2t->idx) |
754 TX_CHAN_V(ep->tx_chan) |
755 SMAC_SEL_V(ep->smac_idx) |
756 DSCP_V(ep->tos >> 2) |
757 ULP_MODE_V(ULP_MODE_TCPDDP) |
759 opt2 = RX_CHANNEL_V(0) |
760 CCTRL_ECN_V(enable_ecn) |
761 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
762 if (enable_tcp_timestamps)
763 opt2 |= TSTAMPS_EN_F;
766 if (wscale && enable_tcp_window_scaling)
767 opt2 |= WND_SCALE_EN_F;
768 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
772 opt2 |= T5_OPT_2_VALID_F;
773 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
777 params = cxgb4_select_ntuple(netdev, ep->l2t);
779 if (ep->com.remote_addr.ss_family == AF_INET6)
780 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
781 (const u32 *)&la6->sin6_addr.s6_addr, 1);
783 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
785 if (ep->com.remote_addr.ss_family == AF_INET) {
786 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
788 req = skb_put(skb, wrlen);
792 t5req = skb_put(skb, wrlen);
793 INIT_TP_WR(t5req, 0);
794 req = (struct cpl_act_open_req *)t5req;
797 t6req = skb_put(skb, wrlen);
798 INIT_TP_WR(t6req, 0);
799 req = (struct cpl_act_open_req *)t6req;
800 t5req = (struct cpl_t5_act_open_req *)t6req;
803 pr_err("T%d Chip is not supported\n",
804 CHELSIO_CHIP_VERSION(adapter_type));
809 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
810 ((ep->rss_qid<<14) | ep->atid)));
811 req->local_port = la->sin_port;
812 req->peer_port = ra->sin_port;
813 req->local_ip = la->sin_addr.s_addr;
814 req->peer_ip = ra->sin_addr.s_addr;
815 req->opt0 = cpu_to_be64(opt0);
817 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
818 req->params = cpu_to_be32(params);
819 req->opt2 = cpu_to_be32(opt2);
821 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
823 cpu_to_be64(FILTER_TUPLE_V(params));
824 t5req->rsvd = cpu_to_be32(isn);
825 pr_debug("snd_isn %u\n", t5req->rsvd);
826 t5req->opt2 = cpu_to_be32(opt2);
829 cpu_to_be64(FILTER_TUPLE_V(params));
830 t6req->rsvd = cpu_to_be32(isn);
831 pr_debug("snd_isn %u\n", t6req->rsvd);
832 t6req->opt2 = cpu_to_be32(opt2);
836 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
838 req6 = skb_put(skb, wrlen);
842 t5req6 = skb_put(skb, wrlen);
843 INIT_TP_WR(t5req6, 0);
844 req6 = (struct cpl_act_open_req6 *)t5req6;
847 t6req6 = skb_put(skb, wrlen);
848 INIT_TP_WR(t6req6, 0);
849 req6 = (struct cpl_act_open_req6 *)t6req6;
850 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
853 pr_err("T%d Chip is not supported\n",
854 CHELSIO_CHIP_VERSION(adapter_type));
859 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
860 ((ep->rss_qid<<14)|ep->atid)));
861 req6->local_port = la6->sin6_port;
862 req6->peer_port = ra6->sin6_port;
863 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
864 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
865 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
866 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
867 req6->opt0 = cpu_to_be64(opt0);
869 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
870 req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
872 req6->opt2 = cpu_to_be32(opt2);
874 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
876 cpu_to_be64(FILTER_TUPLE_V(params));
877 t5req6->rsvd = cpu_to_be32(isn);
878 pr_debug("snd_isn %u\n", t5req6->rsvd);
879 t5req6->opt2 = cpu_to_be32(opt2);
882 cpu_to_be64(FILTER_TUPLE_V(params));
883 t6req6->rsvd = cpu_to_be32(isn);
884 pr_debug("snd_isn %u\n", t6req6->rsvd);
885 t6req6->opt2 = cpu_to_be32(opt2);
891 set_bit(ACT_OPEN_REQ, &ep->com.history);
892 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
894 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
895 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
896 (const u32 *)&la6->sin6_addr.s6_addr, 1);
900 static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
903 int mpalen, wrlen, ret;
904 struct fw_ofld_tx_data_wr *req;
905 struct mpa_message *mpa;
906 struct mpa_v2_conn_params mpa_v2_params;
908 pr_debug("ep %p tid %u pd_len %d\n",
909 ep, ep->hwtid, ep->plen);
911 mpalen = sizeof(*mpa) + ep->plen;
912 if (mpa_rev_to_use == 2)
913 mpalen += sizeof(struct mpa_v2_conn_params);
914 wrlen = roundup(mpalen + sizeof *req, 16);
915 skb = get_skb(skb, wrlen, GFP_KERNEL);
917 connect_reply_upcall(ep, -ENOMEM);
920 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
922 req = skb_put_zero(skb, wrlen);
923 req->op_to_immdlen = cpu_to_be32(
924 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
926 FW_WR_IMMDLEN_V(mpalen));
927 req->flowid_len16 = cpu_to_be32(
928 FW_WR_FLOWID_V(ep->hwtid) |
929 FW_WR_LEN16_V(wrlen >> 4));
930 req->plen = cpu_to_be32(mpalen);
931 req->tunnel_to_proxy = cpu_to_be32(
932 FW_OFLD_TX_DATA_WR_FLUSH_F |
933 FW_OFLD_TX_DATA_WR_SHOVE_F);
935 mpa = (struct mpa_message *)(req + 1);
936 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
940 mpa->flags |= MPA_CRC;
941 if (markers_enabled) {
942 mpa->flags |= MPA_MARKERS;
943 ep->mpa_attr.recv_marker_enabled = 1;
945 ep->mpa_attr.recv_marker_enabled = 0;
947 if (mpa_rev_to_use == 2)
948 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
950 mpa->private_data_size = htons(ep->plen);
951 mpa->revision = mpa_rev_to_use;
952 if (mpa_rev_to_use == 1) {
953 ep->tried_with_mpa_v1 = 1;
954 ep->retry_with_mpa_v1 = 0;
957 if (mpa_rev_to_use == 2) {
958 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
959 sizeof (struct mpa_v2_conn_params));
960 pr_debug("initiator ird %u ord %u\n", ep->ird,
962 mpa_v2_params.ird = htons((u16)ep->ird);
963 mpa_v2_params.ord = htons((u16)ep->ord);
966 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
967 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
969 htons(MPA_V2_RDMA_WRITE_RTR);
970 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
972 htons(MPA_V2_RDMA_READ_RTR);
974 memcpy(mpa->private_data, &mpa_v2_params,
975 sizeof(struct mpa_v2_conn_params));
978 memcpy(mpa->private_data +
979 sizeof(struct mpa_v2_conn_params),
980 ep->mpa_pkt + sizeof(*mpa), ep->plen);
983 memcpy(mpa->private_data,
984 ep->mpa_pkt + sizeof(*mpa), ep->plen);
987 * Reference the mpa skb. This ensures the data area
988 * will remain in memory until the hw acks the tx.
989 * Function fw4_ack() will deref it.
992 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
994 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
998 __state_set(&ep->com, MPA_REQ_SENT);
999 ep->mpa_attr.initiator = 1;
1000 ep->snd_seq += mpalen;
1004 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1007 struct fw_ofld_tx_data_wr *req;
1008 struct mpa_message *mpa;
1009 struct sk_buff *skb;
1010 struct mpa_v2_conn_params mpa_v2_params;
1012 pr_debug("ep %p tid %u pd_len %d\n",
1013 ep, ep->hwtid, ep->plen);
1015 mpalen = sizeof(*mpa) + plen;
1016 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1017 mpalen += sizeof(struct mpa_v2_conn_params);
1018 wrlen = roundup(mpalen + sizeof *req, 16);
1020 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1022 pr_err("%s - cannot alloc skb!\n", __func__);
1025 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1027 req = skb_put_zero(skb, wrlen);
1028 req->op_to_immdlen = cpu_to_be32(
1029 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1031 FW_WR_IMMDLEN_V(mpalen));
1032 req->flowid_len16 = cpu_to_be32(
1033 FW_WR_FLOWID_V(ep->hwtid) |
1034 FW_WR_LEN16_V(wrlen >> 4));
1035 req->plen = cpu_to_be32(mpalen);
1036 req->tunnel_to_proxy = cpu_to_be32(
1037 FW_OFLD_TX_DATA_WR_FLUSH_F |
1038 FW_OFLD_TX_DATA_WR_SHOVE_F);
1040 mpa = (struct mpa_message *)(req + 1);
1041 memset(mpa, 0, sizeof(*mpa));
1042 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1043 mpa->flags = MPA_REJECT;
1044 mpa->revision = ep->mpa_attr.version;
1045 mpa->private_data_size = htons(plen);
1047 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1048 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1049 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1050 sizeof (struct mpa_v2_conn_params));
1051 mpa_v2_params.ird = htons(((u16)ep->ird) |
1052 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1054 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1056 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1057 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1058 FW_RI_INIT_P2PTYPE_READ_REQ ?
1059 MPA_V2_RDMA_READ_RTR : 0) : 0));
1060 memcpy(mpa->private_data, &mpa_v2_params,
1061 sizeof(struct mpa_v2_conn_params));
1064 memcpy(mpa->private_data +
1065 sizeof(struct mpa_v2_conn_params), pdata, plen);
1068 memcpy(mpa->private_data, pdata, plen);
1071 * Reference the mpa skb again. This ensures the data area
1072 * will remain in memory until the hw acks the tx.
1073 * Function fw4_ack() will deref it.
1076 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1077 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1079 ep->snd_seq += mpalen;
1080 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1083 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1086 struct fw_ofld_tx_data_wr *req;
1087 struct mpa_message *mpa;
1088 struct sk_buff *skb;
1089 struct mpa_v2_conn_params mpa_v2_params;
1091 pr_debug("ep %p tid %u pd_len %d\n",
1092 ep, ep->hwtid, ep->plen);
1094 mpalen = sizeof(*mpa) + plen;
1095 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1096 mpalen += sizeof(struct mpa_v2_conn_params);
1097 wrlen = roundup(mpalen + sizeof *req, 16);
1099 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1101 pr_err("%s - cannot alloc skb!\n", __func__);
1104 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1106 req = skb_put_zero(skb, wrlen);
1107 req->op_to_immdlen = cpu_to_be32(
1108 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1110 FW_WR_IMMDLEN_V(mpalen));
1111 req->flowid_len16 = cpu_to_be32(
1112 FW_WR_FLOWID_V(ep->hwtid) |
1113 FW_WR_LEN16_V(wrlen >> 4));
1114 req->plen = cpu_to_be32(mpalen);
1115 req->tunnel_to_proxy = cpu_to_be32(
1116 FW_OFLD_TX_DATA_WR_FLUSH_F |
1117 FW_OFLD_TX_DATA_WR_SHOVE_F);
1119 mpa = (struct mpa_message *)(req + 1);
1120 memset(mpa, 0, sizeof(*mpa));
1121 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1123 if (ep->mpa_attr.crc_enabled)
1124 mpa->flags |= MPA_CRC;
1125 if (ep->mpa_attr.recv_marker_enabled)
1126 mpa->flags |= MPA_MARKERS;
1127 mpa->revision = ep->mpa_attr.version;
1128 mpa->private_data_size = htons(plen);
1130 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1131 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1132 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1133 sizeof (struct mpa_v2_conn_params));
1134 mpa_v2_params.ird = htons((u16)ep->ird);
1135 mpa_v2_params.ord = htons((u16)ep->ord);
1136 if (peer2peer && (ep->mpa_attr.p2p_type !=
1137 FW_RI_INIT_P2PTYPE_DISABLED)) {
1138 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1140 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1141 mpa_v2_params.ord |=
1142 htons(MPA_V2_RDMA_WRITE_RTR);
1143 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1144 mpa_v2_params.ord |=
1145 htons(MPA_V2_RDMA_READ_RTR);
1148 memcpy(mpa->private_data, &mpa_v2_params,
1149 sizeof(struct mpa_v2_conn_params));
1152 memcpy(mpa->private_data +
1153 sizeof(struct mpa_v2_conn_params), pdata, plen);
1156 memcpy(mpa->private_data, pdata, plen);
1159 * Reference the mpa skb. This ensures the data area
1160 * will remain in memory until the hw acks the tx.
1161 * Function fw4_ack() will deref it.
1164 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
1166 __state_set(&ep->com, MPA_REP_SENT);
1167 ep->snd_seq += mpalen;
1168 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1171 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1174 struct cpl_act_establish *req = cplhdr(skb);
1175 unsigned short tcp_opt = ntohs(req->tcp_opt);
1176 unsigned int tid = GET_TID(req);
1177 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
1178 struct tid_info *t = dev->rdev.lldi.tids;
1181 ep = lookup_atid(t, atid);
1183 pr_debug("ep %p tid %u snd_isn %u rcv_isn %u\n", ep, tid,
1184 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1186 mutex_lock(&ep->com.mutex);
1187 dst_confirm(ep->dst);
1189 /* setup the hwtid for this connection */
1191 cxgb4_insert_tid(t, ep, tid, ep->com.local_addr.ss_family);
1194 ep->snd_seq = be32_to_cpu(req->snd_isn);
1195 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1196 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
1198 set_emss(ep, tcp_opt);
1200 /* dealloc the atid */
1201 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1202 cxgb4_free_atid(t, atid);
1203 set_bit(ACT_ESTAB, &ep->com.history);
1205 /* start MPA negotiation */
1206 ret = send_flowc(ep);
1209 if (ep->retry_with_mpa_v1)
1210 ret = send_mpa_req(ep, skb, 1);
1212 ret = send_mpa_req(ep, skb, mpa_rev);
1215 mutex_unlock(&ep->com.mutex);
1218 mutex_unlock(&ep->com.mutex);
1219 connect_reply_upcall(ep, -ENOMEM);
1220 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1224 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1226 struct iw_cm_event event;
1228 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1229 memset(&event, 0, sizeof(event));
1230 event.event = IW_CM_EVENT_CLOSE;
1231 event.status = status;
1232 if (ep->com.cm_id) {
1233 pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
1234 ep, ep->com.cm_id, ep->hwtid);
1235 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1236 deref_cm_id(&ep->com);
1237 set_bit(CLOSE_UPCALL, &ep->com.history);
1241 static void peer_close_upcall(struct c4iw_ep *ep)
1243 struct iw_cm_event event;
1245 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1246 memset(&event, 0, sizeof(event));
1247 event.event = IW_CM_EVENT_DISCONNECT;
1248 if (ep->com.cm_id) {
1249 pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
1250 ep, ep->com.cm_id, ep->hwtid);
1251 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1252 set_bit(DISCONN_UPCALL, &ep->com.history);
1256 static void peer_abort_upcall(struct c4iw_ep *ep)
1258 struct iw_cm_event event;
1260 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1261 memset(&event, 0, sizeof(event));
1262 event.event = IW_CM_EVENT_CLOSE;
1263 event.status = -ECONNRESET;
1264 if (ep->com.cm_id) {
1265 pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep,
1266 ep->com.cm_id, ep->hwtid);
1267 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1268 deref_cm_id(&ep->com);
1269 set_bit(ABORT_UPCALL, &ep->com.history);
1273 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1275 struct iw_cm_event event;
1277 pr_debug("ep %p tid %u status %d\n",
1278 ep, ep->hwtid, status);
1279 memset(&event, 0, sizeof(event));
1280 event.event = IW_CM_EVENT_CONNECT_REPLY;
1281 event.status = status;
1282 memcpy(&event.local_addr, &ep->com.local_addr,
1283 sizeof(ep->com.local_addr));
1284 memcpy(&event.remote_addr, &ep->com.remote_addr,
1285 sizeof(ep->com.remote_addr));
1287 if ((status == 0) || (status == -ECONNREFUSED)) {
1288 if (!ep->tried_with_mpa_v1) {
1289 /* this means MPA_v2 is used */
1290 event.ord = ep->ird;
1291 event.ird = ep->ord;
1292 event.private_data_len = ep->plen -
1293 sizeof(struct mpa_v2_conn_params);
1294 event.private_data = ep->mpa_pkt +
1295 sizeof(struct mpa_message) +
1296 sizeof(struct mpa_v2_conn_params);
1298 /* this means MPA_v1 is used */
1299 event.ord = cur_max_read_depth(ep->com.dev);
1300 event.ird = cur_max_read_depth(ep->com.dev);
1301 event.private_data_len = ep->plen;
1302 event.private_data = ep->mpa_pkt +
1303 sizeof(struct mpa_message);
1307 pr_debug("ep %p tid %u status %d\n", ep,
1309 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1310 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1313 deref_cm_id(&ep->com);
1316 static int connect_request_upcall(struct c4iw_ep *ep)
1318 struct iw_cm_event event;
1321 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1322 memset(&event, 0, sizeof(event));
1323 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1324 memcpy(&event.local_addr, &ep->com.local_addr,
1325 sizeof(ep->com.local_addr));
1326 memcpy(&event.remote_addr, &ep->com.remote_addr,
1327 sizeof(ep->com.remote_addr));
1328 event.provider_data = ep;
1329 if (!ep->tried_with_mpa_v1) {
1330 /* this means MPA_v2 is used */
1331 event.ord = ep->ord;
1332 event.ird = ep->ird;
1333 event.private_data_len = ep->plen -
1334 sizeof(struct mpa_v2_conn_params);
1335 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1336 sizeof(struct mpa_v2_conn_params);
1338 /* this means MPA_v1 is used. Send max supported */
1339 event.ord = cur_max_read_depth(ep->com.dev);
1340 event.ird = cur_max_read_depth(ep->com.dev);
1341 event.private_data_len = ep->plen;
1342 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1344 c4iw_get_ep(&ep->com);
1345 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1348 c4iw_put_ep(&ep->com);
1349 set_bit(CONNREQ_UPCALL, &ep->com.history);
1350 c4iw_put_ep(&ep->parent_ep->com);
1354 static void established_upcall(struct c4iw_ep *ep)
1356 struct iw_cm_event event;
1358 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1359 memset(&event, 0, sizeof(event));
1360 event.event = IW_CM_EVENT_ESTABLISHED;
1361 event.ird = ep->ord;
1362 event.ord = ep->ird;
1363 if (ep->com.cm_id) {
1364 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1365 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1366 set_bit(ESTAB_UPCALL, &ep->com.history);
1370 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1372 struct sk_buff *skb;
1373 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1376 pr_debug("ep %p tid %u credits %u\n",
1377 ep, ep->hwtid, credits);
1378 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1380 pr_err("update_rx_credits - cannot alloc skb!\n");
1385 * If we couldn't specify the entire rcv window at connection setup
1386 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1387 * then add the overage in to the credits returned.
1389 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1390 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
1392 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1393 RX_DACK_MODE_V(dack_mode);
1395 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1398 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1402 #define RELAXED_IRD_NEGOTIATION 1
1405 * process_mpa_reply - process streaming mode MPA reply
1409 * 0 upon success indicating a connect request was delivered to the ULP
1410 * or the mpa request is incomplete but valid so far.
1412 * 1 if a failure requires the caller to close the connection.
1414 * 2 if a failure requires the caller to abort the connection.
1416 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1418 struct mpa_message *mpa;
1419 struct mpa_v2_conn_params *mpa_v2_params;
1421 u16 resp_ird, resp_ord;
1422 u8 rtr_mismatch = 0, insuff_ird = 0;
1423 struct c4iw_qp_attributes attrs;
1424 enum c4iw_qp_attr_mask mask;
1428 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1431 * If we get more than the supported amount of private data
1432 * then we must fail this connection.
1434 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1436 goto err_stop_timer;
1440 * copy the new data into our accumulation buffer.
1442 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1444 ep->mpa_pkt_len += skb->len;
1447 * if we don't even have the mpa message, then bail.
1449 if (ep->mpa_pkt_len < sizeof(*mpa))
1451 mpa = (struct mpa_message *) ep->mpa_pkt;
1453 /* Validate MPA header. */
1454 if (mpa->revision > mpa_rev) {
1455 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1456 __func__, mpa_rev, mpa->revision);
1458 goto err_stop_timer;
1460 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1462 goto err_stop_timer;
1465 plen = ntohs(mpa->private_data_size);
1468 * Fail if there's too much private data.
1470 if (plen > MPA_MAX_PRIVATE_DATA) {
1472 goto err_stop_timer;
1476 * If plen does not account for pkt size
1478 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1480 goto err_stop_timer;
1483 ep->plen = (u8) plen;
1486 * If we don't have all the pdata yet, then bail.
1487 * We'll continue process when more data arrives.
1489 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1492 if (mpa->flags & MPA_REJECT) {
1493 err = -ECONNREFUSED;
1494 goto err_stop_timer;
1498 * Stop mpa timer. If it expired, then
1499 * we ignore the MPA reply. process_timeout()
1500 * will abort the connection.
1502 if (stop_ep_timer(ep))
1506 * If we get here we have accumulated the entire mpa
1507 * start reply message including private data. And
1508 * the MPA header is valid.
1510 __state_set(&ep->com, FPDU_MODE);
1511 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1512 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1513 ep->mpa_attr.version = mpa->revision;
1514 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1516 if (mpa->revision == 2) {
1517 ep->mpa_attr.enhanced_rdma_conn =
1518 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1519 if (ep->mpa_attr.enhanced_rdma_conn) {
1520 mpa_v2_params = (struct mpa_v2_conn_params *)
1521 (ep->mpa_pkt + sizeof(*mpa));
1522 resp_ird = ntohs(mpa_v2_params->ird) &
1523 MPA_V2_IRD_ORD_MASK;
1524 resp_ord = ntohs(mpa_v2_params->ord) &
1525 MPA_V2_IRD_ORD_MASK;
1526 pr_debug("responder ird %u ord %u ep ird %u ord %u\n",
1527 resp_ird, resp_ord, ep->ird, ep->ord);
1530 * This is a double-check. Ideally, below checks are
1531 * not required since ird/ord stuff has been taken
1532 * care of in c4iw_accept_cr
1534 if (ep->ird < resp_ord) {
1535 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1536 ep->com.dev->rdev.lldi.max_ordird_qp)
1540 } else if (ep->ird > resp_ord) {
1543 if (ep->ord > resp_ird) {
1544 if (RELAXED_IRD_NEGOTIATION)
1555 if (ntohs(mpa_v2_params->ird) &
1556 MPA_V2_PEER2PEER_MODEL) {
1557 if (ntohs(mpa_v2_params->ord) &
1558 MPA_V2_RDMA_WRITE_RTR)
1559 ep->mpa_attr.p2p_type =
1560 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1561 else if (ntohs(mpa_v2_params->ord) &
1562 MPA_V2_RDMA_READ_RTR)
1563 ep->mpa_attr.p2p_type =
1564 FW_RI_INIT_P2PTYPE_READ_REQ;
1567 } else if (mpa->revision == 1)
1569 ep->mpa_attr.p2p_type = p2p_type;
1571 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
1572 ep->mpa_attr.crc_enabled,
1573 ep->mpa_attr.recv_marker_enabled,
1574 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1575 ep->mpa_attr.p2p_type, p2p_type);
1578 * If responder's RTR does not match with that of initiator, assign
1579 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1580 * generated when moving QP to RTS state.
1581 * A TERM message will be sent after QP has moved to RTS state
1583 if ((ep->mpa_attr.version == 2) && peer2peer &&
1584 (ep->mpa_attr.p2p_type != p2p_type)) {
1585 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1589 attrs.mpa_attr = ep->mpa_attr;
1590 attrs.max_ird = ep->ird;
1591 attrs.max_ord = ep->ord;
1592 attrs.llp_stream_handle = ep;
1593 attrs.next_state = C4IW_QP_STATE_RTS;
1595 mask = C4IW_QP_ATTR_NEXT_STATE |
1596 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1597 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1599 /* bind QP and TID with INIT_WR */
1600 err = c4iw_modify_qp(ep->com.qp->rhp,
1601 ep->com.qp, mask, &attrs, 1);
1606 * If responder's RTR requirement did not match with what initiator
1607 * supports, generate TERM message
1610 pr_err("%s: RTR mismatch, sending TERM\n", __func__);
1611 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1612 attrs.ecode = MPA_NOMATCH_RTR;
1613 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1614 attrs.send_term = 1;
1615 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1616 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1623 * Generate TERM if initiator IRD is not sufficient for responder
1624 * provided ORD. Currently, we do the same behaviour even when
1625 * responder provided IRD is also not sufficient as regards to
1629 pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
1630 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1631 attrs.ecode = MPA_INSUFF_IRD;
1632 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1633 attrs.send_term = 1;
1634 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1635 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1646 connect_reply_upcall(ep, err);
1651 * process_mpa_request - process streaming mode MPA request
1655 * 0 upon success indicating a connect request was delivered to the ULP
1656 * or the mpa request is incomplete but valid so far.
1658 * 1 if a failure requires the caller to close the connection.
1660 * 2 if a failure requires the caller to abort the connection.
1662 static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1664 struct mpa_message *mpa;
1665 struct mpa_v2_conn_params *mpa_v2_params;
1668 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1671 * If we get more than the supported amount of private data
1672 * then we must fail this connection.
1674 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1675 goto err_stop_timer;
1677 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1680 * Copy the new data into our accumulation buffer.
1682 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1684 ep->mpa_pkt_len += skb->len;
1687 * If we don't even have the mpa message, then bail.
1688 * We'll continue process when more data arrives.
1690 if (ep->mpa_pkt_len < sizeof(*mpa))
1693 pr_debug("enter (%s line %u)\n", __FILE__, __LINE__);
1694 mpa = (struct mpa_message *) ep->mpa_pkt;
1697 * Validate MPA Header.
1699 if (mpa->revision > mpa_rev) {
1700 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1701 __func__, mpa_rev, mpa->revision);
1702 goto err_stop_timer;
1705 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1706 goto err_stop_timer;
1708 plen = ntohs(mpa->private_data_size);
1711 * Fail if there's too much private data.
1713 if (plen > MPA_MAX_PRIVATE_DATA)
1714 goto err_stop_timer;
1717 * If plen does not account for pkt size
1719 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1720 goto err_stop_timer;
1721 ep->plen = (u8) plen;
1724 * If we don't have all the pdata yet, then bail.
1726 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1730 * If we get here we have accumulated the entire mpa
1731 * start reply message including private data.
1733 ep->mpa_attr.initiator = 0;
1734 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1735 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1736 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1737 ep->mpa_attr.version = mpa->revision;
1738 if (mpa->revision == 1)
1739 ep->tried_with_mpa_v1 = 1;
1740 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1742 if (mpa->revision == 2) {
1743 ep->mpa_attr.enhanced_rdma_conn =
1744 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1745 if (ep->mpa_attr.enhanced_rdma_conn) {
1746 mpa_v2_params = (struct mpa_v2_conn_params *)
1747 (ep->mpa_pkt + sizeof(*mpa));
1748 ep->ird = ntohs(mpa_v2_params->ird) &
1749 MPA_V2_IRD_ORD_MASK;
1750 ep->ird = min_t(u32, ep->ird,
1751 cur_max_read_depth(ep->com.dev));
1752 ep->ord = ntohs(mpa_v2_params->ord) &
1753 MPA_V2_IRD_ORD_MASK;
1754 ep->ord = min_t(u32, ep->ord,
1755 cur_max_read_depth(ep->com.dev));
1756 pr_debug("initiator ird %u ord %u\n",
1758 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1760 if (ntohs(mpa_v2_params->ord) &
1761 MPA_V2_RDMA_WRITE_RTR)
1762 ep->mpa_attr.p2p_type =
1763 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1764 else if (ntohs(mpa_v2_params->ord) &
1765 MPA_V2_RDMA_READ_RTR)
1766 ep->mpa_attr.p2p_type =
1767 FW_RI_INIT_P2PTYPE_READ_REQ;
1770 } else if (mpa->revision == 1)
1772 ep->mpa_attr.p2p_type = p2p_type;
1774 pr_debug("crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
1775 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1776 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1777 ep->mpa_attr.p2p_type);
1779 __state_set(&ep->com, MPA_REQ_RCVD);
1782 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1783 if (ep->parent_ep->com.state != DEAD) {
1784 if (connect_request_upcall(ep))
1785 goto err_unlock_parent;
1787 goto err_unlock_parent;
1789 mutex_unlock(&ep->parent_ep->com.mutex);
1793 mutex_unlock(&ep->parent_ep->com.mutex);
1796 (void)stop_ep_timer(ep);
1801 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1804 struct cpl_rx_data *hdr = cplhdr(skb);
1805 unsigned int dlen = ntohs(hdr->len);
1806 unsigned int tid = GET_TID(hdr);
1807 __u8 status = hdr->status;
1810 ep = get_ep_from_tid(dev, tid);
1813 pr_debug("ep %p tid %u dlen %u\n", ep, ep->hwtid, dlen);
1814 skb_pull(skb, sizeof(*hdr));
1815 skb_trim(skb, dlen);
1816 mutex_lock(&ep->com.mutex);
1818 switch (ep->com.state) {
1820 update_rx_credits(ep, dlen);
1821 ep->rcv_seq += dlen;
1822 disconnect = process_mpa_reply(ep, skb);
1825 update_rx_credits(ep, dlen);
1826 ep->rcv_seq += dlen;
1827 disconnect = process_mpa_request(ep, skb);
1830 struct c4iw_qp_attributes attrs;
1832 update_rx_credits(ep, dlen);
1834 pr_err("%s Unexpected streaming data." \
1835 " qpid %u ep %p state %d tid %u status %d\n",
1836 __func__, ep->com.qp->wq.sq.qid, ep,
1837 ep->com.state, ep->hwtid, status);
1838 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1839 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1840 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1847 mutex_unlock(&ep->com.mutex);
1849 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
1850 c4iw_put_ep(&ep->com);
1854 static void complete_cached_srq_buffers(struct c4iw_ep *ep,
1855 __be32 srqidx_status)
1857 enum chip_type adapter_type;
1860 adapter_type = ep->com.dev->rdev.lldi.adapter_type;
1861 srqidx = ABORT_RSS_SRQIDX_G(be32_to_cpu(srqidx_status));
1864 * If this TCB had a srq buffer cached, then we must complete
1865 * it. For user mode, that means saving the srqidx in the
1866 * user/kernel status page for this qp. For kernel mode, just
1867 * synthesize the CQE now.
1869 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T5 && srqidx) {
1870 if (ep->com.qp->ibqp.uobject)
1871 t4_set_wq_in_error(&ep->com.qp->wq, srqidx);
1873 c4iw_flush_srqidx(ep->com.qp, srqidx);
1877 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1880 struct cpl_abort_rpl_rss6 *rpl = cplhdr(skb);
1882 unsigned int tid = GET_TID(rpl);
1884 ep = get_ep_from_tid(dev, tid);
1886 pr_warn("Abort rpl to freed endpoint\n");
1890 complete_cached_srq_buffers(ep, rpl->srqidx_status);
1892 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
1893 mutex_lock(&ep->com.mutex);
1894 switch (ep->com.state) {
1896 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
1897 __state_set(&ep->com, DEAD);
1901 pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
1904 mutex_unlock(&ep->com.mutex);
1907 release_ep_resources(ep);
1908 c4iw_put_ep(&ep->com);
1912 static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1914 struct sk_buff *skb;
1915 struct fw_ofld_connection_wr *req;
1916 unsigned int mtu_idx;
1918 struct sockaddr_in *sin;
1921 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1922 req = __skb_put_zero(skb, sizeof(*req));
1923 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
1924 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
1925 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1926 ep->com.dev->rdev.lldi.ports[0],
1928 sin = (struct sockaddr_in *)&ep->com.local_addr;
1929 req->le.lport = sin->sin_port;
1930 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1931 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1932 req->le.pport = sin->sin_port;
1933 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1934 req->tcb.t_state_to_astid =
1935 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1936 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
1937 req->tcb.cplrxdataack_cplpassacceptrpl =
1938 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
1939 req->tcb.tx_max = (__force __be32) jiffies;
1940 req->tcb.rcv_adv = htons(1);
1941 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1942 enable_tcp_timestamps,
1943 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
1944 wscale = cxgb_compute_wscale(rcv_win);
1947 * Specify the largest window that will fit in opt0. The
1948 * remainder will be specified in the rx_data_ack.
1950 win = ep->rcv_win >> 10;
1951 if (win > RCV_BUFSIZ_M)
1954 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1955 (nocong ? NO_CONG_F : 0) |
1958 WND_SCALE_V(wscale) |
1959 MSS_IDX_V(mtu_idx) |
1960 L2T_IDX_V(ep->l2t->idx) |
1961 TX_CHAN_V(ep->tx_chan) |
1962 SMAC_SEL_V(ep->smac_idx) |
1963 DSCP_V(ep->tos >> 2) |
1964 ULP_MODE_V(ULP_MODE_TCPDDP) |
1966 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1967 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1969 CCTRL_ECN_V(enable_ecn) |
1970 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
1971 if (enable_tcp_timestamps)
1972 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
1973 if (enable_tcp_sack)
1974 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
1975 if (wscale && enable_tcp_window_scaling)
1976 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1977 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1978 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
1979 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1980 set_bit(ACT_OFLD_CONN, &ep->com.history);
1981 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1985 * Some of the error codes above implicitly indicate that there is no TID
1986 * allocated with the result of an ACT_OPEN. We use this predicate to make
1989 static inline int act_open_has_tid(int status)
1991 return (status != CPL_ERR_TCAM_PARITY &&
1992 status != CPL_ERR_TCAM_MISS &&
1993 status != CPL_ERR_TCAM_FULL &&
1994 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1995 status != CPL_ERR_CONN_EXIST);
1998 static char *neg_adv_str(unsigned int status)
2001 case CPL_ERR_RTX_NEG_ADVICE:
2002 return "Retransmit timeout";
2003 case CPL_ERR_PERSIST_NEG_ADVICE:
2004 return "Persist timeout";
2005 case CPL_ERR_KEEPALV_NEG_ADVICE:
2006 return "Keepalive timeout";
2012 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2014 ep->snd_win = snd_win;
2015 ep->rcv_win = rcv_win;
2016 pr_debug("snd_win %d rcv_win %d\n",
2017 ep->snd_win, ep->rcv_win);
2020 #define ACT_OPEN_RETRY_COUNT 2
2022 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2023 struct dst_entry *dst, struct c4iw_dev *cdev,
2024 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
2026 struct neighbour *n;
2028 struct net_device *pdev;
2030 n = dst_neigh_lookup(dst, peer_ip);
2036 if (n->dev->flags & IFF_LOOPBACK) {
2038 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2039 else if (IS_ENABLED(CONFIG_IPV6))
2040 for_each_netdev(&init_net, pdev) {
2041 if (ipv6_chk_addr(&init_net,
2042 (struct in6_addr *)peer_ip,
2053 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2054 n, pdev, rt_tos2priority(tos));
2059 ep->mtu = pdev->mtu;
2060 ep->tx_chan = cxgb4_port_chan(pdev);
2061 ep->smac_idx = ((struct port_info *)netdev_priv(pdev))->smt_idx;
2062 step = cdev->rdev.lldi.ntxq /
2063 cdev->rdev.lldi.nchan;
2064 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2065 step = cdev->rdev.lldi.nrxq /
2066 cdev->rdev.lldi.nchan;
2067 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2068 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2069 cxgb4_port_idx(pdev) * step];
2070 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2073 pdev = get_real_dev(n->dev);
2074 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2078 ep->mtu = dst_mtu(dst);
2079 ep->tx_chan = cxgb4_port_chan(pdev);
2080 ep->smac_idx = ((struct port_info *)netdev_priv(pdev))->smt_idx;
2081 step = cdev->rdev.lldi.ntxq /
2082 cdev->rdev.lldi.nchan;
2083 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2084 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2085 step = cdev->rdev.lldi.nrxq /
2086 cdev->rdev.lldi.nchan;
2087 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2088 cxgb4_port_idx(pdev) * step];
2089 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2092 ep->retry_with_mpa_v1 = 0;
2093 ep->tried_with_mpa_v1 = 0;
2105 static int c4iw_reconnect(struct c4iw_ep *ep)
2109 struct sockaddr_in *laddr = (struct sockaddr_in *)
2110 &ep->com.cm_id->m_local_addr;
2111 struct sockaddr_in *raddr = (struct sockaddr_in *)
2112 &ep->com.cm_id->m_remote_addr;
2113 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2114 &ep->com.cm_id->m_local_addr;
2115 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2116 &ep->com.cm_id->m_remote_addr;
2120 pr_debug("qp %p cm_id %p\n", ep->com.qp, ep->com.cm_id);
2121 c4iw_init_wr_wait(ep->com.wr_waitp);
2123 /* When MPA revision is different on nodes, the node with MPA_rev=2
2124 * tries to reconnect with MPA_rev 1 for the same EP through
2125 * c4iw_reconnect(), where the same EP is assigned with new tid for
2126 * further connection establishment. As we are using the same EP pointer
2127 * for reconnect, few skbs are used during the previous c4iw_connect(),
2128 * which leaves the EP with inadequate skbs for further
2129 * c4iw_reconnect(), Further causing a crash due to an empty
2130 * skb_list() during peer_abort(). Allocate skbs which is already used.
2132 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2133 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2139 * Allocate an active TID to initiate a TCP connection.
2141 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2142 if (ep->atid == -1) {
2143 pr_err("%s - cannot alloc atid\n", __func__);
2147 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2150 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
2151 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2152 laddr->sin_addr.s_addr,
2153 raddr->sin_addr.s_addr,
2155 raddr->sin_port, ep->com.cm_id->tos);
2157 ra = (__u8 *)&raddr->sin_addr;
2159 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2161 laddr6->sin6_addr.s6_addr,
2162 raddr6->sin6_addr.s6_addr,
2164 raddr6->sin6_port, 0,
2165 raddr6->sin6_scope_id);
2167 ra = (__u8 *)&raddr6->sin6_addr;
2170 pr_err("%s - cannot find route\n", __func__);
2171 err = -EHOSTUNREACH;
2174 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2175 ep->com.dev->rdev.lldi.adapter_type,
2176 ep->com.cm_id->tos);
2178 pr_err("%s - cannot alloc l2e\n", __func__);
2182 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2183 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2186 state_set(&ep->com, CONNECTING);
2187 ep->tos = ep->com.cm_id->tos;
2189 /* send connect request to rnic */
2190 err = send_connect(ep);
2194 cxgb4_l2t_release(ep->l2t);
2196 dst_release(ep->dst);
2198 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2199 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2202 * remember to send notification to upper layer.
2203 * We are in here so the upper layer is not aware that this is
2204 * re-connect attempt and so, upper layer is still waiting for
2205 * response of 1st connect request.
2207 connect_reply_upcall(ep, -ECONNRESET);
2209 c4iw_put_ep(&ep->com);
2214 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2217 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2218 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2219 ntohl(rpl->atid_status)));
2220 struct tid_info *t = dev->rdev.lldi.tids;
2221 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
2222 struct sockaddr_in *la;
2223 struct sockaddr_in *ra;
2224 struct sockaddr_in6 *la6;
2225 struct sockaddr_in6 *ra6;
2228 ep = lookup_atid(t, atid);
2229 la = (struct sockaddr_in *)&ep->com.local_addr;
2230 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2231 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2232 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
2234 pr_debug("ep %p atid %u status %u errno %d\n", ep, atid,
2235 status, status2errno(status));
2237 if (cxgb_is_neg_adv(status)) {
2238 pr_debug("Connection problems for atid %u status %u (%s)\n",
2239 atid, status, neg_adv_str(status));
2240 ep->stats.connect_neg_adv++;
2241 mutex_lock(&dev->rdev.stats.lock);
2242 dev->rdev.stats.neg_adv++;
2243 mutex_unlock(&dev->rdev.stats.lock);
2247 set_bit(ACT_OPEN_RPL, &ep->com.history);
2250 * Log interesting failures.
2253 case CPL_ERR_CONN_RESET:
2254 case CPL_ERR_CONN_TIMEDOUT:
2256 case CPL_ERR_TCAM_FULL:
2257 mutex_lock(&dev->rdev.stats.lock);
2258 dev->rdev.stats.tcam_full++;
2259 mutex_unlock(&dev->rdev.stats.lock);
2260 if (ep->com.local_addr.ss_family == AF_INET &&
2261 dev->rdev.lldi.enable_fw_ofld_conn) {
2262 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2263 ntohl(rpl->atid_status))));
2269 case CPL_ERR_CONN_EXIST:
2270 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2271 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2272 if (ep->com.remote_addr.ss_family == AF_INET6) {
2273 struct sockaddr_in6 *sin6 =
2274 (struct sockaddr_in6 *)
2275 &ep->com.local_addr;
2277 ep->com.dev->rdev.lldi.ports[0],
2279 &sin6->sin6_addr.s6_addr, 1);
2281 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2283 cxgb4_free_atid(t, atid);
2284 dst_release(ep->dst);
2285 cxgb4_l2t_release(ep->l2t);
2291 if (ep->com.local_addr.ss_family == AF_INET) {
2292 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2293 atid, status, status2errno(status),
2294 &la->sin_addr.s_addr, ntohs(la->sin_port),
2295 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2297 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2298 atid, status, status2errno(status),
2299 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2300 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2306 connect_reply_upcall(ep, status2errno(status));
2307 state_set(&ep->com, DEAD);
2309 if (ep->com.remote_addr.ss_family == AF_INET6) {
2310 struct sockaddr_in6 *sin6 =
2311 (struct sockaddr_in6 *)&ep->com.local_addr;
2312 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2313 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2315 if (status && act_open_has_tid(status))
2316 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl),
2317 ep->com.local_addr.ss_family);
2319 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2320 cxgb4_free_atid(t, atid);
2321 dst_release(ep->dst);
2322 cxgb4_l2t_release(ep->l2t);
2323 c4iw_put_ep(&ep->com);
2328 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2330 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2331 unsigned int stid = GET_TID(rpl);
2332 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2335 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2338 pr_debug("ep %p status %d error %d\n", ep,
2339 rpl->status, status2errno(rpl->status));
2340 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2341 c4iw_put_ep(&ep->com);
2346 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2348 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2349 unsigned int stid = GET_TID(rpl);
2350 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
2353 pr_warn("%s stid %d lookup failure!\n", __func__, stid);
2356 pr_debug("ep %p\n", ep);
2357 c4iw_wake_up_noref(ep->com.wr_waitp, status2errno(rpl->status));
2358 c4iw_put_ep(&ep->com);
2363 static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2364 struct cpl_pass_accept_req *req)
2366 struct cpl_pass_accept_rpl *rpl;
2367 unsigned int mtu_idx;
2371 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2373 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
2375 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2379 if (!is_t4(adapter_type)) {
2380 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2382 INIT_TP_WR(rpl5, ep->hwtid);
2384 skb_trim(skb, sizeof(*rpl));
2385 INIT_TP_WR(rpl, ep->hwtid);
2387 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2390 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2391 enable_tcp_timestamps && req->tcpopt.tstamp,
2392 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
2393 wscale = cxgb_compute_wscale(rcv_win);
2396 * Specify the largest window that will fit in opt0. The
2397 * remainder will be specified in the rx_data_ack.
2399 win = ep->rcv_win >> 10;
2400 if (win > RCV_BUFSIZ_M)
2402 opt0 = (nocong ? NO_CONG_F : 0) |
2405 WND_SCALE_V(wscale) |
2406 MSS_IDX_V(mtu_idx) |
2407 L2T_IDX_V(ep->l2t->idx) |
2408 TX_CHAN_V(ep->tx_chan) |
2409 SMAC_SEL_V(ep->smac_idx) |
2410 DSCP_V(ep->tos >> 2) |
2411 ULP_MODE_V(ULP_MODE_TCPDDP) |
2413 opt2 = RX_CHANNEL_V(0) |
2414 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
2416 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2417 opt2 |= TSTAMPS_EN_F;
2418 if (enable_tcp_sack && req->tcpopt.sack)
2420 if (wscale && enable_tcp_window_scaling)
2421 opt2 |= WND_SCALE_EN_F;
2423 const struct tcphdr *tcph;
2424 u32 hlen = ntohl(req->hdr_len);
2426 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2427 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2430 tcph = (const void *)(req + 1) +
2431 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
2432 if (tcph->ece && tcph->cwr)
2433 opt2 |= CCTRL_ECN_V(1);
2435 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
2436 u32 isn = (prandom_u32() & ~7UL) - 1;
2437 opt2 |= T5_OPT_2_VALID_F;
2438 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2441 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2444 rpl5->iss = cpu_to_be32(isn);
2445 pr_debug("iss %u\n", be32_to_cpu(rpl5->iss));
2448 rpl->opt0 = cpu_to_be64(opt0);
2449 rpl->opt2 = cpu_to_be32(opt2);
2450 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2451 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
2453 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2456 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2458 pr_debug("c4iw_dev %p tid %u\n", dev, hwtid);
2459 skb_trim(skb, sizeof(struct cpl_tid_release));
2460 release_tid(&dev->rdev, hwtid, skb);
2464 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2466 struct c4iw_ep *child_ep = NULL, *parent_ep;
2467 struct cpl_pass_accept_req *req = cplhdr(skb);
2468 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
2469 struct tid_info *t = dev->rdev.lldi.tids;
2470 unsigned int hwtid = GET_TID(req);
2471 struct dst_entry *dst;
2472 __u8 local_ip[16], peer_ip[16];
2473 __be16 local_port, peer_port;
2474 struct sockaddr_in6 *sin6;
2476 u16 peer_mss = ntohs(req->tcpopt.mss);
2478 unsigned short hdrs;
2479 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
2481 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
2483 pr_err("%s connect request on invalid stid %d\n",
2488 if (state_read(&parent_ep->com) != LISTEN) {
2489 pr_err("%s - listening ep not in LISTEN\n", __func__);
2493 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2494 &iptype, local_ip, peer_ip, &local_port, &peer_port);
2496 /* Find output route */
2498 pr_debug("parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2500 local_ip, peer_ip, ntohs(local_port),
2501 ntohs(peer_port), peer_mss);
2502 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2503 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2504 local_port, peer_port, tos);
2506 pr_debug("parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2508 local_ip, peer_ip, ntohs(local_port),
2509 ntohs(peer_port), peer_mss);
2510 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2511 local_ip, peer_ip, local_port, peer_port,
2512 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2513 ((struct sockaddr_in6 *)
2514 &parent_ep->com.local_addr)->sin6_scope_id);
2517 pr_err("%s - failed to find dst entry!\n", __func__);
2521 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2523 pr_err("%s - failed to allocate ep entry!\n", __func__);
2528 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2529 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
2531 pr_err("%s - failed to allocate l2t entry!\n", __func__);
2537 hdrs = ((iptype == 4) ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)) +
2538 sizeof(struct tcphdr) +
2539 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2540 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2541 child_ep->mtu = peer_mss + hdrs;
2543 skb_queue_head_init(&child_ep->com.ep_skb_list);
2544 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2547 state_set(&child_ep->com, CONNECTING);
2548 child_ep->com.dev = dev;
2549 child_ep->com.cm_id = NULL;
2552 struct sockaddr_in *sin = (struct sockaddr_in *)
2553 &child_ep->com.local_addr;
2555 sin->sin_family = AF_INET;
2556 sin->sin_port = local_port;
2557 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2559 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2560 sin->sin_family = AF_INET;
2561 sin->sin_port = ((struct sockaddr_in *)
2562 &parent_ep->com.local_addr)->sin_port;
2563 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2565 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2566 sin->sin_family = AF_INET;
2567 sin->sin_port = peer_port;
2568 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2570 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2571 sin6->sin6_family = PF_INET6;
2572 sin6->sin6_port = local_port;
2573 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2575 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2576 sin6->sin6_family = PF_INET6;
2577 sin6->sin6_port = ((struct sockaddr_in6 *)
2578 &parent_ep->com.local_addr)->sin6_port;
2579 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2581 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2582 sin6->sin6_family = PF_INET6;
2583 sin6->sin6_port = peer_port;
2584 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2587 c4iw_get_ep(&parent_ep->com);
2588 child_ep->parent_ep = parent_ep;
2589 child_ep->tos = tos;
2590 child_ep->dst = dst;
2591 child_ep->hwtid = hwtid;
2593 pr_debug("tx_chan %u smac_idx %u rss_qid %u\n",
2594 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2596 timer_setup(&child_ep->timer, ep_timeout, 0);
2597 cxgb4_insert_tid(t, child_ep, hwtid,
2598 child_ep->com.local_addr.ss_family);
2599 insert_ep_tid(child_ep);
2600 if (accept_cr(child_ep, skb, req)) {
2601 c4iw_put_ep(&parent_ep->com);
2602 release_ep_resources(child_ep);
2604 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2607 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2608 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2609 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2613 c4iw_put_ep(&child_ep->com);
2615 reject_cr(dev, hwtid, skb);
2618 c4iw_put_ep(&parent_ep->com);
2622 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2625 struct cpl_pass_establish *req = cplhdr(skb);
2626 unsigned int tid = GET_TID(req);
2628 u16 tcp_opt = ntohs(req->tcp_opt);
2630 ep = get_ep_from_tid(dev, tid);
2631 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2632 ep->snd_seq = be32_to_cpu(req->snd_isn);
2633 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2634 ep->snd_wscale = TCPOPT_SND_WSCALE_G(tcp_opt);
2636 pr_debug("ep %p hwtid %u tcp_opt 0x%02x\n", ep, tid, tcp_opt);
2638 set_emss(ep, tcp_opt);
2640 dst_confirm(ep->dst);
2641 mutex_lock(&ep->com.mutex);
2642 ep->com.state = MPA_REQ_WAIT;
2644 set_bit(PASS_ESTAB, &ep->com.history);
2645 ret = send_flowc(ep);
2646 mutex_unlock(&ep->com.mutex);
2648 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
2649 c4iw_put_ep(&ep->com);
2654 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2656 struct cpl_peer_close *hdr = cplhdr(skb);
2658 struct c4iw_qp_attributes attrs;
2661 unsigned int tid = GET_TID(hdr);
2664 ep = get_ep_from_tid(dev, tid);
2668 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2669 dst_confirm(ep->dst);
2671 set_bit(PEER_CLOSE, &ep->com.history);
2672 mutex_lock(&ep->com.mutex);
2673 switch (ep->com.state) {
2675 __state_set(&ep->com, CLOSING);
2678 __state_set(&ep->com, CLOSING);
2679 connect_reply_upcall(ep, -ECONNRESET);
2684 * We're gonna mark this puppy DEAD, but keep
2685 * the reference on it until the ULP accepts or
2686 * rejects the CR. Also wake up anyone waiting
2687 * in rdma connection migration (see c4iw_accept_cr()).
2689 __state_set(&ep->com, CLOSING);
2690 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2691 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2694 __state_set(&ep->com, CLOSING);
2695 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
2696 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2700 __state_set(&ep->com, CLOSING);
2701 attrs.next_state = C4IW_QP_STATE_CLOSING;
2702 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2703 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2704 if (ret != -ECONNRESET) {
2705 peer_close_upcall(ep);
2713 __state_set(&ep->com, MORIBUND);
2717 (void)stop_ep_timer(ep);
2718 if (ep->com.cm_id && ep->com.qp) {
2719 attrs.next_state = C4IW_QP_STATE_IDLE;
2720 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2721 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2723 close_complete_upcall(ep, 0);
2724 __state_set(&ep->com, DEAD);
2732 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2734 mutex_unlock(&ep->com.mutex);
2736 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2738 release_ep_resources(ep);
2739 c4iw_put_ep(&ep->com);
2743 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2745 struct cpl_abort_req_rss6 *req = cplhdr(skb);
2747 struct sk_buff *rpl_skb;
2748 struct c4iw_qp_attributes attrs;
2751 unsigned int tid = GET_TID(req);
2754 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
2756 ep = get_ep_from_tid(dev, tid);
2760 status = ABORT_RSS_STATUS_G(be32_to_cpu(req->srqidx_status));
2762 if (cxgb_is_neg_adv(status)) {
2763 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
2764 ep->hwtid, status, neg_adv_str(status));
2765 ep->stats.abort_neg_adv++;
2766 mutex_lock(&dev->rdev.stats.lock);
2767 dev->rdev.stats.neg_adv++;
2768 mutex_unlock(&dev->rdev.stats.lock);
2772 complete_cached_srq_buffers(ep, req->srqidx_status);
2774 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid,
2776 set_bit(PEER_ABORT, &ep->com.history);
2779 * Wake up any threads in rdma_init() or rdma_fini().
2780 * However, this is not needed if com state is just
2783 if (ep->com.state != MPA_REQ_SENT)
2784 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
2786 mutex_lock(&ep->com.mutex);
2787 switch (ep->com.state) {
2789 c4iw_put_ep(&ep->parent_ep->com);
2792 (void)stop_ep_timer(ep);
2795 (void)stop_ep_timer(ep);
2796 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2797 connect_reply_upcall(ep, -ECONNRESET);
2800 * we just don't send notification upwards because we
2801 * want to retry with mpa_v1 without upper layers even
2804 * do some housekeeping so as to re-initiate the
2807 pr_info("%s: mpa_rev=%d. Retrying with mpav1\n",
2809 ep->retry_with_mpa_v1 = 1;
2821 if (ep->com.cm_id && ep->com.qp) {
2822 attrs.next_state = C4IW_QP_STATE_ERROR;
2823 ret = c4iw_modify_qp(ep->com.qp->rhp,
2824 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2827 pr_err("%s - qp <- error failed!\n", __func__);
2829 peer_abort_upcall(ep);
2834 pr_warn("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2835 mutex_unlock(&ep->com.mutex);
2838 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2841 dst_confirm(ep->dst);
2842 if (ep->com.state != ABORTING) {
2843 __state_set(&ep->com, DEAD);
2844 /* we don't release if we want to retry with mpa_v1 */
2845 if (!ep->retry_with_mpa_v1)
2848 mutex_unlock(&ep->com.mutex);
2850 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2851 if (WARN_ON(!rpl_skb)) {
2856 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2858 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2861 release_ep_resources(ep);
2862 else if (ep->retry_with_mpa_v1) {
2863 if (ep->com.remote_addr.ss_family == AF_INET6) {
2864 struct sockaddr_in6 *sin6 =
2865 (struct sockaddr_in6 *)
2866 &ep->com.local_addr;
2868 ep->com.dev->rdev.lldi.ports[0],
2869 (const u32 *)&sin6->sin6_addr.s6_addr,
2872 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2873 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid,
2874 ep->com.local_addr.ss_family);
2875 dst_release(ep->dst);
2876 cxgb4_l2t_release(ep->l2t);
2881 c4iw_put_ep(&ep->com);
2882 /* Dereferencing ep, referenced in peer_abort_intr() */
2883 c4iw_put_ep(&ep->com);
2887 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2890 struct c4iw_qp_attributes attrs;
2891 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2893 unsigned int tid = GET_TID(rpl);
2895 ep = get_ep_from_tid(dev, tid);
2899 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
2901 /* The cm_id may be null if we failed to connect */
2902 mutex_lock(&ep->com.mutex);
2903 set_bit(CLOSE_CON_RPL, &ep->com.history);
2904 switch (ep->com.state) {
2906 __state_set(&ep->com, MORIBUND);
2909 (void)stop_ep_timer(ep);
2910 if ((ep->com.cm_id) && (ep->com.qp)) {
2911 attrs.next_state = C4IW_QP_STATE_IDLE;
2912 c4iw_modify_qp(ep->com.qp->rhp,
2914 C4IW_QP_ATTR_NEXT_STATE,
2917 close_complete_upcall(ep, 0);
2918 __state_set(&ep->com, DEAD);
2925 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
2928 mutex_unlock(&ep->com.mutex);
2930 release_ep_resources(ep);
2931 c4iw_put_ep(&ep->com);
2935 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2937 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2938 unsigned int tid = GET_TID(rpl);
2940 struct c4iw_qp_attributes attrs;
2942 ep = get_ep_from_tid(dev, tid);
2944 if (ep && ep->com.qp) {
2945 pr_warn("TERM received tid %u qpid %u\n",
2946 tid, ep->com.qp->wq.sq.qid);
2947 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2948 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2949 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2951 pr_warn("TERM received tid %u no ep/qp\n", tid);
2952 c4iw_put_ep(&ep->com);
2958 * Upcall from the adapter indicating data has been transmitted.
2959 * For us its just the single MPA request or reply. We can now free
2960 * the skb holding the mpa message.
2962 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2965 struct cpl_fw4_ack *hdr = cplhdr(skb);
2966 u8 credits = hdr->credits;
2967 unsigned int tid = GET_TID(hdr);
2970 ep = get_ep_from_tid(dev, tid);
2973 pr_debug("ep %p tid %u credits %u\n",
2974 ep, ep->hwtid, credits);
2976 pr_debug("0 credit ack ep %p tid %u state %u\n",
2977 ep, ep->hwtid, state_read(&ep->com));
2981 dst_confirm(ep->dst);
2983 pr_debug("last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
2984 ep, ep->hwtid, state_read(&ep->com),
2985 ep->mpa_attr.initiator ? 1 : 0);
2986 mutex_lock(&ep->com.mutex);
2987 kfree_skb(ep->mpa_skb);
2989 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2991 mutex_unlock(&ep->com.mutex);
2994 c4iw_put_ep(&ep->com);
2998 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3001 struct c4iw_ep *ep = to_ep(cm_id);
3003 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3005 mutex_lock(&ep->com.mutex);
3006 if (ep->com.state != MPA_REQ_RCVD) {
3007 mutex_unlock(&ep->com.mutex);
3008 c4iw_put_ep(&ep->com);
3011 set_bit(ULP_REJECT, &ep->com.history);
3015 abort = send_mpa_reject(ep, pdata, pdata_len);
3016 mutex_unlock(&ep->com.mutex);
3019 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
3020 c4iw_put_ep(&ep->com);
3024 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3027 struct c4iw_qp_attributes attrs;
3028 enum c4iw_qp_attr_mask mask;
3029 struct c4iw_ep *ep = to_ep(cm_id);
3030 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3031 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
3034 pr_debug("ep %p tid %u\n", ep, ep->hwtid);
3036 mutex_lock(&ep->com.mutex);
3037 if (ep->com.state != MPA_REQ_RCVD) {
3047 set_bit(ULP_ACCEPT, &ep->com.history);
3048 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3049 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
3054 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3055 if (conn_param->ord > ep->ird) {
3056 if (RELAXED_IRD_NEGOTIATION) {
3057 conn_param->ord = ep->ird;
3059 ep->ird = conn_param->ird;
3060 ep->ord = conn_param->ord;
3061 send_mpa_reject(ep, conn_param->private_data,
3062 conn_param->private_data_len);
3067 if (conn_param->ird < ep->ord) {
3068 if (RELAXED_IRD_NEGOTIATION &&
3069 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3070 conn_param->ird = ep->ord;
3077 ep->ird = conn_param->ird;
3078 ep->ord = conn_param->ord;
3080 if (ep->mpa_attr.version == 1) {
3081 if (peer2peer && ep->ird == 0)
3085 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
3086 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
3090 pr_debug("ird %d ord %d\n", ep->ird, ep->ord);
3092 ep->com.cm_id = cm_id;
3093 ref_cm_id(&ep->com);
3097 /* bind QP to EP and move to RTS */
3098 attrs.mpa_attr = ep->mpa_attr;
3099 attrs.max_ird = ep->ird;
3100 attrs.max_ord = ep->ord;
3101 attrs.llp_stream_handle = ep;
3102 attrs.next_state = C4IW_QP_STATE_RTS;
3104 /* bind QP and TID with INIT_WR */
3105 mask = C4IW_QP_ATTR_NEXT_STATE |
3106 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3107 C4IW_QP_ATTR_MPA_ATTR |
3108 C4IW_QP_ATTR_MAX_IRD |
3109 C4IW_QP_ATTR_MAX_ORD;
3111 err = c4iw_modify_qp(ep->com.qp->rhp,
3112 ep->com.qp, mask, &attrs, 1);
3114 goto err_deref_cm_id;
3116 set_bit(STOP_MPA_TIMER, &ep->com.flags);
3117 err = send_mpa_reply(ep, conn_param->private_data,
3118 conn_param->private_data_len);
3120 goto err_deref_cm_id;
3122 __state_set(&ep->com, FPDU_MODE);
3123 established_upcall(ep);
3124 mutex_unlock(&ep->com.mutex);
3125 c4iw_put_ep(&ep->com);
3128 deref_cm_id(&ep->com);
3132 mutex_unlock(&ep->com.mutex);
3134 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
3135 c4iw_put_ep(&ep->com);
3139 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3141 struct in_device *ind;
3143 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3144 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
3146 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3148 return -EADDRNOTAVAIL;
3149 for_primary_ifa(ind) {
3150 laddr->sin_addr.s_addr = ifa->ifa_address;
3151 raddr->sin_addr.s_addr = ifa->ifa_address;
3157 return found ? 0 : -EADDRNOTAVAIL;
3160 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3161 unsigned char banned_flags)
3163 struct inet6_dev *idev;
3164 int err = -EADDRNOTAVAIL;
3167 idev = __in6_dev_get(dev);
3169 struct inet6_ifaddr *ifp;
3171 read_lock_bh(&idev->lock);
3172 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3173 if (ifp->scope == IFA_LINK &&
3174 !(ifp->flags & banned_flags)) {
3175 memcpy(addr, &ifp->addr, 16);
3180 read_unlock_bh(&idev->lock);
3186 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3188 struct in6_addr uninitialized_var(addr);
3189 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3190 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
3192 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
3193 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3194 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3197 return -EADDRNOTAVAIL;
3200 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3202 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3205 struct sockaddr_in *laddr;
3206 struct sockaddr_in *raddr;
3207 struct sockaddr_in6 *laddr6;
3208 struct sockaddr_in6 *raddr6;
3212 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3213 (conn_param->ird > cur_max_read_depth(dev))) {
3217 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3219 pr_err("%s - cannot alloc ep\n", __func__);
3224 skb_queue_head_init(&ep->com.ep_skb_list);
3225 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3230 timer_setup(&ep->timer, ep_timeout, 0);
3231 ep->plen = conn_param->private_data_len;
3233 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3234 conn_param->private_data, ep->plen);
3235 ep->ird = conn_param->ird;
3236 ep->ord = conn_param->ord;
3238 if (peer2peer && ep->ord == 0)
3241 ep->com.cm_id = cm_id;
3242 ref_cm_id(&ep->com);
3243 cm_id->provider_data = ep;
3245 ep->com.qp = get_qhp(dev, conn_param->qpn);
3247 pr_warn("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3252 pr_debug("qpn 0x%x qp %p cm_id %p\n", conn_param->qpn,
3256 * Allocate an active TID to initiate a TCP connection.
3258 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3259 if (ep->atid == -1) {
3260 pr_err("%s - cannot alloc atid\n", __func__);
3264 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
3266 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3267 sizeof(ep->com.local_addr));
3268 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
3269 sizeof(ep->com.remote_addr));
3271 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3272 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3273 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3274 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
3276 if (cm_id->m_remote_addr.ss_family == AF_INET) {
3278 ra = (__u8 *)&raddr->sin_addr;
3281 * Handle loopback requests to INADDR_ANY.
3283 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
3284 err = pick_local_ipaddrs(dev, cm_id);
3290 pr_debug("saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3291 &laddr->sin_addr, ntohs(laddr->sin_port),
3292 ra, ntohs(raddr->sin_port));
3293 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3294 laddr->sin_addr.s_addr,
3295 raddr->sin_addr.s_addr,
3297 raddr->sin_port, cm_id->tos);
3300 ra = (__u8 *)&raddr6->sin6_addr;
3303 * Handle loopback requests to INADDR_ANY.
3305 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3306 err = pick_local_ip6addrs(dev, cm_id);
3312 pr_debug("saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3313 laddr6->sin6_addr.s6_addr,
3314 ntohs(laddr6->sin6_port),
3315 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3316 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3317 laddr6->sin6_addr.s6_addr,
3318 raddr6->sin6_addr.s6_addr,
3320 raddr6->sin6_port, 0,
3321 raddr6->sin6_scope_id);
3324 pr_err("%s - cannot find route\n", __func__);
3325 err = -EHOSTUNREACH;
3329 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3330 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
3332 pr_err("%s - cannot alloc l2e\n", __func__);
3336 pr_debug("txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3337 ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3340 state_set(&ep->com, CONNECTING);
3341 ep->tos = cm_id->tos;
3343 /* send connect request to rnic */
3344 err = send_connect(ep);
3348 cxgb4_l2t_release(ep->l2t);
3350 dst_release(ep->dst);
3352 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3353 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3355 skb_queue_purge(&ep->com.ep_skb_list);
3356 deref_cm_id(&ep->com);
3358 c4iw_put_ep(&ep->com);
3363 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3366 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3367 &ep->com.local_addr;
3369 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3370 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3371 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3375 c4iw_init_wr_wait(ep->com.wr_waitp);
3376 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3377 ep->stid, &sin6->sin6_addr,
3379 ep->com.dev->rdev.lldi.rxq_ids[0]);
3381 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3385 err = net_xmit_errno(err);
3387 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3388 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3389 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3391 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3396 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3399 struct sockaddr_in *sin = (struct sockaddr_in *)
3400 &ep->com.local_addr;
3402 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3404 err = cxgb4_create_server_filter(
3405 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3406 sin->sin_addr.s_addr, sin->sin_port, 0,
3407 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3408 if (err == -EBUSY) {
3409 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3413 set_current_state(TASK_UNINTERRUPTIBLE);
3414 schedule_timeout(usecs_to_jiffies(100));
3416 } while (err == -EBUSY);
3418 c4iw_init_wr_wait(ep->com.wr_waitp);
3419 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3420 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3421 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3423 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3427 err = net_xmit_errno(err);
3430 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3432 &sin->sin_addr, ntohs(sin->sin_port));
3436 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3439 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3440 struct c4iw_listen_ep *ep;
3444 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3446 pr_err("%s - cannot alloc ep\n", __func__);
3450 skb_queue_head_init(&ep->com.ep_skb_list);
3451 pr_debug("ep %p\n", ep);
3452 ep->com.cm_id = cm_id;
3453 ref_cm_id(&ep->com);
3455 ep->backlog = backlog;
3456 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3457 sizeof(ep->com.local_addr));
3460 * Allocate a server TID.
3462 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3463 ep->com.local_addr.ss_family == AF_INET)
3464 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3465 cm_id->m_local_addr.ss_family, ep);
3467 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3468 cm_id->m_local_addr.ss_family, ep);
3470 if (ep->stid == -1) {
3471 pr_err("%s - cannot alloc stid\n", __func__);
3475 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3477 state_set(&ep->com, LISTEN);
3478 if (ep->com.local_addr.ss_family == AF_INET)
3479 err = create_server4(dev, ep);
3481 err = create_server6(dev, ep);
3483 cm_id->provider_data = ep;
3486 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3487 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3488 ep->com.local_addr.ss_family);
3490 deref_cm_id(&ep->com);
3491 c4iw_put_ep(&ep->com);
3497 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3500 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3502 pr_debug("ep %p\n", ep);
3505 state_set(&ep->com, DEAD);
3506 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3507 ep->com.local_addr.ss_family == AF_INET) {
3508 err = cxgb4_remove_server_filter(
3509 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3510 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3512 struct sockaddr_in6 *sin6;
3513 c4iw_init_wr_wait(ep->com.wr_waitp);
3514 err = cxgb4_remove_server(
3515 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3516 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3519 err = c4iw_wait_for_reply(&ep->com.dev->rdev, ep->com.wr_waitp,
3521 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3522 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3523 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3525 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3526 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3527 ep->com.local_addr.ss_family);
3529 deref_cm_id(&ep->com);
3530 c4iw_put_ep(&ep->com);
3534 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3539 struct c4iw_rdev *rdev;
3541 mutex_lock(&ep->com.mutex);
3543 pr_debug("ep %p state %s, abrupt %d\n", ep,
3544 states[ep->com.state], abrupt);
3547 * Ref the ep here in case we have fatal errors causing the
3548 * ep to be released and freed.
3550 c4iw_get_ep(&ep->com);
3552 rdev = &ep->com.dev->rdev;
3553 if (c4iw_fatal_error(rdev)) {
3555 close_complete_upcall(ep, -EIO);
3556 ep->com.state = DEAD;
3558 switch (ep->com.state) {
3567 ep->com.state = ABORTING;
3569 ep->com.state = CLOSING;
3572 * if we close before we see the fw4_ack() then we fix
3573 * up the timer state since we're reusing it.
3576 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3577 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3582 set_bit(CLOSE_SENT, &ep->com.flags);
3585 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3588 (void)stop_ep_timer(ep);
3589 ep->com.state = ABORTING;
3591 ep->com.state = MORIBUND;
3597 pr_debug("ignoring disconnect ep %p state %u\n",
3601 WARN_ONCE(1, "Bad endpoint state %u\n", ep->com.state);
3607 set_bit(EP_DISC_ABORT, &ep->com.history);
3608 close_complete_upcall(ep, -ECONNRESET);
3609 ret = send_abort(ep);
3611 set_bit(EP_DISC_CLOSE, &ep->com.history);
3612 ret = send_halfclose(ep);
3615 set_bit(EP_DISC_FAIL, &ep->com.history);
3618 close_complete_upcall(ep, -EIO);
3621 struct c4iw_qp_attributes attrs;
3623 attrs.next_state = C4IW_QP_STATE_ERROR;
3624 ret = c4iw_modify_qp(ep->com.qp->rhp,
3626 C4IW_QP_ATTR_NEXT_STATE,
3629 pr_err("%s - qp <- error failed!\n",
3635 mutex_unlock(&ep->com.mutex);
3636 c4iw_put_ep(&ep->com);
3638 release_ep_resources(ep);
3642 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3643 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3646 int atid = be32_to_cpu(req->tid);
3648 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3649 (__force u32) req->tid);
3653 switch (req->retval) {
3655 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3656 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3657 send_fw_act_open_req(ep, atid);
3662 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3663 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3664 send_fw_act_open_req(ep, atid);
3669 pr_info("%s unexpected ofld conn wr retval %d\n",
3670 __func__, req->retval);
3673 pr_err("active ofld_connect_wr failure %d atid %d\n",
3675 mutex_lock(&dev->rdev.stats.lock);
3676 dev->rdev.stats.act_ofld_conn_fails++;
3677 mutex_unlock(&dev->rdev.stats.lock);
3678 connect_reply_upcall(ep, status2errno(req->retval));
3679 state_set(&ep->com, DEAD);
3680 if (ep->com.remote_addr.ss_family == AF_INET6) {
3681 struct sockaddr_in6 *sin6 =
3682 (struct sockaddr_in6 *)&ep->com.local_addr;
3683 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3684 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3686 remove_handle(dev, &dev->atid_idr, atid);
3687 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3688 dst_release(ep->dst);
3689 cxgb4_l2t_release(ep->l2t);
3690 c4iw_put_ep(&ep->com);
3693 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3694 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3696 struct sk_buff *rpl_skb;
3697 struct cpl_pass_accept_req *cpl;
3700 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3702 pr_err("%s passive open failure %d\n", __func__, req->retval);
3703 mutex_lock(&dev->rdev.stats.lock);
3704 dev->rdev.stats.pas_ofld_conn_fails++;
3705 mutex_unlock(&dev->rdev.stats.lock);
3708 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3709 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3710 (__force u32) htonl(
3711 (__force u32) req->tid)));
3712 ret = pass_accept_req(dev, rpl_skb);
3719 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3721 struct cpl_fw6_msg *rpl = cplhdr(skb);
3722 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3724 switch (rpl->type) {
3726 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3728 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3729 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3730 switch (req->t_state) {
3732 active_ofld_conn_reply(dev, skb, req);
3735 passive_ofld_conn_reply(dev, skb, req);
3738 pr_err("%s unexpected ofld conn wr state %d\n",
3739 __func__, req->t_state);
3747 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3750 __be16 hdr_len, vlantag, len;
3752 int tcp_hdr_len, ip_hdr_len;
3754 struct cpl_rx_pkt *cpl = cplhdr(skb);
3755 struct cpl_pass_accept_req *req;
3756 struct tcp_options_received tmp_opt;
3757 struct c4iw_dev *dev;
3758 enum chip_type type;
3760 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3761 /* Store values from cpl_rx_pkt in temporary location. */
3762 vlantag = cpl->vlan;
3764 l2info = cpl->l2info;
3765 hdr_len = cpl->hdr_len;
3768 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3771 * We need to parse the TCP options from SYN packet.
3772 * to generate cpl_pass_accept_req.
3774 memset(&tmp_opt, 0, sizeof(tmp_opt));
3775 tcp_clear_options(&tmp_opt);
3776 tcp_parse_options(&init_net, skb, &tmp_opt, 0, NULL);
3778 req = __skb_push(skb, sizeof(*req));
3779 memset(req, 0, sizeof(*req));
3780 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3781 SYN_MAC_IDX_V(RX_MACIDX_G(
3782 be32_to_cpu(l2info))) |
3784 type = dev->rdev.lldi.adapter_type;
3785 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3786 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3788 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3789 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3790 eth_hdr_len = is_t4(type) ?
3791 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3792 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3793 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3794 IP_HDR_LEN_V(ip_hdr_len) |
3795 ETH_HDR_LEN_V(eth_hdr_len));
3796 } else { /* T6 and later */
3797 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3798 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3799 T6_IP_HDR_LEN_V(ip_hdr_len) |
3800 T6_ETH_HDR_LEN_V(eth_hdr_len));
3802 req->vlan = vlantag;
3804 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3805 PASS_OPEN_TOS_V(tos));
3806 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3807 if (tmp_opt.wscale_ok)
3808 req->tcpopt.wsf = tmp_opt.snd_wscale;
3809 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3810 if (tmp_opt.sack_ok)
3811 req->tcpopt.sack = 1;
3812 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3816 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3817 __be32 laddr, __be16 lport,
3818 __be32 raddr, __be16 rport,
3819 u32 rcv_isn, u32 filter, u16 window,
3820 u32 rss_qid, u8 port_id)
3822 struct sk_buff *req_skb;
3823 struct fw_ofld_connection_wr *req;
3824 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3827 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3830 req = __skb_put_zero(req_skb, sizeof(*req));
3831 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
3832 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
3833 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
3834 req->le.filter = (__force __be32) filter;
3835 req->le.lport = lport;
3836 req->le.pport = rport;
3837 req->le.u.ipv4.lip = laddr;
3838 req->le.u.ipv4.pip = raddr;
3839 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3840 req->tcb.rcv_adv = htons(window);
3841 req->tcb.t_state_to_astid =
3842 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3843 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3844 FW_OFLD_CONNECTION_WR_ASTID_V(
3845 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
3848 * We store the qid in opt2 which will be used by the firmware
3849 * to send us the wr response.
3851 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
3854 * We initialize the MSS index in TCB to 0xF.
3855 * So that when driver sends cpl_pass_accept_rpl
3856 * TCB picks up the correct value. If this was 0
3857 * TP will ignore any value > 0 for MSS index.
3859 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
3860 req->cookie = (uintptr_t)skb;
3862 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3863 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3865 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3873 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3874 * messages when a filter is being used instead of server to
3875 * redirect a syn packet. When packets hit filter they are redirected
3876 * to the offload queue and driver tries to establish the connection
3877 * using firmware work request.
3879 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3882 unsigned int filter;
3883 struct ethhdr *eh = NULL;
3884 struct vlan_ethhdr *vlan_eh = NULL;
3886 struct tcphdr *tcph;
3887 struct rss_header *rss = (void *)skb->data;
3888 struct cpl_rx_pkt *cpl = (void *)skb->data;
3889 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3890 struct l2t_entry *e;
3891 struct dst_entry *dst;
3892 struct c4iw_ep *lep = NULL;
3894 struct port_info *pi;
3895 struct net_device *pdev;
3896 u16 rss_qid, eth_hdr_len;
3898 struct neighbour *neigh;
3900 /* Drop all non-SYN packets */
3901 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
3905 * Drop all packets which did not hit the filter.
3906 * Unlikely to happen.
3908 if (!(rss->filter_hit && rss->filter_tid))
3912 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3914 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3916 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
3918 pr_warn("%s connect request on invalid stid %d\n",
3923 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3925 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3928 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3931 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3934 pr_err("T%d Chip is not supported\n",
3935 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3939 if (eth_hdr_len == ETH_HLEN) {
3940 eh = (struct ethhdr *)(req + 1);
3941 iph = (struct iphdr *)(eh + 1);
3943 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3944 iph = (struct iphdr *)(vlan_eh + 1);
3945 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ntohs(cpl->vlan));
3948 if (iph->version != 0x4)
3951 tcph = (struct tcphdr *)(iph + 1);
3952 skb_set_network_header(skb, (void *)iph - (void *)rss);
3953 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3956 pr_debug("lip 0x%x lport %u pip 0x%x pport %u tos %d\n",
3957 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3958 ntohs(tcph->source), iph->tos);
3960 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3961 iph->daddr, iph->saddr, tcph->dest,
3962 tcph->source, iph->tos);
3964 pr_err("%s - failed to find dst entry!\n", __func__);
3967 neigh = dst_neigh_lookup_skb(dst, skb);
3970 pr_err("%s - failed to allocate neigh!\n", __func__);
3974 if (neigh->dev->flags & IFF_LOOPBACK) {
3975 pdev = ip_dev_find(&init_net, iph->daddr);
3976 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3978 pi = (struct port_info *)netdev_priv(pdev);
3981 pdev = get_real_dev(neigh->dev);
3982 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3984 pi = (struct port_info *)netdev_priv(pdev);
3986 neigh_release(neigh);
3988 pr_err("%s - failed to allocate l2t entry!\n",
3993 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3994 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3995 window = (__force u16) htons((__force u16)tcph->window);
3997 /* Calcuate filter portion for LE region. */
3998 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3999 dev->rdev.lldi.ports[0],
4003 * Synthesize the cpl_pass_accept_req. We have everything except the
4004 * TID. Once firmware sends a reply with TID we update the TID field
4005 * in cpl and pass it through the regular cpl_pass_accept_req path.
4007 build_cpl_pass_accept_req(skb, stid, iph->tos);
4008 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4009 tcph->source, ntohl(tcph->seq), filter, window,
4010 rss_qid, pi->port_id);
4011 cxgb4_l2t_release(e);
4016 c4iw_put_ep(&lep->com);
4021 * These are the real handlers that are called from a
4024 static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
4025 [CPL_ACT_ESTABLISH] = act_establish,
4026 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4027 [CPL_RX_DATA] = rx_data,
4028 [CPL_ABORT_RPL_RSS] = abort_rpl,
4029 [CPL_ABORT_RPL] = abort_rpl,
4030 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4031 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4032 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4033 [CPL_PASS_ESTABLISH] = pass_establish,
4034 [CPL_PEER_CLOSE] = peer_close,
4035 [CPL_ABORT_REQ_RSS] = peer_abort,
4036 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4037 [CPL_RDMA_TERMINATE] = terminate,
4038 [CPL_FW4_ACK] = fw4_ack,
4039 [CPL_FW6_MSG] = deferred_fw6_msg,
4040 [CPL_RX_PKT] = rx_pkt,
4041 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4042 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
4045 static void process_timeout(struct c4iw_ep *ep)
4047 struct c4iw_qp_attributes attrs;
4050 mutex_lock(&ep->com.mutex);
4051 pr_debug("ep %p tid %u state %d\n", ep, ep->hwtid, ep->com.state);
4052 set_bit(TIMEDOUT, &ep->com.history);
4053 switch (ep->com.state) {
4055 connect_reply_upcall(ep, -ETIMEDOUT);
4064 if (ep->com.cm_id && ep->com.qp) {
4065 attrs.next_state = C4IW_QP_STATE_ERROR;
4066 c4iw_modify_qp(ep->com.qp->rhp,
4067 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4070 close_complete_upcall(ep, -ETIMEDOUT);
4076 * These states are expected if the ep timed out at the same
4077 * time as another thread was calling stop_ep_timer().
4078 * So we silently do nothing for these states.
4083 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
4084 __func__, ep, ep->hwtid, ep->com.state);
4087 mutex_unlock(&ep->com.mutex);
4089 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
4090 c4iw_put_ep(&ep->com);
4093 static void process_timedout_eps(void)
4097 spin_lock_irq(&timeout_lock);
4098 while (!list_empty(&timeout_list)) {
4099 struct list_head *tmp;
4101 tmp = timeout_list.next;
4105 spin_unlock_irq(&timeout_lock);
4106 ep = list_entry(tmp, struct c4iw_ep, entry);
4107 process_timeout(ep);
4108 spin_lock_irq(&timeout_lock);
4110 spin_unlock_irq(&timeout_lock);
4113 static void process_work(struct work_struct *work)
4115 struct sk_buff *skb = NULL;
4116 struct c4iw_dev *dev;
4117 struct cpl_act_establish *rpl;
4118 unsigned int opcode;
4121 process_timedout_eps();
4122 while ((skb = skb_dequeue(&rxq))) {
4124 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4125 opcode = rpl->ot.opcode;
4127 if (opcode >= ARRAY_SIZE(work_handlers) ||
4128 !work_handlers[opcode]) {
4129 pr_err("No handler for opcode 0x%x.\n", opcode);
4132 ret = work_handlers[opcode](dev, skb);
4136 process_timedout_eps();
4140 static DECLARE_WORK(skb_work, process_work);
4142 static void ep_timeout(struct timer_list *t)
4144 struct c4iw_ep *ep = from_timer(ep, t, timer);
4147 spin_lock(&timeout_lock);
4148 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
4150 * Only insert if it is not already on the list.
4152 if (!ep->entry.next) {
4153 list_add_tail(&ep->entry, &timeout_list);
4157 spin_unlock(&timeout_lock);
4159 queue_work(workq, &skb_work);
4163 * All the CM events are handled on a work queue to have a safe context.
4165 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4169 * Save dev in the skb->cb area.
4171 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4174 * Queue the skb and schedule the worker thread.
4176 skb_queue_tail(&rxq, skb);
4177 queue_work(workq, &skb_work);
4181 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4183 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4185 if (rpl->status != CPL_ERR_NONE) {
4186 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4187 rpl->status, GET_TID(rpl));
4193 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4195 struct cpl_fw6_msg *rpl = cplhdr(skb);
4196 struct c4iw_wr_wait *wr_waitp;
4199 pr_debug("type %u\n", rpl->type);
4201 switch (rpl->type) {
4202 case FW6_TYPE_WR_RPL:
4203 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
4204 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
4205 pr_debug("wr_waitp %p ret %u\n", wr_waitp, ret);
4207 c4iw_wake_up_deref(wr_waitp, ret ? -ret : 0);
4211 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
4215 pr_err("%s unexpected fw6 msg type %u\n",
4216 __func__, rpl->type);
4223 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4225 struct cpl_abort_req_rss *req = cplhdr(skb);
4227 unsigned int tid = GET_TID(req);
4229 ep = get_ep_from_tid(dev, tid);
4230 /* This EP will be dereferenced in peer_abort() */
4232 pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
4236 if (cxgb_is_neg_adv(req->status)) {
4237 pr_debug("Negative advice on abort- tid %u status %d (%s)\n",
4238 ep->hwtid, req->status,
4239 neg_adv_str(req->status));
4242 pr_debug("ep %p tid %u state %u\n", ep, ep->hwtid, ep->com.state);
4244 c4iw_wake_up_noref(ep->com.wr_waitp, -ECONNRESET);
4251 * Most upcalls from the T4 Core go to sched() to
4252 * schedule the processing on a work queue.
4254 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4255 [CPL_ACT_ESTABLISH] = sched,
4256 [CPL_ACT_OPEN_RPL] = sched,
4257 [CPL_RX_DATA] = sched,
4258 [CPL_ABORT_RPL_RSS] = sched,
4259 [CPL_ABORT_RPL] = sched,
4260 [CPL_PASS_OPEN_RPL] = sched,
4261 [CPL_CLOSE_LISTSRV_RPL] = sched,
4262 [CPL_PASS_ACCEPT_REQ] = sched,
4263 [CPL_PASS_ESTABLISH] = sched,
4264 [CPL_PEER_CLOSE] = sched,
4265 [CPL_CLOSE_CON_RPL] = sched,
4266 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
4267 [CPL_RDMA_TERMINATE] = sched,
4268 [CPL_FW4_ACK] = sched,
4269 [CPL_SET_TCB_RPL] = set_tcb_rpl,
4270 [CPL_FW6_MSG] = fw6_msg,
4271 [CPL_RX_PKT] = sched
4274 int __init c4iw_cm_init(void)
4276 spin_lock_init(&timeout_lock);
4277 skb_queue_head_init(&rxq);
4279 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
4286 void c4iw_cm_term(void)
4288 WARN_ON(!list_empty(&timeout_list));
4289 flush_workqueue(workq);
4290 destroy_workqueue(workq);