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>
55 static char *states[] = {
72 module_param(nocong, int, 0644);
73 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
75 static int enable_ecn;
76 module_param(enable_ecn, int, 0644);
77 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
79 static int dack_mode = 1;
80 module_param(dack_mode, int, 0644);
81 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
83 uint c4iw_max_read_depth = 32;
84 module_param(c4iw_max_read_depth, int, 0644);
85 MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
88 static int enable_tcp_timestamps;
89 module_param(enable_tcp_timestamps, int, 0644);
90 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
92 static int enable_tcp_sack;
93 module_param(enable_tcp_sack, int, 0644);
94 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
96 static int enable_tcp_window_scaling = 1;
97 module_param(enable_tcp_window_scaling, int, 0644);
98 MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
102 module_param(c4iw_debug, int, 0644);
103 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
105 static int peer2peer = 1;
106 module_param(peer2peer, int, 0644);
107 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
109 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110 module_param(p2p_type, int, 0644);
111 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
114 static int ep_timeout_secs = 60;
115 module_param(ep_timeout_secs, int, 0644);
116 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
119 static int mpa_rev = 2;
120 module_param(mpa_rev, int, 0644);
121 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
122 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
123 " compliant (default=2)");
125 static int markers_enabled;
126 module_param(markers_enabled, int, 0644);
127 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
129 static int crc_enabled = 1;
130 module_param(crc_enabled, int, 0644);
131 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
133 static int rcv_win = 256 * 1024;
134 module_param(rcv_win, int, 0644);
135 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
137 static int snd_win = 128 * 1024;
138 module_param(snd_win, int, 0644);
139 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
141 static struct workqueue_struct *workq;
143 static struct sk_buff_head rxq;
145 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146 static void ep_timeout(unsigned long arg);
147 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
148 static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
150 static LIST_HEAD(timeout_list);
151 static spinlock_t timeout_lock;
153 static void deref_cm_id(struct c4iw_ep_common *epc)
155 epc->cm_id->rem_ref(epc->cm_id);
157 set_bit(CM_ID_DEREFED, &epc->history);
160 static void ref_cm_id(struct c4iw_ep_common *epc)
162 set_bit(CM_ID_REFED, &epc->history);
163 epc->cm_id->add_ref(epc->cm_id);
166 static void deref_qp(struct c4iw_ep *ep)
168 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
169 clear_bit(QP_REFERENCED, &ep->com.flags);
170 set_bit(QP_DEREFED, &ep->com.history);
173 static void ref_qp(struct c4iw_ep *ep)
175 set_bit(QP_REFERENCED, &ep->com.flags);
176 set_bit(QP_REFED, &ep->com.history);
177 c4iw_qp_add_ref(&ep->com.qp->ibqp);
180 static void start_ep_timer(struct c4iw_ep *ep)
182 PDBG("%s ep %p\n", __func__, ep);
183 if (timer_pending(&ep->timer)) {
184 pr_err("%s timer already started! ep %p\n",
188 clear_bit(TIMEOUT, &ep->com.flags);
189 c4iw_get_ep(&ep->com);
190 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
191 ep->timer.data = (unsigned long)ep;
192 ep->timer.function = ep_timeout;
193 add_timer(&ep->timer);
196 static int stop_ep_timer(struct c4iw_ep *ep)
198 PDBG("%s ep %p stopping\n", __func__, ep);
199 del_timer_sync(&ep->timer);
200 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
201 c4iw_put_ep(&ep->com);
207 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
208 struct l2t_entry *l2e)
212 if (c4iw_fatal_error(rdev)) {
214 PDBG("%s - device in error state - dropping\n", __func__);
217 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
220 return error < 0 ? error : 0;
223 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
227 if (c4iw_fatal_error(rdev)) {
229 PDBG("%s - device in error state - dropping\n", __func__);
232 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
235 return error < 0 ? error : 0;
238 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
240 struct cpl_tid_release *req;
242 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
245 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
246 INIT_TP_WR(req, hwtid);
247 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
248 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
249 c4iw_ofld_send(rdev, skb);
253 static void set_emss(struct c4iw_ep *ep, u16 opt)
255 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
256 ((AF_INET == ep->com.remote_addr.ss_family) ?
257 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
258 sizeof(struct tcphdr);
260 if (TCPOPT_TSTAMP_G(opt))
261 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
265 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
266 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
267 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
271 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
273 enum c4iw_ep_state state;
275 mutex_lock(&epc->mutex);
277 mutex_unlock(&epc->mutex);
281 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
286 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
288 mutex_lock(&epc->mutex);
289 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
290 __state_set(epc, new);
291 mutex_unlock(&epc->mutex);
295 static void *alloc_ep(int size, gfp_t gfp)
297 struct c4iw_ep_common *epc;
299 epc = kzalloc(size, gfp);
301 kref_init(&epc->kref);
302 mutex_init(&epc->mutex);
303 c4iw_init_wr_wait(&epc->wr_wait);
305 PDBG("%s alloc ep %p\n", __func__, epc);
309 void _c4iw_free_ep(struct kref *kref)
313 ep = container_of(kref, struct c4iw_ep, com.kref);
314 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
315 if (test_bit(QP_REFERENCED, &ep->com.flags))
317 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
318 if (ep->com.remote_addr.ss_family == AF_INET6) {
319 struct sockaddr_in6 *sin6 =
320 (struct sockaddr_in6 *)
324 ep->com.dev->rdev.lldi.ports[0],
325 (const u32 *)&sin6->sin6_addr.s6_addr,
328 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
329 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
330 dst_release(ep->dst);
331 cxgb4_l2t_release(ep->l2t);
336 static void release_ep_resources(struct c4iw_ep *ep)
338 set_bit(RELEASE_RESOURCES, &ep->com.flags);
339 c4iw_put_ep(&ep->com);
342 static int status2errno(int status)
347 case CPL_ERR_CONN_RESET:
349 case CPL_ERR_ARP_MISS:
350 return -EHOSTUNREACH;
351 case CPL_ERR_CONN_TIMEDOUT:
353 case CPL_ERR_TCAM_FULL:
355 case CPL_ERR_CONN_EXIST:
363 * Try and reuse skbs already allocated...
365 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
367 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
370 skb_reset_transport_header(skb);
372 skb = alloc_skb(len, gfp);
374 t4_set_arp_err_handler(skb, NULL, NULL);
378 static struct net_device *get_real_dev(struct net_device *egress_dev)
380 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
383 static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
387 egress_dev = get_real_dev(egress_dev);
388 for (i = 0; i < dev->rdev.lldi.nports; i++)
389 if (dev->rdev.lldi.ports[i] == egress_dev)
394 static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
395 __u8 *peer_ip, __be16 local_port,
396 __be16 peer_port, u8 tos,
399 struct dst_entry *dst = NULL;
401 if (IS_ENABLED(CONFIG_IPV6)) {
404 memset(&fl6, 0, sizeof(fl6));
405 memcpy(&fl6.daddr, peer_ip, 16);
406 memcpy(&fl6.saddr, local_ip, 16);
407 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
408 fl6.flowi6_oif = sin6_scope_id;
409 dst = ip6_route_output(&init_net, NULL, &fl6);
412 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
413 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
423 static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
424 __be32 peer_ip, __be16 local_port,
425 __be16 peer_port, u8 tos)
431 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
432 peer_port, local_port, IPPROTO_TCP,
436 n = dst_neigh_lookup(&rt->dst, &peer_ip);
439 if (!our_interface(dev, n->dev) &&
440 !(n->dev->flags & IFF_LOOPBACK)) {
442 dst_release(&rt->dst);
449 static void arp_failure_discard(void *handle, struct sk_buff *skb)
451 pr_err(MOD "ARP failure\n");
457 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
460 static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
464 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
465 release_ep_resources(ep);
470 * Fake up a special CPL opcode and call sched() so process_work() will call
471 * _put_ep_safe() in a safe context to free the ep resources. This is needed
472 * because ARP error handlers are called in an ATOMIC context, and
473 * _c4iw_free_ep() needs to block.
475 static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb)
477 struct cpl_act_establish *rpl = cplhdr(skb);
479 /* Set our special ARP_FAILURE opcode */
480 rpl->ot.opcode = FAKE_CPL_PUT_EP_SAFE;
483 * Save ep in the skb->cb area, after where sched() will save the dev
486 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
487 sched(ep->com.dev, skb);
490 /* Handle an ARP failure for an accept */
491 static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
493 struct c4iw_ep *ep = handle;
495 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
498 __state_set(&ep->com, DEAD);
499 queue_arp_failure_cpl(ep, skb);
503 * Handle an ARP failure for an active open.
505 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
507 struct c4iw_ep *ep = handle;
509 printk(KERN_ERR MOD "ARP failure during connect\n");
510 connect_reply_upcall(ep, -EHOSTUNREACH);
511 __state_set(&ep->com, DEAD);
512 if (ep->com.remote_addr.ss_family == AF_INET6) {
513 struct sockaddr_in6 *sin6 =
514 (struct sockaddr_in6 *)&ep->com.local_addr;
515 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
516 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
518 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
519 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
520 queue_arp_failure_cpl(ep, skb);
524 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
527 static void abort_arp_failure(void *handle, struct sk_buff *skb)
529 struct c4iw_rdev *rdev = handle;
530 struct cpl_abort_req *req = cplhdr(skb);
532 PDBG("%s rdev %p\n", __func__, rdev);
533 req->cmd = CPL_ABORT_NO_RST;
534 c4iw_ofld_send(rdev, skb);
537 static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
539 unsigned int flowclen = 80;
540 struct fw_flowc_wr *flowc;
542 u16 vlan = ep->l2t->vlan;
545 if (vlan == CPL_L2T_VLAN_NONE)
550 skb = get_skb(skb, flowclen, GFP_KERNEL);
551 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
553 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
554 FW_FLOWC_WR_NPARAMS_V(nparams));
555 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
556 16)) | FW_WR_FLOWID_V(ep->hwtid));
558 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
559 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
560 (ep->com.dev->rdev.lldi.pf));
561 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
562 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
563 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
564 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
565 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
566 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
567 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
568 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
569 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
570 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
571 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
572 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
573 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
574 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
578 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
579 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
580 flowc->mnemval[8].val = cpu_to_be32(pri);
582 /* Pad WR to 16 byte boundary */
583 flowc->mnemval[8].mnemonic = 0;
584 flowc->mnemval[8].val = 0;
586 for (i = 0; i < 9; i++) {
587 flowc->mnemval[i].r4[0] = 0;
588 flowc->mnemval[i].r4[1] = 0;
589 flowc->mnemval[i].r4[2] = 0;
592 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
593 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
596 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
598 struct cpl_close_con_req *req;
600 int wrlen = roundup(sizeof *req, 16);
602 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
603 skb = get_skb(NULL, wrlen, gfp);
605 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
608 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
609 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
610 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
611 memset(req, 0, wrlen);
612 INIT_TP_WR(req, ep->hwtid);
613 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
615 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
618 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
620 struct cpl_abort_req *req;
621 int wrlen = roundup(sizeof *req, 16);
623 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
624 skb = get_skb(skb, wrlen, gfp);
626 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
630 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
631 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
632 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
633 memset(req, 0, wrlen);
634 INIT_TP_WR(req, ep->hwtid);
635 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
636 req->cmd = CPL_ABORT_SEND_RST;
637 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
640 static void best_mtu(const unsigned short *mtus, unsigned short mtu,
641 unsigned int *idx, int use_ts, int ipv6)
643 unsigned short hdr_size = (ipv6 ?
644 sizeof(struct ipv6hdr) :
645 sizeof(struct iphdr)) +
646 sizeof(struct tcphdr) +
648 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
649 unsigned short data_size = mtu - hdr_size;
651 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
654 static int send_connect(struct c4iw_ep *ep)
656 struct cpl_act_open_req *req = NULL;
657 struct cpl_t5_act_open_req *t5req = NULL;
658 struct cpl_t6_act_open_req *t6req = NULL;
659 struct cpl_act_open_req6 *req6 = NULL;
660 struct cpl_t5_act_open_req6 *t5req6 = NULL;
661 struct cpl_t6_act_open_req6 *t6req6 = NULL;
665 unsigned int mtu_idx;
667 int win, sizev4, sizev6, wrlen;
668 struct sockaddr_in *la = (struct sockaddr_in *)
670 struct sockaddr_in *ra = (struct sockaddr_in *)
671 &ep->com.remote_addr;
672 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
674 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
675 &ep->com.remote_addr;
677 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
678 u32 isn = (prandom_u32() & ~7UL) - 1;
680 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
682 sizev4 = sizeof(struct cpl_act_open_req);
683 sizev6 = sizeof(struct cpl_act_open_req6);
686 sizev4 = sizeof(struct cpl_t5_act_open_req);
687 sizev6 = sizeof(struct cpl_t5_act_open_req6);
690 sizev4 = sizeof(struct cpl_t6_act_open_req);
691 sizev6 = sizeof(struct cpl_t6_act_open_req6);
694 pr_err("T%d Chip is not supported\n",
695 CHELSIO_CHIP_VERSION(adapter_type));
699 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
700 roundup(sizev4, 16) :
703 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
705 skb = get_skb(NULL, wrlen, GFP_KERNEL);
707 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
711 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
713 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
714 enable_tcp_timestamps,
715 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
716 wscale = compute_wscale(rcv_win);
719 * Specify the largest window that will fit in opt0. The
720 * remainder will be specified in the rx_data_ack.
722 win = ep->rcv_win >> 10;
723 if (win > RCV_BUFSIZ_M)
726 opt0 = (nocong ? NO_CONG_F : 0) |
729 WND_SCALE_V(wscale) |
731 L2T_IDX_V(ep->l2t->idx) |
732 TX_CHAN_V(ep->tx_chan) |
733 SMAC_SEL_V(ep->smac_idx) |
734 DSCP_V(ep->tos >> 2) |
735 ULP_MODE_V(ULP_MODE_TCPDDP) |
737 opt2 = RX_CHANNEL_V(0) |
738 CCTRL_ECN_V(enable_ecn) |
739 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
740 if (enable_tcp_timestamps)
741 opt2 |= TSTAMPS_EN_F;
744 if (wscale && enable_tcp_window_scaling)
745 opt2 |= WND_SCALE_EN_F;
746 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
750 opt2 |= T5_OPT_2_VALID_F;
751 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
755 if (ep->com.remote_addr.ss_family == AF_INET6)
756 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
757 (const u32 *)&la6->sin6_addr.s6_addr, 1);
759 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
761 if (ep->com.remote_addr.ss_family == AF_INET) {
762 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
764 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
768 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
770 INIT_TP_WR(t5req, 0);
771 req = (struct cpl_act_open_req *)t5req;
774 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
776 INIT_TP_WR(t6req, 0);
777 req = (struct cpl_act_open_req *)t6req;
778 t5req = (struct cpl_t5_act_open_req *)t6req;
781 pr_err("T%d Chip is not supported\n",
782 CHELSIO_CHIP_VERSION(adapter_type));
787 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
788 ((ep->rss_qid<<14) | ep->atid)));
789 req->local_port = la->sin_port;
790 req->peer_port = ra->sin_port;
791 req->local_ip = la->sin_addr.s_addr;
792 req->peer_ip = ra->sin_addr.s_addr;
793 req->opt0 = cpu_to_be64(opt0);
795 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
796 req->params = cpu_to_be32(cxgb4_select_ntuple(
797 ep->com.dev->rdev.lldi.ports[0],
799 req->opt2 = cpu_to_be32(opt2);
801 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
803 ep->com.dev->rdev.lldi.ports[0],
805 t5req->rsvd = cpu_to_be32(isn);
806 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
807 t5req->opt2 = cpu_to_be32(opt2);
810 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
812 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
816 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
818 INIT_TP_WR(t5req6, 0);
819 req6 = (struct cpl_act_open_req6 *)t5req6;
822 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
824 INIT_TP_WR(t6req6, 0);
825 req6 = (struct cpl_act_open_req6 *)t6req6;
826 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
829 pr_err("T%d Chip is not supported\n",
830 CHELSIO_CHIP_VERSION(adapter_type));
835 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
836 ((ep->rss_qid<<14)|ep->atid)));
837 req6->local_port = la6->sin6_port;
838 req6->peer_port = ra6->sin6_port;
839 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
840 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
841 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
842 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
843 req6->opt0 = cpu_to_be64(opt0);
845 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
846 req6->params = cpu_to_be32(cxgb4_select_ntuple(
847 ep->com.dev->rdev.lldi.ports[0],
849 req6->opt2 = cpu_to_be32(opt2);
851 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
853 ep->com.dev->rdev.lldi.ports[0],
855 t5req6->rsvd = cpu_to_be32(isn);
856 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
857 t5req6->opt2 = cpu_to_be32(opt2);
861 set_bit(ACT_OPEN_REQ, &ep->com.history);
862 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
864 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
865 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
866 (const u32 *)&la6->sin6_addr.s6_addr, 1);
870 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
874 struct fw_ofld_tx_data_wr *req;
875 struct mpa_message *mpa;
876 struct mpa_v2_conn_params mpa_v2_params;
878 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
880 BUG_ON(skb_cloned(skb));
882 mpalen = sizeof(*mpa) + ep->plen;
883 if (mpa_rev_to_use == 2)
884 mpalen += sizeof(struct mpa_v2_conn_params);
885 wrlen = roundup(mpalen + sizeof *req, 16);
886 skb = get_skb(skb, wrlen, GFP_KERNEL);
888 connect_reply_upcall(ep, -ENOMEM);
891 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
893 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
894 memset(req, 0, wrlen);
895 req->op_to_immdlen = cpu_to_be32(
896 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
898 FW_WR_IMMDLEN_V(mpalen));
899 req->flowid_len16 = cpu_to_be32(
900 FW_WR_FLOWID_V(ep->hwtid) |
901 FW_WR_LEN16_V(wrlen >> 4));
902 req->plen = cpu_to_be32(mpalen);
903 req->tunnel_to_proxy = cpu_to_be32(
904 FW_OFLD_TX_DATA_WR_FLUSH_F |
905 FW_OFLD_TX_DATA_WR_SHOVE_F);
907 mpa = (struct mpa_message *)(req + 1);
908 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
909 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
910 (markers_enabled ? MPA_MARKERS : 0) |
911 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
912 mpa->private_data_size = htons(ep->plen);
913 mpa->revision = mpa_rev_to_use;
914 if (mpa_rev_to_use == 1) {
915 ep->tried_with_mpa_v1 = 1;
916 ep->retry_with_mpa_v1 = 0;
919 if (mpa_rev_to_use == 2) {
920 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
921 sizeof (struct mpa_v2_conn_params));
922 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
924 mpa_v2_params.ird = htons((u16)ep->ird);
925 mpa_v2_params.ord = htons((u16)ep->ord);
928 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
929 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
931 htons(MPA_V2_RDMA_WRITE_RTR);
932 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
934 htons(MPA_V2_RDMA_READ_RTR);
936 memcpy(mpa->private_data, &mpa_v2_params,
937 sizeof(struct mpa_v2_conn_params));
940 memcpy(mpa->private_data +
941 sizeof(struct mpa_v2_conn_params),
942 ep->mpa_pkt + sizeof(*mpa), ep->plen);
945 memcpy(mpa->private_data,
946 ep->mpa_pkt + sizeof(*mpa), ep->plen);
949 * Reference the mpa skb. This ensures the data area
950 * will remain in memory until the hw acks the tx.
951 * Function fw4_ack() will deref it.
954 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
957 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
959 __state_set(&ep->com, MPA_REQ_SENT);
960 ep->mpa_attr.initiator = 1;
961 ep->snd_seq += mpalen;
965 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
968 struct fw_ofld_tx_data_wr *req;
969 struct mpa_message *mpa;
971 struct mpa_v2_conn_params mpa_v2_params;
973 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
975 mpalen = sizeof(*mpa) + plen;
976 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
977 mpalen += sizeof(struct mpa_v2_conn_params);
978 wrlen = roundup(mpalen + sizeof *req, 16);
980 skb = get_skb(NULL, wrlen, GFP_KERNEL);
982 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
985 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
987 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
988 memset(req, 0, wrlen);
989 req->op_to_immdlen = cpu_to_be32(
990 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
992 FW_WR_IMMDLEN_V(mpalen));
993 req->flowid_len16 = cpu_to_be32(
994 FW_WR_FLOWID_V(ep->hwtid) |
995 FW_WR_LEN16_V(wrlen >> 4));
996 req->plen = cpu_to_be32(mpalen);
997 req->tunnel_to_proxy = cpu_to_be32(
998 FW_OFLD_TX_DATA_WR_FLUSH_F |
999 FW_OFLD_TX_DATA_WR_SHOVE_F);
1001 mpa = (struct mpa_message *)(req + 1);
1002 memset(mpa, 0, sizeof(*mpa));
1003 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1004 mpa->flags = MPA_REJECT;
1005 mpa->revision = ep->mpa_attr.version;
1006 mpa->private_data_size = htons(plen);
1008 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1009 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1010 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1011 sizeof (struct mpa_v2_conn_params));
1012 mpa_v2_params.ird = htons(((u16)ep->ird) |
1013 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1015 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1017 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1018 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1019 FW_RI_INIT_P2PTYPE_READ_REQ ?
1020 MPA_V2_RDMA_READ_RTR : 0) : 0));
1021 memcpy(mpa->private_data, &mpa_v2_params,
1022 sizeof(struct mpa_v2_conn_params));
1025 memcpy(mpa->private_data +
1026 sizeof(struct mpa_v2_conn_params), pdata, plen);
1029 memcpy(mpa->private_data, pdata, plen);
1032 * Reference the mpa skb again. This ensures the data area
1033 * will remain in memory until the hw acks the tx.
1034 * Function fw4_ack() will deref it.
1037 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1038 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1039 BUG_ON(ep->mpa_skb);
1041 ep->snd_seq += mpalen;
1042 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1045 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1048 struct fw_ofld_tx_data_wr *req;
1049 struct mpa_message *mpa;
1050 struct sk_buff *skb;
1051 struct mpa_v2_conn_params mpa_v2_params;
1053 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1055 mpalen = sizeof(*mpa) + plen;
1056 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1057 mpalen += sizeof(struct mpa_v2_conn_params);
1058 wrlen = roundup(mpalen + sizeof *req, 16);
1060 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1062 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1065 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1067 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1068 memset(req, 0, wrlen);
1069 req->op_to_immdlen = cpu_to_be32(
1070 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1072 FW_WR_IMMDLEN_V(mpalen));
1073 req->flowid_len16 = cpu_to_be32(
1074 FW_WR_FLOWID_V(ep->hwtid) |
1075 FW_WR_LEN16_V(wrlen >> 4));
1076 req->plen = cpu_to_be32(mpalen);
1077 req->tunnel_to_proxy = cpu_to_be32(
1078 FW_OFLD_TX_DATA_WR_FLUSH_F |
1079 FW_OFLD_TX_DATA_WR_SHOVE_F);
1081 mpa = (struct mpa_message *)(req + 1);
1082 memset(mpa, 0, sizeof(*mpa));
1083 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1084 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1085 (markers_enabled ? MPA_MARKERS : 0);
1086 mpa->revision = ep->mpa_attr.version;
1087 mpa->private_data_size = htons(plen);
1089 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1090 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1091 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1092 sizeof (struct mpa_v2_conn_params));
1093 mpa_v2_params.ird = htons((u16)ep->ird);
1094 mpa_v2_params.ord = htons((u16)ep->ord);
1095 if (peer2peer && (ep->mpa_attr.p2p_type !=
1096 FW_RI_INIT_P2PTYPE_DISABLED)) {
1097 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1099 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1100 mpa_v2_params.ord |=
1101 htons(MPA_V2_RDMA_WRITE_RTR);
1102 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1103 mpa_v2_params.ord |=
1104 htons(MPA_V2_RDMA_READ_RTR);
1107 memcpy(mpa->private_data, &mpa_v2_params,
1108 sizeof(struct mpa_v2_conn_params));
1111 memcpy(mpa->private_data +
1112 sizeof(struct mpa_v2_conn_params), pdata, plen);
1115 memcpy(mpa->private_data, pdata, plen);
1118 * Reference the mpa skb. This ensures the data area
1119 * will remain in memory until the hw acks the tx.
1120 * Function fw4_ack() will deref it.
1123 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1125 __state_set(&ep->com, MPA_REP_SENT);
1126 ep->snd_seq += mpalen;
1127 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1130 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1133 struct cpl_act_establish *req = cplhdr(skb);
1134 unsigned int tid = GET_TID(req);
1135 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
1136 struct tid_info *t = dev->rdev.lldi.tids;
1139 ep = lookup_atid(t, atid);
1141 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1142 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1144 mutex_lock(&ep->com.mutex);
1145 dst_confirm(ep->dst);
1147 /* setup the hwtid for this connection */
1149 cxgb4_insert_tid(t, ep, tid);
1150 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
1152 ep->snd_seq = be32_to_cpu(req->snd_isn);
1153 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1155 set_emss(ep, ntohs(req->tcp_opt));
1157 /* dealloc the atid */
1158 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1159 cxgb4_free_atid(t, atid);
1160 set_bit(ACT_ESTAB, &ep->com.history);
1162 /* start MPA negotiation */
1163 ret = send_flowc(ep, NULL);
1166 if (ep->retry_with_mpa_v1)
1167 send_mpa_req(ep, skb, 1);
1169 send_mpa_req(ep, skb, mpa_rev);
1170 mutex_unlock(&ep->com.mutex);
1173 mutex_unlock(&ep->com.mutex);
1174 connect_reply_upcall(ep, -ENOMEM);
1175 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1179 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1181 struct iw_cm_event event;
1183 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1184 memset(&event, 0, sizeof(event));
1185 event.event = IW_CM_EVENT_CLOSE;
1186 event.status = status;
1187 if (ep->com.cm_id) {
1188 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1189 ep, ep->com.cm_id, ep->hwtid);
1190 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1191 deref_cm_id(&ep->com);
1192 set_bit(CLOSE_UPCALL, &ep->com.history);
1196 static void peer_close_upcall(struct c4iw_ep *ep)
1198 struct iw_cm_event event;
1200 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1201 memset(&event, 0, sizeof(event));
1202 event.event = IW_CM_EVENT_DISCONNECT;
1203 if (ep->com.cm_id) {
1204 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1205 ep, ep->com.cm_id, ep->hwtid);
1206 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1207 set_bit(DISCONN_UPCALL, &ep->com.history);
1211 static void peer_abort_upcall(struct c4iw_ep *ep)
1213 struct iw_cm_event event;
1215 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1216 memset(&event, 0, sizeof(event));
1217 event.event = IW_CM_EVENT_CLOSE;
1218 event.status = -ECONNRESET;
1219 if (ep->com.cm_id) {
1220 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1221 ep->com.cm_id, ep->hwtid);
1222 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1223 deref_cm_id(&ep->com);
1224 set_bit(ABORT_UPCALL, &ep->com.history);
1228 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1230 struct iw_cm_event event;
1232 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1233 memset(&event, 0, sizeof(event));
1234 event.event = IW_CM_EVENT_CONNECT_REPLY;
1235 event.status = status;
1236 memcpy(&event.local_addr, &ep->com.local_addr,
1237 sizeof(ep->com.local_addr));
1238 memcpy(&event.remote_addr, &ep->com.remote_addr,
1239 sizeof(ep->com.remote_addr));
1241 if ((status == 0) || (status == -ECONNREFUSED)) {
1242 if (!ep->tried_with_mpa_v1) {
1243 /* this means MPA_v2 is used */
1244 event.ord = ep->ird;
1245 event.ird = ep->ord;
1246 event.private_data_len = ep->plen -
1247 sizeof(struct mpa_v2_conn_params);
1248 event.private_data = ep->mpa_pkt +
1249 sizeof(struct mpa_message) +
1250 sizeof(struct mpa_v2_conn_params);
1252 /* this means MPA_v1 is used */
1253 event.ord = cur_max_read_depth(ep->com.dev);
1254 event.ird = cur_max_read_depth(ep->com.dev);
1255 event.private_data_len = ep->plen;
1256 event.private_data = ep->mpa_pkt +
1257 sizeof(struct mpa_message);
1261 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1263 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1264 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1267 deref_cm_id(&ep->com);
1270 static int connect_request_upcall(struct c4iw_ep *ep)
1272 struct iw_cm_event event;
1275 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1276 memset(&event, 0, sizeof(event));
1277 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1278 memcpy(&event.local_addr, &ep->com.local_addr,
1279 sizeof(ep->com.local_addr));
1280 memcpy(&event.remote_addr, &ep->com.remote_addr,
1281 sizeof(ep->com.remote_addr));
1282 event.provider_data = ep;
1283 if (!ep->tried_with_mpa_v1) {
1284 /* this means MPA_v2 is used */
1285 event.ord = ep->ord;
1286 event.ird = ep->ird;
1287 event.private_data_len = ep->plen -
1288 sizeof(struct mpa_v2_conn_params);
1289 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1290 sizeof(struct mpa_v2_conn_params);
1292 /* this means MPA_v1 is used. Send max supported */
1293 event.ord = cur_max_read_depth(ep->com.dev);
1294 event.ird = cur_max_read_depth(ep->com.dev);
1295 event.private_data_len = ep->plen;
1296 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1298 c4iw_get_ep(&ep->com);
1299 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1302 c4iw_put_ep(&ep->com);
1303 set_bit(CONNREQ_UPCALL, &ep->com.history);
1304 c4iw_put_ep(&ep->parent_ep->com);
1308 static void established_upcall(struct c4iw_ep *ep)
1310 struct iw_cm_event event;
1312 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1313 memset(&event, 0, sizeof(event));
1314 event.event = IW_CM_EVENT_ESTABLISHED;
1315 event.ird = ep->ord;
1316 event.ord = ep->ird;
1317 if (ep->com.cm_id) {
1318 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1319 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1320 set_bit(ESTAB_UPCALL, &ep->com.history);
1324 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1326 struct cpl_rx_data_ack *req;
1327 struct sk_buff *skb;
1328 int wrlen = roundup(sizeof *req, 16);
1330 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1331 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1333 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1338 * If we couldn't specify the entire rcv window at connection setup
1339 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1340 * then add the overage in to the credits returned.
1342 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1343 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
1345 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1346 memset(req, 0, wrlen);
1347 INIT_TP_WR(req, ep->hwtid);
1348 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1350 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
1352 RX_DACK_MODE_V(dack_mode));
1353 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1354 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1358 #define RELAXED_IRD_NEGOTIATION 1
1361 * process_mpa_reply - process streaming mode MPA reply
1365 * 0 upon success indicating a connect request was delivered to the ULP
1366 * or the mpa request is incomplete but valid so far.
1368 * 1 if a failure requires the caller to close the connection.
1370 * 2 if a failure requires the caller to abort the connection.
1372 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1374 struct mpa_message *mpa;
1375 struct mpa_v2_conn_params *mpa_v2_params;
1377 u16 resp_ird, resp_ord;
1378 u8 rtr_mismatch = 0, insuff_ird = 0;
1379 struct c4iw_qp_attributes attrs;
1380 enum c4iw_qp_attr_mask mask;
1384 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1387 * Stop mpa timer. If it expired, then
1388 * we ignore the MPA reply. process_timeout()
1389 * will abort the connection.
1391 if (stop_ep_timer(ep))
1395 * If we get more than the supported amount of private data
1396 * then we must fail this connection.
1398 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1404 * copy the new data into our accumulation buffer.
1406 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1408 ep->mpa_pkt_len += skb->len;
1411 * if we don't even have the mpa message, then bail.
1413 if (ep->mpa_pkt_len < sizeof(*mpa))
1415 mpa = (struct mpa_message *) ep->mpa_pkt;
1417 /* Validate MPA header. */
1418 if (mpa->revision > mpa_rev) {
1419 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1420 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1424 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1429 plen = ntohs(mpa->private_data_size);
1432 * Fail if there's too much private data.
1434 if (plen > MPA_MAX_PRIVATE_DATA) {
1440 * If plen does not account for pkt size
1442 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1447 ep->plen = (u8) plen;
1450 * If we don't have all the pdata yet, then bail.
1451 * We'll continue process when more data arrives.
1453 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1456 if (mpa->flags & MPA_REJECT) {
1457 err = -ECONNREFUSED;
1462 * If we get here we have accumulated the entire mpa
1463 * start reply message including private data. And
1464 * the MPA header is valid.
1466 __state_set(&ep->com, FPDU_MODE);
1467 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1468 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1469 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1470 ep->mpa_attr.version = mpa->revision;
1471 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1473 if (mpa->revision == 2) {
1474 ep->mpa_attr.enhanced_rdma_conn =
1475 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1476 if (ep->mpa_attr.enhanced_rdma_conn) {
1477 mpa_v2_params = (struct mpa_v2_conn_params *)
1478 (ep->mpa_pkt + sizeof(*mpa));
1479 resp_ird = ntohs(mpa_v2_params->ird) &
1480 MPA_V2_IRD_ORD_MASK;
1481 resp_ord = ntohs(mpa_v2_params->ord) &
1482 MPA_V2_IRD_ORD_MASK;
1483 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1484 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
1487 * This is a double-check. Ideally, below checks are
1488 * not required since ird/ord stuff has been taken
1489 * care of in c4iw_accept_cr
1491 if (ep->ird < resp_ord) {
1492 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1493 ep->com.dev->rdev.lldi.max_ordird_qp)
1497 } else if (ep->ird > resp_ord) {
1500 if (ep->ord > resp_ird) {
1501 if (RELAXED_IRD_NEGOTIATION)
1512 if (ntohs(mpa_v2_params->ird) &
1513 MPA_V2_PEER2PEER_MODEL) {
1514 if (ntohs(mpa_v2_params->ord) &
1515 MPA_V2_RDMA_WRITE_RTR)
1516 ep->mpa_attr.p2p_type =
1517 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1518 else if (ntohs(mpa_v2_params->ord) &
1519 MPA_V2_RDMA_READ_RTR)
1520 ep->mpa_attr.p2p_type =
1521 FW_RI_INIT_P2PTYPE_READ_REQ;
1524 } else if (mpa->revision == 1)
1526 ep->mpa_attr.p2p_type = p2p_type;
1528 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1529 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1530 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1531 ep->mpa_attr.recv_marker_enabled,
1532 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1533 ep->mpa_attr.p2p_type, p2p_type);
1536 * If responder's RTR does not match with that of initiator, assign
1537 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1538 * generated when moving QP to RTS state.
1539 * A TERM message will be sent after QP has moved to RTS state
1541 if ((ep->mpa_attr.version == 2) && peer2peer &&
1542 (ep->mpa_attr.p2p_type != p2p_type)) {
1543 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1547 attrs.mpa_attr = ep->mpa_attr;
1548 attrs.max_ird = ep->ird;
1549 attrs.max_ord = ep->ord;
1550 attrs.llp_stream_handle = ep;
1551 attrs.next_state = C4IW_QP_STATE_RTS;
1553 mask = C4IW_QP_ATTR_NEXT_STATE |
1554 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1555 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1557 /* bind QP and TID with INIT_WR */
1558 err = c4iw_modify_qp(ep->com.qp->rhp,
1559 ep->com.qp, mask, &attrs, 1);
1564 * If responder's RTR requirement did not match with what initiator
1565 * supports, generate TERM message
1568 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1569 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1570 attrs.ecode = MPA_NOMATCH_RTR;
1571 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1572 attrs.send_term = 1;
1573 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1574 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1581 * Generate TERM if initiator IRD is not sufficient for responder
1582 * provided ORD. Currently, we do the same behaviour even when
1583 * responder provided IRD is also not sufficient as regards to
1587 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1589 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1590 attrs.ecode = MPA_INSUFF_IRD;
1591 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1592 attrs.send_term = 1;
1593 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1594 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1603 connect_reply_upcall(ep, err);
1608 * process_mpa_request - process streaming mode MPA request
1612 * 0 upon success indicating a connect request was delivered to the ULP
1613 * or the mpa request is incomplete but valid so far.
1615 * 1 if a failure requires the caller to close the connection.
1617 * 2 if a failure requires the caller to abort the connection.
1619 static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1621 struct mpa_message *mpa;
1622 struct mpa_v2_conn_params *mpa_v2_params;
1625 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1628 * If we get more than the supported amount of private data
1629 * then we must fail this connection.
1631 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1632 goto err_stop_timer;
1634 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1637 * Copy the new data into our accumulation buffer.
1639 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1641 ep->mpa_pkt_len += skb->len;
1644 * If we don't even have the mpa message, then bail.
1645 * We'll continue process when more data arrives.
1647 if (ep->mpa_pkt_len < sizeof(*mpa))
1650 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1651 mpa = (struct mpa_message *) ep->mpa_pkt;
1654 * Validate MPA Header.
1656 if (mpa->revision > mpa_rev) {
1657 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1658 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1659 goto err_stop_timer;
1662 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1663 goto err_stop_timer;
1665 plen = ntohs(mpa->private_data_size);
1668 * Fail if there's too much private data.
1670 if (plen > MPA_MAX_PRIVATE_DATA)
1671 goto err_stop_timer;
1674 * If plen does not account for pkt size
1676 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1677 goto err_stop_timer;
1678 ep->plen = (u8) plen;
1681 * If we don't have all the pdata yet, then bail.
1683 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1687 * If we get here we have accumulated the entire mpa
1688 * start reply message including private data.
1690 ep->mpa_attr.initiator = 0;
1691 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1692 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1693 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1694 ep->mpa_attr.version = mpa->revision;
1695 if (mpa->revision == 1)
1696 ep->tried_with_mpa_v1 = 1;
1697 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1699 if (mpa->revision == 2) {
1700 ep->mpa_attr.enhanced_rdma_conn =
1701 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1702 if (ep->mpa_attr.enhanced_rdma_conn) {
1703 mpa_v2_params = (struct mpa_v2_conn_params *)
1704 (ep->mpa_pkt + sizeof(*mpa));
1705 ep->ird = ntohs(mpa_v2_params->ird) &
1706 MPA_V2_IRD_ORD_MASK;
1707 ep->ord = ntohs(mpa_v2_params->ord) &
1708 MPA_V2_IRD_ORD_MASK;
1709 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1711 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1713 if (ntohs(mpa_v2_params->ord) &
1714 MPA_V2_RDMA_WRITE_RTR)
1715 ep->mpa_attr.p2p_type =
1716 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1717 else if (ntohs(mpa_v2_params->ord) &
1718 MPA_V2_RDMA_READ_RTR)
1719 ep->mpa_attr.p2p_type =
1720 FW_RI_INIT_P2PTYPE_READ_REQ;
1723 } else if (mpa->revision == 1)
1725 ep->mpa_attr.p2p_type = p2p_type;
1727 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1728 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1729 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1730 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1731 ep->mpa_attr.p2p_type);
1734 * If the endpoint timer already expired, then we ignore
1735 * the start request. process_timeout() will abort
1738 if (!stop_ep_timer(ep)) {
1739 __state_set(&ep->com, MPA_REQ_RCVD);
1742 mutex_lock_nested(&ep->parent_ep->com.mutex,
1743 SINGLE_DEPTH_NESTING);
1744 if (ep->parent_ep->com.state != DEAD) {
1745 if (connect_request_upcall(ep))
1746 goto err_unlock_parent;
1748 goto err_unlock_parent;
1750 mutex_unlock(&ep->parent_ep->com.mutex);
1755 mutex_unlock(&ep->parent_ep->com.mutex);
1758 (void)stop_ep_timer(ep);
1763 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1766 struct cpl_rx_data *hdr = cplhdr(skb);
1767 unsigned int dlen = ntohs(hdr->len);
1768 unsigned int tid = GET_TID(hdr);
1769 struct tid_info *t = dev->rdev.lldi.tids;
1770 __u8 status = hdr->status;
1773 ep = lookup_tid(t, tid);
1776 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1777 skb_pull(skb, sizeof(*hdr));
1778 skb_trim(skb, dlen);
1779 mutex_lock(&ep->com.mutex);
1781 /* update RX credits */
1782 update_rx_credits(ep, dlen);
1784 switch (ep->com.state) {
1786 ep->rcv_seq += dlen;
1787 disconnect = process_mpa_reply(ep, skb);
1790 ep->rcv_seq += dlen;
1791 process_mpa_request(ep, skb);
1794 struct c4iw_qp_attributes attrs;
1795 BUG_ON(!ep->com.qp);
1797 pr_err("%s Unexpected streaming data." \
1798 " qpid %u ep %p state %d tid %u status %d\n",
1799 __func__, ep->com.qp->wq.sq.qid, ep,
1800 ep->com.state, ep->hwtid, status);
1801 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1802 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1803 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1810 mutex_unlock(&ep->com.mutex);
1812 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1816 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1819 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1821 unsigned int tid = GET_TID(rpl);
1822 struct tid_info *t = dev->rdev.lldi.tids;
1824 ep = lookup_tid(t, tid);
1826 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1829 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1830 mutex_lock(&ep->com.mutex);
1831 switch (ep->com.state) {
1833 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1834 __state_set(&ep->com, DEAD);
1838 printk(KERN_ERR "%s ep %p state %d\n",
1839 __func__, ep, ep->com.state);
1842 mutex_unlock(&ep->com.mutex);
1845 release_ep_resources(ep);
1849 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1851 struct sk_buff *skb;
1852 struct fw_ofld_connection_wr *req;
1853 unsigned int mtu_idx;
1855 struct sockaddr_in *sin;
1858 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1859 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1860 memset(req, 0, sizeof(*req));
1861 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
1862 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
1863 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1864 ep->com.dev->rdev.lldi.ports[0],
1866 sin = (struct sockaddr_in *)&ep->com.local_addr;
1867 req->le.lport = sin->sin_port;
1868 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1869 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1870 req->le.pport = sin->sin_port;
1871 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1872 req->tcb.t_state_to_astid =
1873 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1874 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
1875 req->tcb.cplrxdataack_cplpassacceptrpl =
1876 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
1877 req->tcb.tx_max = (__force __be32) jiffies;
1878 req->tcb.rcv_adv = htons(1);
1879 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1880 enable_tcp_timestamps,
1881 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
1882 wscale = compute_wscale(rcv_win);
1885 * Specify the largest window that will fit in opt0. The
1886 * remainder will be specified in the rx_data_ack.
1888 win = ep->rcv_win >> 10;
1889 if (win > RCV_BUFSIZ_M)
1892 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1893 (nocong ? NO_CONG_F : 0) |
1896 WND_SCALE_V(wscale) |
1897 MSS_IDX_V(mtu_idx) |
1898 L2T_IDX_V(ep->l2t->idx) |
1899 TX_CHAN_V(ep->tx_chan) |
1900 SMAC_SEL_V(ep->smac_idx) |
1901 DSCP_V(ep->tos >> 2) |
1902 ULP_MODE_V(ULP_MODE_TCPDDP) |
1904 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1905 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1907 CCTRL_ECN_V(enable_ecn) |
1908 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
1909 if (enable_tcp_timestamps)
1910 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
1911 if (enable_tcp_sack)
1912 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
1913 if (wscale && enable_tcp_window_scaling)
1914 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1915 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1916 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
1917 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1918 set_bit(ACT_OFLD_CONN, &ep->com.history);
1919 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1923 * Return whether a failed active open has allocated a TID
1925 static inline int act_open_has_tid(int status)
1927 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1928 status != CPL_ERR_ARP_MISS;
1931 /* Returns whether a CPL status conveys negative advice.
1933 static int is_neg_adv(unsigned int status)
1935 return status == CPL_ERR_RTX_NEG_ADVICE ||
1936 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1937 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1940 static char *neg_adv_str(unsigned int status)
1943 case CPL_ERR_RTX_NEG_ADVICE:
1944 return "Retransmit timeout";
1945 case CPL_ERR_PERSIST_NEG_ADVICE:
1946 return "Persist timeout";
1947 case CPL_ERR_KEEPALV_NEG_ADVICE:
1948 return "Keepalive timeout";
1954 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1956 ep->snd_win = snd_win;
1957 ep->rcv_win = rcv_win;
1958 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1961 #define ACT_OPEN_RETRY_COUNT 2
1963 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1964 struct dst_entry *dst, struct c4iw_dev *cdev,
1965 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
1967 struct neighbour *n;
1969 struct net_device *pdev;
1971 n = dst_neigh_lookup(dst, peer_ip);
1977 if (n->dev->flags & IFF_LOOPBACK) {
1979 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1980 else if (IS_ENABLED(CONFIG_IPV6))
1981 for_each_netdev(&init_net, pdev) {
1982 if (ipv6_chk_addr(&init_net,
1983 (struct in6_addr *)peer_ip,
1994 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1995 n, pdev, rt_tos2priority(tos));
1998 ep->mtu = pdev->mtu;
1999 ep->tx_chan = cxgb4_port_chan(pdev);
2000 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2001 cxgb4_port_viid(pdev));
2002 step = cdev->rdev.lldi.ntxq /
2003 cdev->rdev.lldi.nchan;
2004 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2005 step = cdev->rdev.lldi.nrxq /
2006 cdev->rdev.lldi.nchan;
2007 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2008 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2009 cxgb4_port_idx(pdev) * step];
2010 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2013 pdev = get_real_dev(n->dev);
2014 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2018 ep->mtu = dst_mtu(dst);
2019 ep->tx_chan = cxgb4_port_chan(pdev);
2020 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2021 cxgb4_port_viid(pdev));
2022 step = cdev->rdev.lldi.ntxq /
2023 cdev->rdev.lldi.nchan;
2024 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2025 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2026 step = cdev->rdev.lldi.nrxq /
2027 cdev->rdev.lldi.nchan;
2028 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2029 cxgb4_port_idx(pdev) * step];
2030 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
2033 ep->retry_with_mpa_v1 = 0;
2034 ep->tried_with_mpa_v1 = 0;
2046 static int c4iw_reconnect(struct c4iw_ep *ep)
2049 struct sockaddr_in *laddr = (struct sockaddr_in *)
2050 &ep->com.cm_id->m_local_addr;
2051 struct sockaddr_in *raddr = (struct sockaddr_in *)
2052 &ep->com.cm_id->m_remote_addr;
2053 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
2054 &ep->com.cm_id->m_local_addr;
2055 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2056 &ep->com.cm_id->m_remote_addr;
2060 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2061 init_timer(&ep->timer);
2064 * Allocate an active TID to initiate a TCP connection.
2066 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2067 if (ep->atid == -1) {
2068 pr_err("%s - cannot alloc atid.\n", __func__);
2072 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2075 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
2076 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2077 raddr->sin_addr.s_addr, laddr->sin_port,
2078 raddr->sin_port, ep->com.cm_id->tos);
2080 ra = (__u8 *)&raddr->sin_addr;
2082 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2083 raddr6->sin6_addr.s6_addr,
2084 laddr6->sin6_port, raddr6->sin6_port, 0,
2085 raddr6->sin6_scope_id);
2087 ra = (__u8 *)&raddr6->sin6_addr;
2090 pr_err("%s - cannot find route.\n", __func__);
2091 err = -EHOSTUNREACH;
2094 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
2095 ep->com.dev->rdev.lldi.adapter_type,
2096 ep->com.cm_id->tos);
2098 pr_err("%s - cannot alloc l2e.\n", __func__);
2102 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2103 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2106 state_set(&ep->com, CONNECTING);
2107 ep->tos = ep->com.cm_id->tos;
2109 /* send connect request to rnic */
2110 err = send_connect(ep);
2114 cxgb4_l2t_release(ep->l2t);
2116 dst_release(ep->dst);
2118 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2119 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2122 * remember to send notification to upper layer.
2123 * We are in here so the upper layer is not aware that this is
2124 * re-connect attempt and so, upper layer is still waiting for
2125 * response of 1st connect request.
2127 connect_reply_upcall(ep, -ECONNRESET);
2128 c4iw_put_ep(&ep->com);
2133 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2136 struct cpl_act_open_rpl *rpl = cplhdr(skb);
2137 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2138 ntohl(rpl->atid_status)));
2139 struct tid_info *t = dev->rdev.lldi.tids;
2140 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
2141 struct sockaddr_in *la;
2142 struct sockaddr_in *ra;
2143 struct sockaddr_in6 *la6;
2144 struct sockaddr_in6 *ra6;
2146 ep = lookup_atid(t, atid);
2147 la = (struct sockaddr_in *)&ep->com.local_addr;
2148 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2149 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2150 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
2152 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2153 status, status2errno(status));
2155 if (is_neg_adv(status)) {
2156 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2157 __func__, atid, status, neg_adv_str(status));
2158 ep->stats.connect_neg_adv++;
2159 mutex_lock(&dev->rdev.stats.lock);
2160 dev->rdev.stats.neg_adv++;
2161 mutex_unlock(&dev->rdev.stats.lock);
2165 set_bit(ACT_OPEN_RPL, &ep->com.history);
2168 * Log interesting failures.
2171 case CPL_ERR_CONN_RESET:
2172 case CPL_ERR_CONN_TIMEDOUT:
2174 case CPL_ERR_TCAM_FULL:
2175 mutex_lock(&dev->rdev.stats.lock);
2176 dev->rdev.stats.tcam_full++;
2177 mutex_unlock(&dev->rdev.stats.lock);
2178 if (ep->com.local_addr.ss_family == AF_INET &&
2179 dev->rdev.lldi.enable_fw_ofld_conn) {
2180 send_fw_act_open_req(ep,
2181 TID_TID_G(AOPEN_ATID_G(
2182 ntohl(rpl->atid_status))));
2186 case CPL_ERR_CONN_EXIST:
2187 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2188 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2189 if (ep->com.remote_addr.ss_family == AF_INET6) {
2190 struct sockaddr_in6 *sin6 =
2191 (struct sockaddr_in6 *)
2192 &ep->com.local_addr;
2194 ep->com.dev->rdev.lldi.ports[0],
2196 &sin6->sin6_addr.s6_addr, 1);
2198 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2200 cxgb4_free_atid(t, atid);
2201 dst_release(ep->dst);
2202 cxgb4_l2t_release(ep->l2t);
2208 if (ep->com.local_addr.ss_family == AF_INET) {
2209 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2210 atid, status, status2errno(status),
2211 &la->sin_addr.s_addr, ntohs(la->sin_port),
2212 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2214 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2215 atid, status, status2errno(status),
2216 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2217 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2222 connect_reply_upcall(ep, status2errno(status));
2223 state_set(&ep->com, DEAD);
2225 if (ep->com.remote_addr.ss_family == AF_INET6) {
2226 struct sockaddr_in6 *sin6 =
2227 (struct sockaddr_in6 *)&ep->com.local_addr;
2228 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2229 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2231 if (status && act_open_has_tid(status))
2232 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2234 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2235 cxgb4_free_atid(t, atid);
2236 dst_release(ep->dst);
2237 cxgb4_l2t_release(ep->l2t);
2238 c4iw_put_ep(&ep->com);
2243 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2245 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2246 struct tid_info *t = dev->rdev.lldi.tids;
2247 unsigned int stid = GET_TID(rpl);
2248 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2251 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2254 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2255 rpl->status, status2errno(rpl->status));
2256 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2262 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2264 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2265 struct tid_info *t = dev->rdev.lldi.tids;
2266 unsigned int stid = GET_TID(rpl);
2267 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2269 PDBG("%s ep %p\n", __func__, ep);
2270 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2274 static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2275 struct cpl_pass_accept_req *req)
2277 struct cpl_pass_accept_rpl *rpl;
2278 unsigned int mtu_idx;
2282 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2284 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
2286 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2287 BUG_ON(skb_cloned(skb));
2291 if (!is_t4(adapter_type)) {
2292 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2294 INIT_TP_WR(rpl5, ep->hwtid);
2296 skb_trim(skb, sizeof(*rpl));
2297 INIT_TP_WR(rpl, ep->hwtid);
2299 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2302 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2303 enable_tcp_timestamps && req->tcpopt.tstamp,
2304 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
2305 wscale = compute_wscale(rcv_win);
2308 * Specify the largest window that will fit in opt0. The
2309 * remainder will be specified in the rx_data_ack.
2311 win = ep->rcv_win >> 10;
2312 if (win > RCV_BUFSIZ_M)
2314 opt0 = (nocong ? NO_CONG_F : 0) |
2317 WND_SCALE_V(wscale) |
2318 MSS_IDX_V(mtu_idx) |
2319 L2T_IDX_V(ep->l2t->idx) |
2320 TX_CHAN_V(ep->tx_chan) |
2321 SMAC_SEL_V(ep->smac_idx) |
2322 DSCP_V(ep->tos >> 2) |
2323 ULP_MODE_V(ULP_MODE_TCPDDP) |
2325 opt2 = RX_CHANNEL_V(0) |
2326 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
2328 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2329 opt2 |= TSTAMPS_EN_F;
2330 if (enable_tcp_sack && req->tcpopt.sack)
2332 if (wscale && enable_tcp_window_scaling)
2333 opt2 |= WND_SCALE_EN_F;
2335 const struct tcphdr *tcph;
2336 u32 hlen = ntohl(req->hdr_len);
2338 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2339 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2342 tcph = (const void *)(req + 1) +
2343 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
2344 if (tcph->ece && tcph->cwr)
2345 opt2 |= CCTRL_ECN_V(1);
2347 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
2348 u32 isn = (prandom_u32() & ~7UL) - 1;
2349 opt2 |= T5_OPT_2_VALID_F;
2350 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
2353 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2356 rpl5->iss = cpu_to_be32(isn);
2357 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
2360 rpl->opt0 = cpu_to_be64(opt0);
2361 rpl->opt2 = cpu_to_be32(opt2);
2362 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2363 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
2365 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2368 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2370 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
2371 BUG_ON(skb_cloned(skb));
2372 skb_trim(skb, sizeof(struct cpl_tid_release));
2373 release_tid(&dev->rdev, hwtid, skb);
2377 static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2378 int *iptype, __u8 *local_ip, __u8 *peer_ip,
2379 __be16 *local_port, __be16 *peer_port)
2381 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2382 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2383 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2384 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2385 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2386 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2387 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
2388 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
2389 struct tcphdr *tcp = (struct tcphdr *)
2390 ((u8 *)(req + 1) + eth_len + ip_len);
2392 if (ip->version == 4) {
2393 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2394 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2397 memcpy(peer_ip, &ip->saddr, 4);
2398 memcpy(local_ip, &ip->daddr, 4);
2400 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2401 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2404 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2405 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2407 *peer_port = tcp->source;
2408 *local_port = tcp->dest;
2413 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2415 struct c4iw_ep *child_ep = NULL, *parent_ep;
2416 struct cpl_pass_accept_req *req = cplhdr(skb);
2417 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
2418 struct tid_info *t = dev->rdev.lldi.tids;
2419 unsigned int hwtid = GET_TID(req);
2420 struct dst_entry *dst;
2421 __u8 local_ip[16], peer_ip[16];
2422 __be16 local_port, peer_port;
2423 struct sockaddr_in6 *sin6;
2425 u16 peer_mss = ntohs(req->tcpopt.mss);
2427 unsigned short hdrs;
2428 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
2430 parent_ep = lookup_stid(t, stid);
2432 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2436 if (state_read(&parent_ep->com) != LISTEN) {
2437 PDBG("%s - listening ep not in LISTEN\n", __func__);
2441 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2442 local_ip, peer_ip, &local_port, &peer_port);
2444 /* Find output route */
2446 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2447 , __func__, parent_ep, hwtid,
2448 local_ip, peer_ip, ntohs(local_port),
2449 ntohs(peer_port), peer_mss);
2450 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2451 local_port, peer_port,
2454 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2455 , __func__, parent_ep, hwtid,
2456 local_ip, peer_ip, ntohs(local_port),
2457 ntohs(peer_port), peer_mss);
2458 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2459 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2460 ((struct sockaddr_in6 *)
2461 &parent_ep->com.local_addr)->sin6_scope_id);
2464 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2469 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2471 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2477 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
2478 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
2480 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2487 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2488 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2489 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2490 child_ep->mtu = peer_mss + hdrs;
2492 state_set(&child_ep->com, CONNECTING);
2493 child_ep->com.dev = dev;
2494 child_ep->com.cm_id = NULL;
2497 struct sockaddr_in *sin = (struct sockaddr_in *)
2498 &child_ep->com.local_addr;
2500 sin->sin_family = PF_INET;
2501 sin->sin_port = local_port;
2502 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2504 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2505 sin->sin_family = PF_INET;
2506 sin->sin_port = ((struct sockaddr_in *)
2507 &parent_ep->com.local_addr)->sin_port;
2508 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2510 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2511 sin->sin_family = PF_INET;
2512 sin->sin_port = peer_port;
2513 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2515 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2516 sin6->sin6_family = PF_INET6;
2517 sin6->sin6_port = local_port;
2518 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2520 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2521 sin6->sin6_family = PF_INET6;
2522 sin6->sin6_port = ((struct sockaddr_in6 *)
2523 &parent_ep->com.local_addr)->sin6_port;
2524 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2526 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2527 sin6->sin6_family = PF_INET6;
2528 sin6->sin6_port = peer_port;
2529 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2532 c4iw_get_ep(&parent_ep->com);
2533 child_ep->parent_ep = parent_ep;
2534 child_ep->tos = tos;
2535 child_ep->dst = dst;
2536 child_ep->hwtid = hwtid;
2538 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2539 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2541 init_timer(&child_ep->timer);
2542 cxgb4_insert_tid(t, child_ep, hwtid);
2543 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2544 if (accept_cr(child_ep, skb, req)) {
2545 c4iw_put_ep(&parent_ep->com);
2546 release_ep_resources(child_ep);
2548 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2551 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2552 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2553 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2557 reject_cr(dev, hwtid, skb);
2562 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2565 struct cpl_pass_establish *req = cplhdr(skb);
2566 struct tid_info *t = dev->rdev.lldi.tids;
2567 unsigned int tid = GET_TID(req);
2570 ep = lookup_tid(t, tid);
2571 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2572 ep->snd_seq = be32_to_cpu(req->snd_isn);
2573 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2575 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2576 ntohs(req->tcp_opt));
2578 set_emss(ep, ntohs(req->tcp_opt));
2580 dst_confirm(ep->dst);
2581 mutex_lock(&ep->com.mutex);
2582 ep->com.state = MPA_REQ_WAIT;
2584 set_bit(PASS_ESTAB, &ep->com.history);
2585 ret = send_flowc(ep, skb);
2586 mutex_unlock(&ep->com.mutex);
2588 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
2593 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2595 struct cpl_peer_close *hdr = cplhdr(skb);
2597 struct c4iw_qp_attributes attrs;
2600 struct tid_info *t = dev->rdev.lldi.tids;
2601 unsigned int tid = GET_TID(hdr);
2604 ep = lookup_tid(t, tid);
2605 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2606 dst_confirm(ep->dst);
2608 set_bit(PEER_CLOSE, &ep->com.history);
2609 mutex_lock(&ep->com.mutex);
2610 switch (ep->com.state) {
2612 __state_set(&ep->com, CLOSING);
2615 __state_set(&ep->com, CLOSING);
2616 connect_reply_upcall(ep, -ECONNRESET);
2621 * We're gonna mark this puppy DEAD, but keep
2622 * the reference on it until the ULP accepts or
2623 * rejects the CR. Also wake up anyone waiting
2624 * in rdma connection migration (see c4iw_accept_cr()).
2626 __state_set(&ep->com, CLOSING);
2627 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2628 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2631 __state_set(&ep->com, CLOSING);
2632 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2633 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2637 __state_set(&ep->com, CLOSING);
2638 attrs.next_state = C4IW_QP_STATE_CLOSING;
2639 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2640 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2641 if (ret != -ECONNRESET) {
2642 peer_close_upcall(ep);
2650 __state_set(&ep->com, MORIBUND);
2654 (void)stop_ep_timer(ep);
2655 if (ep->com.cm_id && ep->com.qp) {
2656 attrs.next_state = C4IW_QP_STATE_IDLE;
2657 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2658 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2660 close_complete_upcall(ep, 0);
2661 __state_set(&ep->com, DEAD);
2671 mutex_unlock(&ep->com.mutex);
2673 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2675 release_ep_resources(ep);
2679 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2681 struct cpl_abort_req_rss *req = cplhdr(skb);
2683 struct cpl_abort_rpl *rpl;
2684 struct sk_buff *rpl_skb;
2685 struct c4iw_qp_attributes attrs;
2688 struct tid_info *t = dev->rdev.lldi.tids;
2689 unsigned int tid = GET_TID(req);
2691 ep = lookup_tid(t, tid);
2692 if (is_neg_adv(req->status)) {
2693 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2694 __func__, ep->hwtid, req->status,
2695 neg_adv_str(req->status));
2696 ep->stats.abort_neg_adv++;
2697 mutex_lock(&dev->rdev.stats.lock);
2698 dev->rdev.stats.neg_adv++;
2699 mutex_unlock(&dev->rdev.stats.lock);
2702 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2704 set_bit(PEER_ABORT, &ep->com.history);
2707 * Wake up any threads in rdma_init() or rdma_fini().
2708 * However, this is not needed if com state is just
2711 if (ep->com.state != MPA_REQ_SENT)
2712 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2714 mutex_lock(&ep->com.mutex);
2715 switch (ep->com.state) {
2717 c4iw_put_ep(&ep->parent_ep->com);
2720 (void)stop_ep_timer(ep);
2723 (void)stop_ep_timer(ep);
2724 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2725 connect_reply_upcall(ep, -ECONNRESET);
2728 * we just don't send notification upwards because we
2729 * want to retry with mpa_v1 without upper layers even
2732 * do some housekeeping so as to re-initiate the
2735 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2737 ep->retry_with_mpa_v1 = 1;
2749 if (ep->com.cm_id && ep->com.qp) {
2750 attrs.next_state = C4IW_QP_STATE_ERROR;
2751 ret = c4iw_modify_qp(ep->com.qp->rhp,
2752 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2756 "%s - qp <- error failed!\n",
2759 peer_abort_upcall(ep);
2764 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2765 mutex_unlock(&ep->com.mutex);
2771 dst_confirm(ep->dst);
2772 if (ep->com.state != ABORTING) {
2773 __state_set(&ep->com, DEAD);
2774 /* we don't release if we want to retry with mpa_v1 */
2775 if (!ep->retry_with_mpa_v1)
2778 mutex_unlock(&ep->com.mutex);
2780 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2782 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2787 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2788 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2789 INIT_TP_WR(rpl, ep->hwtid);
2790 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2791 rpl->cmd = CPL_ABORT_NO_RST;
2792 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2795 release_ep_resources(ep);
2796 else if (ep->retry_with_mpa_v1) {
2797 if (ep->com.remote_addr.ss_family == AF_INET6) {
2798 struct sockaddr_in6 *sin6 =
2799 (struct sockaddr_in6 *)
2800 &ep->com.local_addr;
2802 ep->com.dev->rdev.lldi.ports[0],
2803 (const u32 *)&sin6->sin6_addr.s6_addr,
2806 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2807 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2808 dst_release(ep->dst);
2809 cxgb4_l2t_release(ep->l2t);
2816 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2819 struct c4iw_qp_attributes attrs;
2820 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2822 struct tid_info *t = dev->rdev.lldi.tids;
2823 unsigned int tid = GET_TID(rpl);
2825 ep = lookup_tid(t, tid);
2827 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2830 /* The cm_id may be null if we failed to connect */
2831 mutex_lock(&ep->com.mutex);
2832 set_bit(CLOSE_CON_RPL, &ep->com.history);
2833 switch (ep->com.state) {
2835 __state_set(&ep->com, MORIBUND);
2838 (void)stop_ep_timer(ep);
2839 if ((ep->com.cm_id) && (ep->com.qp)) {
2840 attrs.next_state = C4IW_QP_STATE_IDLE;
2841 c4iw_modify_qp(ep->com.qp->rhp,
2843 C4IW_QP_ATTR_NEXT_STATE,
2846 close_complete_upcall(ep, 0);
2847 __state_set(&ep->com, DEAD);
2857 mutex_unlock(&ep->com.mutex);
2859 release_ep_resources(ep);
2863 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2865 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2866 struct tid_info *t = dev->rdev.lldi.tids;
2867 unsigned int tid = GET_TID(rpl);
2869 struct c4iw_qp_attributes attrs;
2871 ep = lookup_tid(t, tid);
2874 if (ep && ep->com.qp) {
2875 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2876 ep->com.qp->wq.sq.qid);
2877 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2878 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2879 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2881 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2887 * Upcall from the adapter indicating data has been transmitted.
2888 * For us its just the single MPA request or reply. We can now free
2889 * the skb holding the mpa message.
2891 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2894 struct cpl_fw4_ack *hdr = cplhdr(skb);
2895 u8 credits = hdr->credits;
2896 unsigned int tid = GET_TID(hdr);
2897 struct tid_info *t = dev->rdev.lldi.tids;
2900 ep = lookup_tid(t, tid);
2901 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2903 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2904 __func__, ep, ep->hwtid, state_read(&ep->com));
2908 dst_confirm(ep->dst);
2910 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2911 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2912 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2913 kfree_skb(ep->mpa_skb);
2919 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2923 struct c4iw_ep *ep = to_ep(cm_id);
2924 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2926 mutex_lock(&ep->com.mutex);
2927 if (ep->com.state == DEAD) {
2928 mutex_unlock(&ep->com.mutex);
2929 c4iw_put_ep(&ep->com);
2932 set_bit(ULP_REJECT, &ep->com.history);
2933 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2937 err = send_mpa_reject(ep, pdata, pdata_len);
2940 mutex_unlock(&ep->com.mutex);
2942 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
2943 c4iw_put_ep(&ep->com);
2947 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2950 struct c4iw_qp_attributes attrs;
2951 enum c4iw_qp_attr_mask mask;
2952 struct c4iw_ep *ep = to_ep(cm_id);
2953 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2954 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2957 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2959 mutex_lock(&ep->com.mutex);
2960 if (ep->com.state == DEAD) {
2965 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2968 set_bit(ULP_ACCEPT, &ep->com.history);
2969 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2970 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
2975 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2976 if (conn_param->ord > ep->ird) {
2977 if (RELAXED_IRD_NEGOTIATION) {
2980 ep->ird = conn_param->ird;
2981 ep->ord = conn_param->ord;
2982 send_mpa_reject(ep, conn_param->private_data,
2983 conn_param->private_data_len);
2988 if (conn_param->ird < ep->ord) {
2989 if (RELAXED_IRD_NEGOTIATION &&
2990 ep->ord <= h->rdev.lldi.max_ordird_qp) {
2991 conn_param->ird = ep->ord;
2998 ep->ird = conn_param->ird;
2999 ep->ord = conn_param->ord;
3001 if (ep->mpa_attr.version == 1) {
3002 if (peer2peer && ep->ird == 0)
3006 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
3007 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
3011 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3013 ep->com.cm_id = cm_id;
3014 ref_cm_id(&ep->com);
3018 /* bind QP to EP and move to RTS */
3019 attrs.mpa_attr = ep->mpa_attr;
3020 attrs.max_ird = ep->ird;
3021 attrs.max_ord = ep->ord;
3022 attrs.llp_stream_handle = ep;
3023 attrs.next_state = C4IW_QP_STATE_RTS;
3025 /* bind QP and TID with INIT_WR */
3026 mask = C4IW_QP_ATTR_NEXT_STATE |
3027 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3028 C4IW_QP_ATTR_MPA_ATTR |
3029 C4IW_QP_ATTR_MAX_IRD |
3030 C4IW_QP_ATTR_MAX_ORD;
3032 err = c4iw_modify_qp(ep->com.qp->rhp,
3033 ep->com.qp, mask, &attrs, 1);
3035 goto err_deref_cm_id;
3036 err = send_mpa_reply(ep, conn_param->private_data,
3037 conn_param->private_data_len);
3039 goto err_deref_cm_id;
3041 __state_set(&ep->com, FPDU_MODE);
3042 established_upcall(ep);
3043 mutex_unlock(&ep->com.mutex);
3044 c4iw_put_ep(&ep->com);
3047 deref_cm_id(&ep->com);
3051 mutex_unlock(&ep->com.mutex);
3053 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
3054 c4iw_put_ep(&ep->com);
3058 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3060 struct in_device *ind;
3062 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3063 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
3065 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3067 return -EADDRNOTAVAIL;
3068 for_primary_ifa(ind) {
3069 laddr->sin_addr.s_addr = ifa->ifa_address;
3070 raddr->sin_addr.s_addr = ifa->ifa_address;
3076 return found ? 0 : -EADDRNOTAVAIL;
3079 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3080 unsigned char banned_flags)
3082 struct inet6_dev *idev;
3083 int err = -EADDRNOTAVAIL;
3086 idev = __in6_dev_get(dev);
3088 struct inet6_ifaddr *ifp;
3090 read_lock_bh(&idev->lock);
3091 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3092 if (ifp->scope == IFA_LINK &&
3093 !(ifp->flags & banned_flags)) {
3094 memcpy(addr, &ifp->addr, 16);
3099 read_unlock_bh(&idev->lock);
3105 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3107 struct in6_addr uninitialized_var(addr);
3108 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3109 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
3111 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
3112 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3113 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3116 return -EADDRNOTAVAIL;
3119 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3121 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3124 struct sockaddr_in *laddr;
3125 struct sockaddr_in *raddr;
3126 struct sockaddr_in6 *laddr6;
3127 struct sockaddr_in6 *raddr6;
3131 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3132 (conn_param->ird > cur_max_read_depth(dev))) {
3136 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3138 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3142 init_timer(&ep->timer);
3143 ep->plen = conn_param->private_data_len;
3145 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3146 conn_param->private_data, ep->plen);
3147 ep->ird = conn_param->ird;
3148 ep->ord = conn_param->ord;
3150 if (peer2peer && ep->ord == 0)
3153 ep->com.cm_id = cm_id;
3154 ref_cm_id(&ep->com);
3156 ep->com.qp = get_qhp(dev, conn_param->qpn);
3158 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3163 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3167 * Allocate an active TID to initiate a TCP connection.
3169 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3170 if (ep->atid == -1) {
3171 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3175 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
3177 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3178 sizeof(ep->com.local_addr));
3179 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
3180 sizeof(ep->com.remote_addr));
3182 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3183 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3184 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3185 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
3187 if (cm_id->m_remote_addr.ss_family == AF_INET) {
3189 ra = (__u8 *)&raddr->sin_addr;
3192 * Handle loopback requests to INADDR_ANY.
3194 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3195 err = pick_local_ipaddrs(dev, cm_id);
3201 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3202 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3203 ra, ntohs(raddr->sin_port));
3204 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3205 raddr->sin_addr.s_addr, laddr->sin_port,
3206 raddr->sin_port, cm_id->tos);
3209 ra = (__u8 *)&raddr6->sin6_addr;
3212 * Handle loopback requests to INADDR_ANY.
3214 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3215 err = pick_local_ip6addrs(dev, cm_id);
3221 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3222 __func__, laddr6->sin6_addr.s6_addr,
3223 ntohs(laddr6->sin6_port),
3224 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3225 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3226 raddr6->sin6_addr.s6_addr,
3227 laddr6->sin6_port, raddr6->sin6_port, 0,
3228 raddr6->sin6_scope_id);
3231 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3232 err = -EHOSTUNREACH;
3236 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
3237 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
3239 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
3243 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3244 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3247 state_set(&ep->com, CONNECTING);
3248 ep->tos = cm_id->tos;
3250 /* send connect request to rnic */
3251 err = send_connect(ep);
3255 cxgb4_l2t_release(ep->l2t);
3257 dst_release(ep->dst);
3259 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3260 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3262 deref_cm_id(&ep->com);
3263 c4iw_put_ep(&ep->com);
3268 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3271 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3272 &ep->com.local_addr;
3274 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3275 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3276 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3280 c4iw_init_wr_wait(&ep->com.wr_wait);
3281 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3282 ep->stid, &sin6->sin6_addr,
3284 ep->com.dev->rdev.lldi.rxq_ids[0]);
3286 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3290 err = net_xmit_errno(err);
3292 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3293 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3294 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3296 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3301 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3304 struct sockaddr_in *sin = (struct sockaddr_in *)
3305 &ep->com.local_addr;
3307 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3309 err = cxgb4_create_server_filter(
3310 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3311 sin->sin_addr.s_addr, sin->sin_port, 0,
3312 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3313 if (err == -EBUSY) {
3314 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3318 set_current_state(TASK_UNINTERRUPTIBLE);
3319 schedule_timeout(usecs_to_jiffies(100));
3321 } while (err == -EBUSY);
3323 c4iw_init_wr_wait(&ep->com.wr_wait);
3324 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3325 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3326 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3328 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3332 err = net_xmit_errno(err);
3335 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3337 &sin->sin_addr, ntohs(sin->sin_port));
3341 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3344 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3345 struct c4iw_listen_ep *ep;
3349 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3351 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3355 PDBG("%s ep %p\n", __func__, ep);
3356 ep->com.cm_id = cm_id;
3357 ref_cm_id(&ep->com);
3359 ep->backlog = backlog;
3360 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3361 sizeof(ep->com.local_addr));
3364 * Allocate a server TID.
3366 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3367 ep->com.local_addr.ss_family == AF_INET)
3368 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3369 cm_id->m_local_addr.ss_family, ep);
3371 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3372 cm_id->m_local_addr.ss_family, ep);
3374 if (ep->stid == -1) {
3375 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
3379 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3381 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3382 sizeof(ep->com.local_addr));
3384 state_set(&ep->com, LISTEN);
3385 if (ep->com.local_addr.ss_family == AF_INET)
3386 err = create_server4(dev, ep);
3388 err = create_server6(dev, ep);
3390 cm_id->provider_data = ep;
3394 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3395 ep->com.local_addr.ss_family);
3397 deref_cm_id(&ep->com);
3398 c4iw_put_ep(&ep->com);
3404 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3407 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3409 PDBG("%s ep %p\n", __func__, ep);
3412 state_set(&ep->com, DEAD);
3413 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3414 ep->com.local_addr.ss_family == AF_INET) {
3415 err = cxgb4_remove_server_filter(
3416 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3417 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3419 struct sockaddr_in6 *sin6;
3420 c4iw_init_wr_wait(&ep->com.wr_wait);
3421 err = cxgb4_remove_server(
3422 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3423 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3426 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3428 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3429 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3430 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3432 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3433 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3434 ep->com.local_addr.ss_family);
3436 deref_cm_id(&ep->com);
3437 c4iw_put_ep(&ep->com);
3441 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3446 struct c4iw_rdev *rdev;
3448 mutex_lock(&ep->com.mutex);
3450 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3451 states[ep->com.state], abrupt);
3454 * Ref the ep here in case we have fatal errors causing the
3455 * ep to be released and freed.
3457 c4iw_get_ep(&ep->com);
3459 rdev = &ep->com.dev->rdev;
3460 if (c4iw_fatal_error(rdev)) {
3462 close_complete_upcall(ep, -EIO);
3463 ep->com.state = DEAD;
3465 switch (ep->com.state) {
3473 ep->com.state = ABORTING;
3475 ep->com.state = CLOSING;
3478 set_bit(CLOSE_SENT, &ep->com.flags);
3481 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3484 (void)stop_ep_timer(ep);
3485 ep->com.state = ABORTING;
3487 ep->com.state = MORIBUND;
3493 PDBG("%s ignoring disconnect ep %p state %u\n",
3494 __func__, ep, ep->com.state);
3503 set_bit(EP_DISC_ABORT, &ep->com.history);
3504 close_complete_upcall(ep, -ECONNRESET);
3505 ret = send_abort(ep, NULL, gfp);
3507 set_bit(EP_DISC_CLOSE, &ep->com.history);
3508 ret = send_halfclose(ep, gfp);
3511 set_bit(EP_DISC_FAIL, &ep->com.history);
3514 close_complete_upcall(ep, -EIO);
3517 struct c4iw_qp_attributes attrs;
3519 attrs.next_state = C4IW_QP_STATE_ERROR;
3520 ret = c4iw_modify_qp(ep->com.qp->rhp,
3522 C4IW_QP_ATTR_NEXT_STATE,
3526 "%s - qp <- error failed!\n",
3532 mutex_unlock(&ep->com.mutex);
3533 c4iw_put_ep(&ep->com);
3535 release_ep_resources(ep);
3539 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3540 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3543 int atid = be32_to_cpu(req->tid);
3545 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3546 (__force u32) req->tid);
3550 switch (req->retval) {
3552 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3553 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3554 send_fw_act_open_req(ep, atid);
3558 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3559 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3560 send_fw_act_open_req(ep, atid);
3565 pr_info("%s unexpected ofld conn wr retval %d\n",
3566 __func__, req->retval);
3569 pr_err("active ofld_connect_wr failure %d atid %d\n",
3571 mutex_lock(&dev->rdev.stats.lock);
3572 dev->rdev.stats.act_ofld_conn_fails++;
3573 mutex_unlock(&dev->rdev.stats.lock);
3574 connect_reply_upcall(ep, status2errno(req->retval));
3575 state_set(&ep->com, DEAD);
3576 if (ep->com.remote_addr.ss_family == AF_INET6) {
3577 struct sockaddr_in6 *sin6 =
3578 (struct sockaddr_in6 *)&ep->com.local_addr;
3579 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3580 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3582 remove_handle(dev, &dev->atid_idr, atid);
3583 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3584 dst_release(ep->dst);
3585 cxgb4_l2t_release(ep->l2t);
3586 c4iw_put_ep(&ep->com);
3589 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3590 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3592 struct sk_buff *rpl_skb;
3593 struct cpl_pass_accept_req *cpl;
3596 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3599 PDBG("%s passive open failure %d\n", __func__, req->retval);
3600 mutex_lock(&dev->rdev.stats.lock);
3601 dev->rdev.stats.pas_ofld_conn_fails++;
3602 mutex_unlock(&dev->rdev.stats.lock);
3605 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3606 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3607 (__force u32) htonl(
3608 (__force u32) req->tid)));
3609 ret = pass_accept_req(dev, rpl_skb);
3616 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3618 struct cpl_fw6_msg *rpl = cplhdr(skb);
3619 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3621 switch (rpl->type) {
3623 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3625 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3626 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3627 switch (req->t_state) {
3629 active_ofld_conn_reply(dev, skb, req);
3632 passive_ofld_conn_reply(dev, skb, req);
3635 pr_err("%s unexpected ofld conn wr state %d\n",
3636 __func__, req->t_state);
3644 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3647 __be16 hdr_len, vlantag, len;
3649 int tcp_hdr_len, ip_hdr_len;
3651 struct cpl_rx_pkt *cpl = cplhdr(skb);
3652 struct cpl_pass_accept_req *req;
3653 struct tcp_options_received tmp_opt;
3654 struct c4iw_dev *dev;
3655 enum chip_type type;
3657 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3658 /* Store values from cpl_rx_pkt in temporary location. */
3659 vlantag = cpl->vlan;
3661 l2info = cpl->l2info;
3662 hdr_len = cpl->hdr_len;
3665 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3668 * We need to parse the TCP options from SYN packet.
3669 * to generate cpl_pass_accept_req.
3671 memset(&tmp_opt, 0, sizeof(tmp_opt));
3672 tcp_clear_options(&tmp_opt);
3673 tcp_parse_options(skb, &tmp_opt, 0, NULL);
3675 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3676 memset(req, 0, sizeof(*req));
3677 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3678 SYN_MAC_IDX_V(RX_MACIDX_G(
3679 be32_to_cpu(l2info))) |
3681 type = dev->rdev.lldi.adapter_type;
3682 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3683 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3685 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3686 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3687 eth_hdr_len = is_t4(type) ?
3688 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3689 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3690 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3691 IP_HDR_LEN_V(ip_hdr_len) |
3692 ETH_HDR_LEN_V(eth_hdr_len));
3693 } else { /* T6 and later */
3694 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3695 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3696 T6_IP_HDR_LEN_V(ip_hdr_len) |
3697 T6_ETH_HDR_LEN_V(eth_hdr_len));
3699 req->vlan = vlantag;
3701 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3702 PASS_OPEN_TOS_V(tos));
3703 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3704 if (tmp_opt.wscale_ok)
3705 req->tcpopt.wsf = tmp_opt.snd_wscale;
3706 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3707 if (tmp_opt.sack_ok)
3708 req->tcpopt.sack = 1;
3709 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3713 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3714 __be32 laddr, __be16 lport,
3715 __be32 raddr, __be16 rport,
3716 u32 rcv_isn, u32 filter, u16 window,
3717 u32 rss_qid, u8 port_id)
3719 struct sk_buff *req_skb;
3720 struct fw_ofld_connection_wr *req;
3721 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3724 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3725 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3726 memset(req, 0, sizeof(*req));
3727 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
3728 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
3729 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
3730 req->le.filter = (__force __be32) filter;
3731 req->le.lport = lport;
3732 req->le.pport = rport;
3733 req->le.u.ipv4.lip = laddr;
3734 req->le.u.ipv4.pip = raddr;
3735 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3736 req->tcb.rcv_adv = htons(window);
3737 req->tcb.t_state_to_astid =
3738 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3739 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3740 FW_OFLD_CONNECTION_WR_ASTID_V(
3741 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
3744 * We store the qid in opt2 which will be used by the firmware
3745 * to send us the wr response.
3747 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
3750 * We initialize the MSS index in TCB to 0xF.
3751 * So that when driver sends cpl_pass_accept_rpl
3752 * TCB picks up the correct value. If this was 0
3753 * TP will ignore any value > 0 for MSS index.
3755 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
3756 req->cookie = (uintptr_t)skb;
3758 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3759 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3761 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3769 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3770 * messages when a filter is being used instead of server to
3771 * redirect a syn packet. When packets hit filter they are redirected
3772 * to the offload queue and driver tries to establish the connection
3773 * using firmware work request.
3775 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3778 unsigned int filter;
3779 struct ethhdr *eh = NULL;
3780 struct vlan_ethhdr *vlan_eh = NULL;
3782 struct tcphdr *tcph;
3783 struct rss_header *rss = (void *)skb->data;
3784 struct cpl_rx_pkt *cpl = (void *)skb->data;
3785 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3786 struct l2t_entry *e;
3787 struct dst_entry *dst;
3788 struct c4iw_ep *lep;
3790 struct port_info *pi;
3791 struct net_device *pdev;
3792 u16 rss_qid, eth_hdr_len;
3795 struct neighbour *neigh;
3797 /* Drop all non-SYN packets */
3798 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
3802 * Drop all packets which did not hit the filter.
3803 * Unlikely to happen.
3805 if (!(rss->filter_hit && rss->filter_tid))
3809 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3811 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3813 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3815 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3819 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3821 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3824 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3827 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3830 pr_err("T%d Chip is not supported\n",
3831 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3835 if (eth_hdr_len == ETH_HLEN) {
3836 eh = (struct ethhdr *)(req + 1);
3837 iph = (struct iphdr *)(eh + 1);
3839 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3840 iph = (struct iphdr *)(vlan_eh + 1);
3841 skb->vlan_tci = ntohs(cpl->vlan);
3844 if (iph->version != 0x4)
3847 tcph = (struct tcphdr *)(iph + 1);
3848 skb_set_network_header(skb, (void *)iph - (void *)rss);
3849 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3852 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3853 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3854 ntohs(tcph->source), iph->tos);
3856 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3859 pr_err("%s - failed to find dst entry!\n",
3863 neigh = dst_neigh_lookup_skb(dst, skb);
3866 pr_err("%s - failed to allocate neigh!\n",
3871 if (neigh->dev->flags & IFF_LOOPBACK) {
3872 pdev = ip_dev_find(&init_net, iph->daddr);
3873 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3875 pi = (struct port_info *)netdev_priv(pdev);
3876 tx_chan = cxgb4_port_chan(pdev);
3879 pdev = get_real_dev(neigh->dev);
3880 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3882 pi = (struct port_info *)netdev_priv(pdev);
3883 tx_chan = cxgb4_port_chan(pdev);
3885 neigh_release(neigh);
3887 pr_err("%s - failed to allocate l2t entry!\n",
3892 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3893 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3894 window = (__force u16) htons((__force u16)tcph->window);
3896 /* Calcuate filter portion for LE region. */
3897 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3898 dev->rdev.lldi.ports[0],
3902 * Synthesize the cpl_pass_accept_req. We have everything except the
3903 * TID. Once firmware sends a reply with TID we update the TID field
3904 * in cpl and pass it through the regular cpl_pass_accept_req path.
3906 build_cpl_pass_accept_req(skb, stid, iph->tos);
3907 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3908 tcph->source, ntohl(tcph->seq), filter, window,
3909 rss_qid, pi->port_id);
3910 cxgb4_l2t_release(e);
3918 * These are the real handlers that are called from a
3921 static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
3922 [CPL_ACT_ESTABLISH] = act_establish,
3923 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3924 [CPL_RX_DATA] = rx_data,
3925 [CPL_ABORT_RPL_RSS] = abort_rpl,
3926 [CPL_ABORT_RPL] = abort_rpl,
3927 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3928 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3929 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3930 [CPL_PASS_ESTABLISH] = pass_establish,
3931 [CPL_PEER_CLOSE] = peer_close,
3932 [CPL_ABORT_REQ_RSS] = peer_abort,
3933 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3934 [CPL_RDMA_TERMINATE] = terminate,
3935 [CPL_FW4_ACK] = fw4_ack,
3936 [CPL_FW6_MSG] = deferred_fw6_msg,
3937 [CPL_RX_PKT] = rx_pkt,
3938 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe
3941 static void process_timeout(struct c4iw_ep *ep)
3943 struct c4iw_qp_attributes attrs;
3946 mutex_lock(&ep->com.mutex);
3947 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3949 set_bit(TIMEDOUT, &ep->com.history);
3950 switch (ep->com.state) {
3952 __state_set(&ep->com, ABORTING);
3953 connect_reply_upcall(ep, -ETIMEDOUT);
3956 __state_set(&ep->com, ABORTING);
3960 if (ep->com.cm_id && ep->com.qp) {
3961 attrs.next_state = C4IW_QP_STATE_ERROR;
3962 c4iw_modify_qp(ep->com.qp->rhp,
3963 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3966 __state_set(&ep->com, ABORTING);
3967 close_complete_upcall(ep, -ETIMEDOUT);
3973 * These states are expected if the ep timed out at the same
3974 * time as another thread was calling stop_ep_timer().
3975 * So we silently do nothing for these states.
3980 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3981 __func__, ep, ep->hwtid, ep->com.state);
3984 mutex_unlock(&ep->com.mutex);
3986 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
3987 c4iw_put_ep(&ep->com);
3990 static void process_timedout_eps(void)
3994 spin_lock_irq(&timeout_lock);
3995 while (!list_empty(&timeout_list)) {
3996 struct list_head *tmp;
3998 tmp = timeout_list.next;
4002 spin_unlock_irq(&timeout_lock);
4003 ep = list_entry(tmp, struct c4iw_ep, entry);
4004 process_timeout(ep);
4005 spin_lock_irq(&timeout_lock);
4007 spin_unlock_irq(&timeout_lock);
4010 static void process_work(struct work_struct *work)
4012 struct sk_buff *skb = NULL;
4013 struct c4iw_dev *dev;
4014 struct cpl_act_establish *rpl;
4015 unsigned int opcode;
4018 process_timedout_eps();
4019 while ((skb = skb_dequeue(&rxq))) {
4021 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4022 opcode = rpl->ot.opcode;
4024 BUG_ON(!work_handlers[opcode]);
4025 ret = work_handlers[opcode](dev, skb);
4028 process_timedout_eps();
4032 static DECLARE_WORK(skb_work, process_work);
4034 static void ep_timeout(unsigned long arg)
4036 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
4039 spin_lock(&timeout_lock);
4040 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
4042 * Only insert if it is not already on the list.
4044 if (!ep->entry.next) {
4045 list_add_tail(&ep->entry, &timeout_list);
4049 spin_unlock(&timeout_lock);
4051 queue_work(workq, &skb_work);
4055 * All the CM events are handled on a work queue to have a safe context.
4057 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4061 * Save dev in the skb->cb area.
4063 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4066 * Queue the skb and schedule the worker thread.
4068 skb_queue_tail(&rxq, skb);
4069 queue_work(workq, &skb_work);
4073 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4075 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4077 if (rpl->status != CPL_ERR_NONE) {
4078 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4079 "for tid %u\n", rpl->status, GET_TID(rpl));
4085 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4087 struct cpl_fw6_msg *rpl = cplhdr(skb);
4088 struct c4iw_wr_wait *wr_waitp;
4091 PDBG("%s type %u\n", __func__, rpl->type);
4093 switch (rpl->type) {
4094 case FW6_TYPE_WR_RPL:
4095 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
4096 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
4097 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
4099 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
4103 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
4107 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4115 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4117 struct cpl_abort_req_rss *req = cplhdr(skb);
4119 struct tid_info *t = dev->rdev.lldi.tids;
4120 unsigned int tid = GET_TID(req);
4122 ep = lookup_tid(t, tid);
4124 printk(KERN_WARNING MOD
4125 "Abort on non-existent endpoint, tid %d\n", tid);
4129 if (is_neg_adv(req->status)) {
4130 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4131 __func__, ep->hwtid, req->status,
4132 neg_adv_str(req->status));
4133 ep->stats.abort_neg_adv++;
4134 dev->rdev.stats.neg_adv++;
4138 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4142 * Wake up any threads in rdma_init() or rdma_fini().
4143 * However, if we are on MPAv2 and want to retry with MPAv1
4144 * then, don't wake up yet.
4146 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4147 if (ep->com.state != MPA_REQ_SENT)
4148 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4150 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4156 * Most upcalls from the T4 Core go to sched() to
4157 * schedule the processing on a work queue.
4159 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4160 [CPL_ACT_ESTABLISH] = sched,
4161 [CPL_ACT_OPEN_RPL] = sched,
4162 [CPL_RX_DATA] = sched,
4163 [CPL_ABORT_RPL_RSS] = sched,
4164 [CPL_ABORT_RPL] = sched,
4165 [CPL_PASS_OPEN_RPL] = sched,
4166 [CPL_CLOSE_LISTSRV_RPL] = sched,
4167 [CPL_PASS_ACCEPT_REQ] = sched,
4168 [CPL_PASS_ESTABLISH] = sched,
4169 [CPL_PEER_CLOSE] = sched,
4170 [CPL_CLOSE_CON_RPL] = sched,
4171 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
4172 [CPL_RDMA_TERMINATE] = sched,
4173 [CPL_FW4_ACK] = sched,
4174 [CPL_SET_TCB_RPL] = set_tcb_rpl,
4175 [CPL_FW6_MSG] = fw6_msg,
4176 [CPL_RX_PKT] = sched
4179 int __init c4iw_cm_init(void)
4181 spin_lock_init(&timeout_lock);
4182 skb_queue_head_init(&rxq);
4184 workq = create_singlethread_workqueue("iw_cxgb4");
4191 void c4iw_cm_term(void)
4193 WARN_ON(!list_empty(&timeout_list));
4194 flush_workqueue(workq);
4195 destroy_workqueue(workq);