2 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
50 #include <rdma/ib_addr.h>
54 static char *states[] = {
71 module_param(nocong, int, 0644);
72 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74 static int enable_ecn;
75 module_param(enable_ecn, int, 0644);
76 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78 static int dack_mode = 1;
79 module_param(dack_mode, int, 0644);
80 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
82 int c4iw_max_read_depth = 8;
83 module_param(c4iw_max_read_depth, int, 0644);
84 MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
86 static int enable_tcp_timestamps;
87 module_param(enable_tcp_timestamps, int, 0644);
88 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
90 static int enable_tcp_sack;
91 module_param(enable_tcp_sack, int, 0644);
92 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
94 static int enable_tcp_window_scaling = 1;
95 module_param(enable_tcp_window_scaling, int, 0644);
96 MODULE_PARM_DESC(enable_tcp_window_scaling,
97 "Enable tcp window scaling (default=1)");
100 module_param(c4iw_debug, int, 0644);
101 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
103 static int peer2peer = 1;
104 module_param(peer2peer, int, 0644);
105 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
107 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
108 module_param(p2p_type, int, 0644);
109 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
110 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
112 static int ep_timeout_secs = 60;
113 module_param(ep_timeout_secs, int, 0644);
114 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
115 "in seconds (default=60)");
117 static int mpa_rev = 1;
118 module_param(mpa_rev, int, 0644);
119 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
120 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
121 " compliant (default=1)");
123 static int markers_enabled;
124 module_param(markers_enabled, int, 0644);
125 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
127 static int crc_enabled = 1;
128 module_param(crc_enabled, int, 0644);
129 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
131 static int rcv_win = 256 * 1024;
132 module_param(rcv_win, int, 0644);
133 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
135 static int snd_win = 128 * 1024;
136 module_param(snd_win, int, 0644);
137 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
139 static struct workqueue_struct *workq;
141 static struct sk_buff_head rxq;
143 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
144 static void ep_timeout(unsigned long arg);
145 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
147 static LIST_HEAD(timeout_list);
148 static spinlock_t timeout_lock;
150 static void deref_qp(struct c4iw_ep *ep)
152 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
153 clear_bit(QP_REFERENCED, &ep->com.flags);
156 static void ref_qp(struct c4iw_ep *ep)
158 set_bit(QP_REFERENCED, &ep->com.flags);
159 c4iw_qp_add_ref(&ep->com.qp->ibqp);
162 static void start_ep_timer(struct c4iw_ep *ep)
164 PDBG("%s ep %p\n", __func__, ep);
165 if (timer_pending(&ep->timer)) {
166 pr_err("%s timer already started! ep %p\n",
170 clear_bit(TIMEOUT, &ep->com.flags);
171 c4iw_get_ep(&ep->com);
172 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
173 ep->timer.data = (unsigned long)ep;
174 ep->timer.function = ep_timeout;
175 add_timer(&ep->timer);
178 static int stop_ep_timer(struct c4iw_ep *ep)
180 PDBG("%s ep %p stopping\n", __func__, ep);
181 del_timer_sync(&ep->timer);
182 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
183 c4iw_put_ep(&ep->com);
189 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
190 struct l2t_entry *l2e)
194 if (c4iw_fatal_error(rdev)) {
196 PDBG("%s - device in error state - dropping\n", __func__);
199 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
202 return error < 0 ? error : 0;
205 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
209 if (c4iw_fatal_error(rdev)) {
211 PDBG("%s - device in error state - dropping\n", __func__);
214 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
217 return error < 0 ? error : 0;
220 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
222 struct cpl_tid_release *req;
224 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
227 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
228 INIT_TP_WR(req, hwtid);
229 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
230 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
231 c4iw_ofld_send(rdev, skb);
235 static void set_emss(struct c4iw_ep *ep, u16 opt)
237 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
239 if (GET_TCPOPT_TSTAMP(opt))
243 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
247 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
249 enum c4iw_ep_state state;
251 mutex_lock(&epc->mutex);
253 mutex_unlock(&epc->mutex);
257 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
262 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
264 mutex_lock(&epc->mutex);
265 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
266 __state_set(epc, new);
267 mutex_unlock(&epc->mutex);
271 static void *alloc_ep(int size, gfp_t gfp)
273 struct c4iw_ep_common *epc;
275 epc = kzalloc(size, gfp);
277 kref_init(&epc->kref);
278 mutex_init(&epc->mutex);
279 c4iw_init_wr_wait(&epc->wr_wait);
281 PDBG("%s alloc ep %p\n", __func__, epc);
285 void _c4iw_free_ep(struct kref *kref)
289 ep = container_of(kref, struct c4iw_ep, com.kref);
290 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
291 if (test_bit(QP_REFERENCED, &ep->com.flags))
293 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
294 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
295 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
296 dst_release(ep->dst);
297 cxgb4_l2t_release(ep->l2t);
299 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
300 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
301 iwpm_remove_mapinfo(&ep->com.local_addr,
302 &ep->com.mapped_local_addr);
303 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
308 static void release_ep_resources(struct c4iw_ep *ep)
310 set_bit(RELEASE_RESOURCES, &ep->com.flags);
311 c4iw_put_ep(&ep->com);
314 static int status2errno(int status)
319 case CPL_ERR_CONN_RESET:
321 case CPL_ERR_ARP_MISS:
322 return -EHOSTUNREACH;
323 case CPL_ERR_CONN_TIMEDOUT:
325 case CPL_ERR_TCAM_FULL:
327 case CPL_ERR_CONN_EXIST:
335 * Try and reuse skbs already allocated...
337 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
339 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
342 skb_reset_transport_header(skb);
344 skb = alloc_skb(len, gfp);
346 t4_set_arp_err_handler(skb, NULL, NULL);
350 static struct net_device *get_real_dev(struct net_device *egress_dev)
352 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
355 static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
359 egress_dev = get_real_dev(egress_dev);
360 for (i = 0; i < dev->rdev.lldi.nports; i++)
361 if (dev->rdev.lldi.ports[i] == egress_dev)
366 static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
367 __u8 *peer_ip, __be16 local_port,
368 __be16 peer_port, u8 tos,
371 struct dst_entry *dst = NULL;
373 if (IS_ENABLED(CONFIG_IPV6)) {
376 memset(&fl6, 0, sizeof(fl6));
377 memcpy(&fl6.daddr, peer_ip, 16);
378 memcpy(&fl6.saddr, local_ip, 16);
379 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
380 fl6.flowi6_oif = sin6_scope_id;
381 dst = ip6_route_output(&init_net, NULL, &fl6);
384 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
385 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
395 static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
396 __be32 peer_ip, __be16 local_port,
397 __be16 peer_port, u8 tos)
403 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
404 peer_port, local_port, IPPROTO_TCP,
408 n = dst_neigh_lookup(&rt->dst, &peer_ip);
411 if (!our_interface(dev, n->dev) &&
412 !(n->dev->flags & IFF_LOOPBACK)) {
413 dst_release(&rt->dst);
420 static void arp_failure_discard(void *handle, struct sk_buff *skb)
422 PDBG("%s c4iw_dev %p\n", __func__, handle);
427 * Handle an ARP failure for an active open.
429 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
431 printk(KERN_ERR MOD "ARP failure duing connect\n");
436 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
439 static void abort_arp_failure(void *handle, struct sk_buff *skb)
441 struct c4iw_rdev *rdev = handle;
442 struct cpl_abort_req *req = cplhdr(skb);
444 PDBG("%s rdev %p\n", __func__, rdev);
445 req->cmd = CPL_ABORT_NO_RST;
446 c4iw_ofld_send(rdev, skb);
449 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
451 unsigned int flowclen = 80;
452 struct fw_flowc_wr *flowc;
455 skb = get_skb(skb, flowclen, GFP_KERNEL);
456 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
458 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
459 FW_FLOWC_WR_NPARAMS(8));
460 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
461 16)) | FW_WR_FLOWID(ep->hwtid));
463 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
464 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
465 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
466 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
467 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
468 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
469 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
470 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
471 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
472 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
473 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
474 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
475 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
476 flowc->mnemval[6].val = cpu_to_be32(snd_win);
477 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
478 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
479 /* Pad WR to 16 byte boundary */
480 flowc->mnemval[8].mnemonic = 0;
481 flowc->mnemval[8].val = 0;
482 for (i = 0; i < 9; i++) {
483 flowc->mnemval[i].r4[0] = 0;
484 flowc->mnemval[i].r4[1] = 0;
485 flowc->mnemval[i].r4[2] = 0;
488 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
489 c4iw_ofld_send(&ep->com.dev->rdev, skb);
492 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
494 struct cpl_close_con_req *req;
496 int wrlen = roundup(sizeof *req, 16);
498 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
499 skb = get_skb(NULL, wrlen, gfp);
501 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
504 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
505 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
506 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
507 memset(req, 0, wrlen);
508 INIT_TP_WR(req, ep->hwtid);
509 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
511 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
514 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
516 struct cpl_abort_req *req;
517 int wrlen = roundup(sizeof *req, 16);
519 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
520 skb = get_skb(skb, wrlen, gfp);
522 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
526 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
527 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
528 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
529 memset(req, 0, wrlen);
530 INIT_TP_WR(req, ep->hwtid);
531 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
532 req->cmd = CPL_ABORT_SEND_RST;
533 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
537 * c4iw_form_pm_msg - Form a port mapper message with mapping info
539 static void c4iw_form_pm_msg(struct c4iw_ep *ep,
540 struct iwpm_sa_data *pm_msg)
542 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
543 sizeof(ep->com.local_addr));
544 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
545 sizeof(ep->com.remote_addr));
549 * c4iw_form_reg_msg - Form a port mapper message with dev info
551 static void c4iw_form_reg_msg(struct c4iw_dev *dev,
552 struct iwpm_dev_data *pm_msg)
554 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
555 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
559 static void c4iw_record_pm_msg(struct c4iw_ep *ep,
560 struct iwpm_sa_data *pm_msg)
562 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
563 sizeof(ep->com.mapped_local_addr));
564 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
565 sizeof(ep->com.mapped_remote_addr));
568 static int send_connect(struct c4iw_ep *ep)
570 struct cpl_act_open_req *req;
571 struct cpl_t5_act_open_req *t5_req;
572 struct cpl_act_open_req6 *req6;
573 struct cpl_t5_act_open_req6 *t5_req6;
577 unsigned int mtu_idx;
580 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
581 sizeof(struct cpl_act_open_req) :
582 sizeof(struct cpl_t5_act_open_req);
583 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
584 sizeof(struct cpl_act_open_req6) :
585 sizeof(struct cpl_t5_act_open_req6);
586 struct sockaddr_in *la = (struct sockaddr_in *)
587 &ep->com.mapped_local_addr;
588 struct sockaddr_in *ra = (struct sockaddr_in *)
589 &ep->com.mapped_remote_addr;
590 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
591 &ep->com.mapped_local_addr;
592 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
593 &ep->com.mapped_remote_addr;
595 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
596 roundup(sizev4, 16) :
599 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
601 skb = get_skb(NULL, wrlen, GFP_KERNEL);
603 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
607 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
609 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
610 wscale = compute_wscale(rcv_win);
611 opt0 = (nocong ? NO_CONG(1) : 0) |
616 L2T_IDX(ep->l2t->idx) |
617 TX_CHAN(ep->tx_chan) |
618 SMAC_SEL(ep->smac_idx) |
620 ULP_MODE(ULP_MODE_TCPDDP) |
621 RCV_BUFSIZ(rcv_win>>10);
622 opt2 = RX_CHANNEL(0) |
623 CCTRL_ECN(enable_ecn) |
624 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
625 if (enable_tcp_timestamps)
626 opt2 |= TSTAMPS_EN(1);
629 if (wscale && enable_tcp_window_scaling)
630 opt2 |= WND_SCALE_EN(1);
631 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
632 opt2 |= T5_OPT_2_VALID;
633 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
635 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
637 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
638 if (ep->com.remote_addr.ss_family == AF_INET) {
639 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
641 OPCODE_TID(req) = cpu_to_be32(
642 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
643 ((ep->rss_qid << 14) | ep->atid)));
644 req->local_port = la->sin_port;
645 req->peer_port = ra->sin_port;
646 req->local_ip = la->sin_addr.s_addr;
647 req->peer_ip = ra->sin_addr.s_addr;
648 req->opt0 = cpu_to_be64(opt0);
649 req->params = cpu_to_be32(cxgb4_select_ntuple(
650 ep->com.dev->rdev.lldi.ports[0],
652 req->opt2 = cpu_to_be32(opt2);
654 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
657 OPCODE_TID(req6) = cpu_to_be32(
658 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
659 ((ep->rss_qid<<14)|ep->atid)));
660 req6->local_port = la6->sin6_port;
661 req6->peer_port = ra6->sin6_port;
662 req6->local_ip_hi = *((__be64 *)
663 (la6->sin6_addr.s6_addr));
664 req6->local_ip_lo = *((__be64 *)
665 (la6->sin6_addr.s6_addr + 8));
666 req6->peer_ip_hi = *((__be64 *)
667 (ra6->sin6_addr.s6_addr));
668 req6->peer_ip_lo = *((__be64 *)
669 (ra6->sin6_addr.s6_addr + 8));
670 req6->opt0 = cpu_to_be64(opt0);
671 req6->params = cpu_to_be32(cxgb4_select_ntuple(
672 ep->com.dev->rdev.lldi.ports[0],
674 req6->opt2 = cpu_to_be32(opt2);
677 if (ep->com.remote_addr.ss_family == AF_INET) {
678 t5_req = (struct cpl_t5_act_open_req *)
680 INIT_TP_WR(t5_req, 0);
681 OPCODE_TID(t5_req) = cpu_to_be32(
682 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
683 ((ep->rss_qid << 14) | ep->atid)));
684 t5_req->local_port = la->sin_port;
685 t5_req->peer_port = ra->sin_port;
686 t5_req->local_ip = la->sin_addr.s_addr;
687 t5_req->peer_ip = ra->sin_addr.s_addr;
688 t5_req->opt0 = cpu_to_be64(opt0);
689 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
691 ep->com.dev->rdev.lldi.ports[0],
693 t5_req->opt2 = cpu_to_be32(opt2);
695 t5_req6 = (struct cpl_t5_act_open_req6 *)
697 INIT_TP_WR(t5_req6, 0);
698 OPCODE_TID(t5_req6) = cpu_to_be32(
699 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
700 ((ep->rss_qid<<14)|ep->atid)));
701 t5_req6->local_port = la6->sin6_port;
702 t5_req6->peer_port = ra6->sin6_port;
703 t5_req6->local_ip_hi = *((__be64 *)
704 (la6->sin6_addr.s6_addr));
705 t5_req6->local_ip_lo = *((__be64 *)
706 (la6->sin6_addr.s6_addr + 8));
707 t5_req6->peer_ip_hi = *((__be64 *)
708 (ra6->sin6_addr.s6_addr));
709 t5_req6->peer_ip_lo = *((__be64 *)
710 (ra6->sin6_addr.s6_addr + 8));
711 t5_req6->opt0 = cpu_to_be64(opt0);
712 t5_req6->params = (__force __be64)cpu_to_be32(
714 ep->com.dev->rdev.lldi.ports[0],
716 t5_req6->opt2 = cpu_to_be32(opt2);
720 set_bit(ACT_OPEN_REQ, &ep->com.history);
721 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
724 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
728 struct fw_ofld_tx_data_wr *req;
729 struct mpa_message *mpa;
730 struct mpa_v2_conn_params mpa_v2_params;
732 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
734 BUG_ON(skb_cloned(skb));
736 mpalen = sizeof(*mpa) + ep->plen;
737 if (mpa_rev_to_use == 2)
738 mpalen += sizeof(struct mpa_v2_conn_params);
739 wrlen = roundup(mpalen + sizeof *req, 16);
740 skb = get_skb(skb, wrlen, GFP_KERNEL);
742 connect_reply_upcall(ep, -ENOMEM);
745 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
747 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
748 memset(req, 0, wrlen);
749 req->op_to_immdlen = cpu_to_be32(
750 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
752 FW_WR_IMMDLEN(mpalen));
753 req->flowid_len16 = cpu_to_be32(
754 FW_WR_FLOWID(ep->hwtid) |
755 FW_WR_LEN16(wrlen >> 4));
756 req->plen = cpu_to_be32(mpalen);
757 req->tunnel_to_proxy = cpu_to_be32(
758 FW_OFLD_TX_DATA_WR_FLUSH(1) |
759 FW_OFLD_TX_DATA_WR_SHOVE(1));
761 mpa = (struct mpa_message *)(req + 1);
762 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
763 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
764 (markers_enabled ? MPA_MARKERS : 0) |
765 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
766 mpa->private_data_size = htons(ep->plen);
767 mpa->revision = mpa_rev_to_use;
768 if (mpa_rev_to_use == 1) {
769 ep->tried_with_mpa_v1 = 1;
770 ep->retry_with_mpa_v1 = 0;
773 if (mpa_rev_to_use == 2) {
774 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
775 sizeof (struct mpa_v2_conn_params));
776 mpa_v2_params.ird = htons((u16)ep->ird);
777 mpa_v2_params.ord = htons((u16)ep->ord);
780 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
781 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
783 htons(MPA_V2_RDMA_WRITE_RTR);
784 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
786 htons(MPA_V2_RDMA_READ_RTR);
788 memcpy(mpa->private_data, &mpa_v2_params,
789 sizeof(struct mpa_v2_conn_params));
792 memcpy(mpa->private_data +
793 sizeof(struct mpa_v2_conn_params),
794 ep->mpa_pkt + sizeof(*mpa), ep->plen);
797 memcpy(mpa->private_data,
798 ep->mpa_pkt + sizeof(*mpa), ep->plen);
801 * Reference the mpa skb. This ensures the data area
802 * will remain in memory until the hw acks the tx.
803 * Function fw4_ack() will deref it.
806 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
809 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
811 __state_set(&ep->com, MPA_REQ_SENT);
812 ep->mpa_attr.initiator = 1;
813 ep->snd_seq += mpalen;
817 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
820 struct fw_ofld_tx_data_wr *req;
821 struct mpa_message *mpa;
823 struct mpa_v2_conn_params mpa_v2_params;
825 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
827 mpalen = sizeof(*mpa) + plen;
828 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
829 mpalen += sizeof(struct mpa_v2_conn_params);
830 wrlen = roundup(mpalen + sizeof *req, 16);
832 skb = get_skb(NULL, wrlen, GFP_KERNEL);
834 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
837 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
839 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
840 memset(req, 0, wrlen);
841 req->op_to_immdlen = cpu_to_be32(
842 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
844 FW_WR_IMMDLEN(mpalen));
845 req->flowid_len16 = cpu_to_be32(
846 FW_WR_FLOWID(ep->hwtid) |
847 FW_WR_LEN16(wrlen >> 4));
848 req->plen = cpu_to_be32(mpalen);
849 req->tunnel_to_proxy = cpu_to_be32(
850 FW_OFLD_TX_DATA_WR_FLUSH(1) |
851 FW_OFLD_TX_DATA_WR_SHOVE(1));
853 mpa = (struct mpa_message *)(req + 1);
854 memset(mpa, 0, sizeof(*mpa));
855 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
856 mpa->flags = MPA_REJECT;
857 mpa->revision = ep->mpa_attr.version;
858 mpa->private_data_size = htons(plen);
860 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
861 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
862 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
863 sizeof (struct mpa_v2_conn_params));
864 mpa_v2_params.ird = htons(((u16)ep->ird) |
865 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
867 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
869 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
870 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
871 FW_RI_INIT_P2PTYPE_READ_REQ ?
872 MPA_V2_RDMA_READ_RTR : 0) : 0));
873 memcpy(mpa->private_data, &mpa_v2_params,
874 sizeof(struct mpa_v2_conn_params));
877 memcpy(mpa->private_data +
878 sizeof(struct mpa_v2_conn_params), pdata, plen);
881 memcpy(mpa->private_data, pdata, plen);
884 * Reference the mpa skb again. This ensures the data area
885 * will remain in memory until the hw acks the tx.
886 * Function fw4_ack() will deref it.
889 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
890 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
893 ep->snd_seq += mpalen;
894 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
897 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
900 struct fw_ofld_tx_data_wr *req;
901 struct mpa_message *mpa;
903 struct mpa_v2_conn_params mpa_v2_params;
905 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
907 mpalen = sizeof(*mpa) + plen;
908 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
909 mpalen += sizeof(struct mpa_v2_conn_params);
910 wrlen = roundup(mpalen + sizeof *req, 16);
912 skb = get_skb(NULL, wrlen, GFP_KERNEL);
914 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
917 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
919 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
920 memset(req, 0, wrlen);
921 req->op_to_immdlen = cpu_to_be32(
922 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
924 FW_WR_IMMDLEN(mpalen));
925 req->flowid_len16 = cpu_to_be32(
926 FW_WR_FLOWID(ep->hwtid) |
927 FW_WR_LEN16(wrlen >> 4));
928 req->plen = cpu_to_be32(mpalen);
929 req->tunnel_to_proxy = cpu_to_be32(
930 FW_OFLD_TX_DATA_WR_FLUSH(1) |
931 FW_OFLD_TX_DATA_WR_SHOVE(1));
933 mpa = (struct mpa_message *)(req + 1);
934 memset(mpa, 0, sizeof(*mpa));
935 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
936 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
937 (markers_enabled ? MPA_MARKERS : 0);
938 mpa->revision = ep->mpa_attr.version;
939 mpa->private_data_size = htons(plen);
941 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
942 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
943 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
944 sizeof (struct mpa_v2_conn_params));
945 mpa_v2_params.ird = htons((u16)ep->ird);
946 mpa_v2_params.ord = htons((u16)ep->ord);
947 if (peer2peer && (ep->mpa_attr.p2p_type !=
948 FW_RI_INIT_P2PTYPE_DISABLED)) {
949 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
951 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
953 htons(MPA_V2_RDMA_WRITE_RTR);
954 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
956 htons(MPA_V2_RDMA_READ_RTR);
959 memcpy(mpa->private_data, &mpa_v2_params,
960 sizeof(struct mpa_v2_conn_params));
963 memcpy(mpa->private_data +
964 sizeof(struct mpa_v2_conn_params), pdata, plen);
967 memcpy(mpa->private_data, pdata, plen);
970 * Reference the mpa skb. This ensures the data area
971 * will remain in memory until the hw acks the tx.
972 * Function fw4_ack() will deref it.
975 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
977 __state_set(&ep->com, MPA_REP_SENT);
978 ep->snd_seq += mpalen;
979 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
982 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
985 struct cpl_act_establish *req = cplhdr(skb);
986 unsigned int tid = GET_TID(req);
987 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
988 struct tid_info *t = dev->rdev.lldi.tids;
990 ep = lookup_atid(t, atid);
992 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
993 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
995 mutex_lock(&ep->com.mutex);
996 dst_confirm(ep->dst);
998 /* setup the hwtid for this connection */
1000 cxgb4_insert_tid(t, ep, tid);
1001 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
1003 ep->snd_seq = be32_to_cpu(req->snd_isn);
1004 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1006 set_emss(ep, ntohs(req->tcp_opt));
1008 /* dealloc the atid */
1009 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1010 cxgb4_free_atid(t, atid);
1011 set_bit(ACT_ESTAB, &ep->com.history);
1013 /* start MPA negotiation */
1014 send_flowc(ep, NULL);
1015 if (ep->retry_with_mpa_v1)
1016 send_mpa_req(ep, skb, 1);
1018 send_mpa_req(ep, skb, mpa_rev);
1019 mutex_unlock(&ep->com.mutex);
1023 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1025 struct iw_cm_event event;
1027 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1028 memset(&event, 0, sizeof(event));
1029 event.event = IW_CM_EVENT_CLOSE;
1030 event.status = status;
1031 if (ep->com.cm_id) {
1032 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1033 ep, ep->com.cm_id, ep->hwtid);
1034 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1035 ep->com.cm_id->rem_ref(ep->com.cm_id);
1036 ep->com.cm_id = NULL;
1037 set_bit(CLOSE_UPCALL, &ep->com.history);
1041 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1043 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1044 __state_set(&ep->com, ABORTING);
1045 set_bit(ABORT_CONN, &ep->com.history);
1046 return send_abort(ep, skb, gfp);
1049 static void peer_close_upcall(struct c4iw_ep *ep)
1051 struct iw_cm_event event;
1053 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1054 memset(&event, 0, sizeof(event));
1055 event.event = IW_CM_EVENT_DISCONNECT;
1056 if (ep->com.cm_id) {
1057 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1058 ep, ep->com.cm_id, ep->hwtid);
1059 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1060 set_bit(DISCONN_UPCALL, &ep->com.history);
1064 static void peer_abort_upcall(struct c4iw_ep *ep)
1066 struct iw_cm_event event;
1068 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1069 memset(&event, 0, sizeof(event));
1070 event.event = IW_CM_EVENT_CLOSE;
1071 event.status = -ECONNRESET;
1072 if (ep->com.cm_id) {
1073 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1074 ep->com.cm_id, ep->hwtid);
1075 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1076 ep->com.cm_id->rem_ref(ep->com.cm_id);
1077 ep->com.cm_id = NULL;
1078 set_bit(ABORT_UPCALL, &ep->com.history);
1082 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1084 struct iw_cm_event event;
1086 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1087 memset(&event, 0, sizeof(event));
1088 event.event = IW_CM_EVENT_CONNECT_REPLY;
1089 event.status = status;
1090 memcpy(&event.local_addr, &ep->com.local_addr,
1091 sizeof(ep->com.local_addr));
1092 memcpy(&event.remote_addr, &ep->com.remote_addr,
1093 sizeof(ep->com.remote_addr));
1095 if ((status == 0) || (status == -ECONNREFUSED)) {
1096 if (!ep->tried_with_mpa_v1) {
1097 /* this means MPA_v2 is used */
1098 event.private_data_len = ep->plen -
1099 sizeof(struct mpa_v2_conn_params);
1100 event.private_data = ep->mpa_pkt +
1101 sizeof(struct mpa_message) +
1102 sizeof(struct mpa_v2_conn_params);
1104 /* this means MPA_v1 is used */
1105 event.private_data_len = ep->plen;
1106 event.private_data = ep->mpa_pkt +
1107 sizeof(struct mpa_message);
1111 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1113 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1114 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1117 ep->com.cm_id->rem_ref(ep->com.cm_id);
1118 ep->com.cm_id = NULL;
1122 static int connect_request_upcall(struct c4iw_ep *ep)
1124 struct iw_cm_event event;
1127 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1128 memset(&event, 0, sizeof(event));
1129 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1130 memcpy(&event.local_addr, &ep->com.local_addr,
1131 sizeof(ep->com.local_addr));
1132 memcpy(&event.remote_addr, &ep->com.remote_addr,
1133 sizeof(ep->com.remote_addr));
1134 event.provider_data = ep;
1135 if (!ep->tried_with_mpa_v1) {
1136 /* this means MPA_v2 is used */
1137 event.ord = ep->ord;
1138 event.ird = ep->ird;
1139 event.private_data_len = ep->plen -
1140 sizeof(struct mpa_v2_conn_params);
1141 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1142 sizeof(struct mpa_v2_conn_params);
1144 /* this means MPA_v1 is used. Send max supported */
1145 event.ord = c4iw_max_read_depth;
1146 event.ird = c4iw_max_read_depth;
1147 event.private_data_len = ep->plen;
1148 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1150 c4iw_get_ep(&ep->com);
1151 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1154 c4iw_put_ep(&ep->com);
1155 set_bit(CONNREQ_UPCALL, &ep->com.history);
1156 c4iw_put_ep(&ep->parent_ep->com);
1160 static void established_upcall(struct c4iw_ep *ep)
1162 struct iw_cm_event event;
1164 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1165 memset(&event, 0, sizeof(event));
1166 event.event = IW_CM_EVENT_ESTABLISHED;
1167 event.ird = ep->ird;
1168 event.ord = ep->ord;
1169 if (ep->com.cm_id) {
1170 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1171 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1172 set_bit(ESTAB_UPCALL, &ep->com.history);
1176 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1178 struct cpl_rx_data_ack *req;
1179 struct sk_buff *skb;
1180 int wrlen = roundup(sizeof *req, 16);
1182 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1183 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1185 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1189 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1190 memset(req, 0, wrlen);
1191 INIT_TP_WR(req, ep->hwtid);
1192 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1194 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1196 V_RX_DACK_MODE(dack_mode));
1197 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1198 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1202 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1204 struct mpa_message *mpa;
1205 struct mpa_v2_conn_params *mpa_v2_params;
1207 u16 resp_ird, resp_ord;
1208 u8 rtr_mismatch = 0, insuff_ird = 0;
1209 struct c4iw_qp_attributes attrs;
1210 enum c4iw_qp_attr_mask mask;
1214 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1217 * Stop mpa timer. If it expired, then
1218 * we ignore the MPA reply. process_timeout()
1219 * will abort the connection.
1221 if (stop_ep_timer(ep))
1225 * If we get more than the supported amount of private data
1226 * then we must fail this connection.
1228 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1234 * copy the new data into our accumulation buffer.
1236 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1238 ep->mpa_pkt_len += skb->len;
1241 * if we don't even have the mpa message, then bail.
1243 if (ep->mpa_pkt_len < sizeof(*mpa))
1245 mpa = (struct mpa_message *) ep->mpa_pkt;
1247 /* Validate MPA header. */
1248 if (mpa->revision > mpa_rev) {
1249 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1250 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1254 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1259 plen = ntohs(mpa->private_data_size);
1262 * Fail if there's too much private data.
1264 if (plen > MPA_MAX_PRIVATE_DATA) {
1270 * If plen does not account for pkt size
1272 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1277 ep->plen = (u8) plen;
1280 * If we don't have all the pdata yet, then bail.
1281 * We'll continue process when more data arrives.
1283 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1286 if (mpa->flags & MPA_REJECT) {
1287 err = -ECONNREFUSED;
1292 * If we get here we have accumulated the entire mpa
1293 * start reply message including private data. And
1294 * the MPA header is valid.
1296 __state_set(&ep->com, FPDU_MODE);
1297 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1298 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1299 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1300 ep->mpa_attr.version = mpa->revision;
1301 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1303 if (mpa->revision == 2) {
1304 ep->mpa_attr.enhanced_rdma_conn =
1305 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1306 if (ep->mpa_attr.enhanced_rdma_conn) {
1307 mpa_v2_params = (struct mpa_v2_conn_params *)
1308 (ep->mpa_pkt + sizeof(*mpa));
1309 resp_ird = ntohs(mpa_v2_params->ird) &
1310 MPA_V2_IRD_ORD_MASK;
1311 resp_ord = ntohs(mpa_v2_params->ord) &
1312 MPA_V2_IRD_ORD_MASK;
1315 * This is a double-check. Ideally, below checks are
1316 * not required since ird/ord stuff has been taken
1317 * care of in c4iw_accept_cr
1319 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1326 if (ntohs(mpa_v2_params->ird) &
1327 MPA_V2_PEER2PEER_MODEL) {
1328 if (ntohs(mpa_v2_params->ord) &
1329 MPA_V2_RDMA_WRITE_RTR)
1330 ep->mpa_attr.p2p_type =
1331 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1332 else if (ntohs(mpa_v2_params->ord) &
1333 MPA_V2_RDMA_READ_RTR)
1334 ep->mpa_attr.p2p_type =
1335 FW_RI_INIT_P2PTYPE_READ_REQ;
1338 } else if (mpa->revision == 1)
1340 ep->mpa_attr.p2p_type = p2p_type;
1342 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1343 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1344 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1345 ep->mpa_attr.recv_marker_enabled,
1346 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1347 ep->mpa_attr.p2p_type, p2p_type);
1350 * If responder's RTR does not match with that of initiator, assign
1351 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1352 * generated when moving QP to RTS state.
1353 * A TERM message will be sent after QP has moved to RTS state
1355 if ((ep->mpa_attr.version == 2) && peer2peer &&
1356 (ep->mpa_attr.p2p_type != p2p_type)) {
1357 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1361 attrs.mpa_attr = ep->mpa_attr;
1362 attrs.max_ird = ep->ird;
1363 attrs.max_ord = ep->ord;
1364 attrs.llp_stream_handle = ep;
1365 attrs.next_state = C4IW_QP_STATE_RTS;
1367 mask = C4IW_QP_ATTR_NEXT_STATE |
1368 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1369 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1371 /* bind QP and TID with INIT_WR */
1372 err = c4iw_modify_qp(ep->com.qp->rhp,
1373 ep->com.qp, mask, &attrs, 1);
1378 * If responder's RTR requirement did not match with what initiator
1379 * supports, generate TERM message
1382 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1383 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1384 attrs.ecode = MPA_NOMATCH_RTR;
1385 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1386 attrs.send_term = 1;
1387 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1388 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1395 * Generate TERM if initiator IRD is not sufficient for responder
1396 * provided ORD. Currently, we do the same behaviour even when
1397 * responder provided IRD is also not sufficient as regards to
1401 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1403 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1404 attrs.ecode = MPA_INSUFF_IRD;
1405 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1406 attrs.send_term = 1;
1407 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1408 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1415 __state_set(&ep->com, ABORTING);
1416 send_abort(ep, skb, GFP_KERNEL);
1418 connect_reply_upcall(ep, err);
1422 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1424 struct mpa_message *mpa;
1425 struct mpa_v2_conn_params *mpa_v2_params;
1428 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1431 * If we get more than the supported amount of private data
1432 * then we must fail this connection.
1434 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1435 (void)stop_ep_timer(ep);
1436 abort_connection(ep, skb, GFP_KERNEL);
1440 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1443 * Copy the new data into our accumulation buffer.
1445 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1447 ep->mpa_pkt_len += skb->len;
1450 * If we don't even have the mpa message, then bail.
1451 * We'll continue process when more data arrives.
1453 if (ep->mpa_pkt_len < sizeof(*mpa))
1456 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1457 mpa = (struct mpa_message *) ep->mpa_pkt;
1460 * Validate MPA Header.
1462 if (mpa->revision > mpa_rev) {
1463 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1464 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1465 (void)stop_ep_timer(ep);
1466 abort_connection(ep, skb, GFP_KERNEL);
1470 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1471 (void)stop_ep_timer(ep);
1472 abort_connection(ep, skb, GFP_KERNEL);
1476 plen = ntohs(mpa->private_data_size);
1479 * Fail if there's too much private data.
1481 if (plen > MPA_MAX_PRIVATE_DATA) {
1482 (void)stop_ep_timer(ep);
1483 abort_connection(ep, skb, GFP_KERNEL);
1488 * If plen does not account for pkt size
1490 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1491 (void)stop_ep_timer(ep);
1492 abort_connection(ep, skb, GFP_KERNEL);
1495 ep->plen = (u8) plen;
1498 * If we don't have all the pdata yet, then bail.
1500 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1504 * If we get here we have accumulated the entire mpa
1505 * start reply message including private data.
1507 ep->mpa_attr.initiator = 0;
1508 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1509 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1510 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1511 ep->mpa_attr.version = mpa->revision;
1512 if (mpa->revision == 1)
1513 ep->tried_with_mpa_v1 = 1;
1514 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1516 if (mpa->revision == 2) {
1517 ep->mpa_attr.enhanced_rdma_conn =
1518 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1519 if (ep->mpa_attr.enhanced_rdma_conn) {
1520 mpa_v2_params = (struct mpa_v2_conn_params *)
1521 (ep->mpa_pkt + sizeof(*mpa));
1522 ep->ird = ntohs(mpa_v2_params->ird) &
1523 MPA_V2_IRD_ORD_MASK;
1524 ep->ord = ntohs(mpa_v2_params->ord) &
1525 MPA_V2_IRD_ORD_MASK;
1526 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1528 if (ntohs(mpa_v2_params->ord) &
1529 MPA_V2_RDMA_WRITE_RTR)
1530 ep->mpa_attr.p2p_type =
1531 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1532 else if (ntohs(mpa_v2_params->ord) &
1533 MPA_V2_RDMA_READ_RTR)
1534 ep->mpa_attr.p2p_type =
1535 FW_RI_INIT_P2PTYPE_READ_REQ;
1538 } else if (mpa->revision == 1)
1540 ep->mpa_attr.p2p_type = p2p_type;
1542 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1543 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1544 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1545 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1546 ep->mpa_attr.p2p_type);
1549 * If the endpoint timer already expired, then we ignore
1550 * the start request. process_timeout() will abort
1553 if (!stop_ep_timer(ep)) {
1554 __state_set(&ep->com, MPA_REQ_RCVD);
1557 mutex_lock(&ep->parent_ep->com.mutex);
1558 if (ep->parent_ep->com.state != DEAD) {
1559 if (connect_request_upcall(ep))
1560 abort_connection(ep, skb, GFP_KERNEL);
1562 abort_connection(ep, skb, GFP_KERNEL);
1564 mutex_unlock(&ep->parent_ep->com.mutex);
1569 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1572 struct cpl_rx_data *hdr = cplhdr(skb);
1573 unsigned int dlen = ntohs(hdr->len);
1574 unsigned int tid = GET_TID(hdr);
1575 struct tid_info *t = dev->rdev.lldi.tids;
1576 __u8 status = hdr->status;
1579 ep = lookup_tid(t, tid);
1582 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1583 skb_pull(skb, sizeof(*hdr));
1584 skb_trim(skb, dlen);
1585 mutex_lock(&ep->com.mutex);
1587 /* update RX credits */
1588 update_rx_credits(ep, dlen);
1590 switch (ep->com.state) {
1592 ep->rcv_seq += dlen;
1593 disconnect = process_mpa_reply(ep, skb);
1596 ep->rcv_seq += dlen;
1597 process_mpa_request(ep, skb);
1600 struct c4iw_qp_attributes attrs;
1601 BUG_ON(!ep->com.qp);
1603 pr_err("%s Unexpected streaming data." \
1604 " qpid %u ep %p state %d tid %u status %d\n",
1605 __func__, ep->com.qp->wq.sq.qid, ep,
1606 ep->com.state, ep->hwtid, status);
1607 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1608 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1609 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1616 mutex_unlock(&ep->com.mutex);
1618 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1622 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1625 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1627 unsigned int tid = GET_TID(rpl);
1628 struct tid_info *t = dev->rdev.lldi.tids;
1630 ep = lookup_tid(t, tid);
1632 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1635 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1636 mutex_lock(&ep->com.mutex);
1637 switch (ep->com.state) {
1639 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1640 __state_set(&ep->com, DEAD);
1644 printk(KERN_ERR "%s ep %p state %d\n",
1645 __func__, ep, ep->com.state);
1648 mutex_unlock(&ep->com.mutex);
1651 release_ep_resources(ep);
1655 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1657 struct sk_buff *skb;
1658 struct fw_ofld_connection_wr *req;
1659 unsigned int mtu_idx;
1661 struct sockaddr_in *sin;
1663 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1664 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1665 memset(req, 0, sizeof(*req));
1666 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1667 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1668 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1669 ep->com.dev->rdev.lldi.ports[0],
1671 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1672 req->le.lport = sin->sin_port;
1673 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1674 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1675 req->le.pport = sin->sin_port;
1676 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1677 req->tcb.t_state_to_astid =
1678 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1679 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1680 req->tcb.cplrxdataack_cplpassacceptrpl =
1681 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1682 req->tcb.tx_max = (__force __be32) jiffies;
1683 req->tcb.rcv_adv = htons(1);
1684 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1685 wscale = compute_wscale(rcv_win);
1686 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
1687 (nocong ? NO_CONG(1) : 0) |
1692 L2T_IDX(ep->l2t->idx) |
1693 TX_CHAN(ep->tx_chan) |
1694 SMAC_SEL(ep->smac_idx) |
1696 ULP_MODE(ULP_MODE_TCPDDP) |
1697 RCV_BUFSIZ(rcv_win >> 10));
1698 req->tcb.opt2 = (__force __be32) (PACE(1) |
1699 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1701 CCTRL_ECN(enable_ecn) |
1702 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
1703 if (enable_tcp_timestamps)
1704 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
1705 if (enable_tcp_sack)
1706 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
1707 if (wscale && enable_tcp_window_scaling)
1708 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1709 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1710 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
1711 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1712 set_bit(ACT_OFLD_CONN, &ep->com.history);
1713 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1717 * Return whether a failed active open has allocated a TID
1719 static inline int act_open_has_tid(int status)
1721 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1722 status != CPL_ERR_ARP_MISS;
1725 /* Returns whether a CPL status conveys negative advice.
1727 static int is_neg_adv(unsigned int status)
1729 return status == CPL_ERR_RTX_NEG_ADVICE ||
1730 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1731 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1734 #define ACT_OPEN_RETRY_COUNT 2
1736 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1737 struct dst_entry *dst, struct c4iw_dev *cdev,
1740 struct neighbour *n;
1742 struct net_device *pdev;
1744 n = dst_neigh_lookup(dst, peer_ip);
1750 if (n->dev->flags & IFF_LOOPBACK) {
1752 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1753 else if (IS_ENABLED(CONFIG_IPV6))
1754 for_each_netdev(&init_net, pdev) {
1755 if (ipv6_chk_addr(&init_net,
1756 (struct in6_addr *)peer_ip,
1767 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1771 ep->mtu = pdev->mtu;
1772 ep->tx_chan = cxgb4_port_chan(pdev);
1773 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1774 step = cdev->rdev.lldi.ntxq /
1775 cdev->rdev.lldi.nchan;
1776 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1777 step = cdev->rdev.lldi.nrxq /
1778 cdev->rdev.lldi.nchan;
1779 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1780 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1781 cxgb4_port_idx(pdev) * step];
1784 pdev = get_real_dev(n->dev);
1785 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1789 ep->mtu = dst_mtu(dst);
1790 ep->tx_chan = cxgb4_port_chan(pdev);
1791 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1792 step = cdev->rdev.lldi.ntxq /
1793 cdev->rdev.lldi.nchan;
1794 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1795 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1796 step = cdev->rdev.lldi.nrxq /
1797 cdev->rdev.lldi.nchan;
1798 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1799 cxgb4_port_idx(pdev) * step];
1802 ep->retry_with_mpa_v1 = 0;
1803 ep->tried_with_mpa_v1 = 0;
1815 static int c4iw_reconnect(struct c4iw_ep *ep)
1818 struct sockaddr_in *laddr = (struct sockaddr_in *)
1819 &ep->com.cm_id->local_addr;
1820 struct sockaddr_in *raddr = (struct sockaddr_in *)
1821 &ep->com.cm_id->remote_addr;
1822 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1823 &ep->com.cm_id->local_addr;
1824 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1825 &ep->com.cm_id->remote_addr;
1829 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1830 init_timer(&ep->timer);
1833 * Allocate an active TID to initiate a TCP connection.
1835 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1836 if (ep->atid == -1) {
1837 pr_err("%s - cannot alloc atid.\n", __func__);
1841 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1844 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1845 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1846 raddr->sin_addr.s_addr, laddr->sin_port,
1847 raddr->sin_port, 0);
1849 ra = (__u8 *)&raddr->sin_addr;
1851 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1852 raddr6->sin6_addr.s6_addr,
1853 laddr6->sin6_port, raddr6->sin6_port, 0,
1854 raddr6->sin6_scope_id);
1856 ra = (__u8 *)&raddr6->sin6_addr;
1859 pr_err("%s - cannot find route.\n", __func__);
1860 err = -EHOSTUNREACH;
1863 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1865 pr_err("%s - cannot alloc l2e.\n", __func__);
1869 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1870 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1873 state_set(&ep->com, CONNECTING);
1876 /* send connect request to rnic */
1877 err = send_connect(ep);
1881 cxgb4_l2t_release(ep->l2t);
1883 dst_release(ep->dst);
1885 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1886 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1889 * remember to send notification to upper layer.
1890 * We are in here so the upper layer is not aware that this is
1891 * re-connect attempt and so, upper layer is still waiting for
1892 * response of 1st connect request.
1894 connect_reply_upcall(ep, -ECONNRESET);
1895 c4iw_put_ep(&ep->com);
1900 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1903 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1904 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1905 ntohl(rpl->atid_status)));
1906 struct tid_info *t = dev->rdev.lldi.tids;
1907 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1908 struct sockaddr_in *la;
1909 struct sockaddr_in *ra;
1910 struct sockaddr_in6 *la6;
1911 struct sockaddr_in6 *ra6;
1913 ep = lookup_atid(t, atid);
1914 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1915 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1916 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
1917 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
1919 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1920 status, status2errno(status));
1922 if (is_neg_adv(status)) {
1923 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1928 set_bit(ACT_OPEN_RPL, &ep->com.history);
1931 * Log interesting failures.
1934 case CPL_ERR_CONN_RESET:
1935 case CPL_ERR_CONN_TIMEDOUT:
1937 case CPL_ERR_TCAM_FULL:
1938 mutex_lock(&dev->rdev.stats.lock);
1939 dev->rdev.stats.tcam_full++;
1940 mutex_unlock(&dev->rdev.stats.lock);
1941 if (ep->com.local_addr.ss_family == AF_INET &&
1942 dev->rdev.lldi.enable_fw_ofld_conn) {
1943 send_fw_act_open_req(ep,
1944 GET_TID_TID(GET_AOPEN_ATID(
1945 ntohl(rpl->atid_status))));
1949 case CPL_ERR_CONN_EXIST:
1950 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1951 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1952 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1954 cxgb4_free_atid(t, atid);
1955 dst_release(ep->dst);
1956 cxgb4_l2t_release(ep->l2t);
1962 if (ep->com.local_addr.ss_family == AF_INET) {
1963 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1964 atid, status, status2errno(status),
1965 &la->sin_addr.s_addr, ntohs(la->sin_port),
1966 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1968 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1969 atid, status, status2errno(status),
1970 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1971 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1976 connect_reply_upcall(ep, status2errno(status));
1977 state_set(&ep->com, DEAD);
1979 if (status && act_open_has_tid(status))
1980 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1982 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1983 cxgb4_free_atid(t, atid);
1984 dst_release(ep->dst);
1985 cxgb4_l2t_release(ep->l2t);
1986 c4iw_put_ep(&ep->com);
1991 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1993 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1994 struct tid_info *t = dev->rdev.lldi.tids;
1995 unsigned int stid = GET_TID(rpl);
1996 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1999 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2002 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2003 rpl->status, status2errno(rpl->status));
2004 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2010 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2012 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2013 struct tid_info *t = dev->rdev.lldi.tids;
2014 unsigned int stid = GET_TID(rpl);
2015 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2017 PDBG("%s ep %p\n", __func__, ep);
2018 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2022 static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2023 struct cpl_pass_accept_req *req)
2025 struct cpl_pass_accept_rpl *rpl;
2026 unsigned int mtu_idx;
2031 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2032 BUG_ON(skb_cloned(skb));
2033 skb_trim(skb, sizeof(*rpl));
2035 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
2036 wscale = compute_wscale(rcv_win);
2037 opt0 = (nocong ? NO_CONG(1) : 0) |
2042 L2T_IDX(ep->l2t->idx) |
2043 TX_CHAN(ep->tx_chan) |
2044 SMAC_SEL(ep->smac_idx) |
2045 DSCP(ep->tos >> 2) |
2046 ULP_MODE(ULP_MODE_TCPDDP) |
2047 RCV_BUFSIZ(rcv_win>>10);
2048 opt2 = RX_CHANNEL(0) |
2049 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2051 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2052 opt2 |= TSTAMPS_EN(1);
2053 if (enable_tcp_sack && req->tcpopt.sack)
2055 if (wscale && enable_tcp_window_scaling)
2056 opt2 |= WND_SCALE_EN(1);
2058 const struct tcphdr *tcph;
2059 u32 hlen = ntohl(req->hdr_len);
2061 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2063 if (tcph->ece && tcph->cwr)
2064 opt2 |= CCTRL_ECN(1);
2066 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2067 opt2 |= T5_OPT_2_VALID;
2068 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
2072 INIT_TP_WR(rpl, ep->hwtid);
2073 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2075 rpl->opt0 = cpu_to_be64(opt0);
2076 rpl->opt2 = cpu_to_be32(opt2);
2077 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2078 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
2079 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2084 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2086 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
2087 BUG_ON(skb_cloned(skb));
2088 skb_trim(skb, sizeof(struct cpl_tid_release));
2090 release_tid(&dev->rdev, hwtid, skb);
2094 static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2095 __u8 *local_ip, __u8 *peer_ip,
2096 __be16 *local_port, __be16 *peer_port)
2098 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2099 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2100 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
2101 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
2102 struct tcphdr *tcp = (struct tcphdr *)
2103 ((u8 *)(req + 1) + eth_len + ip_len);
2105 if (ip->version == 4) {
2106 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2107 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2110 memcpy(peer_ip, &ip->saddr, 4);
2111 memcpy(local_ip, &ip->daddr, 4);
2113 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2114 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2117 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2118 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2120 *peer_port = tcp->source;
2121 *local_port = tcp->dest;
2126 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2128 struct c4iw_ep *child_ep = NULL, *parent_ep;
2129 struct cpl_pass_accept_req *req = cplhdr(skb);
2130 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2131 struct tid_info *t = dev->rdev.lldi.tids;
2132 unsigned int hwtid = GET_TID(req);
2133 struct dst_entry *dst;
2134 __u8 local_ip[16], peer_ip[16];
2135 __be16 local_port, peer_port;
2137 u16 peer_mss = ntohs(req->tcpopt.mss);
2140 parent_ep = lookup_stid(t, stid);
2142 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2146 if (state_read(&parent_ep->com) != LISTEN) {
2147 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2152 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2154 /* Find output route */
2156 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2157 , __func__, parent_ep, hwtid,
2158 local_ip, peer_ip, ntohs(local_port),
2159 ntohs(peer_port), peer_mss);
2160 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2161 local_port, peer_port,
2162 GET_POPEN_TOS(ntohl(req->tos_stid)));
2164 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2165 , __func__, parent_ep, hwtid,
2166 local_ip, peer_ip, ntohs(local_port),
2167 ntohs(peer_port), peer_mss);
2168 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2169 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2170 ((struct sockaddr_in6 *)
2171 &parent_ep->com.local_addr)->sin6_scope_id);
2174 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2179 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2181 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2187 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
2189 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2196 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2197 child_ep->mtu = peer_mss + 40;
2199 state_set(&child_ep->com, CONNECTING);
2200 child_ep->com.dev = dev;
2201 child_ep->com.cm_id = NULL;
2203 struct sockaddr_in *sin = (struct sockaddr_in *)
2204 &child_ep->com.local_addr;
2205 sin->sin_family = PF_INET;
2206 sin->sin_port = local_port;
2207 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2208 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2209 sin->sin_family = PF_INET;
2210 sin->sin_port = peer_port;
2211 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2213 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2214 &child_ep->com.local_addr;
2215 sin6->sin6_family = PF_INET6;
2216 sin6->sin6_port = local_port;
2217 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2218 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2219 sin6->sin6_family = PF_INET6;
2220 sin6->sin6_port = peer_port;
2221 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2223 c4iw_get_ep(&parent_ep->com);
2224 child_ep->parent_ep = parent_ep;
2225 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
2226 child_ep->dst = dst;
2227 child_ep->hwtid = hwtid;
2229 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2230 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2232 init_timer(&child_ep->timer);
2233 cxgb4_insert_tid(t, child_ep, hwtid);
2234 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2235 accept_cr(child_ep, skb, req);
2236 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2239 reject_cr(dev, hwtid, skb);
2244 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2247 struct cpl_pass_establish *req = cplhdr(skb);
2248 struct tid_info *t = dev->rdev.lldi.tids;
2249 unsigned int tid = GET_TID(req);
2251 ep = lookup_tid(t, tid);
2252 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2253 ep->snd_seq = be32_to_cpu(req->snd_isn);
2254 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2256 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2257 ntohs(req->tcp_opt));
2259 set_emss(ep, ntohs(req->tcp_opt));
2261 dst_confirm(ep->dst);
2262 state_set(&ep->com, MPA_REQ_WAIT);
2264 send_flowc(ep, skb);
2265 set_bit(PASS_ESTAB, &ep->com.history);
2270 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2272 struct cpl_peer_close *hdr = cplhdr(skb);
2274 struct c4iw_qp_attributes attrs;
2277 struct tid_info *t = dev->rdev.lldi.tids;
2278 unsigned int tid = GET_TID(hdr);
2281 ep = lookup_tid(t, tid);
2282 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2283 dst_confirm(ep->dst);
2285 set_bit(PEER_CLOSE, &ep->com.history);
2286 mutex_lock(&ep->com.mutex);
2287 switch (ep->com.state) {
2289 __state_set(&ep->com, CLOSING);
2292 __state_set(&ep->com, CLOSING);
2293 connect_reply_upcall(ep, -ECONNRESET);
2298 * We're gonna mark this puppy DEAD, but keep
2299 * the reference on it until the ULP accepts or
2300 * rejects the CR. Also wake up anyone waiting
2301 * in rdma connection migration (see c4iw_accept_cr()).
2303 __state_set(&ep->com, CLOSING);
2304 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2305 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2308 __state_set(&ep->com, CLOSING);
2309 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2310 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2314 __state_set(&ep->com, CLOSING);
2315 attrs.next_state = C4IW_QP_STATE_CLOSING;
2316 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2317 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2318 if (ret != -ECONNRESET) {
2319 peer_close_upcall(ep);
2327 __state_set(&ep->com, MORIBUND);
2331 (void)stop_ep_timer(ep);
2332 if (ep->com.cm_id && ep->com.qp) {
2333 attrs.next_state = C4IW_QP_STATE_IDLE;
2334 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2335 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2337 close_complete_upcall(ep, 0);
2338 __state_set(&ep->com, DEAD);
2348 mutex_unlock(&ep->com.mutex);
2350 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2352 release_ep_resources(ep);
2356 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2358 struct cpl_abort_req_rss *req = cplhdr(skb);
2360 struct cpl_abort_rpl *rpl;
2361 struct sk_buff *rpl_skb;
2362 struct c4iw_qp_attributes attrs;
2365 struct tid_info *t = dev->rdev.lldi.tids;
2366 unsigned int tid = GET_TID(req);
2368 ep = lookup_tid(t, tid);
2369 if (is_neg_adv(req->status)) {
2370 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2374 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2376 set_bit(PEER_ABORT, &ep->com.history);
2379 * Wake up any threads in rdma_init() or rdma_fini().
2380 * However, this is not needed if com state is just
2383 if (ep->com.state != MPA_REQ_SENT)
2384 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2386 mutex_lock(&ep->com.mutex);
2387 switch (ep->com.state) {
2391 (void)stop_ep_timer(ep);
2394 (void)stop_ep_timer(ep);
2395 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2396 connect_reply_upcall(ep, -ECONNRESET);
2399 * we just don't send notification upwards because we
2400 * want to retry with mpa_v1 without upper layers even
2403 * do some housekeeping so as to re-initiate the
2406 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2408 ep->retry_with_mpa_v1 = 1;
2420 if (ep->com.cm_id && ep->com.qp) {
2421 attrs.next_state = C4IW_QP_STATE_ERROR;
2422 ret = c4iw_modify_qp(ep->com.qp->rhp,
2423 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2427 "%s - qp <- error failed!\n",
2430 peer_abort_upcall(ep);
2435 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2436 mutex_unlock(&ep->com.mutex);
2442 dst_confirm(ep->dst);
2443 if (ep->com.state != ABORTING) {
2444 __state_set(&ep->com, DEAD);
2445 /* we don't release if we want to retry with mpa_v1 */
2446 if (!ep->retry_with_mpa_v1)
2449 mutex_unlock(&ep->com.mutex);
2451 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2453 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2458 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2459 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2460 INIT_TP_WR(rpl, ep->hwtid);
2461 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2462 rpl->cmd = CPL_ABORT_NO_RST;
2463 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2466 release_ep_resources(ep);
2467 else if (ep->retry_with_mpa_v1) {
2468 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2469 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2470 dst_release(ep->dst);
2471 cxgb4_l2t_release(ep->l2t);
2478 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2481 struct c4iw_qp_attributes attrs;
2482 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2484 struct tid_info *t = dev->rdev.lldi.tids;
2485 unsigned int tid = GET_TID(rpl);
2487 ep = lookup_tid(t, tid);
2489 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2492 /* The cm_id may be null if we failed to connect */
2493 mutex_lock(&ep->com.mutex);
2494 switch (ep->com.state) {
2496 __state_set(&ep->com, MORIBUND);
2499 (void)stop_ep_timer(ep);
2500 if ((ep->com.cm_id) && (ep->com.qp)) {
2501 attrs.next_state = C4IW_QP_STATE_IDLE;
2502 c4iw_modify_qp(ep->com.qp->rhp,
2504 C4IW_QP_ATTR_NEXT_STATE,
2507 close_complete_upcall(ep, 0);
2508 __state_set(&ep->com, DEAD);
2518 mutex_unlock(&ep->com.mutex);
2520 release_ep_resources(ep);
2524 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2526 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2527 struct tid_info *t = dev->rdev.lldi.tids;
2528 unsigned int tid = GET_TID(rpl);
2530 struct c4iw_qp_attributes attrs;
2532 ep = lookup_tid(t, tid);
2535 if (ep && ep->com.qp) {
2536 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2537 ep->com.qp->wq.sq.qid);
2538 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2539 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2540 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2542 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2548 * Upcall from the adapter indicating data has been transmitted.
2549 * For us its just the single MPA request or reply. We can now free
2550 * the skb holding the mpa message.
2552 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2555 struct cpl_fw4_ack *hdr = cplhdr(skb);
2556 u8 credits = hdr->credits;
2557 unsigned int tid = GET_TID(hdr);
2558 struct tid_info *t = dev->rdev.lldi.tids;
2561 ep = lookup_tid(t, tid);
2562 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2564 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2565 __func__, ep, ep->hwtid, state_read(&ep->com));
2569 dst_confirm(ep->dst);
2571 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2572 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2573 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2574 kfree_skb(ep->mpa_skb);
2580 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2584 struct c4iw_ep *ep = to_ep(cm_id);
2585 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2587 mutex_lock(&ep->com.mutex);
2588 if (ep->com.state == DEAD) {
2589 mutex_unlock(&ep->com.mutex);
2590 c4iw_put_ep(&ep->com);
2593 set_bit(ULP_REJECT, &ep->com.history);
2594 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2596 abort_connection(ep, NULL, GFP_KERNEL);
2598 err = send_mpa_reject(ep, pdata, pdata_len);
2601 mutex_unlock(&ep->com.mutex);
2603 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2604 c4iw_put_ep(&ep->com);
2608 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2611 struct c4iw_qp_attributes attrs;
2612 enum c4iw_qp_attr_mask mask;
2613 struct c4iw_ep *ep = to_ep(cm_id);
2614 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2615 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2617 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2619 mutex_lock(&ep->com.mutex);
2620 if (ep->com.state == DEAD) {
2625 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2628 set_bit(ULP_ACCEPT, &ep->com.history);
2629 if ((conn_param->ord > c4iw_max_read_depth) ||
2630 (conn_param->ird > c4iw_max_read_depth)) {
2631 abort_connection(ep, NULL, GFP_KERNEL);
2636 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2637 if (conn_param->ord > ep->ird) {
2638 ep->ird = conn_param->ird;
2639 ep->ord = conn_param->ord;
2640 send_mpa_reject(ep, conn_param->private_data,
2641 conn_param->private_data_len);
2642 abort_connection(ep, NULL, GFP_KERNEL);
2646 if (conn_param->ird > ep->ord) {
2648 conn_param->ird = 1;
2650 abort_connection(ep, NULL, GFP_KERNEL);
2657 ep->ird = conn_param->ird;
2658 ep->ord = conn_param->ord;
2660 if (ep->mpa_attr.version != 2)
2661 if (peer2peer && ep->ird == 0)
2664 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2666 cm_id->add_ref(cm_id);
2667 ep->com.cm_id = cm_id;
2671 /* bind QP to EP and move to RTS */
2672 attrs.mpa_attr = ep->mpa_attr;
2673 attrs.max_ird = ep->ird;
2674 attrs.max_ord = ep->ord;
2675 attrs.llp_stream_handle = ep;
2676 attrs.next_state = C4IW_QP_STATE_RTS;
2678 /* bind QP and TID with INIT_WR */
2679 mask = C4IW_QP_ATTR_NEXT_STATE |
2680 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2681 C4IW_QP_ATTR_MPA_ATTR |
2682 C4IW_QP_ATTR_MAX_IRD |
2683 C4IW_QP_ATTR_MAX_ORD;
2685 err = c4iw_modify_qp(ep->com.qp->rhp,
2686 ep->com.qp, mask, &attrs, 1);
2689 err = send_mpa_reply(ep, conn_param->private_data,
2690 conn_param->private_data_len);
2694 __state_set(&ep->com, FPDU_MODE);
2695 established_upcall(ep);
2696 mutex_unlock(&ep->com.mutex);
2697 c4iw_put_ep(&ep->com);
2700 ep->com.cm_id = NULL;
2701 cm_id->rem_ref(cm_id);
2703 mutex_unlock(&ep->com.mutex);
2704 c4iw_put_ep(&ep->com);
2708 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2710 struct in_device *ind;
2712 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2713 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2715 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2717 return -EADDRNOTAVAIL;
2718 for_primary_ifa(ind) {
2719 laddr->sin_addr.s_addr = ifa->ifa_address;
2720 raddr->sin_addr.s_addr = ifa->ifa_address;
2726 return found ? 0 : -EADDRNOTAVAIL;
2729 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2730 unsigned char banned_flags)
2732 struct inet6_dev *idev;
2733 int err = -EADDRNOTAVAIL;
2736 idev = __in6_dev_get(dev);
2738 struct inet6_ifaddr *ifp;
2740 read_lock_bh(&idev->lock);
2741 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2742 if (ifp->scope == IFA_LINK &&
2743 !(ifp->flags & banned_flags)) {
2744 memcpy(addr, &ifp->addr, 16);
2749 read_unlock_bh(&idev->lock);
2755 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2757 struct in6_addr uninitialized_var(addr);
2758 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2759 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2761 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2762 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2763 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2766 return -EADDRNOTAVAIL;
2769 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2771 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2774 struct sockaddr_in *laddr;
2775 struct sockaddr_in *raddr;
2776 struct sockaddr_in6 *laddr6;
2777 struct sockaddr_in6 *raddr6;
2778 struct iwpm_dev_data pm_reg_msg;
2779 struct iwpm_sa_data pm_msg;
2784 if ((conn_param->ord > c4iw_max_read_depth) ||
2785 (conn_param->ird > c4iw_max_read_depth)) {
2789 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2791 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2795 init_timer(&ep->timer);
2796 ep->plen = conn_param->private_data_len;
2798 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2799 conn_param->private_data, ep->plen);
2800 ep->ird = conn_param->ird;
2801 ep->ord = conn_param->ord;
2803 if (peer2peer && ep->ord == 0)
2806 cm_id->add_ref(cm_id);
2808 ep->com.cm_id = cm_id;
2809 ep->com.qp = get_qhp(dev, conn_param->qpn);
2811 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2816 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2820 * Allocate an active TID to initiate a TCP connection.
2822 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2823 if (ep->atid == -1) {
2824 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2828 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2830 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2831 sizeof(ep->com.local_addr));
2832 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2833 sizeof(ep->com.remote_addr));
2835 /* No port mapper available, go with the specified peer information */
2836 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
2837 sizeof(ep->com.mapped_local_addr));
2838 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
2839 sizeof(ep->com.mapped_remote_addr));
2841 c4iw_form_reg_msg(dev, &pm_reg_msg);
2842 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
2844 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
2845 __func__, iwpm_err);
2847 if (iwpm_valid_pid() && !iwpm_err) {
2848 c4iw_form_pm_msg(ep, &pm_msg);
2849 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
2851 PDBG("%s: Port Mapper query fail (err = %d).\n",
2852 __func__, iwpm_err);
2854 c4iw_record_pm_msg(ep, &pm_msg);
2856 if (iwpm_create_mapinfo(&ep->com.local_addr,
2857 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
2858 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
2862 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
2863 set_bit(RELEASE_MAPINFO, &ep->com.flags);
2865 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2866 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2867 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2868 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
2870 if (cm_id->remote_addr.ss_family == AF_INET) {
2872 ra = (__u8 *)&raddr->sin_addr;
2875 * Handle loopback requests to INADDR_ANY.
2877 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2878 err = pick_local_ipaddrs(dev, cm_id);
2884 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2885 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2886 ra, ntohs(raddr->sin_port));
2887 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2888 raddr->sin_addr.s_addr, laddr->sin_port,
2889 raddr->sin_port, 0);
2892 ra = (__u8 *)&raddr6->sin6_addr;
2895 * Handle loopback requests to INADDR_ANY.
2897 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2898 err = pick_local_ip6addrs(dev, cm_id);
2904 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2905 __func__, laddr6->sin6_addr.s6_addr,
2906 ntohs(laddr6->sin6_port),
2907 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2908 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2909 raddr6->sin6_addr.s6_addr,
2910 laddr6->sin6_port, raddr6->sin6_port, 0,
2911 raddr6->sin6_scope_id);
2914 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2915 err = -EHOSTUNREACH;
2919 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
2921 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2925 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2926 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2929 state_set(&ep->com, CONNECTING);
2932 /* send connect request to rnic */
2933 err = send_connect(ep);
2937 cxgb4_l2t_release(ep->l2t);
2939 dst_release(ep->dst);
2941 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2942 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2944 cm_id->rem_ref(cm_id);
2945 c4iw_put_ep(&ep->com);
2950 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2953 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2954 &ep->com.mapped_local_addr;
2956 c4iw_init_wr_wait(&ep->com.wr_wait);
2957 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2958 ep->stid, &sin6->sin6_addr,
2960 ep->com.dev->rdev.lldi.rxq_ids[0]);
2962 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2966 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2968 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2972 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2975 struct sockaddr_in *sin = (struct sockaddr_in *)
2976 &ep->com.mapped_local_addr;
2978 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2980 err = cxgb4_create_server_filter(
2981 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2982 sin->sin_addr.s_addr, sin->sin_port, 0,
2983 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2984 if (err == -EBUSY) {
2985 set_current_state(TASK_UNINTERRUPTIBLE);
2986 schedule_timeout(usecs_to_jiffies(100));
2988 } while (err == -EBUSY);
2990 c4iw_init_wr_wait(&ep->com.wr_wait);
2991 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2992 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2993 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2995 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3000 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3002 &sin->sin_addr, ntohs(sin->sin_port));
3006 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3009 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3010 struct c4iw_listen_ep *ep;
3011 struct iwpm_dev_data pm_reg_msg;
3012 struct iwpm_sa_data pm_msg;
3017 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3019 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3023 PDBG("%s ep %p\n", __func__, ep);
3024 cm_id->add_ref(cm_id);
3025 ep->com.cm_id = cm_id;
3027 ep->backlog = backlog;
3028 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3029 sizeof(ep->com.local_addr));
3032 * Allocate a server TID.
3034 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3035 ep->com.local_addr.ss_family == AF_INET)
3036 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3037 cm_id->local_addr.ss_family, ep);
3039 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3040 cm_id->local_addr.ss_family, ep);
3042 if (ep->stid == -1) {
3043 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
3047 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3049 /* No port mapper available, go with the specified info */
3050 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3051 sizeof(ep->com.mapped_local_addr));
3053 c4iw_form_reg_msg(dev, &pm_reg_msg);
3054 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3056 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3057 __func__, iwpm_err);
3059 if (iwpm_valid_pid() && !iwpm_err) {
3060 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3061 sizeof(ep->com.local_addr));
3062 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3064 PDBG("%s: Port Mapper query fail (err = %d).\n",
3065 __func__, iwpm_err);
3067 memcpy(&ep->com.mapped_local_addr,
3068 &pm_msg.mapped_loc_addr,
3069 sizeof(ep->com.mapped_local_addr));
3071 if (iwpm_create_mapinfo(&ep->com.local_addr,
3072 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3076 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3078 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3079 state_set(&ep->com, LISTEN);
3080 if (ep->com.local_addr.ss_family == AF_INET)
3081 err = create_server4(dev, ep);
3083 err = create_server6(dev, ep);
3085 cm_id->provider_data = ep;
3090 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3091 ep->com.local_addr.ss_family);
3093 cm_id->rem_ref(cm_id);
3094 c4iw_put_ep(&ep->com);
3100 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3103 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3105 PDBG("%s ep %p\n", __func__, ep);
3108 state_set(&ep->com, DEAD);
3109 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3110 ep->com.local_addr.ss_family == AF_INET) {
3111 err = cxgb4_remove_server_filter(
3112 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3113 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3115 c4iw_init_wr_wait(&ep->com.wr_wait);
3116 err = cxgb4_remove_server(
3117 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3118 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3121 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3124 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3125 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3126 ep->com.local_addr.ss_family);
3128 cm_id->rem_ref(cm_id);
3129 c4iw_put_ep(&ep->com);
3133 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3138 struct c4iw_rdev *rdev;
3140 mutex_lock(&ep->com.mutex);
3142 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3143 states[ep->com.state], abrupt);
3145 rdev = &ep->com.dev->rdev;
3146 if (c4iw_fatal_error(rdev)) {
3148 close_complete_upcall(ep, -EIO);
3149 ep->com.state = DEAD;
3151 switch (ep->com.state) {
3159 ep->com.state = ABORTING;
3161 ep->com.state = CLOSING;
3164 set_bit(CLOSE_SENT, &ep->com.flags);
3167 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3170 (void)stop_ep_timer(ep);
3171 ep->com.state = ABORTING;
3173 ep->com.state = MORIBUND;
3179 PDBG("%s ignoring disconnect ep %p state %u\n",
3180 __func__, ep, ep->com.state);
3189 set_bit(EP_DISC_ABORT, &ep->com.history);
3190 close_complete_upcall(ep, -ECONNRESET);
3191 ret = send_abort(ep, NULL, gfp);
3193 set_bit(EP_DISC_CLOSE, &ep->com.history);
3194 ret = send_halfclose(ep, gfp);
3199 mutex_unlock(&ep->com.mutex);
3201 release_ep_resources(ep);
3205 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3206 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3209 int atid = be32_to_cpu(req->tid);
3211 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3212 (__force u32) req->tid);
3216 switch (req->retval) {
3218 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3219 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3220 send_fw_act_open_req(ep, atid);
3224 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3225 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3226 send_fw_act_open_req(ep, atid);
3231 pr_info("%s unexpected ofld conn wr retval %d\n",
3232 __func__, req->retval);
3235 pr_err("active ofld_connect_wr failure %d atid %d\n",
3237 mutex_lock(&dev->rdev.stats.lock);
3238 dev->rdev.stats.act_ofld_conn_fails++;
3239 mutex_unlock(&dev->rdev.stats.lock);
3240 connect_reply_upcall(ep, status2errno(req->retval));
3241 state_set(&ep->com, DEAD);
3242 remove_handle(dev, &dev->atid_idr, atid);
3243 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3244 dst_release(ep->dst);
3245 cxgb4_l2t_release(ep->l2t);
3246 c4iw_put_ep(&ep->com);
3249 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3250 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3252 struct sk_buff *rpl_skb;
3253 struct cpl_pass_accept_req *cpl;
3256 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3259 PDBG("%s passive open failure %d\n", __func__, req->retval);
3260 mutex_lock(&dev->rdev.stats.lock);
3261 dev->rdev.stats.pas_ofld_conn_fails++;
3262 mutex_unlock(&dev->rdev.stats.lock);
3265 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3266 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3267 (__force u32) htonl(
3268 (__force u32) req->tid)));
3269 ret = pass_accept_req(dev, rpl_skb);
3276 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3278 struct cpl_fw6_msg *rpl = cplhdr(skb);
3279 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3281 switch (rpl->type) {
3283 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3285 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3286 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3287 switch (req->t_state) {
3289 active_ofld_conn_reply(dev, skb, req);
3292 passive_ofld_conn_reply(dev, skb, req);
3295 pr_err("%s unexpected ofld conn wr state %d\n",
3296 __func__, req->t_state);
3304 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3307 u16 vlantag, len, hdr_len, eth_hdr_len;
3309 struct cpl_rx_pkt *cpl = cplhdr(skb);
3310 struct cpl_pass_accept_req *req;
3311 struct tcp_options_received tmp_opt;
3312 struct c4iw_dev *dev;
3314 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3315 /* Store values from cpl_rx_pkt in temporary location. */
3316 vlantag = (__force u16) cpl->vlan;
3317 len = (__force u16) cpl->len;
3318 l2info = (__force u32) cpl->l2info;
3319 hdr_len = (__force u16) cpl->hdr_len;
3322 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3325 * We need to parse the TCP options from SYN packet.
3326 * to generate cpl_pass_accept_req.
3328 memset(&tmp_opt, 0, sizeof(tmp_opt));
3329 tcp_clear_options(&tmp_opt);
3330 tcp_parse_options(skb, &tmp_opt, 0, NULL);
3332 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3333 memset(req, 0, sizeof(*req));
3334 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
3335 V_SYN_MAC_IDX(G_RX_MACIDX(
3336 (__force int) htonl(l2info))) |
3338 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3339 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3340 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
3341 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3342 (__force int) htonl(l2info))) |
3343 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3344 (__force int) htons(hdr_len))) |
3345 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3346 (__force int) htons(hdr_len))) |
3347 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
3348 req->vlan = (__force __be16) vlantag;
3349 req->len = (__force __be16) len;
3350 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3351 PASS_OPEN_TOS(tos));
3352 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3353 if (tmp_opt.wscale_ok)
3354 req->tcpopt.wsf = tmp_opt.snd_wscale;
3355 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3356 if (tmp_opt.sack_ok)
3357 req->tcpopt.sack = 1;
3358 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3362 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3363 __be32 laddr, __be16 lport,
3364 __be32 raddr, __be16 rport,
3365 u32 rcv_isn, u32 filter, u16 window,
3366 u32 rss_qid, u8 port_id)
3368 struct sk_buff *req_skb;
3369 struct fw_ofld_connection_wr *req;
3370 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3373 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3374 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3375 memset(req, 0, sizeof(*req));
3376 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3377 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3378 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
3379 req->le.filter = (__force __be32) filter;
3380 req->le.lport = lport;
3381 req->le.pport = rport;
3382 req->le.u.ipv4.lip = laddr;
3383 req->le.u.ipv4.pip = raddr;
3384 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3385 req->tcb.rcv_adv = htons(window);
3386 req->tcb.t_state_to_astid =
3387 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3388 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3389 V_FW_OFLD_CONNECTION_WR_ASTID(
3390 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3393 * We store the qid in opt2 which will be used by the firmware
3394 * to send us the wr response.
3396 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3399 * We initialize the MSS index in TCB to 0xF.
3400 * So that when driver sends cpl_pass_accept_rpl
3401 * TCB picks up the correct value. If this was 0
3402 * TP will ignore any value > 0 for MSS index.
3404 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
3405 req->cookie = (unsigned long)skb;
3407 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3408 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3410 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3418 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3419 * messages when a filter is being used instead of server to
3420 * redirect a syn packet. When packets hit filter they are redirected
3421 * to the offload queue and driver tries to establish the connection
3422 * using firmware work request.
3424 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3427 unsigned int filter;
3428 struct ethhdr *eh = NULL;
3429 struct vlan_ethhdr *vlan_eh = NULL;
3431 struct tcphdr *tcph;
3432 struct rss_header *rss = (void *)skb->data;
3433 struct cpl_rx_pkt *cpl = (void *)skb->data;
3434 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3435 struct l2t_entry *e;
3436 struct dst_entry *dst;
3437 struct c4iw_ep *lep;
3439 struct port_info *pi;
3440 struct net_device *pdev;
3441 u16 rss_qid, eth_hdr_len;
3444 struct neighbour *neigh;
3446 /* Drop all non-SYN packets */
3447 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3451 * Drop all packets which did not hit the filter.
3452 * Unlikely to happen.
3454 if (!(rss->filter_hit && rss->filter_tid))
3458 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3460 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3462 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3464 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3468 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3469 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3470 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3471 if (eth_hdr_len == ETH_HLEN) {
3472 eh = (struct ethhdr *)(req + 1);
3473 iph = (struct iphdr *)(eh + 1);
3475 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3476 iph = (struct iphdr *)(vlan_eh + 1);
3477 skb->vlan_tci = ntohs(cpl->vlan);
3480 if (iph->version != 0x4)
3483 tcph = (struct tcphdr *)(iph + 1);
3484 skb_set_network_header(skb, (void *)iph - (void *)rss);
3485 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3488 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3489 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3490 ntohs(tcph->source), iph->tos);
3492 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3495 pr_err("%s - failed to find dst entry!\n",
3499 neigh = dst_neigh_lookup_skb(dst, skb);
3502 pr_err("%s - failed to allocate neigh!\n",
3507 if (neigh->dev->flags & IFF_LOOPBACK) {
3508 pdev = ip_dev_find(&init_net, iph->daddr);
3509 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3511 pi = (struct port_info *)netdev_priv(pdev);
3512 tx_chan = cxgb4_port_chan(pdev);
3515 pdev = get_real_dev(neigh->dev);
3516 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3518 pi = (struct port_info *)netdev_priv(pdev);
3519 tx_chan = cxgb4_port_chan(pdev);
3521 neigh_release(neigh);
3523 pr_err("%s - failed to allocate l2t entry!\n",
3528 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3529 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3530 window = (__force u16) htons((__force u16)tcph->window);
3532 /* Calcuate filter portion for LE region. */
3533 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3534 dev->rdev.lldi.ports[0],
3538 * Synthesize the cpl_pass_accept_req. We have everything except the
3539 * TID. Once firmware sends a reply with TID we update the TID field
3540 * in cpl and pass it through the regular cpl_pass_accept_req path.
3542 build_cpl_pass_accept_req(skb, stid, iph->tos);
3543 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3544 tcph->source, ntohl(tcph->seq), filter, window,
3545 rss_qid, pi->port_id);
3546 cxgb4_l2t_release(e);
3554 * These are the real handlers that are called from a
3557 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3558 [CPL_ACT_ESTABLISH] = act_establish,
3559 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3560 [CPL_RX_DATA] = rx_data,
3561 [CPL_ABORT_RPL_RSS] = abort_rpl,
3562 [CPL_ABORT_RPL] = abort_rpl,
3563 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3564 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3565 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3566 [CPL_PASS_ESTABLISH] = pass_establish,
3567 [CPL_PEER_CLOSE] = peer_close,
3568 [CPL_ABORT_REQ_RSS] = peer_abort,
3569 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3570 [CPL_RDMA_TERMINATE] = terminate,
3571 [CPL_FW4_ACK] = fw4_ack,
3572 [CPL_FW6_MSG] = deferred_fw6_msg,
3573 [CPL_RX_PKT] = rx_pkt
3576 static void process_timeout(struct c4iw_ep *ep)
3578 struct c4iw_qp_attributes attrs;
3581 mutex_lock(&ep->com.mutex);
3582 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3584 set_bit(TIMEDOUT, &ep->com.history);
3585 switch (ep->com.state) {
3587 __state_set(&ep->com, ABORTING);
3588 connect_reply_upcall(ep, -ETIMEDOUT);
3591 __state_set(&ep->com, ABORTING);
3595 if (ep->com.cm_id && ep->com.qp) {
3596 attrs.next_state = C4IW_QP_STATE_ERROR;
3597 c4iw_modify_qp(ep->com.qp->rhp,
3598 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3601 __state_set(&ep->com, ABORTING);
3602 close_complete_upcall(ep, -ETIMEDOUT);
3608 * These states are expected if the ep timed out at the same
3609 * time as another thread was calling stop_ep_timer().
3610 * So we silently do nothing for these states.
3615 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3616 __func__, ep, ep->hwtid, ep->com.state);
3620 abort_connection(ep, NULL, GFP_KERNEL);
3621 mutex_unlock(&ep->com.mutex);
3622 c4iw_put_ep(&ep->com);
3625 static void process_timedout_eps(void)
3629 spin_lock_irq(&timeout_lock);
3630 while (!list_empty(&timeout_list)) {
3631 struct list_head *tmp;
3633 tmp = timeout_list.next;
3637 spin_unlock_irq(&timeout_lock);
3638 ep = list_entry(tmp, struct c4iw_ep, entry);
3639 process_timeout(ep);
3640 spin_lock_irq(&timeout_lock);
3642 spin_unlock_irq(&timeout_lock);
3645 static void process_work(struct work_struct *work)
3647 struct sk_buff *skb = NULL;
3648 struct c4iw_dev *dev;
3649 struct cpl_act_establish *rpl;
3650 unsigned int opcode;
3653 process_timedout_eps();
3654 while ((skb = skb_dequeue(&rxq))) {
3656 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3657 opcode = rpl->ot.opcode;
3659 BUG_ON(!work_handlers[opcode]);
3660 ret = work_handlers[opcode](dev, skb);
3663 process_timedout_eps();
3667 static DECLARE_WORK(skb_work, process_work);
3669 static void ep_timeout(unsigned long arg)
3671 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3674 spin_lock(&timeout_lock);
3675 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3677 * Only insert if it is not already on the list.
3679 if (!ep->entry.next) {
3680 list_add_tail(&ep->entry, &timeout_list);
3684 spin_unlock(&timeout_lock);
3686 queue_work(workq, &skb_work);
3690 * All the CM events are handled on a work queue to have a safe context.
3692 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3696 * Save dev in the skb->cb area.
3698 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3701 * Queue the skb and schedule the worker thread.
3703 skb_queue_tail(&rxq, skb);
3704 queue_work(workq, &skb_work);
3708 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3710 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3712 if (rpl->status != CPL_ERR_NONE) {
3713 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3714 "for tid %u\n", rpl->status, GET_TID(rpl));
3720 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3722 struct cpl_fw6_msg *rpl = cplhdr(skb);
3723 struct c4iw_wr_wait *wr_waitp;
3726 PDBG("%s type %u\n", __func__, rpl->type);
3728 switch (rpl->type) {
3729 case FW6_TYPE_WR_RPL:
3730 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
3731 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
3732 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
3734 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3738 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3742 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3750 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3752 struct cpl_abort_req_rss *req = cplhdr(skb);
3754 struct tid_info *t = dev->rdev.lldi.tids;
3755 unsigned int tid = GET_TID(req);
3757 ep = lookup_tid(t, tid);
3759 printk(KERN_WARNING MOD
3760 "Abort on non-existent endpoint, tid %d\n", tid);
3764 if (is_neg_adv(req->status)) {
3765 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3770 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3774 * Wake up any threads in rdma_init() or rdma_fini().
3775 * However, if we are on MPAv2 and want to retry with MPAv1
3776 * then, don't wake up yet.
3778 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3779 if (ep->com.state != MPA_REQ_SENT)
3780 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3782 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3788 * Most upcalls from the T4 Core go to sched() to
3789 * schedule the processing on a work queue.
3791 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3792 [CPL_ACT_ESTABLISH] = sched,
3793 [CPL_ACT_OPEN_RPL] = sched,
3794 [CPL_RX_DATA] = sched,
3795 [CPL_ABORT_RPL_RSS] = sched,
3796 [CPL_ABORT_RPL] = sched,
3797 [CPL_PASS_OPEN_RPL] = sched,
3798 [CPL_CLOSE_LISTSRV_RPL] = sched,
3799 [CPL_PASS_ACCEPT_REQ] = sched,
3800 [CPL_PASS_ESTABLISH] = sched,
3801 [CPL_PEER_CLOSE] = sched,
3802 [CPL_CLOSE_CON_RPL] = sched,
3803 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
3804 [CPL_RDMA_TERMINATE] = sched,
3805 [CPL_FW4_ACK] = sched,
3806 [CPL_SET_TCB_RPL] = set_tcb_rpl,
3807 [CPL_FW6_MSG] = fw6_msg,
3808 [CPL_RX_PKT] = sched
3811 int __init c4iw_cm_init(void)
3813 spin_lock_init(&timeout_lock);
3814 skb_queue_head_init(&rxq);
3816 workq = create_singlethread_workqueue("iw_cxgb4");
3823 void __exit c4iw_cm_term(void)
3825 WARN_ON(!list_empty(&timeout_list));
3826 flush_workqueue(workq);
3827 destroy_workqueue(workq);