2 * Copyright (c) 2009-2010 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>
52 static char *states[] = {
69 module_param(nocong, int, 0644);
70 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
72 static int enable_ecn;
73 module_param(enable_ecn, int, 0644);
74 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
76 static int dack_mode = 1;
77 module_param(dack_mode, int, 0644);
78 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
80 int c4iw_max_read_depth = 8;
81 module_param(c4iw_max_read_depth, int, 0644);
82 MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
84 static int enable_tcp_timestamps;
85 module_param(enable_tcp_timestamps, int, 0644);
86 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
88 static int enable_tcp_sack;
89 module_param(enable_tcp_sack, int, 0644);
90 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
92 static int enable_tcp_window_scaling = 1;
93 module_param(enable_tcp_window_scaling, int, 0644);
94 MODULE_PARM_DESC(enable_tcp_window_scaling,
95 "Enable tcp window scaling (default=1)");
98 module_param(c4iw_debug, int, 0644);
99 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
101 static int peer2peer;
102 module_param(peer2peer, int, 0644);
103 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
105 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
106 module_param(p2p_type, int, 0644);
107 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
108 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
110 static int ep_timeout_secs = 60;
111 module_param(ep_timeout_secs, int, 0644);
112 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
113 "in seconds (default=60)");
115 static int mpa_rev = 1;
116 module_param(mpa_rev, int, 0644);
117 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
118 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
119 " compliant (default=1)");
121 static int markers_enabled;
122 module_param(markers_enabled, int, 0644);
123 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
125 static int crc_enabled = 1;
126 module_param(crc_enabled, int, 0644);
127 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
129 static int rcv_win = 256 * 1024;
130 module_param(rcv_win, int, 0644);
131 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
133 static int snd_win = 128 * 1024;
134 module_param(snd_win, int, 0644);
135 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
137 static struct workqueue_struct *workq;
139 static struct sk_buff_head rxq;
141 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
142 static void ep_timeout(unsigned long arg);
143 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
145 static LIST_HEAD(timeout_list);
146 static spinlock_t timeout_lock;
148 static void deref_qp(struct c4iw_ep *ep)
150 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
151 clear_bit(QP_REFERENCED, &ep->com.flags);
154 static void ref_qp(struct c4iw_ep *ep)
156 set_bit(QP_REFERENCED, &ep->com.flags);
157 c4iw_qp_add_ref(&ep->com.qp->ibqp);
160 static void start_ep_timer(struct c4iw_ep *ep)
162 PDBG("%s ep %p\n", __func__, ep);
163 if (timer_pending(&ep->timer)) {
164 pr_err("%s timer already started! ep %p\n",
168 clear_bit(TIMEOUT, &ep->com.flags);
169 c4iw_get_ep(&ep->com);
170 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
171 ep->timer.data = (unsigned long)ep;
172 ep->timer.function = ep_timeout;
173 add_timer(&ep->timer);
176 static void stop_ep_timer(struct c4iw_ep *ep)
178 PDBG("%s ep %p stopping\n", __func__, ep);
179 del_timer_sync(&ep->timer);
180 if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
181 c4iw_put_ep(&ep->com);
184 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
185 struct l2t_entry *l2e)
189 if (c4iw_fatal_error(rdev)) {
191 PDBG("%s - device in error state - dropping\n", __func__);
194 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
197 return error < 0 ? error : 0;
200 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
204 if (c4iw_fatal_error(rdev)) {
206 PDBG("%s - device in error state - dropping\n", __func__);
209 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
212 return error < 0 ? error : 0;
215 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
217 struct cpl_tid_release *req;
219 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
222 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
223 INIT_TP_WR(req, hwtid);
224 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
225 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
226 c4iw_ofld_send(rdev, skb);
230 static void set_emss(struct c4iw_ep *ep, u16 opt)
232 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
234 if (GET_TCPOPT_TSTAMP(opt))
238 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
242 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
244 enum c4iw_ep_state state;
246 mutex_lock(&epc->mutex);
248 mutex_unlock(&epc->mutex);
252 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
257 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
259 mutex_lock(&epc->mutex);
260 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
261 __state_set(epc, new);
262 mutex_unlock(&epc->mutex);
266 static void *alloc_ep(int size, gfp_t gfp)
268 struct c4iw_ep_common *epc;
270 epc = kzalloc(size, gfp);
272 kref_init(&epc->kref);
273 mutex_init(&epc->mutex);
274 c4iw_init_wr_wait(&epc->wr_wait);
276 PDBG("%s alloc ep %p\n", __func__, epc);
280 void _c4iw_free_ep(struct kref *kref)
284 ep = container_of(kref, struct c4iw_ep, com.kref);
285 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
286 if (test_bit(QP_REFERENCED, &ep->com.flags))
288 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
289 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
290 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
291 dst_release(ep->dst);
292 cxgb4_l2t_release(ep->l2t);
297 static void release_ep_resources(struct c4iw_ep *ep)
299 set_bit(RELEASE_RESOURCES, &ep->com.flags);
300 c4iw_put_ep(&ep->com);
303 static int status2errno(int status)
308 case CPL_ERR_CONN_RESET:
310 case CPL_ERR_ARP_MISS:
311 return -EHOSTUNREACH;
312 case CPL_ERR_CONN_TIMEDOUT:
314 case CPL_ERR_TCAM_FULL:
316 case CPL_ERR_CONN_EXIST:
324 * Try and reuse skbs already allocated...
326 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
328 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
331 skb_reset_transport_header(skb);
333 skb = alloc_skb(len, gfp);
338 static struct net_device *get_real_dev(struct net_device *egress_dev)
340 struct net_device *phys_dev = egress_dev;
341 if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
342 phys_dev = vlan_dev_real_dev(egress_dev);
346 static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
350 egress_dev = get_real_dev(egress_dev);
351 for (i = 0; i < dev->rdev.lldi.nports; i++)
352 if (dev->rdev.lldi.ports[i] == egress_dev)
357 static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
358 __u8 *peer_ip, __be16 local_port,
359 __be16 peer_port, u8 tos,
362 struct dst_entry *dst = NULL;
364 if (IS_ENABLED(CONFIG_IPV6)) {
367 memset(&fl6, 0, sizeof(fl6));
368 memcpy(&fl6.daddr, peer_ip, 16);
369 memcpy(&fl6.saddr, local_ip, 16);
370 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
371 fl6.flowi6_oif = sin6_scope_id;
372 dst = ip6_route_output(&init_net, NULL, &fl6);
375 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
376 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
386 static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
387 __be32 peer_ip, __be16 local_port,
388 __be16 peer_port, u8 tos)
394 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
395 peer_port, local_port, IPPROTO_TCP,
399 n = dst_neigh_lookup(&rt->dst, &peer_ip);
402 if (!our_interface(dev, n->dev)) {
403 dst_release(&rt->dst);
410 static void arp_failure_discard(void *handle, struct sk_buff *skb)
412 PDBG("%s c4iw_dev %p\n", __func__, handle);
417 * Handle an ARP failure for an active open.
419 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
421 printk(KERN_ERR MOD "ARP failure duing connect\n");
426 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
429 static void abort_arp_failure(void *handle, struct sk_buff *skb)
431 struct c4iw_rdev *rdev = handle;
432 struct cpl_abort_req *req = cplhdr(skb);
434 PDBG("%s rdev %p\n", __func__, rdev);
435 req->cmd = CPL_ABORT_NO_RST;
436 c4iw_ofld_send(rdev, skb);
439 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
441 unsigned int flowclen = 80;
442 struct fw_flowc_wr *flowc;
445 skb = get_skb(skb, flowclen, GFP_KERNEL);
446 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
448 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
449 FW_FLOWC_WR_NPARAMS(8));
450 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
451 16)) | FW_WR_FLOWID(ep->hwtid));
453 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
454 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
455 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
456 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
457 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
458 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
459 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
460 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
461 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
462 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
463 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
464 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
465 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
466 flowc->mnemval[6].val = cpu_to_be32(snd_win);
467 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
468 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
469 /* Pad WR to 16 byte boundary */
470 flowc->mnemval[8].mnemonic = 0;
471 flowc->mnemval[8].val = 0;
472 for (i = 0; i < 9; i++) {
473 flowc->mnemval[i].r4[0] = 0;
474 flowc->mnemval[i].r4[1] = 0;
475 flowc->mnemval[i].r4[2] = 0;
478 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
479 c4iw_ofld_send(&ep->com.dev->rdev, skb);
482 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
484 struct cpl_close_con_req *req;
486 int wrlen = roundup(sizeof *req, 16);
488 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
489 skb = get_skb(NULL, wrlen, gfp);
491 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
494 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
495 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
496 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
497 memset(req, 0, wrlen);
498 INIT_TP_WR(req, ep->hwtid);
499 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
501 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
504 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
506 struct cpl_abort_req *req;
507 int wrlen = roundup(sizeof *req, 16);
509 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
510 skb = get_skb(skb, wrlen, gfp);
512 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
516 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
517 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
518 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
519 memset(req, 0, wrlen);
520 INIT_TP_WR(req, ep->hwtid);
521 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
522 req->cmd = CPL_ABORT_SEND_RST;
523 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
526 #define VLAN_NONE 0xfff
527 #define FILTER_SEL_VLAN_NONE 0xffff
528 #define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
529 #define FILTER_SEL_WIDTH_VIN_P_FC \
530 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
531 #define FILTER_SEL_WIDTH_TAG_P_FC \
532 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
533 #define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
535 static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
536 struct l2t_entry *l2t)
538 unsigned int ntuple = 0;
541 switch (dev->rdev.lldi.filt_mode) {
543 /* default filter mode */
544 case HW_TPL_FR_MT_PR_IV_P_FC:
545 if (l2t->vlan == VLAN_NONE)
546 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
548 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
549 ntuple |= 1 << FILTER_SEL_WIDTH_TAG_P_FC;
551 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
552 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
554 case HW_TPL_FR_MT_PR_OV_P_FC: {
555 viid = cxgb4_port_viid(l2t->neigh->dev);
557 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
558 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
559 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
560 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
561 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
570 static int send_connect(struct c4iw_ep *ep)
572 struct cpl_act_open_req *req;
573 struct cpl_t5_act_open_req *t5_req;
574 struct cpl_act_open_req6 *req6;
575 struct cpl_t5_act_open_req6 *t5_req6;
579 unsigned int mtu_idx;
582 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
583 sizeof(struct cpl_act_open_req) :
584 sizeof(struct cpl_t5_act_open_req);
585 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
586 sizeof(struct cpl_act_open_req6) :
587 sizeof(struct cpl_t5_act_open_req6);
588 struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
589 struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
590 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
591 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
593 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
594 roundup(sizev4, 16) :
597 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
599 skb = get_skb(NULL, wrlen, GFP_KERNEL);
601 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
605 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
607 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
608 wscale = compute_wscale(rcv_win);
609 opt0 = (nocong ? NO_CONG(1) : 0) |
614 L2T_IDX(ep->l2t->idx) |
615 TX_CHAN(ep->tx_chan) |
616 SMAC_SEL(ep->smac_idx) |
618 ULP_MODE(ULP_MODE_TCPDDP) |
619 RCV_BUFSIZ(rcv_win>>10);
620 opt2 = RX_CHANNEL(0) |
621 CCTRL_ECN(enable_ecn) |
622 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
623 if (enable_tcp_timestamps)
624 opt2 |= TSTAMPS_EN(1);
627 if (wscale && enable_tcp_window_scaling)
628 opt2 |= WND_SCALE_EN(1);
629 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
631 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
632 if (ep->com.remote_addr.ss_family == AF_INET) {
633 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
635 OPCODE_TID(req) = cpu_to_be32(
636 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
637 ((ep->rss_qid << 14) | ep->atid)));
638 req->local_port = la->sin_port;
639 req->peer_port = ra->sin_port;
640 req->local_ip = la->sin_addr.s_addr;
641 req->peer_ip = ra->sin_addr.s_addr;
642 req->opt0 = cpu_to_be64(opt0);
643 req->params = cpu_to_be32(select_ntuple(ep->com.dev,
645 req->opt2 = cpu_to_be32(opt2);
647 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
650 OPCODE_TID(req6) = cpu_to_be32(
651 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
652 ((ep->rss_qid<<14)|ep->atid)));
653 req6->local_port = la6->sin6_port;
654 req6->peer_port = ra6->sin6_port;
655 req6->local_ip_hi = *((__be64 *)
656 (la6->sin6_addr.s6_addr));
657 req6->local_ip_lo = *((__be64 *)
658 (la6->sin6_addr.s6_addr + 8));
659 req6->peer_ip_hi = *((__be64 *)
660 (ra6->sin6_addr.s6_addr));
661 req6->peer_ip_lo = *((__be64 *)
662 (ra6->sin6_addr.s6_addr + 8));
663 req6->opt0 = cpu_to_be64(opt0);
664 req6->params = cpu_to_be32(
665 select_ntuple(ep->com.dev, ep->dst,
667 req6->opt2 = cpu_to_be32(opt2);
670 if (ep->com.remote_addr.ss_family == AF_INET) {
671 t5_req = (struct cpl_t5_act_open_req *)
673 INIT_TP_WR(t5_req, 0);
674 OPCODE_TID(t5_req) = cpu_to_be32(
675 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
676 ((ep->rss_qid << 14) | ep->atid)));
677 t5_req->local_port = la->sin_port;
678 t5_req->peer_port = ra->sin_port;
679 t5_req->local_ip = la->sin_addr.s_addr;
680 t5_req->peer_ip = ra->sin_addr.s_addr;
681 t5_req->opt0 = cpu_to_be64(opt0);
682 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
683 select_ntuple(ep->com.dev,
685 t5_req->opt2 = cpu_to_be32(opt2);
687 t5_req6 = (struct cpl_t5_act_open_req6 *)
689 INIT_TP_WR(t5_req6, 0);
690 OPCODE_TID(t5_req6) = cpu_to_be32(
691 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
692 ((ep->rss_qid<<14)|ep->atid)));
693 t5_req6->local_port = la6->sin6_port;
694 t5_req6->peer_port = ra6->sin6_port;
695 t5_req6->local_ip_hi = *((__be64 *)
696 (la6->sin6_addr.s6_addr));
697 t5_req6->local_ip_lo = *((__be64 *)
698 (la6->sin6_addr.s6_addr + 8));
699 t5_req6->peer_ip_hi = *((__be64 *)
700 (ra6->sin6_addr.s6_addr));
701 t5_req6->peer_ip_lo = *((__be64 *)
702 (ra6->sin6_addr.s6_addr + 8));
703 t5_req6->opt0 = cpu_to_be64(opt0);
704 t5_req6->params = (__force __be64)cpu_to_be32(
705 select_ntuple(ep->com.dev, ep->dst, ep->l2t));
706 t5_req6->opt2 = cpu_to_be32(opt2);
710 set_bit(ACT_OPEN_REQ, &ep->com.history);
711 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
714 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
718 struct fw_ofld_tx_data_wr *req;
719 struct mpa_message *mpa;
720 struct mpa_v2_conn_params mpa_v2_params;
722 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
724 BUG_ON(skb_cloned(skb));
726 mpalen = sizeof(*mpa) + ep->plen;
727 if (mpa_rev_to_use == 2)
728 mpalen += sizeof(struct mpa_v2_conn_params);
729 wrlen = roundup(mpalen + sizeof *req, 16);
730 skb = get_skb(skb, wrlen, GFP_KERNEL);
732 connect_reply_upcall(ep, -ENOMEM);
735 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
737 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
738 memset(req, 0, wrlen);
739 req->op_to_immdlen = cpu_to_be32(
740 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
742 FW_WR_IMMDLEN(mpalen));
743 req->flowid_len16 = cpu_to_be32(
744 FW_WR_FLOWID(ep->hwtid) |
745 FW_WR_LEN16(wrlen >> 4));
746 req->plen = cpu_to_be32(mpalen);
747 req->tunnel_to_proxy = cpu_to_be32(
748 FW_OFLD_TX_DATA_WR_FLUSH(1) |
749 FW_OFLD_TX_DATA_WR_SHOVE(1));
751 mpa = (struct mpa_message *)(req + 1);
752 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
753 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
754 (markers_enabled ? MPA_MARKERS : 0) |
755 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
756 mpa->private_data_size = htons(ep->plen);
757 mpa->revision = mpa_rev_to_use;
758 if (mpa_rev_to_use == 1) {
759 ep->tried_with_mpa_v1 = 1;
760 ep->retry_with_mpa_v1 = 0;
763 if (mpa_rev_to_use == 2) {
764 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
765 sizeof (struct mpa_v2_conn_params));
766 mpa_v2_params.ird = htons((u16)ep->ird);
767 mpa_v2_params.ord = htons((u16)ep->ord);
770 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
771 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
773 htons(MPA_V2_RDMA_WRITE_RTR);
774 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
776 htons(MPA_V2_RDMA_READ_RTR);
778 memcpy(mpa->private_data, &mpa_v2_params,
779 sizeof(struct mpa_v2_conn_params));
782 memcpy(mpa->private_data +
783 sizeof(struct mpa_v2_conn_params),
784 ep->mpa_pkt + sizeof(*mpa), ep->plen);
787 memcpy(mpa->private_data,
788 ep->mpa_pkt + sizeof(*mpa), ep->plen);
791 * Reference the mpa skb. This ensures the data area
792 * will remain in memory until the hw acks the tx.
793 * Function fw4_ack() will deref it.
796 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
799 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
801 state_set(&ep->com, MPA_REQ_SENT);
802 ep->mpa_attr.initiator = 1;
806 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
809 struct fw_ofld_tx_data_wr *req;
810 struct mpa_message *mpa;
812 struct mpa_v2_conn_params mpa_v2_params;
814 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
816 mpalen = sizeof(*mpa) + plen;
817 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
818 mpalen += sizeof(struct mpa_v2_conn_params);
819 wrlen = roundup(mpalen + sizeof *req, 16);
821 skb = get_skb(NULL, wrlen, GFP_KERNEL);
823 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
826 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
828 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
829 memset(req, 0, wrlen);
830 req->op_to_immdlen = cpu_to_be32(
831 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
833 FW_WR_IMMDLEN(mpalen));
834 req->flowid_len16 = cpu_to_be32(
835 FW_WR_FLOWID(ep->hwtid) |
836 FW_WR_LEN16(wrlen >> 4));
837 req->plen = cpu_to_be32(mpalen);
838 req->tunnel_to_proxy = cpu_to_be32(
839 FW_OFLD_TX_DATA_WR_FLUSH(1) |
840 FW_OFLD_TX_DATA_WR_SHOVE(1));
842 mpa = (struct mpa_message *)(req + 1);
843 memset(mpa, 0, sizeof(*mpa));
844 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
845 mpa->flags = MPA_REJECT;
846 mpa->revision = ep->mpa_attr.version;
847 mpa->private_data_size = htons(plen);
849 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
850 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
851 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
852 sizeof (struct mpa_v2_conn_params));
853 mpa_v2_params.ird = htons(((u16)ep->ird) |
854 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
856 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
858 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
859 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
860 FW_RI_INIT_P2PTYPE_READ_REQ ?
861 MPA_V2_RDMA_READ_RTR : 0) : 0));
862 memcpy(mpa->private_data, &mpa_v2_params,
863 sizeof(struct mpa_v2_conn_params));
866 memcpy(mpa->private_data +
867 sizeof(struct mpa_v2_conn_params), pdata, plen);
870 memcpy(mpa->private_data, pdata, plen);
873 * Reference the mpa skb again. This ensures the data area
874 * will remain in memory until the hw acks the tx.
875 * Function fw4_ack() will deref it.
878 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
879 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
882 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
885 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
888 struct fw_ofld_tx_data_wr *req;
889 struct mpa_message *mpa;
891 struct mpa_v2_conn_params mpa_v2_params;
893 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
895 mpalen = sizeof(*mpa) + plen;
896 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
897 mpalen += sizeof(struct mpa_v2_conn_params);
898 wrlen = roundup(mpalen + sizeof *req, 16);
900 skb = get_skb(NULL, wrlen, GFP_KERNEL);
902 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
905 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
907 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
908 memset(req, 0, wrlen);
909 req->op_to_immdlen = cpu_to_be32(
910 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
912 FW_WR_IMMDLEN(mpalen));
913 req->flowid_len16 = cpu_to_be32(
914 FW_WR_FLOWID(ep->hwtid) |
915 FW_WR_LEN16(wrlen >> 4));
916 req->plen = cpu_to_be32(mpalen);
917 req->tunnel_to_proxy = cpu_to_be32(
918 FW_OFLD_TX_DATA_WR_FLUSH(1) |
919 FW_OFLD_TX_DATA_WR_SHOVE(1));
921 mpa = (struct mpa_message *)(req + 1);
922 memset(mpa, 0, sizeof(*mpa));
923 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
924 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
925 (markers_enabled ? MPA_MARKERS : 0);
926 mpa->revision = ep->mpa_attr.version;
927 mpa->private_data_size = htons(plen);
929 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
930 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
931 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
932 sizeof (struct mpa_v2_conn_params));
933 mpa_v2_params.ird = htons((u16)ep->ird);
934 mpa_v2_params.ord = htons((u16)ep->ord);
935 if (peer2peer && (ep->mpa_attr.p2p_type !=
936 FW_RI_INIT_P2PTYPE_DISABLED)) {
937 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
939 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
941 htons(MPA_V2_RDMA_WRITE_RTR);
942 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
944 htons(MPA_V2_RDMA_READ_RTR);
947 memcpy(mpa->private_data, &mpa_v2_params,
948 sizeof(struct mpa_v2_conn_params));
951 memcpy(mpa->private_data +
952 sizeof(struct mpa_v2_conn_params), pdata, plen);
955 memcpy(mpa->private_data, pdata, plen);
958 * Reference the mpa skb. This ensures the data area
959 * will remain in memory until the hw acks the tx.
960 * Function fw4_ack() will deref it.
963 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
965 state_set(&ep->com, MPA_REP_SENT);
966 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
969 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
972 struct cpl_act_establish *req = cplhdr(skb);
973 unsigned int tid = GET_TID(req);
974 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
975 struct tid_info *t = dev->rdev.lldi.tids;
977 ep = lookup_atid(t, atid);
979 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
980 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
982 dst_confirm(ep->dst);
984 /* setup the hwtid for this connection */
986 cxgb4_insert_tid(t, ep, tid);
987 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
989 ep->snd_seq = be32_to_cpu(req->snd_isn);
990 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
992 set_emss(ep, ntohs(req->tcp_opt));
994 /* dealloc the atid */
995 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
996 cxgb4_free_atid(t, atid);
997 set_bit(ACT_ESTAB, &ep->com.history);
999 /* start MPA negotiation */
1000 send_flowc(ep, NULL);
1001 if (ep->retry_with_mpa_v1)
1002 send_mpa_req(ep, skb, 1);
1004 send_mpa_req(ep, skb, mpa_rev);
1009 static void close_complete_upcall(struct c4iw_ep *ep)
1011 struct iw_cm_event event;
1013 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1014 memset(&event, 0, sizeof(event));
1015 event.event = IW_CM_EVENT_CLOSE;
1016 if (ep->com.cm_id) {
1017 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1018 ep, ep->com.cm_id, ep->hwtid);
1019 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1020 ep->com.cm_id->rem_ref(ep->com.cm_id);
1021 ep->com.cm_id = NULL;
1022 set_bit(CLOSE_UPCALL, &ep->com.history);
1026 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1028 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1029 close_complete_upcall(ep);
1030 state_set(&ep->com, ABORTING);
1031 set_bit(ABORT_CONN, &ep->com.history);
1032 return send_abort(ep, skb, gfp);
1035 static void peer_close_upcall(struct c4iw_ep *ep)
1037 struct iw_cm_event event;
1039 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1040 memset(&event, 0, sizeof(event));
1041 event.event = IW_CM_EVENT_DISCONNECT;
1042 if (ep->com.cm_id) {
1043 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1044 ep, ep->com.cm_id, ep->hwtid);
1045 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1046 set_bit(DISCONN_UPCALL, &ep->com.history);
1050 static void peer_abort_upcall(struct c4iw_ep *ep)
1052 struct iw_cm_event event;
1054 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1055 memset(&event, 0, sizeof(event));
1056 event.event = IW_CM_EVENT_CLOSE;
1057 event.status = -ECONNRESET;
1058 if (ep->com.cm_id) {
1059 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1060 ep->com.cm_id, ep->hwtid);
1061 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1062 ep->com.cm_id->rem_ref(ep->com.cm_id);
1063 ep->com.cm_id = NULL;
1064 set_bit(ABORT_UPCALL, &ep->com.history);
1068 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1070 struct iw_cm_event event;
1072 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1073 memset(&event, 0, sizeof(event));
1074 event.event = IW_CM_EVENT_CONNECT_REPLY;
1075 event.status = status;
1076 memcpy(&event.local_addr, &ep->com.local_addr,
1077 sizeof(ep->com.local_addr));
1078 memcpy(&event.remote_addr, &ep->com.remote_addr,
1079 sizeof(ep->com.remote_addr));
1081 if ((status == 0) || (status == -ECONNREFUSED)) {
1082 if (!ep->tried_with_mpa_v1) {
1083 /* this means MPA_v2 is used */
1084 event.private_data_len = ep->plen -
1085 sizeof(struct mpa_v2_conn_params);
1086 event.private_data = ep->mpa_pkt +
1087 sizeof(struct mpa_message) +
1088 sizeof(struct mpa_v2_conn_params);
1090 /* this means MPA_v1 is used */
1091 event.private_data_len = ep->plen;
1092 event.private_data = ep->mpa_pkt +
1093 sizeof(struct mpa_message);
1097 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1099 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1100 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1103 ep->com.cm_id->rem_ref(ep->com.cm_id);
1104 ep->com.cm_id = NULL;
1108 static void connect_request_upcall(struct c4iw_ep *ep)
1110 struct iw_cm_event event;
1112 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1113 memset(&event, 0, sizeof(event));
1114 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1115 memcpy(&event.local_addr, &ep->com.local_addr,
1116 sizeof(ep->com.local_addr));
1117 memcpy(&event.remote_addr, &ep->com.remote_addr,
1118 sizeof(ep->com.remote_addr));
1119 event.provider_data = ep;
1120 if (!ep->tried_with_mpa_v1) {
1121 /* this means MPA_v2 is used */
1122 event.ord = ep->ord;
1123 event.ird = ep->ird;
1124 event.private_data_len = ep->plen -
1125 sizeof(struct mpa_v2_conn_params);
1126 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1127 sizeof(struct mpa_v2_conn_params);
1129 /* this means MPA_v1 is used. Send max supported */
1130 event.ord = c4iw_max_read_depth;
1131 event.ird = c4iw_max_read_depth;
1132 event.private_data_len = ep->plen;
1133 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1135 if (state_read(&ep->parent_ep->com) != DEAD) {
1136 c4iw_get_ep(&ep->com);
1137 ep->parent_ep->com.cm_id->event_handler(
1138 ep->parent_ep->com.cm_id,
1141 set_bit(CONNREQ_UPCALL, &ep->com.history);
1142 c4iw_put_ep(&ep->parent_ep->com);
1143 ep->parent_ep = NULL;
1146 static void established_upcall(struct c4iw_ep *ep)
1148 struct iw_cm_event event;
1150 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1151 memset(&event, 0, sizeof(event));
1152 event.event = IW_CM_EVENT_ESTABLISHED;
1153 event.ird = ep->ird;
1154 event.ord = ep->ord;
1155 if (ep->com.cm_id) {
1156 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1157 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1158 set_bit(ESTAB_UPCALL, &ep->com.history);
1162 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1164 struct cpl_rx_data_ack *req;
1165 struct sk_buff *skb;
1166 int wrlen = roundup(sizeof *req, 16);
1168 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1169 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1171 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1175 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1176 memset(req, 0, wrlen);
1177 INIT_TP_WR(req, ep->hwtid);
1178 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1180 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1182 V_RX_DACK_MODE(dack_mode));
1183 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1184 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1188 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1190 struct mpa_message *mpa;
1191 struct mpa_v2_conn_params *mpa_v2_params;
1193 u16 resp_ird, resp_ord;
1194 u8 rtr_mismatch = 0, insuff_ird = 0;
1195 struct c4iw_qp_attributes attrs;
1196 enum c4iw_qp_attr_mask mask;
1199 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1202 * Stop mpa timer. If it expired, then the state has
1203 * changed and we bail since ep_timeout already aborted
1207 if (state_read(&ep->com) != MPA_REQ_SENT)
1211 * If we get more than the supported amount of private data
1212 * then we must fail this connection.
1214 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1220 * copy the new data into our accumulation buffer.
1222 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1224 ep->mpa_pkt_len += skb->len;
1227 * if we don't even have the mpa message, then bail.
1229 if (ep->mpa_pkt_len < sizeof(*mpa))
1231 mpa = (struct mpa_message *) ep->mpa_pkt;
1233 /* Validate MPA header. */
1234 if (mpa->revision > mpa_rev) {
1235 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1236 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1240 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1245 plen = ntohs(mpa->private_data_size);
1248 * Fail if there's too much private data.
1250 if (plen > MPA_MAX_PRIVATE_DATA) {
1256 * If plen does not account for pkt size
1258 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1263 ep->plen = (u8) plen;
1266 * If we don't have all the pdata yet, then bail.
1267 * We'll continue process when more data arrives.
1269 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1272 if (mpa->flags & MPA_REJECT) {
1273 err = -ECONNREFUSED;
1278 * If we get here we have accumulated the entire mpa
1279 * start reply message including private data. And
1280 * the MPA header is valid.
1282 state_set(&ep->com, FPDU_MODE);
1283 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1284 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1285 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1286 ep->mpa_attr.version = mpa->revision;
1287 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1289 if (mpa->revision == 2) {
1290 ep->mpa_attr.enhanced_rdma_conn =
1291 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1292 if (ep->mpa_attr.enhanced_rdma_conn) {
1293 mpa_v2_params = (struct mpa_v2_conn_params *)
1294 (ep->mpa_pkt + sizeof(*mpa));
1295 resp_ird = ntohs(mpa_v2_params->ird) &
1296 MPA_V2_IRD_ORD_MASK;
1297 resp_ord = ntohs(mpa_v2_params->ord) &
1298 MPA_V2_IRD_ORD_MASK;
1301 * This is a double-check. Ideally, below checks are
1302 * not required since ird/ord stuff has been taken
1303 * care of in c4iw_accept_cr
1305 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1312 if (ntohs(mpa_v2_params->ird) &
1313 MPA_V2_PEER2PEER_MODEL) {
1314 if (ntohs(mpa_v2_params->ord) &
1315 MPA_V2_RDMA_WRITE_RTR)
1316 ep->mpa_attr.p2p_type =
1317 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1318 else if (ntohs(mpa_v2_params->ord) &
1319 MPA_V2_RDMA_READ_RTR)
1320 ep->mpa_attr.p2p_type =
1321 FW_RI_INIT_P2PTYPE_READ_REQ;
1324 } else if (mpa->revision == 1)
1326 ep->mpa_attr.p2p_type = p2p_type;
1328 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1329 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1330 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1331 ep->mpa_attr.recv_marker_enabled,
1332 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1333 ep->mpa_attr.p2p_type, p2p_type);
1336 * If responder's RTR does not match with that of initiator, assign
1337 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1338 * generated when moving QP to RTS state.
1339 * A TERM message will be sent after QP has moved to RTS state
1341 if ((ep->mpa_attr.version == 2) && peer2peer &&
1342 (ep->mpa_attr.p2p_type != p2p_type)) {
1343 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1347 attrs.mpa_attr = ep->mpa_attr;
1348 attrs.max_ird = ep->ird;
1349 attrs.max_ord = ep->ord;
1350 attrs.llp_stream_handle = ep;
1351 attrs.next_state = C4IW_QP_STATE_RTS;
1353 mask = C4IW_QP_ATTR_NEXT_STATE |
1354 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1355 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1357 /* bind QP and TID with INIT_WR */
1358 err = c4iw_modify_qp(ep->com.qp->rhp,
1359 ep->com.qp, mask, &attrs, 1);
1364 * If responder's RTR requirement did not match with what initiator
1365 * supports, generate TERM message
1368 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1369 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1370 attrs.ecode = MPA_NOMATCH_RTR;
1371 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1372 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1373 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1379 * Generate TERM if initiator IRD is not sufficient for responder
1380 * provided ORD. Currently, we do the same behaviour even when
1381 * responder provided IRD is also not sufficient as regards to
1385 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1387 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1388 attrs.ecode = MPA_INSUFF_IRD;
1389 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1390 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1391 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1397 state_set(&ep->com, ABORTING);
1398 send_abort(ep, skb, GFP_KERNEL);
1400 connect_reply_upcall(ep, err);
1404 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1406 struct mpa_message *mpa;
1407 struct mpa_v2_conn_params *mpa_v2_params;
1410 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1412 if (state_read(&ep->com) != MPA_REQ_WAIT)
1416 * If we get more than the supported amount of private data
1417 * then we must fail this connection.
1419 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1421 abort_connection(ep, skb, GFP_KERNEL);
1425 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1428 * Copy the new data into our accumulation buffer.
1430 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1432 ep->mpa_pkt_len += skb->len;
1435 * If we don't even have the mpa message, then bail.
1436 * We'll continue process when more data arrives.
1438 if (ep->mpa_pkt_len < sizeof(*mpa))
1441 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1443 mpa = (struct mpa_message *) ep->mpa_pkt;
1446 * Validate MPA Header.
1448 if (mpa->revision > mpa_rev) {
1449 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1450 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1452 abort_connection(ep, skb, GFP_KERNEL);
1456 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1458 abort_connection(ep, skb, GFP_KERNEL);
1462 plen = ntohs(mpa->private_data_size);
1465 * Fail if there's too much private data.
1467 if (plen > MPA_MAX_PRIVATE_DATA) {
1469 abort_connection(ep, skb, GFP_KERNEL);
1474 * If plen does not account for pkt size
1476 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1478 abort_connection(ep, skb, GFP_KERNEL);
1481 ep->plen = (u8) plen;
1484 * If we don't have all the pdata yet, then bail.
1486 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1490 * If we get here we have accumulated the entire mpa
1491 * start reply message including private data.
1493 ep->mpa_attr.initiator = 0;
1494 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1495 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1496 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1497 ep->mpa_attr.version = mpa->revision;
1498 if (mpa->revision == 1)
1499 ep->tried_with_mpa_v1 = 1;
1500 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1502 if (mpa->revision == 2) {
1503 ep->mpa_attr.enhanced_rdma_conn =
1504 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1505 if (ep->mpa_attr.enhanced_rdma_conn) {
1506 mpa_v2_params = (struct mpa_v2_conn_params *)
1507 (ep->mpa_pkt + sizeof(*mpa));
1508 ep->ird = ntohs(mpa_v2_params->ird) &
1509 MPA_V2_IRD_ORD_MASK;
1510 ep->ord = ntohs(mpa_v2_params->ord) &
1511 MPA_V2_IRD_ORD_MASK;
1512 if (ntohs(mpa_v2_params->ird) & 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\n", __func__,
1530 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1531 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1532 ep->mpa_attr.p2p_type);
1534 state_set(&ep->com, MPA_REQ_RCVD);
1537 connect_request_upcall(ep);
1541 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1544 struct cpl_rx_data *hdr = cplhdr(skb);
1545 unsigned int dlen = ntohs(hdr->len);
1546 unsigned int tid = GET_TID(hdr);
1547 struct tid_info *t = dev->rdev.lldi.tids;
1548 __u8 status = hdr->status;
1550 ep = lookup_tid(t, tid);
1551 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1552 skb_pull(skb, sizeof(*hdr));
1553 skb_trim(skb, dlen);
1555 /* update RX credits */
1556 update_rx_credits(ep, dlen);
1558 switch (state_read(&ep->com)) {
1560 ep->rcv_seq += dlen;
1561 process_mpa_reply(ep, skb);
1564 ep->rcv_seq += dlen;
1565 process_mpa_request(ep, skb);
1568 struct c4iw_qp_attributes attrs;
1569 BUG_ON(!ep->com.qp);
1571 pr_err("%s Unexpected streaming data." \
1572 " qpid %u ep %p state %d tid %u status %d\n",
1573 __func__, ep->com.qp->wq.sq.qid, ep,
1574 state_read(&ep->com), ep->hwtid, status);
1575 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1576 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1577 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1586 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1589 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1591 unsigned int tid = GET_TID(rpl);
1592 struct tid_info *t = dev->rdev.lldi.tids;
1594 ep = lookup_tid(t, tid);
1596 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1599 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1600 mutex_lock(&ep->com.mutex);
1601 switch (ep->com.state) {
1603 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1604 __state_set(&ep->com, DEAD);
1608 printk(KERN_ERR "%s ep %p state %d\n",
1609 __func__, ep, ep->com.state);
1612 mutex_unlock(&ep->com.mutex);
1615 release_ep_resources(ep);
1619 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1621 struct sk_buff *skb;
1622 struct fw_ofld_connection_wr *req;
1623 unsigned int mtu_idx;
1625 struct sockaddr_in *sin;
1627 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1628 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1629 memset(req, 0, sizeof(*req));
1630 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1631 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1632 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1634 sin = (struct sockaddr_in *)&ep->com.local_addr;
1635 req->le.lport = sin->sin_port;
1636 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1637 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1638 req->le.pport = sin->sin_port;
1639 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1640 req->tcb.t_state_to_astid =
1641 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1642 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1643 req->tcb.cplrxdataack_cplpassacceptrpl =
1644 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1645 req->tcb.tx_max = (__force __be32) jiffies;
1646 req->tcb.rcv_adv = htons(1);
1647 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1648 wscale = compute_wscale(rcv_win);
1649 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
1650 (nocong ? NO_CONG(1) : 0) |
1655 L2T_IDX(ep->l2t->idx) |
1656 TX_CHAN(ep->tx_chan) |
1657 SMAC_SEL(ep->smac_idx) |
1659 ULP_MODE(ULP_MODE_TCPDDP) |
1660 RCV_BUFSIZ(rcv_win >> 10));
1661 req->tcb.opt2 = (__force __be32) (PACE(1) |
1662 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1664 CCTRL_ECN(enable_ecn) |
1665 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
1666 if (enable_tcp_timestamps)
1667 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
1668 if (enable_tcp_sack)
1669 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
1670 if (wscale && enable_tcp_window_scaling)
1671 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1672 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1673 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
1674 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1675 set_bit(ACT_OFLD_CONN, &ep->com.history);
1676 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1680 * Return whether a failed active open has allocated a TID
1682 static inline int act_open_has_tid(int status)
1684 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1685 status != CPL_ERR_ARP_MISS;
1688 #define ACT_OPEN_RETRY_COUNT 2
1690 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1691 struct dst_entry *dst, struct c4iw_dev *cdev,
1694 struct neighbour *n;
1696 struct net_device *pdev;
1698 n = dst_neigh_lookup(dst, peer_ip);
1704 if (n->dev->flags & IFF_LOOPBACK) {
1706 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1707 else if (IS_ENABLED(CONFIG_IPV6))
1708 for_each_netdev(&init_net, pdev) {
1709 if (ipv6_chk_addr(&init_net,
1710 (struct in6_addr *)peer_ip,
1721 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1725 ep->mtu = pdev->mtu;
1726 ep->tx_chan = cxgb4_port_chan(pdev);
1727 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1728 step = cdev->rdev.lldi.ntxq /
1729 cdev->rdev.lldi.nchan;
1730 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1731 step = cdev->rdev.lldi.nrxq /
1732 cdev->rdev.lldi.nchan;
1733 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1734 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1735 cxgb4_port_idx(pdev) * step];
1738 pdev = get_real_dev(n->dev);
1739 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1743 ep->mtu = dst_mtu(dst);
1744 ep->tx_chan = cxgb4_port_chan(n->dev);
1745 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1746 step = cdev->rdev.lldi.ntxq /
1747 cdev->rdev.lldi.nchan;
1748 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1749 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1750 step = cdev->rdev.lldi.nrxq /
1751 cdev->rdev.lldi.nchan;
1752 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1753 cxgb4_port_idx(n->dev) * step];
1756 ep->retry_with_mpa_v1 = 0;
1757 ep->tried_with_mpa_v1 = 0;
1769 static int c4iw_reconnect(struct c4iw_ep *ep)
1772 struct sockaddr_in *laddr = (struct sockaddr_in *)
1773 &ep->com.cm_id->local_addr;
1774 struct sockaddr_in *raddr = (struct sockaddr_in *)
1775 &ep->com.cm_id->remote_addr;
1776 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1777 &ep->com.cm_id->local_addr;
1778 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1779 &ep->com.cm_id->remote_addr;
1783 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1784 init_timer(&ep->timer);
1787 * Allocate an active TID to initiate a TCP connection.
1789 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1790 if (ep->atid == -1) {
1791 pr_err("%s - cannot alloc atid.\n", __func__);
1795 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1798 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1799 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1800 raddr->sin_addr.s_addr, laddr->sin_port,
1801 raddr->sin_port, 0);
1803 ra = (__u8 *)&raddr->sin_addr;
1805 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1806 raddr6->sin6_addr.s6_addr,
1807 laddr6->sin6_port, raddr6->sin6_port, 0,
1808 raddr6->sin6_scope_id);
1810 ra = (__u8 *)&raddr6->sin6_addr;
1813 pr_err("%s - cannot find route.\n", __func__);
1814 err = -EHOSTUNREACH;
1817 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1819 pr_err("%s - cannot alloc l2e.\n", __func__);
1823 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1824 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1827 state_set(&ep->com, CONNECTING);
1830 /* send connect request to rnic */
1831 err = send_connect(ep);
1835 cxgb4_l2t_release(ep->l2t);
1837 dst_release(ep->dst);
1839 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1840 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1843 * remember to send notification to upper layer.
1844 * We are in here so the upper layer is not aware that this is
1845 * re-connect attempt and so, upper layer is still waiting for
1846 * response of 1st connect request.
1848 connect_reply_upcall(ep, -ECONNRESET);
1849 c4iw_put_ep(&ep->com);
1854 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1857 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1858 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1859 ntohl(rpl->atid_status)));
1860 struct tid_info *t = dev->rdev.lldi.tids;
1861 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1862 struct sockaddr_in *la;
1863 struct sockaddr_in *ra;
1864 struct sockaddr_in6 *la6;
1865 struct sockaddr_in6 *ra6;
1867 ep = lookup_atid(t, atid);
1868 la = (struct sockaddr_in *)&ep->com.local_addr;
1869 ra = (struct sockaddr_in *)&ep->com.remote_addr;
1870 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
1871 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
1873 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1874 status, status2errno(status));
1876 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1877 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1882 set_bit(ACT_OPEN_RPL, &ep->com.history);
1885 * Log interesting failures.
1888 case CPL_ERR_CONN_RESET:
1889 case CPL_ERR_CONN_TIMEDOUT:
1891 case CPL_ERR_TCAM_FULL:
1892 mutex_lock(&dev->rdev.stats.lock);
1893 dev->rdev.stats.tcam_full++;
1894 mutex_unlock(&dev->rdev.stats.lock);
1895 if (ep->com.local_addr.ss_family == AF_INET &&
1896 dev->rdev.lldi.enable_fw_ofld_conn) {
1897 send_fw_act_open_req(ep,
1898 GET_TID_TID(GET_AOPEN_ATID(
1899 ntohl(rpl->atid_status))));
1903 case CPL_ERR_CONN_EXIST:
1904 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1905 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1906 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1908 cxgb4_free_atid(t, atid);
1909 dst_release(ep->dst);
1910 cxgb4_l2t_release(ep->l2t);
1916 if (ep->com.local_addr.ss_family == AF_INET) {
1917 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1918 atid, status, status2errno(status),
1919 &la->sin_addr.s_addr, ntohs(la->sin_port),
1920 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1922 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1923 atid, status, status2errno(status),
1924 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1925 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1930 connect_reply_upcall(ep, status2errno(status));
1931 state_set(&ep->com, DEAD);
1933 if (status && act_open_has_tid(status))
1934 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1936 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1937 cxgb4_free_atid(t, atid);
1938 dst_release(ep->dst);
1939 cxgb4_l2t_release(ep->l2t);
1940 c4iw_put_ep(&ep->com);
1945 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1947 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1948 struct tid_info *t = dev->rdev.lldi.tids;
1949 unsigned int stid = GET_TID(rpl);
1950 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1953 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1956 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1957 rpl->status, status2errno(rpl->status));
1958 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1964 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1966 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1967 struct tid_info *t = dev->rdev.lldi.tids;
1968 unsigned int stid = GET_TID(rpl);
1969 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1971 PDBG("%s ep %p\n", __func__, ep);
1972 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1976 static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
1977 struct cpl_pass_accept_req *req)
1979 struct cpl_pass_accept_rpl *rpl;
1980 unsigned int mtu_idx;
1985 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1986 BUG_ON(skb_cloned(skb));
1987 skb_trim(skb, sizeof(*rpl));
1989 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1990 wscale = compute_wscale(rcv_win);
1991 opt0 = (nocong ? NO_CONG(1) : 0) |
1996 L2T_IDX(ep->l2t->idx) |
1997 TX_CHAN(ep->tx_chan) |
1998 SMAC_SEL(ep->smac_idx) |
1999 DSCP(ep->tos >> 2) |
2000 ULP_MODE(ULP_MODE_TCPDDP) |
2001 RCV_BUFSIZ(rcv_win>>10);
2002 opt2 = RX_CHANNEL(0) |
2003 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2005 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2006 opt2 |= TSTAMPS_EN(1);
2007 if (enable_tcp_sack && req->tcpopt.sack)
2009 if (wscale && enable_tcp_window_scaling)
2010 opt2 |= WND_SCALE_EN(1);
2012 const struct tcphdr *tcph;
2013 u32 hlen = ntohl(req->hdr_len);
2015 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2017 if (tcph->ece && tcph->cwr)
2018 opt2 |= CCTRL_ECN(1);
2022 INIT_TP_WR(rpl, ep->hwtid);
2023 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2025 rpl->opt0 = cpu_to_be64(opt0);
2026 rpl->opt2 = cpu_to_be32(opt2);
2027 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2028 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2033 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2035 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
2036 BUG_ON(skb_cloned(skb));
2037 skb_trim(skb, sizeof(struct cpl_tid_release));
2039 release_tid(&dev->rdev, hwtid, skb);
2043 static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2044 __u8 *local_ip, __u8 *peer_ip,
2045 __be16 *local_port, __be16 *peer_port)
2047 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2048 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2049 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
2050 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
2051 struct tcphdr *tcp = (struct tcphdr *)
2052 ((u8 *)(req + 1) + eth_len + ip_len);
2054 if (ip->version == 4) {
2055 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2056 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2059 memcpy(peer_ip, &ip->saddr, 4);
2060 memcpy(local_ip, &ip->daddr, 4);
2062 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2063 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2066 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2067 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2069 *peer_port = tcp->source;
2070 *local_port = tcp->dest;
2075 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2077 struct c4iw_ep *child_ep = NULL, *parent_ep;
2078 struct cpl_pass_accept_req *req = cplhdr(skb);
2079 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2080 struct tid_info *t = dev->rdev.lldi.tids;
2081 unsigned int hwtid = GET_TID(req);
2082 struct dst_entry *dst;
2083 __u8 local_ip[16], peer_ip[16];
2084 __be16 local_port, peer_port;
2086 u16 peer_mss = ntohs(req->tcpopt.mss);
2089 parent_ep = lookup_stid(t, stid);
2091 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2095 if (state_read(&parent_ep->com) != LISTEN) {
2096 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2101 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2103 /* Find output route */
2105 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2106 , __func__, parent_ep, hwtid,
2107 local_ip, peer_ip, ntohs(local_port),
2108 ntohs(peer_port), peer_mss);
2109 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2110 local_port, peer_port,
2111 GET_POPEN_TOS(ntohl(req->tos_stid)));
2113 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2114 , __func__, parent_ep, hwtid,
2115 local_ip, peer_ip, ntohs(local_port),
2116 ntohs(peer_port), peer_mss);
2117 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2118 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2119 ((struct sockaddr_in6 *)
2120 &parent_ep->com.local_addr)->sin6_scope_id);
2123 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2128 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2130 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2136 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
2138 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2145 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2146 child_ep->mtu = peer_mss + 40;
2148 state_set(&child_ep->com, CONNECTING);
2149 child_ep->com.dev = dev;
2150 child_ep->com.cm_id = NULL;
2152 struct sockaddr_in *sin = (struct sockaddr_in *)
2153 &child_ep->com.local_addr;
2154 sin->sin_family = PF_INET;
2155 sin->sin_port = local_port;
2156 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2157 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2158 sin->sin_family = PF_INET;
2159 sin->sin_port = peer_port;
2160 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2162 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2163 &child_ep->com.local_addr;
2164 sin6->sin6_family = PF_INET6;
2165 sin6->sin6_port = local_port;
2166 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2167 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2168 sin6->sin6_family = PF_INET6;
2169 sin6->sin6_port = peer_port;
2170 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2172 c4iw_get_ep(&parent_ep->com);
2173 child_ep->parent_ep = parent_ep;
2174 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
2175 child_ep->dst = dst;
2176 child_ep->hwtid = hwtid;
2178 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2179 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2181 init_timer(&child_ep->timer);
2182 cxgb4_insert_tid(t, child_ep, hwtid);
2183 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2184 accept_cr(child_ep, skb, req);
2185 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2188 reject_cr(dev, hwtid, skb);
2193 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2196 struct cpl_pass_establish *req = cplhdr(skb);
2197 struct tid_info *t = dev->rdev.lldi.tids;
2198 unsigned int tid = GET_TID(req);
2200 ep = lookup_tid(t, tid);
2201 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2202 ep->snd_seq = be32_to_cpu(req->snd_isn);
2203 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2205 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2206 ntohs(req->tcp_opt));
2208 set_emss(ep, ntohs(req->tcp_opt));
2210 dst_confirm(ep->dst);
2211 state_set(&ep->com, MPA_REQ_WAIT);
2213 send_flowc(ep, skb);
2214 set_bit(PASS_ESTAB, &ep->com.history);
2219 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2221 struct cpl_peer_close *hdr = cplhdr(skb);
2223 struct c4iw_qp_attributes attrs;
2226 struct tid_info *t = dev->rdev.lldi.tids;
2227 unsigned int tid = GET_TID(hdr);
2230 ep = lookup_tid(t, tid);
2231 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2232 dst_confirm(ep->dst);
2234 set_bit(PEER_CLOSE, &ep->com.history);
2235 mutex_lock(&ep->com.mutex);
2236 switch (ep->com.state) {
2238 __state_set(&ep->com, CLOSING);
2241 __state_set(&ep->com, CLOSING);
2242 connect_reply_upcall(ep, -ECONNRESET);
2247 * We're gonna mark this puppy DEAD, but keep
2248 * the reference on it until the ULP accepts or
2249 * rejects the CR. Also wake up anyone waiting
2250 * in rdma connection migration (see c4iw_accept_cr()).
2252 __state_set(&ep->com, CLOSING);
2253 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2254 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2257 __state_set(&ep->com, CLOSING);
2258 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2259 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2263 __state_set(&ep->com, CLOSING);
2264 attrs.next_state = C4IW_QP_STATE_CLOSING;
2265 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2266 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2267 if (ret != -ECONNRESET) {
2268 peer_close_upcall(ep);
2276 __state_set(&ep->com, MORIBUND);
2281 if (ep->com.cm_id && ep->com.qp) {
2282 attrs.next_state = C4IW_QP_STATE_IDLE;
2283 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2284 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2286 close_complete_upcall(ep);
2287 __state_set(&ep->com, DEAD);
2297 mutex_unlock(&ep->com.mutex);
2299 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2301 release_ep_resources(ep);
2306 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2308 static int is_neg_adv_abort(unsigned int status)
2310 return status == CPL_ERR_RTX_NEG_ADVICE ||
2311 status == CPL_ERR_PERSIST_NEG_ADVICE;
2314 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2316 struct cpl_abort_req_rss *req = cplhdr(skb);
2318 struct cpl_abort_rpl *rpl;
2319 struct sk_buff *rpl_skb;
2320 struct c4iw_qp_attributes attrs;
2323 struct tid_info *t = dev->rdev.lldi.tids;
2324 unsigned int tid = GET_TID(req);
2326 ep = lookup_tid(t, tid);
2327 if (is_neg_adv_abort(req->status)) {
2328 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2332 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2334 set_bit(PEER_ABORT, &ep->com.history);
2337 * Wake up any threads in rdma_init() or rdma_fini().
2338 * However, this is not needed if com state is just
2341 if (ep->com.state != MPA_REQ_SENT)
2342 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2344 mutex_lock(&ep->com.mutex);
2345 switch (ep->com.state) {
2353 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2354 connect_reply_upcall(ep, -ECONNRESET);
2357 * we just don't send notification upwards because we
2358 * want to retry with mpa_v1 without upper layers even
2361 * do some housekeeping so as to re-initiate the
2364 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2366 ep->retry_with_mpa_v1 = 1;
2378 if (ep->com.cm_id && ep->com.qp) {
2379 attrs.next_state = C4IW_QP_STATE_ERROR;
2380 ret = c4iw_modify_qp(ep->com.qp->rhp,
2381 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2385 "%s - qp <- error failed!\n",
2388 peer_abort_upcall(ep);
2393 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2394 mutex_unlock(&ep->com.mutex);
2400 dst_confirm(ep->dst);
2401 if (ep->com.state != ABORTING) {
2402 __state_set(&ep->com, DEAD);
2403 /* we don't release if we want to retry with mpa_v1 */
2404 if (!ep->retry_with_mpa_v1)
2407 mutex_unlock(&ep->com.mutex);
2409 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2411 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2416 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2417 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2418 INIT_TP_WR(rpl, ep->hwtid);
2419 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2420 rpl->cmd = CPL_ABORT_NO_RST;
2421 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2424 release_ep_resources(ep);
2425 else if (ep->retry_with_mpa_v1) {
2426 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2427 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2428 dst_release(ep->dst);
2429 cxgb4_l2t_release(ep->l2t);
2436 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2439 struct c4iw_qp_attributes attrs;
2440 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2442 struct tid_info *t = dev->rdev.lldi.tids;
2443 unsigned int tid = GET_TID(rpl);
2445 ep = lookup_tid(t, tid);
2447 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2450 /* The cm_id may be null if we failed to connect */
2451 mutex_lock(&ep->com.mutex);
2452 switch (ep->com.state) {
2454 __state_set(&ep->com, MORIBUND);
2458 if ((ep->com.cm_id) && (ep->com.qp)) {
2459 attrs.next_state = C4IW_QP_STATE_IDLE;
2460 c4iw_modify_qp(ep->com.qp->rhp,
2462 C4IW_QP_ATTR_NEXT_STATE,
2465 close_complete_upcall(ep);
2466 __state_set(&ep->com, DEAD);
2476 mutex_unlock(&ep->com.mutex);
2478 release_ep_resources(ep);
2482 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2484 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2485 struct tid_info *t = dev->rdev.lldi.tids;
2486 unsigned int tid = GET_TID(rpl);
2488 struct c4iw_qp_attributes attrs;
2490 ep = lookup_tid(t, tid);
2493 if (ep && ep->com.qp) {
2494 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2495 ep->com.qp->wq.sq.qid);
2496 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2497 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2498 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2500 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2506 * Upcall from the adapter indicating data has been transmitted.
2507 * For us its just the single MPA request or reply. We can now free
2508 * the skb holding the mpa message.
2510 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2513 struct cpl_fw4_ack *hdr = cplhdr(skb);
2514 u8 credits = hdr->credits;
2515 unsigned int tid = GET_TID(hdr);
2516 struct tid_info *t = dev->rdev.lldi.tids;
2519 ep = lookup_tid(t, tid);
2520 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2522 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2523 __func__, ep, ep->hwtid, state_read(&ep->com));
2527 dst_confirm(ep->dst);
2529 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2530 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2531 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2532 kfree_skb(ep->mpa_skb);
2538 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2541 struct c4iw_ep *ep = to_ep(cm_id);
2542 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2544 if (state_read(&ep->com) == DEAD) {
2545 c4iw_put_ep(&ep->com);
2548 set_bit(ULP_REJECT, &ep->com.history);
2549 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2551 abort_connection(ep, NULL, GFP_KERNEL);
2553 err = send_mpa_reject(ep, pdata, pdata_len);
2554 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2556 c4iw_put_ep(&ep->com);
2560 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2563 struct c4iw_qp_attributes attrs;
2564 enum c4iw_qp_attr_mask mask;
2565 struct c4iw_ep *ep = to_ep(cm_id);
2566 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2567 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2569 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2570 if (state_read(&ep->com) == DEAD) {
2575 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2578 set_bit(ULP_ACCEPT, &ep->com.history);
2579 if ((conn_param->ord > c4iw_max_read_depth) ||
2580 (conn_param->ird > c4iw_max_read_depth)) {
2581 abort_connection(ep, NULL, GFP_KERNEL);
2586 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2587 if (conn_param->ord > ep->ird) {
2588 ep->ird = conn_param->ird;
2589 ep->ord = conn_param->ord;
2590 send_mpa_reject(ep, conn_param->private_data,
2591 conn_param->private_data_len);
2592 abort_connection(ep, NULL, GFP_KERNEL);
2596 if (conn_param->ird > ep->ord) {
2598 conn_param->ird = 1;
2600 abort_connection(ep, NULL, GFP_KERNEL);
2607 ep->ird = conn_param->ird;
2608 ep->ord = conn_param->ord;
2610 if (ep->mpa_attr.version != 2)
2611 if (peer2peer && ep->ird == 0)
2614 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2616 cm_id->add_ref(cm_id);
2617 ep->com.cm_id = cm_id;
2621 /* bind QP to EP and move to RTS */
2622 attrs.mpa_attr = ep->mpa_attr;
2623 attrs.max_ird = ep->ird;
2624 attrs.max_ord = ep->ord;
2625 attrs.llp_stream_handle = ep;
2626 attrs.next_state = C4IW_QP_STATE_RTS;
2628 /* bind QP and TID with INIT_WR */
2629 mask = C4IW_QP_ATTR_NEXT_STATE |
2630 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2631 C4IW_QP_ATTR_MPA_ATTR |
2632 C4IW_QP_ATTR_MAX_IRD |
2633 C4IW_QP_ATTR_MAX_ORD;
2635 err = c4iw_modify_qp(ep->com.qp->rhp,
2636 ep->com.qp, mask, &attrs, 1);
2639 err = send_mpa_reply(ep, conn_param->private_data,
2640 conn_param->private_data_len);
2644 state_set(&ep->com, FPDU_MODE);
2645 established_upcall(ep);
2646 c4iw_put_ep(&ep->com);
2649 ep->com.cm_id = NULL;
2650 cm_id->rem_ref(cm_id);
2652 c4iw_put_ep(&ep->com);
2656 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2658 struct in_device *ind;
2660 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2661 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2663 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2665 return -EADDRNOTAVAIL;
2666 for_primary_ifa(ind) {
2667 laddr->sin_addr.s_addr = ifa->ifa_address;
2668 raddr->sin_addr.s_addr = ifa->ifa_address;
2674 return found ? 0 : -EADDRNOTAVAIL;
2677 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2678 unsigned char banned_flags)
2680 struct inet6_dev *idev;
2681 int err = -EADDRNOTAVAIL;
2684 idev = __in6_dev_get(dev);
2686 struct inet6_ifaddr *ifp;
2688 read_lock_bh(&idev->lock);
2689 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2690 if (ifp->scope == IFA_LINK &&
2691 !(ifp->flags & banned_flags)) {
2692 memcpy(addr, &ifp->addr, 16);
2697 read_unlock_bh(&idev->lock);
2703 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2705 struct in6_addr uninitialized_var(addr);
2706 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2707 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2709 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2710 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2711 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2714 return -EADDRNOTAVAIL;
2717 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2719 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2722 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2723 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2724 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2725 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2726 &cm_id->remote_addr;
2730 if ((conn_param->ord > c4iw_max_read_depth) ||
2731 (conn_param->ird > c4iw_max_read_depth)) {
2735 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2737 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2741 init_timer(&ep->timer);
2742 ep->plen = conn_param->private_data_len;
2744 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2745 conn_param->private_data, ep->plen);
2746 ep->ird = conn_param->ird;
2747 ep->ord = conn_param->ord;
2749 if (peer2peer && ep->ord == 0)
2752 cm_id->add_ref(cm_id);
2754 ep->com.cm_id = cm_id;
2755 ep->com.qp = get_qhp(dev, conn_param->qpn);
2757 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2762 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2766 * Allocate an active TID to initiate a TCP connection.
2768 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2769 if (ep->atid == -1) {
2770 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2774 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2776 if (cm_id->remote_addr.ss_family == AF_INET) {
2778 ra = (__u8 *)&raddr->sin_addr;
2781 * Handle loopback requests to INADDR_ANY.
2783 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2784 err = pick_local_ipaddrs(dev, cm_id);
2790 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2791 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2792 ra, ntohs(raddr->sin_port));
2793 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2794 raddr->sin_addr.s_addr, laddr->sin_port,
2795 raddr->sin_port, 0);
2798 ra = (__u8 *)&raddr6->sin6_addr;
2801 * Handle loopback requests to INADDR_ANY.
2803 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2804 err = pick_local_ip6addrs(dev, cm_id);
2810 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2811 __func__, laddr6->sin6_addr.s6_addr,
2812 ntohs(laddr6->sin6_port),
2813 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2814 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2815 raddr6->sin6_addr.s6_addr,
2816 laddr6->sin6_port, raddr6->sin6_port, 0,
2817 raddr6->sin6_scope_id);
2820 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2821 err = -EHOSTUNREACH;
2825 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
2827 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2831 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2832 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2835 state_set(&ep->com, CONNECTING);
2837 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2838 sizeof(ep->com.local_addr));
2839 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2840 sizeof(ep->com.remote_addr));
2842 /* send connect request to rnic */
2843 err = send_connect(ep);
2847 cxgb4_l2t_release(ep->l2t);
2849 dst_release(ep->dst);
2851 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2852 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2854 cm_id->rem_ref(cm_id);
2855 c4iw_put_ep(&ep->com);
2860 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2863 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2865 c4iw_init_wr_wait(&ep->com.wr_wait);
2866 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2867 ep->stid, &sin6->sin6_addr,
2869 ep->com.dev->rdev.lldi.rxq_ids[0]);
2871 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2875 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2877 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2881 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2884 struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
2886 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2888 err = cxgb4_create_server_filter(
2889 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2890 sin->sin_addr.s_addr, sin->sin_port, 0,
2891 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2892 if (err == -EBUSY) {
2893 set_current_state(TASK_UNINTERRUPTIBLE);
2894 schedule_timeout(usecs_to_jiffies(100));
2896 } while (err == -EBUSY);
2898 c4iw_init_wr_wait(&ep->com.wr_wait);
2899 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2900 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2901 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2903 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2908 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
2910 &sin->sin_addr, ntohs(sin->sin_port));
2914 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2917 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2918 struct c4iw_listen_ep *ep;
2922 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2924 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2928 PDBG("%s ep %p\n", __func__, ep);
2929 cm_id->add_ref(cm_id);
2930 ep->com.cm_id = cm_id;
2932 ep->backlog = backlog;
2933 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2934 sizeof(ep->com.local_addr));
2937 * Allocate a server TID.
2939 if (dev->rdev.lldi.enable_fw_ofld_conn)
2940 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
2941 cm_id->local_addr.ss_family, ep);
2943 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
2944 cm_id->local_addr.ss_family, ep);
2946 if (ep->stid == -1) {
2947 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
2951 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
2952 state_set(&ep->com, LISTEN);
2953 if (ep->com.local_addr.ss_family == AF_INET)
2954 err = create_server4(dev, ep);
2956 err = create_server6(dev, ep);
2958 cm_id->provider_data = ep;
2961 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2962 ep->com.local_addr.ss_family);
2964 cm_id->rem_ref(cm_id);
2965 c4iw_put_ep(&ep->com);
2971 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2974 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2976 PDBG("%s ep %p\n", __func__, ep);
2979 state_set(&ep->com, DEAD);
2980 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
2981 ep->com.local_addr.ss_family == AF_INET) {
2982 err = cxgb4_remove_server_filter(
2983 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2984 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2986 c4iw_init_wr_wait(&ep->com.wr_wait);
2987 err = cxgb4_remove_server(
2988 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2989 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2992 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2995 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
2996 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2997 ep->com.local_addr.ss_family);
2999 cm_id->rem_ref(cm_id);
3000 c4iw_put_ep(&ep->com);
3004 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3009 struct c4iw_rdev *rdev;
3011 mutex_lock(&ep->com.mutex);
3013 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3014 states[ep->com.state], abrupt);
3016 rdev = &ep->com.dev->rdev;
3017 if (c4iw_fatal_error(rdev)) {
3019 close_complete_upcall(ep);
3020 ep->com.state = DEAD;
3022 switch (ep->com.state) {
3030 ep->com.state = ABORTING;
3032 ep->com.state = CLOSING;
3035 set_bit(CLOSE_SENT, &ep->com.flags);
3038 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3042 ep->com.state = ABORTING;
3044 ep->com.state = MORIBUND;
3050 PDBG("%s ignoring disconnect ep %p state %u\n",
3051 __func__, ep, ep->com.state);
3060 set_bit(EP_DISC_ABORT, &ep->com.history);
3061 close_complete_upcall(ep);
3062 ret = send_abort(ep, NULL, gfp);
3064 set_bit(EP_DISC_CLOSE, &ep->com.history);
3065 ret = send_halfclose(ep, gfp);
3070 mutex_unlock(&ep->com.mutex);
3072 release_ep_resources(ep);
3076 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3077 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3080 int atid = be32_to_cpu(req->tid);
3082 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3083 (__force u32) req->tid);
3087 switch (req->retval) {
3089 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3090 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3091 send_fw_act_open_req(ep, atid);
3095 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3096 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3097 send_fw_act_open_req(ep, atid);
3102 pr_info("%s unexpected ofld conn wr retval %d\n",
3103 __func__, req->retval);
3106 pr_err("active ofld_connect_wr failure %d atid %d\n",
3108 mutex_lock(&dev->rdev.stats.lock);
3109 dev->rdev.stats.act_ofld_conn_fails++;
3110 mutex_unlock(&dev->rdev.stats.lock);
3111 connect_reply_upcall(ep, status2errno(req->retval));
3112 state_set(&ep->com, DEAD);
3113 remove_handle(dev, &dev->atid_idr, atid);
3114 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3115 dst_release(ep->dst);
3116 cxgb4_l2t_release(ep->l2t);
3117 c4iw_put_ep(&ep->com);
3120 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3121 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3123 struct sk_buff *rpl_skb;
3124 struct cpl_pass_accept_req *cpl;
3127 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3130 PDBG("%s passive open failure %d\n", __func__, req->retval);
3131 mutex_lock(&dev->rdev.stats.lock);
3132 dev->rdev.stats.pas_ofld_conn_fails++;
3133 mutex_unlock(&dev->rdev.stats.lock);
3136 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3137 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3138 (__force u32) htonl(
3139 (__force u32) req->tid)));
3140 ret = pass_accept_req(dev, rpl_skb);
3147 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3149 struct cpl_fw6_msg *rpl = cplhdr(skb);
3150 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3152 switch (rpl->type) {
3154 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3156 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3157 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3158 switch (req->t_state) {
3160 active_ofld_conn_reply(dev, skb, req);
3163 passive_ofld_conn_reply(dev, skb, req);
3166 pr_err("%s unexpected ofld conn wr state %d\n",
3167 __func__, req->t_state);
3175 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3178 u16 vlantag, len, hdr_len, eth_hdr_len;
3180 struct cpl_rx_pkt *cpl = cplhdr(skb);
3181 struct cpl_pass_accept_req *req;
3182 struct tcp_options_received tmp_opt;
3183 struct c4iw_dev *dev;
3185 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3186 /* Store values from cpl_rx_pkt in temporary location. */
3187 vlantag = (__force u16) cpl->vlan;
3188 len = (__force u16) cpl->len;
3189 l2info = (__force u32) cpl->l2info;
3190 hdr_len = (__force u16) cpl->hdr_len;
3193 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3196 * We need to parse the TCP options from SYN packet.
3197 * to generate cpl_pass_accept_req.
3199 memset(&tmp_opt, 0, sizeof(tmp_opt));
3200 tcp_clear_options(&tmp_opt);
3201 tcp_parse_options(skb, &tmp_opt, 0, NULL);
3203 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3204 memset(req, 0, sizeof(*req));
3205 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
3206 V_SYN_MAC_IDX(G_RX_MACIDX(
3207 (__force int) htonl(l2info))) |
3209 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3210 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3211 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
3212 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3213 (__force int) htonl(l2info))) |
3214 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3215 (__force int) htons(hdr_len))) |
3216 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3217 (__force int) htons(hdr_len))) |
3218 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
3219 req->vlan = (__force __be16) vlantag;
3220 req->len = (__force __be16) len;
3221 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3222 PASS_OPEN_TOS(tos));
3223 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3224 if (tmp_opt.wscale_ok)
3225 req->tcpopt.wsf = tmp_opt.snd_wscale;
3226 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3227 if (tmp_opt.sack_ok)
3228 req->tcpopt.sack = 1;
3229 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3233 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3234 __be32 laddr, __be16 lport,
3235 __be32 raddr, __be16 rport,
3236 u32 rcv_isn, u32 filter, u16 window,
3237 u32 rss_qid, u8 port_id)
3239 struct sk_buff *req_skb;
3240 struct fw_ofld_connection_wr *req;
3241 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3243 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3244 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3245 memset(req, 0, sizeof(*req));
3246 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3247 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3248 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
3249 req->le.filter = (__force __be32) filter;
3250 req->le.lport = lport;
3251 req->le.pport = rport;
3252 req->le.u.ipv4.lip = laddr;
3253 req->le.u.ipv4.pip = raddr;
3254 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3255 req->tcb.rcv_adv = htons(window);
3256 req->tcb.t_state_to_astid =
3257 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3258 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3259 V_FW_OFLD_CONNECTION_WR_ASTID(
3260 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3263 * We store the qid in opt2 which will be used by the firmware
3264 * to send us the wr response.
3266 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3269 * We initialize the MSS index in TCB to 0xF.
3270 * So that when driver sends cpl_pass_accept_rpl
3271 * TCB picks up the correct value. If this was 0
3272 * TP will ignore any value > 0 for MSS index.
3274 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
3275 req->cookie = (unsigned long)skb;
3277 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3278 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3282 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3283 * messages when a filter is being used instead of server to
3284 * redirect a syn packet. When packets hit filter they are redirected
3285 * to the offload queue and driver tries to establish the connection
3286 * using firmware work request.
3288 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3291 unsigned int filter;
3292 struct ethhdr *eh = NULL;
3293 struct vlan_ethhdr *vlan_eh = NULL;
3295 struct tcphdr *tcph;
3296 struct rss_header *rss = (void *)skb->data;
3297 struct cpl_rx_pkt *cpl = (void *)skb->data;
3298 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3299 struct l2t_entry *e;
3300 struct dst_entry *dst;
3301 struct c4iw_ep *lep;
3303 struct port_info *pi;
3304 struct net_device *pdev;
3305 u16 rss_qid, eth_hdr_len;
3308 struct neighbour *neigh;
3310 /* Drop all non-SYN packets */
3311 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3315 * Drop all packets which did not hit the filter.
3316 * Unlikely to happen.
3318 if (!(rss->filter_hit && rss->filter_tid))
3322 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3324 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
3325 - dev->rdev.lldi.tids->sftid_base
3326 + dev->rdev.lldi.tids->nstids;
3328 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3330 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3334 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3335 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3336 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3337 if (eth_hdr_len == ETH_HLEN) {
3338 eh = (struct ethhdr *)(req + 1);
3339 iph = (struct iphdr *)(eh + 1);
3341 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3342 iph = (struct iphdr *)(vlan_eh + 1);
3343 skb->vlan_tci = ntohs(cpl->vlan);
3346 if (iph->version != 0x4)
3349 tcph = (struct tcphdr *)(iph + 1);
3350 skb_set_network_header(skb, (void *)iph - (void *)rss);
3351 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3354 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3355 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3356 ntohs(tcph->source), iph->tos);
3358 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3361 pr_err("%s - failed to find dst entry!\n",
3365 neigh = dst_neigh_lookup_skb(dst, skb);
3368 pr_err("%s - failed to allocate neigh!\n",
3373 if (neigh->dev->flags & IFF_LOOPBACK) {
3374 pdev = ip_dev_find(&init_net, iph->daddr);
3375 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3377 pi = (struct port_info *)netdev_priv(pdev);
3378 tx_chan = cxgb4_port_chan(pdev);
3381 pdev = get_real_dev(neigh->dev);
3382 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3384 pi = (struct port_info *)netdev_priv(pdev);
3385 tx_chan = cxgb4_port_chan(pdev);
3388 pr_err("%s - failed to allocate l2t entry!\n",
3393 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3394 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3395 window = (__force u16) htons((__force u16)tcph->window);
3397 /* Calcuate filter portion for LE region. */
3398 filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
3401 * Synthesize the cpl_pass_accept_req. We have everything except the
3402 * TID. Once firmware sends a reply with TID we update the TID field
3403 * in cpl and pass it through the regular cpl_pass_accept_req path.
3405 build_cpl_pass_accept_req(skb, stid, iph->tos);
3406 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3407 tcph->source, ntohl(tcph->seq), filter, window,
3408 rss_qid, pi->port_id);
3409 cxgb4_l2t_release(e);
3417 * These are the real handlers that are called from a
3420 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3421 [CPL_ACT_ESTABLISH] = act_establish,
3422 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3423 [CPL_RX_DATA] = rx_data,
3424 [CPL_ABORT_RPL_RSS] = abort_rpl,
3425 [CPL_ABORT_RPL] = abort_rpl,
3426 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3427 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3428 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3429 [CPL_PASS_ESTABLISH] = pass_establish,
3430 [CPL_PEER_CLOSE] = peer_close,
3431 [CPL_ABORT_REQ_RSS] = peer_abort,
3432 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3433 [CPL_RDMA_TERMINATE] = terminate,
3434 [CPL_FW4_ACK] = fw4_ack,
3435 [CPL_FW6_MSG] = deferred_fw6_msg,
3436 [CPL_RX_PKT] = rx_pkt
3439 static void process_timeout(struct c4iw_ep *ep)
3441 struct c4iw_qp_attributes attrs;
3444 mutex_lock(&ep->com.mutex);
3445 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3447 set_bit(TIMEDOUT, &ep->com.history);
3448 switch (ep->com.state) {
3450 __state_set(&ep->com, ABORTING);
3451 connect_reply_upcall(ep, -ETIMEDOUT);
3454 __state_set(&ep->com, ABORTING);
3458 if (ep->com.cm_id && ep->com.qp) {
3459 attrs.next_state = C4IW_QP_STATE_ERROR;
3460 c4iw_modify_qp(ep->com.qp->rhp,
3461 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3464 __state_set(&ep->com, ABORTING);
3467 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3468 __func__, ep, ep->hwtid, ep->com.state);
3471 mutex_unlock(&ep->com.mutex);
3473 abort_connection(ep, NULL, GFP_KERNEL);
3474 c4iw_put_ep(&ep->com);
3477 static void process_timedout_eps(void)
3481 spin_lock_irq(&timeout_lock);
3482 while (!list_empty(&timeout_list)) {
3483 struct list_head *tmp;
3485 tmp = timeout_list.next;
3487 spin_unlock_irq(&timeout_lock);
3488 ep = list_entry(tmp, struct c4iw_ep, entry);
3489 process_timeout(ep);
3490 spin_lock_irq(&timeout_lock);
3492 spin_unlock_irq(&timeout_lock);
3495 static void process_work(struct work_struct *work)
3497 struct sk_buff *skb = NULL;
3498 struct c4iw_dev *dev;
3499 struct cpl_act_establish *rpl;
3500 unsigned int opcode;
3503 while ((skb = skb_dequeue(&rxq))) {
3505 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3506 opcode = rpl->ot.opcode;
3508 BUG_ON(!work_handlers[opcode]);
3509 ret = work_handlers[opcode](dev, skb);
3513 process_timedout_eps();
3516 static DECLARE_WORK(skb_work, process_work);
3518 static void ep_timeout(unsigned long arg)
3520 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3523 spin_lock(&timeout_lock);
3524 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3525 list_add_tail(&ep->entry, &timeout_list);
3528 spin_unlock(&timeout_lock);
3530 queue_work(workq, &skb_work);
3534 * All the CM events are handled on a work queue to have a safe context.
3536 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3540 * Save dev in the skb->cb area.
3542 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3545 * Queue the skb and schedule the worker thread.
3547 skb_queue_tail(&rxq, skb);
3548 queue_work(workq, &skb_work);
3552 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3554 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3556 if (rpl->status != CPL_ERR_NONE) {
3557 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3558 "for tid %u\n", rpl->status, GET_TID(rpl));
3564 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3566 struct cpl_fw6_msg *rpl = cplhdr(skb);
3567 struct c4iw_wr_wait *wr_waitp;
3570 PDBG("%s type %u\n", __func__, rpl->type);
3572 switch (rpl->type) {
3573 case FW6_TYPE_WR_RPL:
3574 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
3575 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
3576 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
3578 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3582 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3586 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3594 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3596 struct cpl_abort_req_rss *req = cplhdr(skb);
3598 struct tid_info *t = dev->rdev.lldi.tids;
3599 unsigned int tid = GET_TID(req);
3601 ep = lookup_tid(t, tid);
3603 printk(KERN_WARNING MOD
3604 "Abort on non-existent endpoint, tid %d\n", tid);
3608 if (is_neg_adv_abort(req->status)) {
3609 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3614 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3618 * Wake up any threads in rdma_init() or rdma_fini().
3619 * However, if we are on MPAv2 and want to retry with MPAv1
3620 * then, don't wake up yet.
3622 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3623 if (ep->com.state != MPA_REQ_SENT)
3624 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3626 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3632 * Most upcalls from the T4 Core go to sched() to
3633 * schedule the processing on a work queue.
3635 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3636 [CPL_ACT_ESTABLISH] = sched,
3637 [CPL_ACT_OPEN_RPL] = sched,
3638 [CPL_RX_DATA] = sched,
3639 [CPL_ABORT_RPL_RSS] = sched,
3640 [CPL_ABORT_RPL] = sched,
3641 [CPL_PASS_OPEN_RPL] = sched,
3642 [CPL_CLOSE_LISTSRV_RPL] = sched,
3643 [CPL_PASS_ACCEPT_REQ] = sched,
3644 [CPL_PASS_ESTABLISH] = sched,
3645 [CPL_PEER_CLOSE] = sched,
3646 [CPL_CLOSE_CON_RPL] = sched,
3647 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
3648 [CPL_RDMA_TERMINATE] = sched,
3649 [CPL_FW4_ACK] = sched,
3650 [CPL_SET_TCB_RPL] = set_tcb_rpl,
3651 [CPL_FW6_MSG] = fw6_msg,
3652 [CPL_RX_PKT] = sched
3655 int __init c4iw_cm_init(void)
3657 spin_lock_init(&timeout_lock);
3658 skb_queue_head_init(&rxq);
3660 workq = create_singlethread_workqueue("iw_cxgb4");
3667 void __exit c4iw_cm_term(void)
3669 WARN_ON(!list_empty(&timeout_list));
3670 flush_workqueue(workq);
3671 destroy_workqueue(workq);