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)] -
238 sizeof(struct iphdr) - sizeof(struct tcphdr);
240 if (GET_TCPOPT_TSTAMP(opt))
245 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
246 GET_TCPOPT_MSS(opt), ep->mss, ep->emss);
247 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
251 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
253 enum c4iw_ep_state state;
255 mutex_lock(&epc->mutex);
257 mutex_unlock(&epc->mutex);
261 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
266 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
268 mutex_lock(&epc->mutex);
269 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
270 __state_set(epc, new);
271 mutex_unlock(&epc->mutex);
275 static void *alloc_ep(int size, gfp_t gfp)
277 struct c4iw_ep_common *epc;
279 epc = kzalloc(size, gfp);
281 kref_init(&epc->kref);
282 mutex_init(&epc->mutex);
283 c4iw_init_wr_wait(&epc->wr_wait);
285 PDBG("%s alloc ep %p\n", __func__, epc);
289 void _c4iw_free_ep(struct kref *kref)
293 ep = container_of(kref, struct c4iw_ep, com.kref);
294 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
295 if (test_bit(QP_REFERENCED, &ep->com.flags))
297 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
298 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
299 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
300 dst_release(ep->dst);
301 cxgb4_l2t_release(ep->l2t);
303 if (test_bit(RELEASE_MAPINFO, &ep->com.flags)) {
304 print_addr(&ep->com, __func__, "remove_mapinfo/mapping");
305 iwpm_remove_mapinfo(&ep->com.local_addr,
306 &ep->com.mapped_local_addr);
307 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
312 static void release_ep_resources(struct c4iw_ep *ep)
314 set_bit(RELEASE_RESOURCES, &ep->com.flags);
315 c4iw_put_ep(&ep->com);
318 static int status2errno(int status)
323 case CPL_ERR_CONN_RESET:
325 case CPL_ERR_ARP_MISS:
326 return -EHOSTUNREACH;
327 case CPL_ERR_CONN_TIMEDOUT:
329 case CPL_ERR_TCAM_FULL:
331 case CPL_ERR_CONN_EXIST:
339 * Try and reuse skbs already allocated...
341 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
343 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
346 skb_reset_transport_header(skb);
348 skb = alloc_skb(len, gfp);
350 t4_set_arp_err_handler(skb, NULL, NULL);
354 static struct net_device *get_real_dev(struct net_device *egress_dev)
356 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
359 static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
363 egress_dev = get_real_dev(egress_dev);
364 for (i = 0; i < dev->rdev.lldi.nports; i++)
365 if (dev->rdev.lldi.ports[i] == egress_dev)
370 static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
371 __u8 *peer_ip, __be16 local_port,
372 __be16 peer_port, u8 tos,
375 struct dst_entry *dst = NULL;
377 if (IS_ENABLED(CONFIG_IPV6)) {
380 memset(&fl6, 0, sizeof(fl6));
381 memcpy(&fl6.daddr, peer_ip, 16);
382 memcpy(&fl6.saddr, local_ip, 16);
383 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
384 fl6.flowi6_oif = sin6_scope_id;
385 dst = ip6_route_output(&init_net, NULL, &fl6);
388 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
389 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
399 static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
400 __be32 peer_ip, __be16 local_port,
401 __be16 peer_port, u8 tos)
407 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
408 peer_port, local_port, IPPROTO_TCP,
412 n = dst_neigh_lookup(&rt->dst, &peer_ip);
415 if (!our_interface(dev, n->dev) &&
416 !(n->dev->flags & IFF_LOOPBACK)) {
417 dst_release(&rt->dst);
424 static void arp_failure_discard(void *handle, struct sk_buff *skb)
426 PDBG("%s c4iw_dev %p\n", __func__, handle);
431 * Handle an ARP failure for an active open.
433 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
435 printk(KERN_ERR MOD "ARP failure duing connect\n");
440 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
443 static void abort_arp_failure(void *handle, struct sk_buff *skb)
445 struct c4iw_rdev *rdev = handle;
446 struct cpl_abort_req *req = cplhdr(skb);
448 PDBG("%s rdev %p\n", __func__, rdev);
449 req->cmd = CPL_ABORT_NO_RST;
450 c4iw_ofld_send(rdev, skb);
453 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
455 unsigned int flowclen = 80;
456 struct fw_flowc_wr *flowc;
459 skb = get_skb(skb, flowclen, GFP_KERNEL);
460 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
462 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
463 FW_FLOWC_WR_NPARAMS(8));
464 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
465 16)) | FW_WR_FLOWID(ep->hwtid));
467 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
468 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
469 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
470 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
471 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
472 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
473 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
474 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
475 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
476 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
477 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
478 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
479 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
480 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
481 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
482 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
483 /* Pad WR to 16 byte boundary */
484 flowc->mnemval[8].mnemonic = 0;
485 flowc->mnemval[8].val = 0;
486 for (i = 0; i < 9; i++) {
487 flowc->mnemval[i].r4[0] = 0;
488 flowc->mnemval[i].r4[1] = 0;
489 flowc->mnemval[i].r4[2] = 0;
492 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
493 c4iw_ofld_send(&ep->com.dev->rdev, skb);
496 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
498 struct cpl_close_con_req *req;
500 int wrlen = roundup(sizeof *req, 16);
502 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
503 skb = get_skb(NULL, wrlen, gfp);
505 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
508 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
509 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
510 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
511 memset(req, 0, wrlen);
512 INIT_TP_WR(req, ep->hwtid);
513 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
515 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
518 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
520 struct cpl_abort_req *req;
521 int wrlen = roundup(sizeof *req, 16);
523 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
524 skb = get_skb(skb, wrlen, gfp);
526 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
530 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
531 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
532 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
533 memset(req, 0, wrlen);
534 INIT_TP_WR(req, ep->hwtid);
535 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
536 req->cmd = CPL_ABORT_SEND_RST;
537 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
541 * c4iw_form_pm_msg - Form a port mapper message with mapping info
543 static void c4iw_form_pm_msg(struct c4iw_ep *ep,
544 struct iwpm_sa_data *pm_msg)
546 memcpy(&pm_msg->loc_addr, &ep->com.local_addr,
547 sizeof(ep->com.local_addr));
548 memcpy(&pm_msg->rem_addr, &ep->com.remote_addr,
549 sizeof(ep->com.remote_addr));
553 * c4iw_form_reg_msg - Form a port mapper message with dev info
555 static void c4iw_form_reg_msg(struct c4iw_dev *dev,
556 struct iwpm_dev_data *pm_msg)
558 memcpy(pm_msg->dev_name, dev->ibdev.name, IWPM_DEVNAME_SIZE);
559 memcpy(pm_msg->if_name, dev->rdev.lldi.ports[0]->name,
563 static void c4iw_record_pm_msg(struct c4iw_ep *ep,
564 struct iwpm_sa_data *pm_msg)
566 memcpy(&ep->com.mapped_local_addr, &pm_msg->mapped_loc_addr,
567 sizeof(ep->com.mapped_local_addr));
568 memcpy(&ep->com.mapped_remote_addr, &pm_msg->mapped_rem_addr,
569 sizeof(ep->com.mapped_remote_addr));
572 static void best_mtu(const unsigned short *mtus, unsigned short mtu,
573 unsigned int *idx, int use_ts)
575 unsigned short hdr_size = sizeof(struct iphdr) +
576 sizeof(struct tcphdr) +
578 unsigned short data_size = mtu - hdr_size;
580 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
583 static int send_connect(struct c4iw_ep *ep)
585 struct cpl_act_open_req *req;
586 struct cpl_t5_act_open_req *t5_req;
587 struct cpl_act_open_req6 *req6;
588 struct cpl_t5_act_open_req6 *t5_req6;
592 unsigned int mtu_idx;
595 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
596 sizeof(struct cpl_act_open_req) :
597 sizeof(struct cpl_t5_act_open_req);
598 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
599 sizeof(struct cpl_act_open_req6) :
600 sizeof(struct cpl_t5_act_open_req6);
601 struct sockaddr_in *la = (struct sockaddr_in *)
602 &ep->com.mapped_local_addr;
603 struct sockaddr_in *ra = (struct sockaddr_in *)
604 &ep->com.mapped_remote_addr;
605 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
606 &ep->com.mapped_local_addr;
607 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
608 &ep->com.mapped_remote_addr;
611 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
612 roundup(sizev4, 16) :
615 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
617 skb = get_skb(NULL, wrlen, GFP_KERNEL);
619 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
623 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
625 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
626 enable_tcp_timestamps);
627 wscale = compute_wscale(rcv_win);
630 * Specify the largest window that will fit in opt0. The
631 * remainder will be specified in the rx_data_ack.
633 win = ep->rcv_win >> 10;
634 if (win > RCV_BUFSIZ_MASK)
635 win = RCV_BUFSIZ_MASK;
637 opt0 = (nocong ? NO_CONG(1) : 0) |
642 L2T_IDX(ep->l2t->idx) |
643 TX_CHAN(ep->tx_chan) |
644 SMAC_SEL(ep->smac_idx) |
646 ULP_MODE(ULP_MODE_TCPDDP) |
648 opt2 = RX_CHANNEL(0) |
649 CCTRL_ECN(enable_ecn) |
650 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
651 if (enable_tcp_timestamps)
652 opt2 |= TSTAMPS_EN(1);
655 if (wscale && enable_tcp_window_scaling)
656 opt2 |= WND_SCALE_EN(1);
657 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
658 opt2 |= T5_OPT_2_VALID;
659 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
661 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
663 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
664 if (ep->com.remote_addr.ss_family == AF_INET) {
665 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
667 OPCODE_TID(req) = cpu_to_be32(
668 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
669 ((ep->rss_qid << 14) | ep->atid)));
670 req->local_port = la->sin_port;
671 req->peer_port = ra->sin_port;
672 req->local_ip = la->sin_addr.s_addr;
673 req->peer_ip = ra->sin_addr.s_addr;
674 req->opt0 = cpu_to_be64(opt0);
675 req->params = cpu_to_be32(cxgb4_select_ntuple(
676 ep->com.dev->rdev.lldi.ports[0],
678 req->opt2 = cpu_to_be32(opt2);
680 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
683 OPCODE_TID(req6) = cpu_to_be32(
684 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
685 ((ep->rss_qid<<14)|ep->atid)));
686 req6->local_port = la6->sin6_port;
687 req6->peer_port = ra6->sin6_port;
688 req6->local_ip_hi = *((__be64 *)
689 (la6->sin6_addr.s6_addr));
690 req6->local_ip_lo = *((__be64 *)
691 (la6->sin6_addr.s6_addr + 8));
692 req6->peer_ip_hi = *((__be64 *)
693 (ra6->sin6_addr.s6_addr));
694 req6->peer_ip_lo = *((__be64 *)
695 (ra6->sin6_addr.s6_addr + 8));
696 req6->opt0 = cpu_to_be64(opt0);
697 req6->params = cpu_to_be32(cxgb4_select_ntuple(
698 ep->com.dev->rdev.lldi.ports[0],
700 req6->opt2 = cpu_to_be32(opt2);
703 u32 isn = (prandom_u32() & ~7UL) - 1;
705 opt2 |= T5_OPT_2_VALID;
706 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
710 if (ep->com.remote_addr.ss_family == AF_INET) {
711 t5_req = (struct cpl_t5_act_open_req *)
713 INIT_TP_WR(t5_req, 0);
714 OPCODE_TID(t5_req) = cpu_to_be32(
715 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
716 ((ep->rss_qid << 14) | ep->atid)));
717 t5_req->local_port = la->sin_port;
718 t5_req->peer_port = ra->sin_port;
719 t5_req->local_ip = la->sin_addr.s_addr;
720 t5_req->peer_ip = ra->sin_addr.s_addr;
721 t5_req->opt0 = cpu_to_be64(opt0);
722 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
724 ep->com.dev->rdev.lldi.ports[0],
726 t5_req->rsvd = cpu_to_be32(isn);
727 PDBG("%s snd_isn %u\n", __func__,
728 be32_to_cpu(t5_req->rsvd));
729 t5_req->opt2 = cpu_to_be32(opt2);
731 t5_req6 = (struct cpl_t5_act_open_req6 *)
733 INIT_TP_WR(t5_req6, 0);
734 OPCODE_TID(t5_req6) = cpu_to_be32(
735 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
736 ((ep->rss_qid<<14)|ep->atid)));
737 t5_req6->local_port = la6->sin6_port;
738 t5_req6->peer_port = ra6->sin6_port;
739 t5_req6->local_ip_hi = *((__be64 *)
740 (la6->sin6_addr.s6_addr));
741 t5_req6->local_ip_lo = *((__be64 *)
742 (la6->sin6_addr.s6_addr + 8));
743 t5_req6->peer_ip_hi = *((__be64 *)
744 (ra6->sin6_addr.s6_addr));
745 t5_req6->peer_ip_lo = *((__be64 *)
746 (ra6->sin6_addr.s6_addr + 8));
747 t5_req6->opt0 = cpu_to_be64(opt0);
748 t5_req6->params = (__force __be64)cpu_to_be32(
750 ep->com.dev->rdev.lldi.ports[0],
752 t5_req6->rsvd = cpu_to_be32(isn);
753 PDBG("%s snd_isn %u\n", __func__,
754 be32_to_cpu(t5_req6->rsvd));
755 t5_req6->opt2 = cpu_to_be32(opt2);
759 set_bit(ACT_OPEN_REQ, &ep->com.history);
760 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
763 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
767 struct fw_ofld_tx_data_wr *req;
768 struct mpa_message *mpa;
769 struct mpa_v2_conn_params mpa_v2_params;
771 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
773 BUG_ON(skb_cloned(skb));
775 mpalen = sizeof(*mpa) + ep->plen;
776 if (mpa_rev_to_use == 2)
777 mpalen += sizeof(struct mpa_v2_conn_params);
778 wrlen = roundup(mpalen + sizeof *req, 16);
779 skb = get_skb(skb, wrlen, GFP_KERNEL);
781 connect_reply_upcall(ep, -ENOMEM);
784 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
786 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
787 memset(req, 0, wrlen);
788 req->op_to_immdlen = cpu_to_be32(
789 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
791 FW_WR_IMMDLEN(mpalen));
792 req->flowid_len16 = cpu_to_be32(
793 FW_WR_FLOWID(ep->hwtid) |
794 FW_WR_LEN16(wrlen >> 4));
795 req->plen = cpu_to_be32(mpalen);
796 req->tunnel_to_proxy = cpu_to_be32(
797 FW_OFLD_TX_DATA_WR_FLUSH(1) |
798 FW_OFLD_TX_DATA_WR_SHOVE(1));
800 mpa = (struct mpa_message *)(req + 1);
801 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
802 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
803 (markers_enabled ? MPA_MARKERS : 0) |
804 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
805 mpa->private_data_size = htons(ep->plen);
806 mpa->revision = mpa_rev_to_use;
807 if (mpa_rev_to_use == 1) {
808 ep->tried_with_mpa_v1 = 1;
809 ep->retry_with_mpa_v1 = 0;
812 if (mpa_rev_to_use == 2) {
813 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
814 sizeof (struct mpa_v2_conn_params));
815 mpa_v2_params.ird = htons((u16)ep->ird);
816 mpa_v2_params.ord = htons((u16)ep->ord);
819 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
820 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
822 htons(MPA_V2_RDMA_WRITE_RTR);
823 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
825 htons(MPA_V2_RDMA_READ_RTR);
827 memcpy(mpa->private_data, &mpa_v2_params,
828 sizeof(struct mpa_v2_conn_params));
831 memcpy(mpa->private_data +
832 sizeof(struct mpa_v2_conn_params),
833 ep->mpa_pkt + sizeof(*mpa), ep->plen);
836 memcpy(mpa->private_data,
837 ep->mpa_pkt + sizeof(*mpa), ep->plen);
840 * Reference the mpa skb. This ensures the data area
841 * will remain in memory until the hw acks the tx.
842 * Function fw4_ack() will deref it.
845 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
848 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
850 __state_set(&ep->com, MPA_REQ_SENT);
851 ep->mpa_attr.initiator = 1;
852 ep->snd_seq += mpalen;
856 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
859 struct fw_ofld_tx_data_wr *req;
860 struct mpa_message *mpa;
862 struct mpa_v2_conn_params mpa_v2_params;
864 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
866 mpalen = sizeof(*mpa) + plen;
867 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
868 mpalen += sizeof(struct mpa_v2_conn_params);
869 wrlen = roundup(mpalen + sizeof *req, 16);
871 skb = get_skb(NULL, wrlen, GFP_KERNEL);
873 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
876 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
878 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
879 memset(req, 0, wrlen);
880 req->op_to_immdlen = cpu_to_be32(
881 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
883 FW_WR_IMMDLEN(mpalen));
884 req->flowid_len16 = cpu_to_be32(
885 FW_WR_FLOWID(ep->hwtid) |
886 FW_WR_LEN16(wrlen >> 4));
887 req->plen = cpu_to_be32(mpalen);
888 req->tunnel_to_proxy = cpu_to_be32(
889 FW_OFLD_TX_DATA_WR_FLUSH(1) |
890 FW_OFLD_TX_DATA_WR_SHOVE(1));
892 mpa = (struct mpa_message *)(req + 1);
893 memset(mpa, 0, sizeof(*mpa));
894 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
895 mpa->flags = MPA_REJECT;
896 mpa->revision = ep->mpa_attr.version;
897 mpa->private_data_size = htons(plen);
899 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
900 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
901 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
902 sizeof (struct mpa_v2_conn_params));
903 mpa_v2_params.ird = htons(((u16)ep->ird) |
904 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
906 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
908 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
909 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
910 FW_RI_INIT_P2PTYPE_READ_REQ ?
911 MPA_V2_RDMA_READ_RTR : 0) : 0));
912 memcpy(mpa->private_data, &mpa_v2_params,
913 sizeof(struct mpa_v2_conn_params));
916 memcpy(mpa->private_data +
917 sizeof(struct mpa_v2_conn_params), pdata, plen);
920 memcpy(mpa->private_data, pdata, plen);
923 * Reference the mpa skb again. This ensures the data area
924 * will remain in memory until the hw acks the tx.
925 * Function fw4_ack() will deref it.
928 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
929 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
932 ep->snd_seq += mpalen;
933 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
936 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
939 struct fw_ofld_tx_data_wr *req;
940 struct mpa_message *mpa;
942 struct mpa_v2_conn_params mpa_v2_params;
944 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
946 mpalen = sizeof(*mpa) + plen;
947 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
948 mpalen += sizeof(struct mpa_v2_conn_params);
949 wrlen = roundup(mpalen + sizeof *req, 16);
951 skb = get_skb(NULL, wrlen, GFP_KERNEL);
953 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
956 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
958 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
959 memset(req, 0, wrlen);
960 req->op_to_immdlen = cpu_to_be32(
961 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
963 FW_WR_IMMDLEN(mpalen));
964 req->flowid_len16 = cpu_to_be32(
965 FW_WR_FLOWID(ep->hwtid) |
966 FW_WR_LEN16(wrlen >> 4));
967 req->plen = cpu_to_be32(mpalen);
968 req->tunnel_to_proxy = cpu_to_be32(
969 FW_OFLD_TX_DATA_WR_FLUSH(1) |
970 FW_OFLD_TX_DATA_WR_SHOVE(1));
972 mpa = (struct mpa_message *)(req + 1);
973 memset(mpa, 0, sizeof(*mpa));
974 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
975 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
976 (markers_enabled ? MPA_MARKERS : 0);
977 mpa->revision = ep->mpa_attr.version;
978 mpa->private_data_size = htons(plen);
980 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
981 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
982 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
983 sizeof (struct mpa_v2_conn_params));
984 mpa_v2_params.ird = htons((u16)ep->ird);
985 mpa_v2_params.ord = htons((u16)ep->ord);
986 if (peer2peer && (ep->mpa_attr.p2p_type !=
987 FW_RI_INIT_P2PTYPE_DISABLED)) {
988 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
990 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
992 htons(MPA_V2_RDMA_WRITE_RTR);
993 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
995 htons(MPA_V2_RDMA_READ_RTR);
998 memcpy(mpa->private_data, &mpa_v2_params,
999 sizeof(struct mpa_v2_conn_params));
1002 memcpy(mpa->private_data +
1003 sizeof(struct mpa_v2_conn_params), pdata, plen);
1006 memcpy(mpa->private_data, pdata, plen);
1009 * Reference the mpa skb. This ensures the data area
1010 * will remain in memory until the hw acks the tx.
1011 * Function fw4_ack() will deref it.
1014 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1016 __state_set(&ep->com, MPA_REP_SENT);
1017 ep->snd_seq += mpalen;
1018 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1021 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1024 struct cpl_act_establish *req = cplhdr(skb);
1025 unsigned int tid = GET_TID(req);
1026 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
1027 struct tid_info *t = dev->rdev.lldi.tids;
1029 ep = lookup_atid(t, atid);
1031 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1032 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1034 mutex_lock(&ep->com.mutex);
1035 dst_confirm(ep->dst);
1037 /* setup the hwtid for this connection */
1039 cxgb4_insert_tid(t, ep, tid);
1040 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
1042 ep->snd_seq = be32_to_cpu(req->snd_isn);
1043 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1045 set_emss(ep, ntohs(req->tcp_opt));
1047 /* dealloc the atid */
1048 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1049 cxgb4_free_atid(t, atid);
1050 set_bit(ACT_ESTAB, &ep->com.history);
1052 /* start MPA negotiation */
1053 send_flowc(ep, NULL);
1054 if (ep->retry_with_mpa_v1)
1055 send_mpa_req(ep, skb, 1);
1057 send_mpa_req(ep, skb, mpa_rev);
1058 mutex_unlock(&ep->com.mutex);
1062 static void close_complete_upcall(struct c4iw_ep *ep, int status)
1064 struct iw_cm_event event;
1066 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1067 memset(&event, 0, sizeof(event));
1068 event.event = IW_CM_EVENT_CLOSE;
1069 event.status = status;
1070 if (ep->com.cm_id) {
1071 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1072 ep, ep->com.cm_id, ep->hwtid);
1073 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1074 ep->com.cm_id->rem_ref(ep->com.cm_id);
1075 ep->com.cm_id = NULL;
1076 set_bit(CLOSE_UPCALL, &ep->com.history);
1080 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1082 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1083 __state_set(&ep->com, ABORTING);
1084 set_bit(ABORT_CONN, &ep->com.history);
1085 return send_abort(ep, skb, gfp);
1088 static void peer_close_upcall(struct c4iw_ep *ep)
1090 struct iw_cm_event event;
1092 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1093 memset(&event, 0, sizeof(event));
1094 event.event = IW_CM_EVENT_DISCONNECT;
1095 if (ep->com.cm_id) {
1096 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1097 ep, ep->com.cm_id, ep->hwtid);
1098 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1099 set_bit(DISCONN_UPCALL, &ep->com.history);
1103 static void peer_abort_upcall(struct c4iw_ep *ep)
1105 struct iw_cm_event event;
1107 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1108 memset(&event, 0, sizeof(event));
1109 event.event = IW_CM_EVENT_CLOSE;
1110 event.status = -ECONNRESET;
1111 if (ep->com.cm_id) {
1112 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1113 ep->com.cm_id, ep->hwtid);
1114 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1115 ep->com.cm_id->rem_ref(ep->com.cm_id);
1116 ep->com.cm_id = NULL;
1117 set_bit(ABORT_UPCALL, &ep->com.history);
1121 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1123 struct iw_cm_event event;
1125 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1126 memset(&event, 0, sizeof(event));
1127 event.event = IW_CM_EVENT_CONNECT_REPLY;
1128 event.status = status;
1129 memcpy(&event.local_addr, &ep->com.local_addr,
1130 sizeof(ep->com.local_addr));
1131 memcpy(&event.remote_addr, &ep->com.remote_addr,
1132 sizeof(ep->com.remote_addr));
1134 if ((status == 0) || (status == -ECONNREFUSED)) {
1135 if (!ep->tried_with_mpa_v1) {
1136 /* this means MPA_v2 is used */
1137 event.private_data_len = ep->plen -
1138 sizeof(struct mpa_v2_conn_params);
1139 event.private_data = ep->mpa_pkt +
1140 sizeof(struct mpa_message) +
1141 sizeof(struct mpa_v2_conn_params);
1143 /* this means MPA_v1 is used */
1144 event.private_data_len = ep->plen;
1145 event.private_data = ep->mpa_pkt +
1146 sizeof(struct mpa_message);
1150 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1152 set_bit(CONN_RPL_UPCALL, &ep->com.history);
1153 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1156 ep->com.cm_id->rem_ref(ep->com.cm_id);
1157 ep->com.cm_id = NULL;
1161 static int connect_request_upcall(struct c4iw_ep *ep)
1163 struct iw_cm_event event;
1166 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1167 memset(&event, 0, sizeof(event));
1168 event.event = IW_CM_EVENT_CONNECT_REQUEST;
1169 memcpy(&event.local_addr, &ep->com.local_addr,
1170 sizeof(ep->com.local_addr));
1171 memcpy(&event.remote_addr, &ep->com.remote_addr,
1172 sizeof(ep->com.remote_addr));
1173 event.provider_data = ep;
1174 if (!ep->tried_with_mpa_v1) {
1175 /* this means MPA_v2 is used */
1176 event.ord = ep->ord;
1177 event.ird = ep->ird;
1178 event.private_data_len = ep->plen -
1179 sizeof(struct mpa_v2_conn_params);
1180 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1181 sizeof(struct mpa_v2_conn_params);
1183 /* this means MPA_v1 is used. Send max supported */
1184 event.ord = c4iw_max_read_depth;
1185 event.ird = c4iw_max_read_depth;
1186 event.private_data_len = ep->plen;
1187 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1189 c4iw_get_ep(&ep->com);
1190 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1193 c4iw_put_ep(&ep->com);
1194 set_bit(CONNREQ_UPCALL, &ep->com.history);
1195 c4iw_put_ep(&ep->parent_ep->com);
1199 static void established_upcall(struct c4iw_ep *ep)
1201 struct iw_cm_event event;
1203 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1204 memset(&event, 0, sizeof(event));
1205 event.event = IW_CM_EVENT_ESTABLISHED;
1206 event.ird = ep->ird;
1207 event.ord = ep->ord;
1208 if (ep->com.cm_id) {
1209 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1210 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1211 set_bit(ESTAB_UPCALL, &ep->com.history);
1215 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1217 struct cpl_rx_data_ack *req;
1218 struct sk_buff *skb;
1219 int wrlen = roundup(sizeof *req, 16);
1221 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1222 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1224 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1229 * If we couldn't specify the entire rcv window at connection setup
1230 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1231 * then add the overage in to the credits returned.
1233 if (ep->rcv_win > RCV_BUFSIZ_MASK * 1024)
1234 credits += ep->rcv_win - RCV_BUFSIZ_MASK * 1024;
1236 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1237 memset(req, 0, wrlen);
1238 INIT_TP_WR(req, ep->hwtid);
1239 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1241 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1243 V_RX_DACK_MODE(dack_mode));
1244 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1245 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1249 static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1251 struct mpa_message *mpa;
1252 struct mpa_v2_conn_params *mpa_v2_params;
1254 u16 resp_ird, resp_ord;
1255 u8 rtr_mismatch = 0, insuff_ird = 0;
1256 struct c4iw_qp_attributes attrs;
1257 enum c4iw_qp_attr_mask mask;
1261 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1264 * Stop mpa timer. If it expired, then
1265 * we ignore the MPA reply. process_timeout()
1266 * will abort the connection.
1268 if (stop_ep_timer(ep))
1272 * If we get more than the supported amount of private data
1273 * then we must fail this connection.
1275 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1281 * copy the new data into our accumulation buffer.
1283 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1285 ep->mpa_pkt_len += skb->len;
1288 * if we don't even have the mpa message, then bail.
1290 if (ep->mpa_pkt_len < sizeof(*mpa))
1292 mpa = (struct mpa_message *) ep->mpa_pkt;
1294 /* Validate MPA header. */
1295 if (mpa->revision > mpa_rev) {
1296 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1297 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1301 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1306 plen = ntohs(mpa->private_data_size);
1309 * Fail if there's too much private data.
1311 if (plen > MPA_MAX_PRIVATE_DATA) {
1317 * If plen does not account for pkt size
1319 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1324 ep->plen = (u8) plen;
1327 * If we don't have all the pdata yet, then bail.
1328 * We'll continue process when more data arrives.
1330 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1333 if (mpa->flags & MPA_REJECT) {
1334 err = -ECONNREFUSED;
1339 * If we get here we have accumulated the entire mpa
1340 * start reply message including private data. And
1341 * the MPA header is valid.
1343 __state_set(&ep->com, FPDU_MODE);
1344 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1345 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1346 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1347 ep->mpa_attr.version = mpa->revision;
1348 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1350 if (mpa->revision == 2) {
1351 ep->mpa_attr.enhanced_rdma_conn =
1352 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1353 if (ep->mpa_attr.enhanced_rdma_conn) {
1354 mpa_v2_params = (struct mpa_v2_conn_params *)
1355 (ep->mpa_pkt + sizeof(*mpa));
1356 resp_ird = ntohs(mpa_v2_params->ird) &
1357 MPA_V2_IRD_ORD_MASK;
1358 resp_ord = ntohs(mpa_v2_params->ord) &
1359 MPA_V2_IRD_ORD_MASK;
1362 * This is a double-check. Ideally, below checks are
1363 * not required since ird/ord stuff has been taken
1364 * care of in c4iw_accept_cr
1366 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1373 if (ntohs(mpa_v2_params->ird) &
1374 MPA_V2_PEER2PEER_MODEL) {
1375 if (ntohs(mpa_v2_params->ord) &
1376 MPA_V2_RDMA_WRITE_RTR)
1377 ep->mpa_attr.p2p_type =
1378 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1379 else if (ntohs(mpa_v2_params->ord) &
1380 MPA_V2_RDMA_READ_RTR)
1381 ep->mpa_attr.p2p_type =
1382 FW_RI_INIT_P2PTYPE_READ_REQ;
1385 } else if (mpa->revision == 1)
1387 ep->mpa_attr.p2p_type = p2p_type;
1389 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1390 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1391 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1392 ep->mpa_attr.recv_marker_enabled,
1393 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1394 ep->mpa_attr.p2p_type, p2p_type);
1397 * If responder's RTR does not match with that of initiator, assign
1398 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1399 * generated when moving QP to RTS state.
1400 * A TERM message will be sent after QP has moved to RTS state
1402 if ((ep->mpa_attr.version == 2) && peer2peer &&
1403 (ep->mpa_attr.p2p_type != p2p_type)) {
1404 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1408 attrs.mpa_attr = ep->mpa_attr;
1409 attrs.max_ird = ep->ird;
1410 attrs.max_ord = ep->ord;
1411 attrs.llp_stream_handle = ep;
1412 attrs.next_state = C4IW_QP_STATE_RTS;
1414 mask = C4IW_QP_ATTR_NEXT_STATE |
1415 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1416 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1418 /* bind QP and TID with INIT_WR */
1419 err = c4iw_modify_qp(ep->com.qp->rhp,
1420 ep->com.qp, mask, &attrs, 1);
1425 * If responder's RTR requirement did not match with what initiator
1426 * supports, generate TERM message
1429 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1430 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1431 attrs.ecode = MPA_NOMATCH_RTR;
1432 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1433 attrs.send_term = 1;
1434 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1435 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1442 * Generate TERM if initiator IRD is not sufficient for responder
1443 * provided ORD. Currently, we do the same behaviour even when
1444 * responder provided IRD is also not sufficient as regards to
1448 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1450 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1451 attrs.ecode = MPA_INSUFF_IRD;
1452 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1453 attrs.send_term = 1;
1454 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1455 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1462 __state_set(&ep->com, ABORTING);
1463 send_abort(ep, skb, GFP_KERNEL);
1465 connect_reply_upcall(ep, err);
1469 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1471 struct mpa_message *mpa;
1472 struct mpa_v2_conn_params *mpa_v2_params;
1475 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1478 * If we get more than the supported amount of private data
1479 * then we must fail this connection.
1481 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1482 (void)stop_ep_timer(ep);
1483 abort_connection(ep, skb, GFP_KERNEL);
1487 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1490 * Copy the new data into our accumulation buffer.
1492 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1494 ep->mpa_pkt_len += skb->len;
1497 * If we don't even have the mpa message, then bail.
1498 * We'll continue process when more data arrives.
1500 if (ep->mpa_pkt_len < sizeof(*mpa))
1503 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1504 mpa = (struct mpa_message *) ep->mpa_pkt;
1507 * Validate MPA Header.
1509 if (mpa->revision > mpa_rev) {
1510 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1511 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1512 (void)stop_ep_timer(ep);
1513 abort_connection(ep, skb, GFP_KERNEL);
1517 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1518 (void)stop_ep_timer(ep);
1519 abort_connection(ep, skb, GFP_KERNEL);
1523 plen = ntohs(mpa->private_data_size);
1526 * Fail if there's too much private data.
1528 if (plen > MPA_MAX_PRIVATE_DATA) {
1529 (void)stop_ep_timer(ep);
1530 abort_connection(ep, skb, GFP_KERNEL);
1535 * If plen does not account for pkt size
1537 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1538 (void)stop_ep_timer(ep);
1539 abort_connection(ep, skb, GFP_KERNEL);
1542 ep->plen = (u8) plen;
1545 * If we don't have all the pdata yet, then bail.
1547 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1551 * If we get here we have accumulated the entire mpa
1552 * start reply message including private data.
1554 ep->mpa_attr.initiator = 0;
1555 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1556 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1557 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1558 ep->mpa_attr.version = mpa->revision;
1559 if (mpa->revision == 1)
1560 ep->tried_with_mpa_v1 = 1;
1561 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1563 if (mpa->revision == 2) {
1564 ep->mpa_attr.enhanced_rdma_conn =
1565 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1566 if (ep->mpa_attr.enhanced_rdma_conn) {
1567 mpa_v2_params = (struct mpa_v2_conn_params *)
1568 (ep->mpa_pkt + sizeof(*mpa));
1569 ep->ird = ntohs(mpa_v2_params->ird) &
1570 MPA_V2_IRD_ORD_MASK;
1571 ep->ord = ntohs(mpa_v2_params->ord) &
1572 MPA_V2_IRD_ORD_MASK;
1573 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1575 if (ntohs(mpa_v2_params->ord) &
1576 MPA_V2_RDMA_WRITE_RTR)
1577 ep->mpa_attr.p2p_type =
1578 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1579 else if (ntohs(mpa_v2_params->ord) &
1580 MPA_V2_RDMA_READ_RTR)
1581 ep->mpa_attr.p2p_type =
1582 FW_RI_INIT_P2PTYPE_READ_REQ;
1585 } else if (mpa->revision == 1)
1587 ep->mpa_attr.p2p_type = p2p_type;
1589 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1590 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1591 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1592 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1593 ep->mpa_attr.p2p_type);
1596 * If the endpoint timer already expired, then we ignore
1597 * the start request. process_timeout() will abort
1600 if (!stop_ep_timer(ep)) {
1601 __state_set(&ep->com, MPA_REQ_RCVD);
1604 mutex_lock(&ep->parent_ep->com.mutex);
1605 if (ep->parent_ep->com.state != DEAD) {
1606 if (connect_request_upcall(ep))
1607 abort_connection(ep, skb, GFP_KERNEL);
1609 abort_connection(ep, skb, GFP_KERNEL);
1611 mutex_unlock(&ep->parent_ep->com.mutex);
1616 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1619 struct cpl_rx_data *hdr = cplhdr(skb);
1620 unsigned int dlen = ntohs(hdr->len);
1621 unsigned int tid = GET_TID(hdr);
1622 struct tid_info *t = dev->rdev.lldi.tids;
1623 __u8 status = hdr->status;
1626 ep = lookup_tid(t, tid);
1629 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1630 skb_pull(skb, sizeof(*hdr));
1631 skb_trim(skb, dlen);
1632 mutex_lock(&ep->com.mutex);
1634 /* update RX credits */
1635 update_rx_credits(ep, dlen);
1637 switch (ep->com.state) {
1639 ep->rcv_seq += dlen;
1640 disconnect = process_mpa_reply(ep, skb);
1643 ep->rcv_seq += dlen;
1644 process_mpa_request(ep, skb);
1647 struct c4iw_qp_attributes attrs;
1648 BUG_ON(!ep->com.qp);
1650 pr_err("%s Unexpected streaming data." \
1651 " qpid %u ep %p state %d tid %u status %d\n",
1652 __func__, ep->com.qp->wq.sq.qid, ep,
1653 ep->com.state, ep->hwtid, status);
1654 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1655 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1656 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1663 mutex_unlock(&ep->com.mutex);
1665 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1669 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1672 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1674 unsigned int tid = GET_TID(rpl);
1675 struct tid_info *t = dev->rdev.lldi.tids;
1677 ep = lookup_tid(t, tid);
1679 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1682 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1683 mutex_lock(&ep->com.mutex);
1684 switch (ep->com.state) {
1686 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1687 __state_set(&ep->com, DEAD);
1691 printk(KERN_ERR "%s ep %p state %d\n",
1692 __func__, ep, ep->com.state);
1695 mutex_unlock(&ep->com.mutex);
1698 release_ep_resources(ep);
1702 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1704 struct sk_buff *skb;
1705 struct fw_ofld_connection_wr *req;
1706 unsigned int mtu_idx;
1708 struct sockaddr_in *sin;
1711 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1712 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1713 memset(req, 0, sizeof(*req));
1714 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1715 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1716 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1717 ep->com.dev->rdev.lldi.ports[0],
1719 sin = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1720 req->le.lport = sin->sin_port;
1721 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1722 sin = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1723 req->le.pport = sin->sin_port;
1724 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
1725 req->tcb.t_state_to_astid =
1726 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1727 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1728 req->tcb.cplrxdataack_cplpassacceptrpl =
1729 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1730 req->tcb.tx_max = (__force __be32) jiffies;
1731 req->tcb.rcv_adv = htons(1);
1732 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1733 enable_tcp_timestamps);
1734 wscale = compute_wscale(rcv_win);
1737 * Specify the largest window that will fit in opt0. The
1738 * remainder will be specified in the rx_data_ack.
1740 win = ep->rcv_win >> 10;
1741 if (win > RCV_BUFSIZ_MASK)
1742 win = RCV_BUFSIZ_MASK;
1744 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
1745 (nocong ? NO_CONG(1) : 0) |
1750 L2T_IDX(ep->l2t->idx) |
1751 TX_CHAN(ep->tx_chan) |
1752 SMAC_SEL(ep->smac_idx) |
1754 ULP_MODE(ULP_MODE_TCPDDP) |
1756 req->tcb.opt2 = (__force __be32) (PACE(1) |
1757 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1759 CCTRL_ECN(enable_ecn) |
1760 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
1761 if (enable_tcp_timestamps)
1762 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
1763 if (enable_tcp_sack)
1764 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
1765 if (wscale && enable_tcp_window_scaling)
1766 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1767 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1768 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
1769 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1770 set_bit(ACT_OFLD_CONN, &ep->com.history);
1771 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1775 * Return whether a failed active open has allocated a TID
1777 static inline int act_open_has_tid(int status)
1779 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1780 status != CPL_ERR_ARP_MISS;
1783 /* Returns whether a CPL status conveys negative advice.
1785 static int is_neg_adv(unsigned int status)
1787 return status == CPL_ERR_RTX_NEG_ADVICE ||
1788 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1789 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1792 static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1794 ep->snd_win = snd_win;
1795 ep->rcv_win = rcv_win;
1796 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1799 #define ACT_OPEN_RETRY_COUNT 2
1801 static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1802 struct dst_entry *dst, struct c4iw_dev *cdev,
1805 struct neighbour *n;
1807 struct net_device *pdev;
1809 n = dst_neigh_lookup(dst, peer_ip);
1815 if (n->dev->flags & IFF_LOOPBACK) {
1817 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1818 else if (IS_ENABLED(CONFIG_IPV6))
1819 for_each_netdev(&init_net, pdev) {
1820 if (ipv6_chk_addr(&init_net,
1821 (struct in6_addr *)peer_ip,
1832 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1836 ep->mtu = pdev->mtu;
1837 ep->tx_chan = cxgb4_port_chan(pdev);
1838 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1839 step = cdev->rdev.lldi.ntxq /
1840 cdev->rdev.lldi.nchan;
1841 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1842 step = cdev->rdev.lldi.nrxq /
1843 cdev->rdev.lldi.nchan;
1844 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1845 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1846 cxgb4_port_idx(pdev) * step];
1847 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
1850 pdev = get_real_dev(n->dev);
1851 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1855 ep->mtu = dst_mtu(dst);
1856 ep->tx_chan = cxgb4_port_chan(pdev);
1857 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1858 step = cdev->rdev.lldi.ntxq /
1859 cdev->rdev.lldi.nchan;
1860 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1861 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1862 step = cdev->rdev.lldi.nrxq /
1863 cdev->rdev.lldi.nchan;
1864 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1865 cxgb4_port_idx(pdev) * step];
1866 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
1869 ep->retry_with_mpa_v1 = 0;
1870 ep->tried_with_mpa_v1 = 0;
1882 static int c4iw_reconnect(struct c4iw_ep *ep)
1885 struct sockaddr_in *laddr = (struct sockaddr_in *)
1886 &ep->com.cm_id->local_addr;
1887 struct sockaddr_in *raddr = (struct sockaddr_in *)
1888 &ep->com.cm_id->remote_addr;
1889 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1890 &ep->com.cm_id->local_addr;
1891 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1892 &ep->com.cm_id->remote_addr;
1896 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1897 init_timer(&ep->timer);
1900 * Allocate an active TID to initiate a TCP connection.
1902 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1903 if (ep->atid == -1) {
1904 pr_err("%s - cannot alloc atid.\n", __func__);
1908 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1911 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1912 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1913 raddr->sin_addr.s_addr, laddr->sin_port,
1914 raddr->sin_port, 0);
1916 ra = (__u8 *)&raddr->sin_addr;
1918 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1919 raddr6->sin6_addr.s6_addr,
1920 laddr6->sin6_port, raddr6->sin6_port, 0,
1921 raddr6->sin6_scope_id);
1923 ra = (__u8 *)&raddr6->sin6_addr;
1926 pr_err("%s - cannot find route.\n", __func__);
1927 err = -EHOSTUNREACH;
1930 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1932 pr_err("%s - cannot alloc l2e.\n", __func__);
1936 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1937 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1940 state_set(&ep->com, CONNECTING);
1943 /* send connect request to rnic */
1944 err = send_connect(ep);
1948 cxgb4_l2t_release(ep->l2t);
1950 dst_release(ep->dst);
1952 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1953 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1956 * remember to send notification to upper layer.
1957 * We are in here so the upper layer is not aware that this is
1958 * re-connect attempt and so, upper layer is still waiting for
1959 * response of 1st connect request.
1961 connect_reply_upcall(ep, -ECONNRESET);
1962 c4iw_put_ep(&ep->com);
1967 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1970 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1971 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1972 ntohl(rpl->atid_status)));
1973 struct tid_info *t = dev->rdev.lldi.tids;
1974 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1975 struct sockaddr_in *la;
1976 struct sockaddr_in *ra;
1977 struct sockaddr_in6 *la6;
1978 struct sockaddr_in6 *ra6;
1980 ep = lookup_atid(t, atid);
1981 la = (struct sockaddr_in *)&ep->com.mapped_local_addr;
1982 ra = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
1983 la6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
1984 ra6 = (struct sockaddr_in6 *)&ep->com.mapped_remote_addr;
1986 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1987 status, status2errno(status));
1989 if (is_neg_adv(status)) {
1990 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1995 set_bit(ACT_OPEN_RPL, &ep->com.history);
1998 * Log interesting failures.
2001 case CPL_ERR_CONN_RESET:
2002 case CPL_ERR_CONN_TIMEDOUT:
2004 case CPL_ERR_TCAM_FULL:
2005 mutex_lock(&dev->rdev.stats.lock);
2006 dev->rdev.stats.tcam_full++;
2007 mutex_unlock(&dev->rdev.stats.lock);
2008 if (ep->com.local_addr.ss_family == AF_INET &&
2009 dev->rdev.lldi.enable_fw_ofld_conn) {
2010 send_fw_act_open_req(ep,
2011 GET_TID_TID(GET_AOPEN_ATID(
2012 ntohl(rpl->atid_status))));
2016 case CPL_ERR_CONN_EXIST:
2017 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2018 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2019 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2021 cxgb4_free_atid(t, atid);
2022 dst_release(ep->dst);
2023 cxgb4_l2t_release(ep->l2t);
2029 if (ep->com.local_addr.ss_family == AF_INET) {
2030 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2031 atid, status, status2errno(status),
2032 &la->sin_addr.s_addr, ntohs(la->sin_port),
2033 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2035 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2036 atid, status, status2errno(status),
2037 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2038 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2043 connect_reply_upcall(ep, status2errno(status));
2044 state_set(&ep->com, DEAD);
2046 if (status && act_open_has_tid(status))
2047 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2049 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
2050 cxgb4_free_atid(t, atid);
2051 dst_release(ep->dst);
2052 cxgb4_l2t_release(ep->l2t);
2053 c4iw_put_ep(&ep->com);
2058 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2060 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2061 struct tid_info *t = dev->rdev.lldi.tids;
2062 unsigned int stid = GET_TID(rpl);
2063 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2066 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2069 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2070 rpl->status, status2errno(rpl->status));
2071 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2077 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2079 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2080 struct tid_info *t = dev->rdev.lldi.tids;
2081 unsigned int stid = GET_TID(rpl);
2082 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2084 PDBG("%s ep %p\n", __func__, ep);
2085 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
2089 static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2090 struct cpl_pass_accept_req *req)
2092 struct cpl_pass_accept_rpl *rpl;
2093 unsigned int mtu_idx;
2097 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
2100 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2101 BUG_ON(skb_cloned(skb));
2105 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2106 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2108 INIT_TP_WR(rpl5, ep->hwtid);
2110 skb_trim(skb, sizeof(*rpl));
2111 INIT_TP_WR(rpl, ep->hwtid);
2113 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2116 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2117 enable_tcp_timestamps && req->tcpopt.tstamp);
2118 wscale = compute_wscale(rcv_win);
2121 * Specify the largest window that will fit in opt0. The
2122 * remainder will be specified in the rx_data_ack.
2124 win = ep->rcv_win >> 10;
2125 if (win > RCV_BUFSIZ_MASK)
2126 win = RCV_BUFSIZ_MASK;
2127 opt0 = (nocong ? NO_CONG(1) : 0) |
2132 L2T_IDX(ep->l2t->idx) |
2133 TX_CHAN(ep->tx_chan) |
2134 SMAC_SEL(ep->smac_idx) |
2135 DSCP(ep->tos >> 2) |
2136 ULP_MODE(ULP_MODE_TCPDDP) |
2138 opt2 = RX_CHANNEL(0) |
2139 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2141 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2142 opt2 |= TSTAMPS_EN(1);
2143 if (enable_tcp_sack && req->tcpopt.sack)
2145 if (wscale && enable_tcp_window_scaling)
2146 opt2 |= WND_SCALE_EN(1);
2148 const struct tcphdr *tcph;
2149 u32 hlen = ntohl(req->hdr_len);
2151 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2153 if (tcph->ece && tcph->cwr)
2154 opt2 |= CCTRL_ECN(1);
2156 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
2157 u32 isn = (prandom_u32() & ~7UL) - 1;
2158 opt2 |= T5_OPT_2_VALID;
2159 opt2 |= V_CONG_CNTRL(CONG_ALG_TAHOE);
2160 opt2 |= CONG_CNTRL_VALID; /* OPT_2_ISS for T5 */
2162 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2165 rpl5->iss = cpu_to_be32(isn);
2166 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
2169 rpl->opt0 = cpu_to_be64(opt0);
2170 rpl->opt2 = cpu_to_be32(opt2);
2171 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
2172 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
2173 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2178 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
2180 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
2181 BUG_ON(skb_cloned(skb));
2182 skb_trim(skb, sizeof(struct cpl_tid_release));
2184 release_tid(&dev->rdev, hwtid, skb);
2188 static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2189 __u8 *local_ip, __u8 *peer_ip,
2190 __be16 *local_port, __be16 *peer_port)
2192 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2193 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2194 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
2195 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
2196 struct tcphdr *tcp = (struct tcphdr *)
2197 ((u8 *)(req + 1) + eth_len + ip_len);
2199 if (ip->version == 4) {
2200 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2201 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2204 memcpy(peer_ip, &ip->saddr, 4);
2205 memcpy(local_ip, &ip->daddr, 4);
2207 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2208 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2211 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2212 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2214 *peer_port = tcp->source;
2215 *local_port = tcp->dest;
2220 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2222 struct c4iw_ep *child_ep = NULL, *parent_ep;
2223 struct cpl_pass_accept_req *req = cplhdr(skb);
2224 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2225 struct tid_info *t = dev->rdev.lldi.tids;
2226 unsigned int hwtid = GET_TID(req);
2227 struct dst_entry *dst;
2228 __u8 local_ip[16], peer_ip[16];
2229 __be16 local_port, peer_port;
2231 u16 peer_mss = ntohs(req->tcpopt.mss);
2233 unsigned short hdrs;
2235 parent_ep = lookup_stid(t, stid);
2237 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2241 if (state_read(&parent_ep->com) != LISTEN) {
2242 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2247 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2249 /* Find output route */
2251 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2252 , __func__, parent_ep, hwtid,
2253 local_ip, peer_ip, ntohs(local_port),
2254 ntohs(peer_port), peer_mss);
2255 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2256 local_port, peer_port,
2257 GET_POPEN_TOS(ntohl(req->tos_stid)));
2259 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2260 , __func__, parent_ep, hwtid,
2261 local_ip, peer_ip, ntohs(local_port),
2262 ntohs(peer_port), peer_mss);
2263 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2264 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2265 ((struct sockaddr_in6 *)
2266 &parent_ep->com.local_addr)->sin6_scope_id);
2269 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2274 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2276 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2282 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
2284 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2291 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2292 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2293 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2294 child_ep->mtu = peer_mss + hdrs;
2296 state_set(&child_ep->com, CONNECTING);
2297 child_ep->com.dev = dev;
2298 child_ep->com.cm_id = NULL;
2300 struct sockaddr_in *sin = (struct sockaddr_in *)
2301 &child_ep->com.local_addr;
2302 sin->sin_family = PF_INET;
2303 sin->sin_port = local_port;
2304 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2305 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2306 sin->sin_family = PF_INET;
2307 sin->sin_port = peer_port;
2308 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2310 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2311 &child_ep->com.local_addr;
2312 sin6->sin6_family = PF_INET6;
2313 sin6->sin6_port = local_port;
2314 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2315 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2316 sin6->sin6_family = PF_INET6;
2317 sin6->sin6_port = peer_port;
2318 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2320 c4iw_get_ep(&parent_ep->com);
2321 child_ep->parent_ep = parent_ep;
2322 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
2323 child_ep->dst = dst;
2324 child_ep->hwtid = hwtid;
2326 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2327 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2329 init_timer(&child_ep->timer);
2330 cxgb4_insert_tid(t, child_ep, hwtid);
2331 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2332 accept_cr(child_ep, skb, req);
2333 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2336 reject_cr(dev, hwtid, skb);
2341 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2344 struct cpl_pass_establish *req = cplhdr(skb);
2345 struct tid_info *t = dev->rdev.lldi.tids;
2346 unsigned int tid = GET_TID(req);
2348 ep = lookup_tid(t, tid);
2349 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2350 ep->snd_seq = be32_to_cpu(req->snd_isn);
2351 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2353 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2354 ntohs(req->tcp_opt));
2356 set_emss(ep, ntohs(req->tcp_opt));
2358 dst_confirm(ep->dst);
2359 state_set(&ep->com, MPA_REQ_WAIT);
2361 send_flowc(ep, skb);
2362 set_bit(PASS_ESTAB, &ep->com.history);
2367 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2369 struct cpl_peer_close *hdr = cplhdr(skb);
2371 struct c4iw_qp_attributes attrs;
2374 struct tid_info *t = dev->rdev.lldi.tids;
2375 unsigned int tid = GET_TID(hdr);
2378 ep = lookup_tid(t, tid);
2379 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2380 dst_confirm(ep->dst);
2382 set_bit(PEER_CLOSE, &ep->com.history);
2383 mutex_lock(&ep->com.mutex);
2384 switch (ep->com.state) {
2386 __state_set(&ep->com, CLOSING);
2389 __state_set(&ep->com, CLOSING);
2390 connect_reply_upcall(ep, -ECONNRESET);
2395 * We're gonna mark this puppy DEAD, but keep
2396 * the reference on it until the ULP accepts or
2397 * rejects the CR. Also wake up anyone waiting
2398 * in rdma connection migration (see c4iw_accept_cr()).
2400 __state_set(&ep->com, CLOSING);
2401 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2402 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2405 __state_set(&ep->com, CLOSING);
2406 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2407 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2411 __state_set(&ep->com, CLOSING);
2412 attrs.next_state = C4IW_QP_STATE_CLOSING;
2413 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2414 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2415 if (ret != -ECONNRESET) {
2416 peer_close_upcall(ep);
2424 __state_set(&ep->com, MORIBUND);
2428 (void)stop_ep_timer(ep);
2429 if (ep->com.cm_id && ep->com.qp) {
2430 attrs.next_state = C4IW_QP_STATE_IDLE;
2431 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2432 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2434 close_complete_upcall(ep, 0);
2435 __state_set(&ep->com, DEAD);
2445 mutex_unlock(&ep->com.mutex);
2447 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2449 release_ep_resources(ep);
2453 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2455 struct cpl_abort_req_rss *req = cplhdr(skb);
2457 struct cpl_abort_rpl *rpl;
2458 struct sk_buff *rpl_skb;
2459 struct c4iw_qp_attributes attrs;
2462 struct tid_info *t = dev->rdev.lldi.tids;
2463 unsigned int tid = GET_TID(req);
2465 ep = lookup_tid(t, tid);
2466 if (is_neg_adv(req->status)) {
2467 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2471 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2473 set_bit(PEER_ABORT, &ep->com.history);
2476 * Wake up any threads in rdma_init() or rdma_fini().
2477 * However, this is not needed if com state is just
2480 if (ep->com.state != MPA_REQ_SENT)
2481 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2483 mutex_lock(&ep->com.mutex);
2484 switch (ep->com.state) {
2488 (void)stop_ep_timer(ep);
2491 (void)stop_ep_timer(ep);
2492 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2493 connect_reply_upcall(ep, -ECONNRESET);
2496 * we just don't send notification upwards because we
2497 * want to retry with mpa_v1 without upper layers even
2500 * do some housekeeping so as to re-initiate the
2503 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2505 ep->retry_with_mpa_v1 = 1;
2517 if (ep->com.cm_id && ep->com.qp) {
2518 attrs.next_state = C4IW_QP_STATE_ERROR;
2519 ret = c4iw_modify_qp(ep->com.qp->rhp,
2520 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2524 "%s - qp <- error failed!\n",
2527 peer_abort_upcall(ep);
2532 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2533 mutex_unlock(&ep->com.mutex);
2539 dst_confirm(ep->dst);
2540 if (ep->com.state != ABORTING) {
2541 __state_set(&ep->com, DEAD);
2542 /* we don't release if we want to retry with mpa_v1 */
2543 if (!ep->retry_with_mpa_v1)
2546 mutex_unlock(&ep->com.mutex);
2548 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2550 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2555 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2556 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2557 INIT_TP_WR(rpl, ep->hwtid);
2558 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2559 rpl->cmd = CPL_ABORT_NO_RST;
2560 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2563 release_ep_resources(ep);
2564 else if (ep->retry_with_mpa_v1) {
2565 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2566 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2567 dst_release(ep->dst);
2568 cxgb4_l2t_release(ep->l2t);
2575 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2578 struct c4iw_qp_attributes attrs;
2579 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2581 struct tid_info *t = dev->rdev.lldi.tids;
2582 unsigned int tid = GET_TID(rpl);
2584 ep = lookup_tid(t, tid);
2586 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2589 /* The cm_id may be null if we failed to connect */
2590 mutex_lock(&ep->com.mutex);
2591 switch (ep->com.state) {
2593 __state_set(&ep->com, MORIBUND);
2596 (void)stop_ep_timer(ep);
2597 if ((ep->com.cm_id) && (ep->com.qp)) {
2598 attrs.next_state = C4IW_QP_STATE_IDLE;
2599 c4iw_modify_qp(ep->com.qp->rhp,
2601 C4IW_QP_ATTR_NEXT_STATE,
2604 close_complete_upcall(ep, 0);
2605 __state_set(&ep->com, DEAD);
2615 mutex_unlock(&ep->com.mutex);
2617 release_ep_resources(ep);
2621 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2623 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2624 struct tid_info *t = dev->rdev.lldi.tids;
2625 unsigned int tid = GET_TID(rpl);
2627 struct c4iw_qp_attributes attrs;
2629 ep = lookup_tid(t, tid);
2632 if (ep && ep->com.qp) {
2633 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2634 ep->com.qp->wq.sq.qid);
2635 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2636 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2637 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2639 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2645 * Upcall from the adapter indicating data has been transmitted.
2646 * For us its just the single MPA request or reply. We can now free
2647 * the skb holding the mpa message.
2649 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2652 struct cpl_fw4_ack *hdr = cplhdr(skb);
2653 u8 credits = hdr->credits;
2654 unsigned int tid = GET_TID(hdr);
2655 struct tid_info *t = dev->rdev.lldi.tids;
2658 ep = lookup_tid(t, tid);
2659 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2661 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2662 __func__, ep, ep->hwtid, state_read(&ep->com));
2666 dst_confirm(ep->dst);
2668 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2669 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2670 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2671 kfree_skb(ep->mpa_skb);
2677 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2681 struct c4iw_ep *ep = to_ep(cm_id);
2682 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2684 mutex_lock(&ep->com.mutex);
2685 if (ep->com.state == DEAD) {
2686 mutex_unlock(&ep->com.mutex);
2687 c4iw_put_ep(&ep->com);
2690 set_bit(ULP_REJECT, &ep->com.history);
2691 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2693 abort_connection(ep, NULL, GFP_KERNEL);
2695 err = send_mpa_reject(ep, pdata, pdata_len);
2698 mutex_unlock(&ep->com.mutex);
2700 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2701 c4iw_put_ep(&ep->com);
2705 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2708 struct c4iw_qp_attributes attrs;
2709 enum c4iw_qp_attr_mask mask;
2710 struct c4iw_ep *ep = to_ep(cm_id);
2711 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2712 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2714 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2716 mutex_lock(&ep->com.mutex);
2717 if (ep->com.state == DEAD) {
2722 BUG_ON(ep->com.state != MPA_REQ_RCVD);
2725 set_bit(ULP_ACCEPT, &ep->com.history);
2726 if ((conn_param->ord > c4iw_max_read_depth) ||
2727 (conn_param->ird > c4iw_max_read_depth)) {
2728 abort_connection(ep, NULL, GFP_KERNEL);
2733 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2734 if (conn_param->ord > ep->ird) {
2735 ep->ird = conn_param->ird;
2736 ep->ord = conn_param->ord;
2737 send_mpa_reject(ep, conn_param->private_data,
2738 conn_param->private_data_len);
2739 abort_connection(ep, NULL, GFP_KERNEL);
2743 if (conn_param->ird > ep->ord) {
2745 conn_param->ird = 1;
2747 abort_connection(ep, NULL, GFP_KERNEL);
2754 ep->ird = conn_param->ird;
2755 ep->ord = conn_param->ord;
2757 if (ep->mpa_attr.version != 2)
2758 if (peer2peer && ep->ird == 0)
2761 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2763 cm_id->add_ref(cm_id);
2764 ep->com.cm_id = cm_id;
2768 /* bind QP to EP and move to RTS */
2769 attrs.mpa_attr = ep->mpa_attr;
2770 attrs.max_ird = ep->ird;
2771 attrs.max_ord = ep->ord;
2772 attrs.llp_stream_handle = ep;
2773 attrs.next_state = C4IW_QP_STATE_RTS;
2775 /* bind QP and TID with INIT_WR */
2776 mask = C4IW_QP_ATTR_NEXT_STATE |
2777 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2778 C4IW_QP_ATTR_MPA_ATTR |
2779 C4IW_QP_ATTR_MAX_IRD |
2780 C4IW_QP_ATTR_MAX_ORD;
2782 err = c4iw_modify_qp(ep->com.qp->rhp,
2783 ep->com.qp, mask, &attrs, 1);
2786 err = send_mpa_reply(ep, conn_param->private_data,
2787 conn_param->private_data_len);
2791 __state_set(&ep->com, FPDU_MODE);
2792 established_upcall(ep);
2793 mutex_unlock(&ep->com.mutex);
2794 c4iw_put_ep(&ep->com);
2797 ep->com.cm_id = NULL;
2798 cm_id->rem_ref(cm_id);
2800 mutex_unlock(&ep->com.mutex);
2801 c4iw_put_ep(&ep->com);
2805 static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2807 struct in_device *ind;
2809 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2810 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2812 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2814 return -EADDRNOTAVAIL;
2815 for_primary_ifa(ind) {
2816 laddr->sin_addr.s_addr = ifa->ifa_address;
2817 raddr->sin_addr.s_addr = ifa->ifa_address;
2823 return found ? 0 : -EADDRNOTAVAIL;
2826 static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2827 unsigned char banned_flags)
2829 struct inet6_dev *idev;
2830 int err = -EADDRNOTAVAIL;
2833 idev = __in6_dev_get(dev);
2835 struct inet6_ifaddr *ifp;
2837 read_lock_bh(&idev->lock);
2838 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2839 if (ifp->scope == IFA_LINK &&
2840 !(ifp->flags & banned_flags)) {
2841 memcpy(addr, &ifp->addr, 16);
2846 read_unlock_bh(&idev->lock);
2852 static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2854 struct in6_addr uninitialized_var(addr);
2855 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2856 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2858 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2859 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2860 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2863 return -EADDRNOTAVAIL;
2866 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2868 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2871 struct sockaddr_in *laddr;
2872 struct sockaddr_in *raddr;
2873 struct sockaddr_in6 *laddr6;
2874 struct sockaddr_in6 *raddr6;
2875 struct iwpm_dev_data pm_reg_msg;
2876 struct iwpm_sa_data pm_msg;
2881 if ((conn_param->ord > c4iw_max_read_depth) ||
2882 (conn_param->ird > c4iw_max_read_depth)) {
2886 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2888 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2892 init_timer(&ep->timer);
2893 ep->plen = conn_param->private_data_len;
2895 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2896 conn_param->private_data, ep->plen);
2897 ep->ird = conn_param->ird;
2898 ep->ord = conn_param->ord;
2900 if (peer2peer && ep->ord == 0)
2903 cm_id->add_ref(cm_id);
2905 ep->com.cm_id = cm_id;
2906 ep->com.qp = get_qhp(dev, conn_param->qpn);
2908 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2913 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2917 * Allocate an active TID to initiate a TCP connection.
2919 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2920 if (ep->atid == -1) {
2921 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2925 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2927 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2928 sizeof(ep->com.local_addr));
2929 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2930 sizeof(ep->com.remote_addr));
2932 /* No port mapper available, go with the specified peer information */
2933 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
2934 sizeof(ep->com.mapped_local_addr));
2935 memcpy(&ep->com.mapped_remote_addr, &cm_id->remote_addr,
2936 sizeof(ep->com.mapped_remote_addr));
2938 c4iw_form_reg_msg(dev, &pm_reg_msg);
2939 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
2941 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
2942 __func__, iwpm_err);
2944 if (iwpm_valid_pid() && !iwpm_err) {
2945 c4iw_form_pm_msg(ep, &pm_msg);
2946 iwpm_err = iwpm_add_and_query_mapping(&pm_msg, RDMA_NL_C4IW);
2948 PDBG("%s: Port Mapper query fail (err = %d).\n",
2949 __func__, iwpm_err);
2951 c4iw_record_pm_msg(ep, &pm_msg);
2953 if (iwpm_create_mapinfo(&ep->com.local_addr,
2954 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
2955 iwpm_remove_mapping(&ep->com.local_addr, RDMA_NL_C4IW);
2959 print_addr(&ep->com, __func__, "add_query/create_mapinfo");
2960 set_bit(RELEASE_MAPINFO, &ep->com.flags);
2962 laddr = (struct sockaddr_in *)&ep->com.mapped_local_addr;
2963 raddr = (struct sockaddr_in *)&ep->com.mapped_remote_addr;
2964 laddr6 = (struct sockaddr_in6 *)&ep->com.mapped_local_addr;
2965 raddr6 = (struct sockaddr_in6 *) &ep->com.mapped_remote_addr;
2967 if (cm_id->remote_addr.ss_family == AF_INET) {
2969 ra = (__u8 *)&raddr->sin_addr;
2972 * Handle loopback requests to INADDR_ANY.
2974 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2975 err = pick_local_ipaddrs(dev, cm_id);
2981 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2982 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2983 ra, ntohs(raddr->sin_port));
2984 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2985 raddr->sin_addr.s_addr, laddr->sin_port,
2986 raddr->sin_port, 0);
2989 ra = (__u8 *)&raddr6->sin6_addr;
2992 * Handle loopback requests to INADDR_ANY.
2994 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2995 err = pick_local_ip6addrs(dev, cm_id);
3001 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3002 __func__, laddr6->sin6_addr.s6_addr,
3003 ntohs(laddr6->sin6_port),
3004 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3005 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3006 raddr6->sin6_addr.s6_addr,
3007 laddr6->sin6_port, raddr6->sin6_port, 0,
3008 raddr6->sin6_scope_id);
3011 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3012 err = -EHOSTUNREACH;
3016 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
3018 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
3022 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3023 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3026 state_set(&ep->com, CONNECTING);
3029 /* send connect request to rnic */
3030 err = send_connect(ep);
3034 cxgb4_l2t_release(ep->l2t);
3036 dst_release(ep->dst);
3038 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
3039 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
3041 cm_id->rem_ref(cm_id);
3042 c4iw_put_ep(&ep->com);
3047 static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3050 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
3051 &ep->com.mapped_local_addr;
3053 c4iw_init_wr_wait(&ep->com.wr_wait);
3054 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3055 ep->stid, &sin6->sin6_addr,
3057 ep->com.dev->rdev.lldi.rxq_ids[0]);
3059 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3063 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3065 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
3069 static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3072 struct sockaddr_in *sin = (struct sockaddr_in *)
3073 &ep->com.mapped_local_addr;
3075 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3077 err = cxgb4_create_server_filter(
3078 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3079 sin->sin_addr.s_addr, sin->sin_port, 0,
3080 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3081 if (err == -EBUSY) {
3082 set_current_state(TASK_UNINTERRUPTIBLE);
3083 schedule_timeout(usecs_to_jiffies(100));
3085 } while (err == -EBUSY);
3087 c4iw_init_wr_wait(&ep->com.wr_wait);
3088 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3089 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3090 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3092 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3097 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3099 &sin->sin_addr, ntohs(sin->sin_port));
3103 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3106 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3107 struct c4iw_listen_ep *ep;
3108 struct iwpm_dev_data pm_reg_msg;
3109 struct iwpm_sa_data pm_msg;
3114 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3116 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3120 PDBG("%s ep %p\n", __func__, ep);
3121 cm_id->add_ref(cm_id);
3122 ep->com.cm_id = cm_id;
3124 ep->backlog = backlog;
3125 memcpy(&ep->com.local_addr, &cm_id->local_addr,
3126 sizeof(ep->com.local_addr));
3129 * Allocate a server TID.
3131 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3132 ep->com.local_addr.ss_family == AF_INET)
3133 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
3134 cm_id->local_addr.ss_family, ep);
3136 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
3137 cm_id->local_addr.ss_family, ep);
3139 if (ep->stid == -1) {
3140 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
3144 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
3146 /* No port mapper available, go with the specified info */
3147 memcpy(&ep->com.mapped_local_addr, &cm_id->local_addr,
3148 sizeof(ep->com.mapped_local_addr));
3150 c4iw_form_reg_msg(dev, &pm_reg_msg);
3151 iwpm_err = iwpm_register_pid(&pm_reg_msg, RDMA_NL_C4IW);
3153 PDBG("%s: Port Mapper reg pid fail (err = %d).\n",
3154 __func__, iwpm_err);
3156 if (iwpm_valid_pid() && !iwpm_err) {
3157 memcpy(&pm_msg.loc_addr, &ep->com.local_addr,
3158 sizeof(ep->com.local_addr));
3159 iwpm_err = iwpm_add_mapping(&pm_msg, RDMA_NL_C4IW);
3161 PDBG("%s: Port Mapper query fail (err = %d).\n",
3162 __func__, iwpm_err);
3164 memcpy(&ep->com.mapped_local_addr,
3165 &pm_msg.mapped_loc_addr,
3166 sizeof(ep->com.mapped_local_addr));
3168 if (iwpm_create_mapinfo(&ep->com.local_addr,
3169 &ep->com.mapped_local_addr, RDMA_NL_C4IW)) {
3173 print_addr(&ep->com, __func__, "add_mapping/create_mapinfo");
3175 set_bit(RELEASE_MAPINFO, &ep->com.flags);
3176 state_set(&ep->com, LISTEN);
3177 if (ep->com.local_addr.ss_family == AF_INET)
3178 err = create_server4(dev, ep);
3180 err = create_server6(dev, ep);
3182 cm_id->provider_data = ep;
3187 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3188 ep->com.local_addr.ss_family);
3190 cm_id->rem_ref(cm_id);
3191 c4iw_put_ep(&ep->com);
3197 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3200 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3202 PDBG("%s ep %p\n", __func__, ep);
3205 state_set(&ep->com, DEAD);
3206 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3207 ep->com.local_addr.ss_family == AF_INET) {
3208 err = cxgb4_remove_server_filter(
3209 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3210 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3212 c4iw_init_wr_wait(&ep->com.wr_wait);
3213 err = cxgb4_remove_server(
3214 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3215 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3218 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3221 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
3222 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3223 ep->com.local_addr.ss_family);
3225 cm_id->rem_ref(cm_id);
3226 c4iw_put_ep(&ep->com);
3230 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3235 struct c4iw_rdev *rdev;
3237 mutex_lock(&ep->com.mutex);
3239 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3240 states[ep->com.state], abrupt);
3242 rdev = &ep->com.dev->rdev;
3243 if (c4iw_fatal_error(rdev)) {
3245 close_complete_upcall(ep, -EIO);
3246 ep->com.state = DEAD;
3248 switch (ep->com.state) {
3256 ep->com.state = ABORTING;
3258 ep->com.state = CLOSING;
3261 set_bit(CLOSE_SENT, &ep->com.flags);
3264 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3267 (void)stop_ep_timer(ep);
3268 ep->com.state = ABORTING;
3270 ep->com.state = MORIBUND;
3276 PDBG("%s ignoring disconnect ep %p state %u\n",
3277 __func__, ep, ep->com.state);
3286 set_bit(EP_DISC_ABORT, &ep->com.history);
3287 close_complete_upcall(ep, -ECONNRESET);
3288 ret = send_abort(ep, NULL, gfp);
3290 set_bit(EP_DISC_CLOSE, &ep->com.history);
3291 ret = send_halfclose(ep, gfp);
3296 mutex_unlock(&ep->com.mutex);
3298 release_ep_resources(ep);
3302 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3303 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3306 int atid = be32_to_cpu(req->tid);
3308 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3309 (__force u32) req->tid);
3313 switch (req->retval) {
3315 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3316 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3317 send_fw_act_open_req(ep, atid);
3321 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3322 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3323 send_fw_act_open_req(ep, atid);
3328 pr_info("%s unexpected ofld conn wr retval %d\n",
3329 __func__, req->retval);
3332 pr_err("active ofld_connect_wr failure %d atid %d\n",
3334 mutex_lock(&dev->rdev.stats.lock);
3335 dev->rdev.stats.act_ofld_conn_fails++;
3336 mutex_unlock(&dev->rdev.stats.lock);
3337 connect_reply_upcall(ep, status2errno(req->retval));
3338 state_set(&ep->com, DEAD);
3339 remove_handle(dev, &dev->atid_idr, atid);
3340 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3341 dst_release(ep->dst);
3342 cxgb4_l2t_release(ep->l2t);
3343 c4iw_put_ep(&ep->com);
3346 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3347 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3349 struct sk_buff *rpl_skb;
3350 struct cpl_pass_accept_req *cpl;
3353 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
3356 PDBG("%s passive open failure %d\n", __func__, req->retval);
3357 mutex_lock(&dev->rdev.stats.lock);
3358 dev->rdev.stats.pas_ofld_conn_fails++;
3359 mutex_unlock(&dev->rdev.stats.lock);
3362 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3363 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
3364 (__force u32) htonl(
3365 (__force u32) req->tid)));
3366 ret = pass_accept_req(dev, rpl_skb);
3373 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3375 struct cpl_fw6_msg *rpl = cplhdr(skb);
3376 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3378 switch (rpl->type) {
3380 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3382 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3383 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3384 switch (req->t_state) {
3386 active_ofld_conn_reply(dev, skb, req);
3389 passive_ofld_conn_reply(dev, skb, req);
3392 pr_err("%s unexpected ofld conn wr state %d\n",
3393 __func__, req->t_state);
3401 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3404 u16 vlantag, len, hdr_len, eth_hdr_len;
3406 struct cpl_rx_pkt *cpl = cplhdr(skb);
3407 struct cpl_pass_accept_req *req;
3408 struct tcp_options_received tmp_opt;
3409 struct c4iw_dev *dev;
3411 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3412 /* Store values from cpl_rx_pkt in temporary location. */
3413 vlantag = (__force u16) cpl->vlan;
3414 len = (__force u16) cpl->len;
3415 l2info = (__force u32) cpl->l2info;
3416 hdr_len = (__force u16) cpl->hdr_len;
3419 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3422 * We need to parse the TCP options from SYN packet.
3423 * to generate cpl_pass_accept_req.
3425 memset(&tmp_opt, 0, sizeof(tmp_opt));
3426 tcp_clear_options(&tmp_opt);
3427 tcp_parse_options(skb, &tmp_opt, 0, NULL);
3429 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3430 memset(req, 0, sizeof(*req));
3431 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
3432 V_SYN_MAC_IDX(G_RX_MACIDX(
3433 (__force int) htonl(l2info))) |
3435 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3436 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3437 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
3438 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3439 (__force int) htonl(l2info))) |
3440 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3441 (__force int) htons(hdr_len))) |
3442 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3443 (__force int) htons(hdr_len))) |
3444 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
3445 req->vlan = (__force __be16) vlantag;
3446 req->len = (__force __be16) len;
3447 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3448 PASS_OPEN_TOS(tos));
3449 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3450 if (tmp_opt.wscale_ok)
3451 req->tcpopt.wsf = tmp_opt.snd_wscale;
3452 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3453 if (tmp_opt.sack_ok)
3454 req->tcpopt.sack = 1;
3455 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3459 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3460 __be32 laddr, __be16 lport,
3461 __be32 raddr, __be16 rport,
3462 u32 rcv_isn, u32 filter, u16 window,
3463 u32 rss_qid, u8 port_id)
3465 struct sk_buff *req_skb;
3466 struct fw_ofld_connection_wr *req;
3467 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3470 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3471 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3472 memset(req, 0, sizeof(*req));
3473 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3474 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3475 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
3476 req->le.filter = (__force __be32) filter;
3477 req->le.lport = lport;
3478 req->le.pport = rport;
3479 req->le.u.ipv4.lip = laddr;
3480 req->le.u.ipv4.pip = raddr;
3481 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3482 req->tcb.rcv_adv = htons(window);
3483 req->tcb.t_state_to_astid =
3484 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3485 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3486 V_FW_OFLD_CONNECTION_WR_ASTID(
3487 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3490 * We store the qid in opt2 which will be used by the firmware
3491 * to send us the wr response.
3493 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3496 * We initialize the MSS index in TCB to 0xF.
3497 * So that when driver sends cpl_pass_accept_rpl
3498 * TCB picks up the correct value. If this was 0
3499 * TP will ignore any value > 0 for MSS index.
3501 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
3502 req->cookie = (unsigned long)skb;
3504 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3505 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3507 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3515 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3516 * messages when a filter is being used instead of server to
3517 * redirect a syn packet. When packets hit filter they are redirected
3518 * to the offload queue and driver tries to establish the connection
3519 * using firmware work request.
3521 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3524 unsigned int filter;
3525 struct ethhdr *eh = NULL;
3526 struct vlan_ethhdr *vlan_eh = NULL;
3528 struct tcphdr *tcph;
3529 struct rss_header *rss = (void *)skb->data;
3530 struct cpl_rx_pkt *cpl = (void *)skb->data;
3531 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3532 struct l2t_entry *e;
3533 struct dst_entry *dst;
3534 struct c4iw_ep *lep;
3536 struct port_info *pi;
3537 struct net_device *pdev;
3538 u16 rss_qid, eth_hdr_len;
3541 struct neighbour *neigh;
3543 /* Drop all non-SYN packets */
3544 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3548 * Drop all packets which did not hit the filter.
3549 * Unlikely to happen.
3551 if (!(rss->filter_hit && rss->filter_tid))
3555 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3557 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
3559 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3561 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3565 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3566 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3567 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3568 if (eth_hdr_len == ETH_HLEN) {
3569 eh = (struct ethhdr *)(req + 1);
3570 iph = (struct iphdr *)(eh + 1);
3572 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3573 iph = (struct iphdr *)(vlan_eh + 1);
3574 skb->vlan_tci = ntohs(cpl->vlan);
3577 if (iph->version != 0x4)
3580 tcph = (struct tcphdr *)(iph + 1);
3581 skb_set_network_header(skb, (void *)iph - (void *)rss);
3582 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3585 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3586 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3587 ntohs(tcph->source), iph->tos);
3589 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3592 pr_err("%s - failed to find dst entry!\n",
3596 neigh = dst_neigh_lookup_skb(dst, skb);
3599 pr_err("%s - failed to allocate neigh!\n",
3604 if (neigh->dev->flags & IFF_LOOPBACK) {
3605 pdev = ip_dev_find(&init_net, iph->daddr);
3606 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3608 pi = (struct port_info *)netdev_priv(pdev);
3609 tx_chan = cxgb4_port_chan(pdev);
3612 pdev = get_real_dev(neigh->dev);
3613 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3615 pi = (struct port_info *)netdev_priv(pdev);
3616 tx_chan = cxgb4_port_chan(pdev);
3618 neigh_release(neigh);
3620 pr_err("%s - failed to allocate l2t entry!\n",
3625 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3626 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3627 window = (__force u16) htons((__force u16)tcph->window);
3629 /* Calcuate filter portion for LE region. */
3630 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3631 dev->rdev.lldi.ports[0],
3635 * Synthesize the cpl_pass_accept_req. We have everything except the
3636 * TID. Once firmware sends a reply with TID we update the TID field
3637 * in cpl and pass it through the regular cpl_pass_accept_req path.
3639 build_cpl_pass_accept_req(skb, stid, iph->tos);
3640 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3641 tcph->source, ntohl(tcph->seq), filter, window,
3642 rss_qid, pi->port_id);
3643 cxgb4_l2t_release(e);
3651 * These are the real handlers that are called from a
3654 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3655 [CPL_ACT_ESTABLISH] = act_establish,
3656 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3657 [CPL_RX_DATA] = rx_data,
3658 [CPL_ABORT_RPL_RSS] = abort_rpl,
3659 [CPL_ABORT_RPL] = abort_rpl,
3660 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3661 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3662 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3663 [CPL_PASS_ESTABLISH] = pass_establish,
3664 [CPL_PEER_CLOSE] = peer_close,
3665 [CPL_ABORT_REQ_RSS] = peer_abort,
3666 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3667 [CPL_RDMA_TERMINATE] = terminate,
3668 [CPL_FW4_ACK] = fw4_ack,
3669 [CPL_FW6_MSG] = deferred_fw6_msg,
3670 [CPL_RX_PKT] = rx_pkt
3673 static void process_timeout(struct c4iw_ep *ep)
3675 struct c4iw_qp_attributes attrs;
3678 mutex_lock(&ep->com.mutex);
3679 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3681 set_bit(TIMEDOUT, &ep->com.history);
3682 switch (ep->com.state) {
3684 __state_set(&ep->com, ABORTING);
3685 connect_reply_upcall(ep, -ETIMEDOUT);
3688 __state_set(&ep->com, ABORTING);
3692 if (ep->com.cm_id && ep->com.qp) {
3693 attrs.next_state = C4IW_QP_STATE_ERROR;
3694 c4iw_modify_qp(ep->com.qp->rhp,
3695 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3698 __state_set(&ep->com, ABORTING);
3699 close_complete_upcall(ep, -ETIMEDOUT);
3705 * These states are expected if the ep timed out at the same
3706 * time as another thread was calling stop_ep_timer().
3707 * So we silently do nothing for these states.
3712 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3713 __func__, ep, ep->hwtid, ep->com.state);
3717 abort_connection(ep, NULL, GFP_KERNEL);
3718 mutex_unlock(&ep->com.mutex);
3719 c4iw_put_ep(&ep->com);
3722 static void process_timedout_eps(void)
3726 spin_lock_irq(&timeout_lock);
3727 while (!list_empty(&timeout_list)) {
3728 struct list_head *tmp;
3730 tmp = timeout_list.next;
3734 spin_unlock_irq(&timeout_lock);
3735 ep = list_entry(tmp, struct c4iw_ep, entry);
3736 process_timeout(ep);
3737 spin_lock_irq(&timeout_lock);
3739 spin_unlock_irq(&timeout_lock);
3742 static void process_work(struct work_struct *work)
3744 struct sk_buff *skb = NULL;
3745 struct c4iw_dev *dev;
3746 struct cpl_act_establish *rpl;
3747 unsigned int opcode;
3750 process_timedout_eps();
3751 while ((skb = skb_dequeue(&rxq))) {
3753 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3754 opcode = rpl->ot.opcode;
3756 BUG_ON(!work_handlers[opcode]);
3757 ret = work_handlers[opcode](dev, skb);
3760 process_timedout_eps();
3764 static DECLARE_WORK(skb_work, process_work);
3766 static void ep_timeout(unsigned long arg)
3768 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3771 spin_lock(&timeout_lock);
3772 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3774 * Only insert if it is not already on the list.
3776 if (!ep->entry.next) {
3777 list_add_tail(&ep->entry, &timeout_list);
3781 spin_unlock(&timeout_lock);
3783 queue_work(workq, &skb_work);
3787 * All the CM events are handled on a work queue to have a safe context.
3789 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3793 * Save dev in the skb->cb area.
3795 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3798 * Queue the skb and schedule the worker thread.
3800 skb_queue_tail(&rxq, skb);
3801 queue_work(workq, &skb_work);
3805 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3807 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3809 if (rpl->status != CPL_ERR_NONE) {
3810 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3811 "for tid %u\n", rpl->status, GET_TID(rpl));
3817 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3819 struct cpl_fw6_msg *rpl = cplhdr(skb);
3820 struct c4iw_wr_wait *wr_waitp;
3823 PDBG("%s type %u\n", __func__, rpl->type);
3825 switch (rpl->type) {
3826 case FW6_TYPE_WR_RPL:
3827 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
3828 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
3829 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
3831 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3835 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3839 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3847 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3849 struct cpl_abort_req_rss *req = cplhdr(skb);
3851 struct tid_info *t = dev->rdev.lldi.tids;
3852 unsigned int tid = GET_TID(req);
3854 ep = lookup_tid(t, tid);
3856 printk(KERN_WARNING MOD
3857 "Abort on non-existent endpoint, tid %d\n", tid);
3861 if (is_neg_adv(req->status)) {
3862 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3867 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3871 * Wake up any threads in rdma_init() or rdma_fini().
3872 * However, if we are on MPAv2 and want to retry with MPAv1
3873 * then, don't wake up yet.
3875 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3876 if (ep->com.state != MPA_REQ_SENT)
3877 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3879 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3885 * Most upcalls from the T4 Core go to sched() to
3886 * schedule the processing on a work queue.
3888 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3889 [CPL_ACT_ESTABLISH] = sched,
3890 [CPL_ACT_OPEN_RPL] = sched,
3891 [CPL_RX_DATA] = sched,
3892 [CPL_ABORT_RPL_RSS] = sched,
3893 [CPL_ABORT_RPL] = sched,
3894 [CPL_PASS_OPEN_RPL] = sched,
3895 [CPL_CLOSE_LISTSRV_RPL] = sched,
3896 [CPL_PASS_ACCEPT_REQ] = sched,
3897 [CPL_PASS_ESTABLISH] = sched,
3898 [CPL_PEER_CLOSE] = sched,
3899 [CPL_CLOSE_CON_RPL] = sched,
3900 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
3901 [CPL_RDMA_TERMINATE] = sched,
3902 [CPL_FW4_ACK] = sched,
3903 [CPL_SET_TCB_RPL] = set_tcb_rpl,
3904 [CPL_FW6_MSG] = fw6_msg,
3905 [CPL_RX_PKT] = sched
3908 int __init c4iw_cm_init(void)
3910 spin_lock_init(&timeout_lock);
3911 skb_queue_head_init(&rxq);
3913 workq = create_singlethread_workqueue("iw_cxgb4");
3920 void __exit c4iw_cm_term(void)
3922 WARN_ON(!list_empty(&timeout_list));
3923 flush_workqueue(workq);
3924 destroy_workqueue(workq);