2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include <linux/module.h>
33 #include <linux/list.h>
34 #include <linux/workqueue.h>
35 #include <linux/skbuff.h>
36 #include <linux/timer.h>
37 #include <linux/notifier.h>
38 #include <linux/inetdevice.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
50 static char *states[] = {
67 module_param(nocong, int, 0644);
68 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
70 static int enable_ecn;
71 module_param(enable_ecn, int, 0644);
72 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
74 static int dack_mode = 1;
75 module_param(dack_mode, int, 0644);
76 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
78 int c4iw_max_read_depth = 8;
79 module_param(c4iw_max_read_depth, int, 0644);
80 MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
82 static int enable_tcp_timestamps;
83 module_param(enable_tcp_timestamps, int, 0644);
84 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
86 static int enable_tcp_sack;
87 module_param(enable_tcp_sack, int, 0644);
88 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
90 static int enable_tcp_window_scaling = 1;
91 module_param(enable_tcp_window_scaling, int, 0644);
92 MODULE_PARM_DESC(enable_tcp_window_scaling,
93 "Enable tcp window scaling (default=1)");
96 module_param(c4iw_debug, int, 0644);
97 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
100 module_param(peer2peer, int, 0644);
101 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
103 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
104 module_param(p2p_type, int, 0644);
105 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
106 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
108 static int ep_timeout_secs = 60;
109 module_param(ep_timeout_secs, int, 0644);
110 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
111 "in seconds (default=60)");
113 static int mpa_rev = 1;
114 module_param(mpa_rev, int, 0644);
115 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
116 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
117 " compliant (default=1)");
119 static int markers_enabled;
120 module_param(markers_enabled, int, 0644);
121 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
123 static int crc_enabled = 1;
124 module_param(crc_enabled, int, 0644);
125 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
127 static int rcv_win = 256 * 1024;
128 module_param(rcv_win, int, 0644);
129 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
131 static int snd_win = 128 * 1024;
132 module_param(snd_win, int, 0644);
133 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
135 static struct workqueue_struct *workq;
137 static struct sk_buff_head rxq;
139 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
140 static void ep_timeout(unsigned long arg);
141 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
143 static LIST_HEAD(timeout_list);
144 static spinlock_t timeout_lock;
146 static void deref_qp(struct c4iw_ep *ep)
148 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
149 clear_bit(QP_REFERENCED, &ep->com.flags);
152 static void ref_qp(struct c4iw_ep *ep)
154 set_bit(QP_REFERENCED, &ep->com.flags);
155 c4iw_qp_add_ref(&ep->com.qp->ibqp);
158 static void start_ep_timer(struct c4iw_ep *ep)
160 PDBG("%s ep %p\n", __func__, ep);
161 if (timer_pending(&ep->timer)) {
162 pr_err("%s timer already started! ep %p\n",
166 clear_bit(TIMEOUT, &ep->com.flags);
167 c4iw_get_ep(&ep->com);
168 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
169 ep->timer.data = (unsigned long)ep;
170 ep->timer.function = ep_timeout;
171 add_timer(&ep->timer);
174 static void stop_ep_timer(struct c4iw_ep *ep)
176 PDBG("%s ep %p stopping\n", __func__, ep);
177 del_timer_sync(&ep->timer);
178 if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
179 c4iw_put_ep(&ep->com);
182 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
183 struct l2t_entry *l2e)
187 if (c4iw_fatal_error(rdev)) {
189 PDBG("%s - device in error state - dropping\n", __func__);
192 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
195 return error < 0 ? error : 0;
198 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
202 if (c4iw_fatal_error(rdev)) {
204 PDBG("%s - device in error state - dropping\n", __func__);
207 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
210 return error < 0 ? error : 0;
213 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
215 struct cpl_tid_release *req;
217 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
220 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
221 INIT_TP_WR(req, hwtid);
222 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
223 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
224 c4iw_ofld_send(rdev, skb);
228 static void set_emss(struct c4iw_ep *ep, u16 opt)
230 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
232 if (GET_TCPOPT_TSTAMP(opt))
236 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
240 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
242 enum c4iw_ep_state state;
244 mutex_lock(&epc->mutex);
246 mutex_unlock(&epc->mutex);
250 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
255 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
257 mutex_lock(&epc->mutex);
258 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
259 __state_set(epc, new);
260 mutex_unlock(&epc->mutex);
264 static void *alloc_ep(int size, gfp_t gfp)
266 struct c4iw_ep_common *epc;
268 epc = kzalloc(size, gfp);
270 kref_init(&epc->kref);
271 mutex_init(&epc->mutex);
272 c4iw_init_wr_wait(&epc->wr_wait);
274 PDBG("%s alloc ep %p\n", __func__, epc);
278 void _c4iw_free_ep(struct kref *kref)
282 ep = container_of(kref, struct c4iw_ep, com.kref);
283 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
284 if (test_bit(QP_REFERENCED, &ep->com.flags))
286 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
287 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
288 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
289 dst_release(ep->dst);
290 cxgb4_l2t_release(ep->l2t);
295 static void release_ep_resources(struct c4iw_ep *ep)
297 set_bit(RELEASE_RESOURCES, &ep->com.flags);
298 c4iw_put_ep(&ep->com);
301 static int status2errno(int status)
306 case CPL_ERR_CONN_RESET:
308 case CPL_ERR_ARP_MISS:
309 return -EHOSTUNREACH;
310 case CPL_ERR_CONN_TIMEDOUT:
312 case CPL_ERR_TCAM_FULL:
314 case CPL_ERR_CONN_EXIST:
322 * Try and reuse skbs already allocated...
324 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
326 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
329 skb_reset_transport_header(skb);
331 skb = alloc_skb(len, gfp);
336 static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
337 __be32 peer_ip, __be16 local_port,
338 __be16 peer_port, u8 tos)
343 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
344 peer_port, local_port, IPPROTO_TCP,
351 static void arp_failure_discard(void *handle, struct sk_buff *skb)
353 PDBG("%s c4iw_dev %p\n", __func__, handle);
358 * Handle an ARP failure for an active open.
360 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
362 printk(KERN_ERR MOD "ARP failure duing connect\n");
367 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
370 static void abort_arp_failure(void *handle, struct sk_buff *skb)
372 struct c4iw_rdev *rdev = handle;
373 struct cpl_abort_req *req = cplhdr(skb);
375 PDBG("%s rdev %p\n", __func__, rdev);
376 req->cmd = CPL_ABORT_NO_RST;
377 c4iw_ofld_send(rdev, skb);
380 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
382 unsigned int flowclen = 80;
383 struct fw_flowc_wr *flowc;
386 skb = get_skb(skb, flowclen, GFP_KERNEL);
387 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
389 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
390 FW_FLOWC_WR_NPARAMS(8));
391 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
392 16)) | FW_WR_FLOWID(ep->hwtid));
394 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
395 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
396 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
397 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
398 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
399 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
400 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
401 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
402 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
403 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
404 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
405 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
406 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
407 flowc->mnemval[6].val = cpu_to_be32(snd_win);
408 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
409 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
410 /* Pad WR to 16 byte boundary */
411 flowc->mnemval[8].mnemonic = 0;
412 flowc->mnemval[8].val = 0;
413 for (i = 0; i < 9; i++) {
414 flowc->mnemval[i].r4[0] = 0;
415 flowc->mnemval[i].r4[1] = 0;
416 flowc->mnemval[i].r4[2] = 0;
419 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
420 c4iw_ofld_send(&ep->com.dev->rdev, skb);
423 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
425 struct cpl_close_con_req *req;
427 int wrlen = roundup(sizeof *req, 16);
429 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
430 skb = get_skb(NULL, wrlen, gfp);
432 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
435 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
436 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
437 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
438 memset(req, 0, wrlen);
439 INIT_TP_WR(req, ep->hwtid);
440 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
442 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
445 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
447 struct cpl_abort_req *req;
448 int wrlen = roundup(sizeof *req, 16);
450 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
451 skb = get_skb(skb, wrlen, gfp);
453 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
457 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
458 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
459 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
460 memset(req, 0, wrlen);
461 INIT_TP_WR(req, ep->hwtid);
462 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
463 req->cmd = CPL_ABORT_SEND_RST;
464 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
467 #define VLAN_NONE 0xfff
468 #define FILTER_SEL_VLAN_NONE 0xffff
469 #define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
470 #define FILTER_SEL_WIDTH_VIN_P_FC \
471 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
472 #define FILTER_SEL_WIDTH_TAG_P_FC \
473 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
474 #define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
476 static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
477 struct l2t_entry *l2t)
479 unsigned int ntuple = 0;
482 switch (dev->rdev.lldi.filt_mode) {
484 /* default filter mode */
485 case HW_TPL_FR_MT_PR_IV_P_FC:
486 if (l2t->vlan == VLAN_NONE)
487 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
489 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
490 ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
492 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
493 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
495 case HW_TPL_FR_MT_PR_OV_P_FC: {
496 viid = cxgb4_port_viid(l2t->neigh->dev);
498 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
499 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
500 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
501 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
502 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
511 static int send_connect(struct c4iw_ep *ep)
513 struct cpl_act_open_req *req;
514 struct cpl_t5_act_open_req *t5_req;
518 unsigned int mtu_idx;
520 int size = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
521 sizeof(struct cpl_act_open_req) :
522 sizeof(struct cpl_t5_act_open_req);
523 int wrlen = roundup(size, 16);
525 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
527 skb = get_skb(NULL, wrlen, GFP_KERNEL);
529 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
533 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
535 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
536 wscale = compute_wscale(rcv_win);
537 opt0 = (nocong ? NO_CONG(1) : 0) |
542 L2T_IDX(ep->l2t->idx) |
543 TX_CHAN(ep->tx_chan) |
544 SMAC_SEL(ep->smac_idx) |
546 ULP_MODE(ULP_MODE_TCPDDP) |
547 RCV_BUFSIZ(rcv_win>>10);
548 opt2 = RX_CHANNEL(0) |
549 CCTRL_ECN(enable_ecn) |
550 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
551 if (enable_tcp_timestamps)
552 opt2 |= TSTAMPS_EN(1);
555 if (wscale && enable_tcp_window_scaling)
556 opt2 |= WND_SCALE_EN(1);
557 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
559 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
560 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
562 OPCODE_TID(req) = cpu_to_be32(
563 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
564 ((ep->rss_qid << 14) | ep->atid)));
565 req->local_port = ep->com.local_addr.sin_port;
566 req->peer_port = ep->com.remote_addr.sin_port;
567 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
568 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
569 req->opt0 = cpu_to_be64(opt0);
570 req->params = cpu_to_be32(select_ntuple(ep->com.dev,
572 req->opt2 = cpu_to_be32(opt2);
574 t5_req = (struct cpl_t5_act_open_req *) skb_put(skb, wrlen);
575 INIT_TP_WR(t5_req, 0);
576 OPCODE_TID(t5_req) = cpu_to_be32(
577 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
578 ((ep->rss_qid << 14) | ep->atid)));
579 t5_req->local_port = ep->com.local_addr.sin_port;
580 t5_req->peer_port = ep->com.remote_addr.sin_port;
581 t5_req->local_ip = ep->com.local_addr.sin_addr.s_addr;
582 t5_req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
583 t5_req->opt0 = cpu_to_be64(opt0);
584 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
585 select_ntuple(ep->com.dev, ep->dst, ep->l2t)));
586 t5_req->opt2 = cpu_to_be32(opt2);
589 set_bit(ACT_OPEN_REQ, &ep->com.history);
590 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
593 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
597 struct fw_ofld_tx_data_wr *req;
598 struct mpa_message *mpa;
599 struct mpa_v2_conn_params mpa_v2_params;
601 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
603 BUG_ON(skb_cloned(skb));
605 mpalen = sizeof(*mpa) + ep->plen;
606 if (mpa_rev_to_use == 2)
607 mpalen += sizeof(struct mpa_v2_conn_params);
608 wrlen = roundup(mpalen + sizeof *req, 16);
609 skb = get_skb(skb, wrlen, GFP_KERNEL);
611 connect_reply_upcall(ep, -ENOMEM);
614 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
616 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
617 memset(req, 0, wrlen);
618 req->op_to_immdlen = cpu_to_be32(
619 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
621 FW_WR_IMMDLEN(mpalen));
622 req->flowid_len16 = cpu_to_be32(
623 FW_WR_FLOWID(ep->hwtid) |
624 FW_WR_LEN16(wrlen >> 4));
625 req->plen = cpu_to_be32(mpalen);
626 req->tunnel_to_proxy = cpu_to_be32(
627 FW_OFLD_TX_DATA_WR_FLUSH(1) |
628 FW_OFLD_TX_DATA_WR_SHOVE(1));
630 mpa = (struct mpa_message *)(req + 1);
631 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
632 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
633 (markers_enabled ? MPA_MARKERS : 0) |
634 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
635 mpa->private_data_size = htons(ep->plen);
636 mpa->revision = mpa_rev_to_use;
637 if (mpa_rev_to_use == 1) {
638 ep->tried_with_mpa_v1 = 1;
639 ep->retry_with_mpa_v1 = 0;
642 if (mpa_rev_to_use == 2) {
643 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
644 sizeof (struct mpa_v2_conn_params));
645 mpa_v2_params.ird = htons((u16)ep->ird);
646 mpa_v2_params.ord = htons((u16)ep->ord);
649 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
650 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
652 htons(MPA_V2_RDMA_WRITE_RTR);
653 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
655 htons(MPA_V2_RDMA_READ_RTR);
657 memcpy(mpa->private_data, &mpa_v2_params,
658 sizeof(struct mpa_v2_conn_params));
661 memcpy(mpa->private_data +
662 sizeof(struct mpa_v2_conn_params),
663 ep->mpa_pkt + sizeof(*mpa), ep->plen);
666 memcpy(mpa->private_data,
667 ep->mpa_pkt + sizeof(*mpa), ep->plen);
670 * Reference the mpa skb. This ensures the data area
671 * will remain in memory until the hw acks the tx.
672 * Function fw4_ack() will deref it.
675 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
678 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
680 state_set(&ep->com, MPA_REQ_SENT);
681 ep->mpa_attr.initiator = 1;
685 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
688 struct fw_ofld_tx_data_wr *req;
689 struct mpa_message *mpa;
691 struct mpa_v2_conn_params mpa_v2_params;
693 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
695 mpalen = sizeof(*mpa) + plen;
696 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
697 mpalen += sizeof(struct mpa_v2_conn_params);
698 wrlen = roundup(mpalen + sizeof *req, 16);
700 skb = get_skb(NULL, wrlen, GFP_KERNEL);
702 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
705 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
707 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
708 memset(req, 0, wrlen);
709 req->op_to_immdlen = cpu_to_be32(
710 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
712 FW_WR_IMMDLEN(mpalen));
713 req->flowid_len16 = cpu_to_be32(
714 FW_WR_FLOWID(ep->hwtid) |
715 FW_WR_LEN16(wrlen >> 4));
716 req->plen = cpu_to_be32(mpalen);
717 req->tunnel_to_proxy = cpu_to_be32(
718 FW_OFLD_TX_DATA_WR_FLUSH(1) |
719 FW_OFLD_TX_DATA_WR_SHOVE(1));
721 mpa = (struct mpa_message *)(req + 1);
722 memset(mpa, 0, sizeof(*mpa));
723 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
724 mpa->flags = MPA_REJECT;
725 mpa->revision = ep->mpa_attr.version;
726 mpa->private_data_size = htons(plen);
728 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
729 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
730 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
731 sizeof (struct mpa_v2_conn_params));
732 mpa_v2_params.ird = htons(((u16)ep->ird) |
733 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
735 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
737 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
738 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
739 FW_RI_INIT_P2PTYPE_READ_REQ ?
740 MPA_V2_RDMA_READ_RTR : 0) : 0));
741 memcpy(mpa->private_data, &mpa_v2_params,
742 sizeof(struct mpa_v2_conn_params));
745 memcpy(mpa->private_data +
746 sizeof(struct mpa_v2_conn_params), pdata, plen);
749 memcpy(mpa->private_data, pdata, plen);
752 * Reference the mpa skb again. This ensures the data area
753 * will remain in memory until the hw acks the tx.
754 * Function fw4_ack() will deref it.
757 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
758 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
761 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
764 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
767 struct fw_ofld_tx_data_wr *req;
768 struct mpa_message *mpa;
770 struct mpa_v2_conn_params mpa_v2_params;
772 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
774 mpalen = sizeof(*mpa) + plen;
775 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
776 mpalen += sizeof(struct mpa_v2_conn_params);
777 wrlen = roundup(mpalen + sizeof *req, 16);
779 skb = get_skb(NULL, wrlen, GFP_KERNEL);
781 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
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 memset(mpa, 0, sizeof(*mpa));
802 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
803 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
804 (markers_enabled ? MPA_MARKERS : 0);
805 mpa->revision = ep->mpa_attr.version;
806 mpa->private_data_size = htons(plen);
808 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
809 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
810 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
811 sizeof (struct mpa_v2_conn_params));
812 mpa_v2_params.ird = htons((u16)ep->ird);
813 mpa_v2_params.ord = htons((u16)ep->ord);
814 if (peer2peer && (ep->mpa_attr.p2p_type !=
815 FW_RI_INIT_P2PTYPE_DISABLED)) {
816 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
818 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
820 htons(MPA_V2_RDMA_WRITE_RTR);
821 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
823 htons(MPA_V2_RDMA_READ_RTR);
826 memcpy(mpa->private_data, &mpa_v2_params,
827 sizeof(struct mpa_v2_conn_params));
830 memcpy(mpa->private_data +
831 sizeof(struct mpa_v2_conn_params), pdata, plen);
834 memcpy(mpa->private_data, pdata, plen);
837 * Reference the mpa skb. This ensures the data area
838 * will remain in memory until the hw acks the tx.
839 * Function fw4_ack() will deref it.
842 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
844 state_set(&ep->com, MPA_REP_SENT);
845 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
848 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
851 struct cpl_act_establish *req = cplhdr(skb);
852 unsigned int tid = GET_TID(req);
853 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
854 struct tid_info *t = dev->rdev.lldi.tids;
856 ep = lookup_atid(t, atid);
858 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
859 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
861 dst_confirm(ep->dst);
863 /* setup the hwtid for this connection */
865 cxgb4_insert_tid(t, ep, tid);
866 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
868 ep->snd_seq = be32_to_cpu(req->snd_isn);
869 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
871 set_emss(ep, ntohs(req->tcp_opt));
873 /* dealloc the atid */
874 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
875 cxgb4_free_atid(t, atid);
876 set_bit(ACT_ESTAB, &ep->com.history);
878 /* start MPA negotiation */
879 send_flowc(ep, NULL);
880 if (ep->retry_with_mpa_v1)
881 send_mpa_req(ep, skb, 1);
883 send_mpa_req(ep, skb, mpa_rev);
888 static void close_complete_upcall(struct c4iw_ep *ep)
890 struct iw_cm_event event;
892 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
893 memset(&event, 0, sizeof(event));
894 event.event = IW_CM_EVENT_CLOSE;
896 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
897 ep, ep->com.cm_id, ep->hwtid);
898 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
899 ep->com.cm_id->rem_ref(ep->com.cm_id);
900 ep->com.cm_id = NULL;
901 set_bit(CLOSE_UPCALL, &ep->com.history);
905 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
907 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
908 close_complete_upcall(ep);
909 state_set(&ep->com, ABORTING);
910 set_bit(ABORT_CONN, &ep->com.history);
911 return send_abort(ep, skb, gfp);
914 static void peer_close_upcall(struct c4iw_ep *ep)
916 struct iw_cm_event event;
918 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
919 memset(&event, 0, sizeof(event));
920 event.event = IW_CM_EVENT_DISCONNECT;
922 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
923 ep, ep->com.cm_id, ep->hwtid);
924 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
925 set_bit(DISCONN_UPCALL, &ep->com.history);
929 static void peer_abort_upcall(struct c4iw_ep *ep)
931 struct iw_cm_event event;
933 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
934 memset(&event, 0, sizeof(event));
935 event.event = IW_CM_EVENT_CLOSE;
936 event.status = -ECONNRESET;
938 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
939 ep->com.cm_id, ep->hwtid);
940 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
941 ep->com.cm_id->rem_ref(ep->com.cm_id);
942 ep->com.cm_id = NULL;
943 set_bit(ABORT_UPCALL, &ep->com.history);
947 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
949 struct iw_cm_event event;
951 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
952 memset(&event, 0, sizeof(event));
953 event.event = IW_CM_EVENT_CONNECT_REPLY;
954 event.status = status;
955 event.local_addr = ep->com.local_addr;
956 event.remote_addr = ep->com.remote_addr;
958 if ((status == 0) || (status == -ECONNREFUSED)) {
959 if (!ep->tried_with_mpa_v1) {
960 /* this means MPA_v2 is used */
961 event.private_data_len = ep->plen -
962 sizeof(struct mpa_v2_conn_params);
963 event.private_data = ep->mpa_pkt +
964 sizeof(struct mpa_message) +
965 sizeof(struct mpa_v2_conn_params);
967 /* this means MPA_v1 is used */
968 event.private_data_len = ep->plen;
969 event.private_data = ep->mpa_pkt +
970 sizeof(struct mpa_message);
974 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
976 set_bit(CONN_RPL_UPCALL, &ep->com.history);
977 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
980 ep->com.cm_id->rem_ref(ep->com.cm_id);
981 ep->com.cm_id = NULL;
985 static void connect_request_upcall(struct c4iw_ep *ep)
987 struct iw_cm_event event;
989 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
990 memset(&event, 0, sizeof(event));
991 event.event = IW_CM_EVENT_CONNECT_REQUEST;
992 event.local_addr = ep->com.local_addr;
993 event.remote_addr = ep->com.remote_addr;
994 event.provider_data = ep;
995 if (!ep->tried_with_mpa_v1) {
996 /* this means MPA_v2 is used */
999 event.private_data_len = ep->plen -
1000 sizeof(struct mpa_v2_conn_params);
1001 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1002 sizeof(struct mpa_v2_conn_params);
1004 /* this means MPA_v1 is used. Send max supported */
1005 event.ord = c4iw_max_read_depth;
1006 event.ird = c4iw_max_read_depth;
1007 event.private_data_len = ep->plen;
1008 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1010 if (state_read(&ep->parent_ep->com) != DEAD) {
1011 c4iw_get_ep(&ep->com);
1012 ep->parent_ep->com.cm_id->event_handler(
1013 ep->parent_ep->com.cm_id,
1016 set_bit(CONNREQ_UPCALL, &ep->com.history);
1017 c4iw_put_ep(&ep->parent_ep->com);
1018 ep->parent_ep = NULL;
1021 static void established_upcall(struct c4iw_ep *ep)
1023 struct iw_cm_event event;
1025 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1026 memset(&event, 0, sizeof(event));
1027 event.event = IW_CM_EVENT_ESTABLISHED;
1028 event.ird = ep->ird;
1029 event.ord = ep->ord;
1030 if (ep->com.cm_id) {
1031 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1032 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1033 set_bit(ESTAB_UPCALL, &ep->com.history);
1037 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1039 struct cpl_rx_data_ack *req;
1040 struct sk_buff *skb;
1041 int wrlen = roundup(sizeof *req, 16);
1043 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1044 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1046 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1050 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1051 memset(req, 0, wrlen);
1052 INIT_TP_WR(req, ep->hwtid);
1053 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1055 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1057 V_RX_DACK_MODE(dack_mode));
1058 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1059 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1063 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1065 struct mpa_message *mpa;
1066 struct mpa_v2_conn_params *mpa_v2_params;
1068 u16 resp_ird, resp_ord;
1069 u8 rtr_mismatch = 0, insuff_ird = 0;
1070 struct c4iw_qp_attributes attrs;
1071 enum c4iw_qp_attr_mask mask;
1074 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1077 * Stop mpa timer. If it expired, then the state has
1078 * changed and we bail since ep_timeout already aborted
1082 if (state_read(&ep->com) != MPA_REQ_SENT)
1086 * If we get more than the supported amount of private data
1087 * then we must fail this connection.
1089 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1095 * copy the new data into our accumulation buffer.
1097 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1099 ep->mpa_pkt_len += skb->len;
1102 * if we don't even have the mpa message, then bail.
1104 if (ep->mpa_pkt_len < sizeof(*mpa))
1106 mpa = (struct mpa_message *) ep->mpa_pkt;
1108 /* Validate MPA header. */
1109 if (mpa->revision > mpa_rev) {
1110 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1111 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1115 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1120 plen = ntohs(mpa->private_data_size);
1123 * Fail if there's too much private data.
1125 if (plen > MPA_MAX_PRIVATE_DATA) {
1131 * If plen does not account for pkt size
1133 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1138 ep->plen = (u8) plen;
1141 * If we don't have all the pdata yet, then bail.
1142 * We'll continue process when more data arrives.
1144 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1147 if (mpa->flags & MPA_REJECT) {
1148 err = -ECONNREFUSED;
1153 * If we get here we have accumulated the entire mpa
1154 * start reply message including private data. And
1155 * the MPA header is valid.
1157 state_set(&ep->com, FPDU_MODE);
1158 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1159 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1160 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1161 ep->mpa_attr.version = mpa->revision;
1162 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1164 if (mpa->revision == 2) {
1165 ep->mpa_attr.enhanced_rdma_conn =
1166 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1167 if (ep->mpa_attr.enhanced_rdma_conn) {
1168 mpa_v2_params = (struct mpa_v2_conn_params *)
1169 (ep->mpa_pkt + sizeof(*mpa));
1170 resp_ird = ntohs(mpa_v2_params->ird) &
1171 MPA_V2_IRD_ORD_MASK;
1172 resp_ord = ntohs(mpa_v2_params->ord) &
1173 MPA_V2_IRD_ORD_MASK;
1176 * This is a double-check. Ideally, below checks are
1177 * not required since ird/ord stuff has been taken
1178 * care of in c4iw_accept_cr
1180 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1187 if (ntohs(mpa_v2_params->ird) &
1188 MPA_V2_PEER2PEER_MODEL) {
1189 if (ntohs(mpa_v2_params->ord) &
1190 MPA_V2_RDMA_WRITE_RTR)
1191 ep->mpa_attr.p2p_type =
1192 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1193 else if (ntohs(mpa_v2_params->ord) &
1194 MPA_V2_RDMA_READ_RTR)
1195 ep->mpa_attr.p2p_type =
1196 FW_RI_INIT_P2PTYPE_READ_REQ;
1199 } else if (mpa->revision == 1)
1201 ep->mpa_attr.p2p_type = p2p_type;
1203 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1204 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1205 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1206 ep->mpa_attr.recv_marker_enabled,
1207 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1208 ep->mpa_attr.p2p_type, p2p_type);
1211 * If responder's RTR does not match with that of initiator, assign
1212 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1213 * generated when moving QP to RTS state.
1214 * A TERM message will be sent after QP has moved to RTS state
1216 if ((ep->mpa_attr.version == 2) && peer2peer &&
1217 (ep->mpa_attr.p2p_type != p2p_type)) {
1218 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1222 attrs.mpa_attr = ep->mpa_attr;
1223 attrs.max_ird = ep->ird;
1224 attrs.max_ord = ep->ord;
1225 attrs.llp_stream_handle = ep;
1226 attrs.next_state = C4IW_QP_STATE_RTS;
1228 mask = C4IW_QP_ATTR_NEXT_STATE |
1229 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1230 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1232 /* bind QP and TID with INIT_WR */
1233 err = c4iw_modify_qp(ep->com.qp->rhp,
1234 ep->com.qp, mask, &attrs, 1);
1239 * If responder's RTR requirement did not match with what initiator
1240 * supports, generate TERM message
1243 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1244 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1245 attrs.ecode = MPA_NOMATCH_RTR;
1246 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1247 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1248 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1254 * Generate TERM if initiator IRD is not sufficient for responder
1255 * provided ORD. Currently, we do the same behaviour even when
1256 * responder provided IRD is also not sufficient as regards to
1260 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1262 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1263 attrs.ecode = MPA_INSUFF_IRD;
1264 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1265 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1266 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1272 state_set(&ep->com, ABORTING);
1273 send_abort(ep, skb, GFP_KERNEL);
1275 connect_reply_upcall(ep, err);
1279 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1281 struct mpa_message *mpa;
1282 struct mpa_v2_conn_params *mpa_v2_params;
1285 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1287 if (state_read(&ep->com) != MPA_REQ_WAIT)
1291 * If we get more than the supported amount of private data
1292 * then we must fail this connection.
1294 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1296 abort_connection(ep, skb, GFP_KERNEL);
1300 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1303 * Copy the new data into our accumulation buffer.
1305 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1307 ep->mpa_pkt_len += skb->len;
1310 * If we don't even have the mpa message, then bail.
1311 * We'll continue process when more data arrives.
1313 if (ep->mpa_pkt_len < sizeof(*mpa))
1316 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1318 mpa = (struct mpa_message *) ep->mpa_pkt;
1321 * Validate MPA Header.
1323 if (mpa->revision > mpa_rev) {
1324 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1325 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1327 abort_connection(ep, skb, GFP_KERNEL);
1331 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1333 abort_connection(ep, skb, GFP_KERNEL);
1337 plen = ntohs(mpa->private_data_size);
1340 * Fail if there's too much private data.
1342 if (plen > MPA_MAX_PRIVATE_DATA) {
1344 abort_connection(ep, skb, GFP_KERNEL);
1349 * If plen does not account for pkt size
1351 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1353 abort_connection(ep, skb, GFP_KERNEL);
1356 ep->plen = (u8) plen;
1359 * If we don't have all the pdata yet, then bail.
1361 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1365 * If we get here we have accumulated the entire mpa
1366 * start reply message including private data.
1368 ep->mpa_attr.initiator = 0;
1369 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1370 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1371 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1372 ep->mpa_attr.version = mpa->revision;
1373 if (mpa->revision == 1)
1374 ep->tried_with_mpa_v1 = 1;
1375 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1377 if (mpa->revision == 2) {
1378 ep->mpa_attr.enhanced_rdma_conn =
1379 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1380 if (ep->mpa_attr.enhanced_rdma_conn) {
1381 mpa_v2_params = (struct mpa_v2_conn_params *)
1382 (ep->mpa_pkt + sizeof(*mpa));
1383 ep->ird = ntohs(mpa_v2_params->ird) &
1384 MPA_V2_IRD_ORD_MASK;
1385 ep->ord = ntohs(mpa_v2_params->ord) &
1386 MPA_V2_IRD_ORD_MASK;
1387 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1389 if (ntohs(mpa_v2_params->ord) &
1390 MPA_V2_RDMA_WRITE_RTR)
1391 ep->mpa_attr.p2p_type =
1392 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1393 else if (ntohs(mpa_v2_params->ord) &
1394 MPA_V2_RDMA_READ_RTR)
1395 ep->mpa_attr.p2p_type =
1396 FW_RI_INIT_P2PTYPE_READ_REQ;
1399 } else if (mpa->revision == 1)
1401 ep->mpa_attr.p2p_type = p2p_type;
1403 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1404 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1405 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1406 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1407 ep->mpa_attr.p2p_type);
1409 state_set(&ep->com, MPA_REQ_RCVD);
1412 connect_request_upcall(ep);
1416 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1419 struct cpl_rx_data *hdr = cplhdr(skb);
1420 unsigned int dlen = ntohs(hdr->len);
1421 unsigned int tid = GET_TID(hdr);
1422 struct tid_info *t = dev->rdev.lldi.tids;
1423 __u8 status = hdr->status;
1425 ep = lookup_tid(t, tid);
1426 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1427 skb_pull(skb, sizeof(*hdr));
1428 skb_trim(skb, dlen);
1430 /* update RX credits */
1431 update_rx_credits(ep, dlen);
1433 switch (state_read(&ep->com)) {
1435 ep->rcv_seq += dlen;
1436 process_mpa_reply(ep, skb);
1439 ep->rcv_seq += dlen;
1440 process_mpa_request(ep, skb);
1443 struct c4iw_qp_attributes attrs;
1444 BUG_ON(!ep->com.qp);
1446 pr_err("%s Unexpected streaming data." \
1447 " qpid %u ep %p state %d tid %u status %d\n",
1448 __func__, ep->com.qp->wq.sq.qid, ep,
1449 state_read(&ep->com), ep->hwtid, status);
1450 attrs.next_state = C4IW_QP_STATE_ERROR;
1451 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1452 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1453 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
1462 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1465 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1467 unsigned int tid = GET_TID(rpl);
1468 struct tid_info *t = dev->rdev.lldi.tids;
1470 ep = lookup_tid(t, tid);
1472 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1475 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1476 mutex_lock(&ep->com.mutex);
1477 switch (ep->com.state) {
1479 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1480 __state_set(&ep->com, DEAD);
1484 printk(KERN_ERR "%s ep %p state %d\n",
1485 __func__, ep, ep->com.state);
1488 mutex_unlock(&ep->com.mutex);
1491 release_ep_resources(ep);
1495 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1497 struct sk_buff *skb;
1498 struct fw_ofld_connection_wr *req;
1499 unsigned int mtu_idx;
1502 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1503 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1504 memset(req, 0, sizeof(*req));
1505 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1506 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1507 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1509 req->le.lport = ep->com.local_addr.sin_port;
1510 req->le.pport = ep->com.remote_addr.sin_port;
1511 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1512 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1513 req->tcb.t_state_to_astid =
1514 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1515 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1516 req->tcb.cplrxdataack_cplpassacceptrpl =
1517 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1518 req->tcb.tx_max = (__force __be32) jiffies;
1519 req->tcb.rcv_adv = htons(1);
1520 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1521 wscale = compute_wscale(rcv_win);
1522 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
1523 (nocong ? NO_CONG(1) : 0) |
1528 L2T_IDX(ep->l2t->idx) |
1529 TX_CHAN(ep->tx_chan) |
1530 SMAC_SEL(ep->smac_idx) |
1532 ULP_MODE(ULP_MODE_TCPDDP) |
1533 RCV_BUFSIZ(rcv_win >> 10));
1534 req->tcb.opt2 = (__force __be32) (PACE(1) |
1535 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1537 CCTRL_ECN(enable_ecn) |
1538 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
1539 if (enable_tcp_timestamps)
1540 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
1541 if (enable_tcp_sack)
1542 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
1543 if (wscale && enable_tcp_window_scaling)
1544 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1545 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1546 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
1547 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1548 set_bit(ACT_OFLD_CONN, &ep->com.history);
1549 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1553 * Return whether a failed active open has allocated a TID
1555 static inline int act_open_has_tid(int status)
1557 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1558 status != CPL_ERR_ARP_MISS;
1561 #define ACT_OPEN_RETRY_COUNT 2
1563 static int c4iw_reconnect(struct c4iw_ep *ep)
1567 struct port_info *pi;
1568 struct net_device *pdev;
1570 struct neighbour *neigh;
1572 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1573 init_timer(&ep->timer);
1576 * Allocate an active TID to initiate a TCP connection.
1578 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1579 if (ep->atid == -1) {
1580 pr_err("%s - cannot alloc atid.\n", __func__);
1584 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1587 rt = find_route(ep->com.dev,
1588 ep->com.cm_id->local_addr.sin_addr.s_addr,
1589 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1590 ep->com.cm_id->local_addr.sin_port,
1591 ep->com.cm_id->remote_addr.sin_port, 0);
1593 pr_err("%s - cannot find route.\n", __func__);
1594 err = -EHOSTUNREACH;
1599 neigh = dst_neigh_lookup(ep->dst,
1600 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1601 /* get a l2t entry */
1602 if (neigh->dev->flags & IFF_LOOPBACK) {
1603 PDBG("%s LOOPBACK\n", __func__);
1604 pdev = ip_dev_find(&init_net,
1605 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1606 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1608 pi = (struct port_info *)netdev_priv(pdev);
1609 ep->mtu = pdev->mtu;
1610 ep->tx_chan = cxgb4_port_chan(pdev);
1611 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1614 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1615 neigh, neigh->dev, 0);
1616 pi = (struct port_info *)netdev_priv(neigh->dev);
1617 ep->mtu = dst_mtu(ep->dst);
1618 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1619 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1623 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1624 ep->txq_idx = pi->port_id * step;
1625 ep->ctrlq_idx = pi->port_id;
1626 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1627 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1630 pr_err("%s - cannot alloc l2e.\n", __func__);
1635 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1636 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1639 state_set(&ep->com, CONNECTING);
1642 /* send connect request to rnic */
1643 err = send_connect(ep);
1647 cxgb4_l2t_release(ep->l2t);
1649 dst_release(ep->dst);
1651 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1652 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1655 * remember to send notification to upper layer.
1656 * We are in here so the upper layer is not aware that this is
1657 * re-connect attempt and so, upper layer is still waiting for
1658 * response of 1st connect request.
1660 connect_reply_upcall(ep, -ECONNRESET);
1661 c4iw_put_ep(&ep->com);
1666 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1669 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1670 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1671 ntohl(rpl->atid_status)));
1672 struct tid_info *t = dev->rdev.lldi.tids;
1673 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1675 ep = lookup_atid(t, atid);
1677 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1678 status, status2errno(status));
1680 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1681 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1686 set_bit(ACT_OPEN_RPL, &ep->com.history);
1689 * Log interesting failures.
1692 case CPL_ERR_CONN_RESET:
1693 case CPL_ERR_CONN_TIMEDOUT:
1695 case CPL_ERR_TCAM_FULL:
1696 dev->rdev.stats.tcam_full++;
1697 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1698 mutex_lock(&dev->rdev.stats.lock);
1699 mutex_unlock(&dev->rdev.stats.lock);
1700 send_fw_act_open_req(ep,
1701 GET_TID_TID(GET_AOPEN_ATID(
1702 ntohl(rpl->atid_status))));
1706 case CPL_ERR_CONN_EXIST:
1707 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1708 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1709 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1711 cxgb4_free_atid(t, atid);
1712 dst_release(ep->dst);
1713 cxgb4_l2t_release(ep->l2t);
1719 printk(KERN_INFO MOD "Active open failure - "
1720 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1721 atid, status, status2errno(status),
1722 &ep->com.local_addr.sin_addr.s_addr,
1723 ntohs(ep->com.local_addr.sin_port),
1724 &ep->com.remote_addr.sin_addr.s_addr,
1725 ntohs(ep->com.remote_addr.sin_port));
1729 connect_reply_upcall(ep, status2errno(status));
1730 state_set(&ep->com, DEAD);
1732 if (status && act_open_has_tid(status))
1733 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1735 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1736 cxgb4_free_atid(t, atid);
1737 dst_release(ep->dst);
1738 cxgb4_l2t_release(ep->l2t);
1739 c4iw_put_ep(&ep->com);
1744 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1746 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1747 struct tid_info *t = dev->rdev.lldi.tids;
1748 unsigned int stid = GET_TID(rpl);
1749 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1752 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1755 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1756 rpl->status, status2errno(rpl->status));
1757 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1763 static int listen_stop(struct c4iw_listen_ep *ep)
1765 struct sk_buff *skb;
1766 struct cpl_close_listsvr_req *req;
1768 PDBG("%s ep %p\n", __func__, ep);
1769 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1771 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1774 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1776 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1778 req->reply_ctrl = cpu_to_be16(
1779 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1780 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1781 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1784 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1786 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1787 struct tid_info *t = dev->rdev.lldi.tids;
1788 unsigned int stid = GET_TID(rpl);
1789 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1791 PDBG("%s ep %p\n", __func__, ep);
1792 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1796 static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1797 struct cpl_pass_accept_req *req)
1799 struct cpl_pass_accept_rpl *rpl;
1800 unsigned int mtu_idx;
1805 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1806 BUG_ON(skb_cloned(skb));
1807 skb_trim(skb, sizeof(*rpl));
1809 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1810 wscale = compute_wscale(rcv_win);
1811 opt0 = (nocong ? NO_CONG(1) : 0) |
1816 L2T_IDX(ep->l2t->idx) |
1817 TX_CHAN(ep->tx_chan) |
1818 SMAC_SEL(ep->smac_idx) |
1819 DSCP(ep->tos >> 2) |
1820 ULP_MODE(ULP_MODE_TCPDDP) |
1821 RCV_BUFSIZ(rcv_win>>10);
1822 opt2 = RX_CHANNEL(0) |
1823 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1825 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1826 opt2 |= TSTAMPS_EN(1);
1827 if (enable_tcp_sack && req->tcpopt.sack)
1829 if (wscale && enable_tcp_window_scaling)
1830 opt2 |= WND_SCALE_EN(1);
1832 const struct tcphdr *tcph;
1833 u32 hlen = ntohl(req->hdr_len);
1835 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1837 if (tcph->ece && tcph->cwr)
1838 opt2 |= CCTRL_ECN(1);
1842 INIT_TP_WR(rpl, ep->hwtid);
1843 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1845 rpl->opt0 = cpu_to_be64(opt0);
1846 rpl->opt2 = cpu_to_be32(opt2);
1847 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
1848 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1853 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1854 struct sk_buff *skb)
1856 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1858 BUG_ON(skb_cloned(skb));
1859 skb_trim(skb, sizeof(struct cpl_tid_release));
1861 release_tid(&dev->rdev, hwtid, skb);
1865 static void get_4tuple(struct cpl_pass_accept_req *req,
1866 __be32 *local_ip, __be32 *peer_ip,
1867 __be16 *local_port, __be16 *peer_port)
1869 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1870 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1871 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1872 struct tcphdr *tcp = (struct tcphdr *)
1873 ((u8 *)(req + 1) + eth_len + ip_len);
1875 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1876 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1879 *peer_ip = ip->saddr;
1880 *local_ip = ip->daddr;
1881 *peer_port = tcp->source;
1882 *local_port = tcp->dest;
1887 static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1888 struct c4iw_dev *cdev, bool clear_mpa_v1)
1890 struct neighbour *n;
1893 n = dst_neigh_lookup(dst, &peer_ip);
1899 if (n->dev->flags & IFF_LOOPBACK) {
1900 struct net_device *pdev;
1902 pdev = ip_dev_find(&init_net, peer_ip);
1907 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1911 ep->mtu = pdev->mtu;
1912 ep->tx_chan = cxgb4_port_chan(pdev);
1913 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1914 step = cdev->rdev.lldi.ntxq /
1915 cdev->rdev.lldi.nchan;
1916 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1917 step = cdev->rdev.lldi.nrxq /
1918 cdev->rdev.lldi.nchan;
1919 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1920 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1921 cxgb4_port_idx(pdev) * step];
1924 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1928 ep->mtu = dst_mtu(dst);
1929 ep->tx_chan = cxgb4_port_chan(n->dev);
1930 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1931 step = cdev->rdev.lldi.ntxq /
1932 cdev->rdev.lldi.nchan;
1933 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1934 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1935 step = cdev->rdev.lldi.nrxq /
1936 cdev->rdev.lldi.nchan;
1937 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1938 cxgb4_port_idx(n->dev) * step];
1941 ep->retry_with_mpa_v1 = 0;
1942 ep->tried_with_mpa_v1 = 0;
1954 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1956 struct c4iw_ep *child_ep = NULL, *parent_ep;
1957 struct cpl_pass_accept_req *req = cplhdr(skb);
1958 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1959 struct tid_info *t = dev->rdev.lldi.tids;
1960 unsigned int hwtid = GET_TID(req);
1961 struct dst_entry *dst;
1963 __be32 local_ip, peer_ip = 0;
1964 __be16 local_port, peer_port;
1966 u16 peer_mss = ntohs(req->tcpopt.mss);
1968 parent_ep = lookup_stid(t, stid);
1970 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1973 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1975 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1976 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1977 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1978 ntohs(peer_port), peer_mss);
1980 if (state_read(&parent_ep->com) != LISTEN) {
1981 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1986 /* Find output route */
1987 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1988 GET_POPEN_TOS(ntohl(req->tos_stid)));
1990 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1996 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1998 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2004 err = import_ep(child_ep, peer_ip, dst, dev, false);
2006 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2013 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2014 child_ep->mtu = peer_mss + 40;
2016 state_set(&child_ep->com, CONNECTING);
2017 child_ep->com.dev = dev;
2018 child_ep->com.cm_id = NULL;
2019 child_ep->com.local_addr.sin_family = PF_INET;
2020 child_ep->com.local_addr.sin_port = local_port;
2021 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
2022 child_ep->com.remote_addr.sin_family = PF_INET;
2023 child_ep->com.remote_addr.sin_port = peer_port;
2024 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
2025 c4iw_get_ep(&parent_ep->com);
2026 child_ep->parent_ep = parent_ep;
2027 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
2028 child_ep->dst = dst;
2029 child_ep->hwtid = hwtid;
2031 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2032 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2034 init_timer(&child_ep->timer);
2035 cxgb4_insert_tid(t, child_ep, hwtid);
2036 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
2037 accept_cr(child_ep, peer_ip, skb, req);
2038 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2041 reject_cr(dev, hwtid, peer_ip, skb);
2046 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2049 struct cpl_pass_establish *req = cplhdr(skb);
2050 struct tid_info *t = dev->rdev.lldi.tids;
2051 unsigned int tid = GET_TID(req);
2053 ep = lookup_tid(t, tid);
2054 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2055 ep->snd_seq = be32_to_cpu(req->snd_isn);
2056 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2058 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2059 ntohs(req->tcp_opt));
2061 set_emss(ep, ntohs(req->tcp_opt));
2063 dst_confirm(ep->dst);
2064 state_set(&ep->com, MPA_REQ_WAIT);
2066 send_flowc(ep, skb);
2067 set_bit(PASS_ESTAB, &ep->com.history);
2072 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2074 struct cpl_peer_close *hdr = cplhdr(skb);
2076 struct c4iw_qp_attributes attrs;
2079 struct tid_info *t = dev->rdev.lldi.tids;
2080 unsigned int tid = GET_TID(hdr);
2083 ep = lookup_tid(t, tid);
2084 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2085 dst_confirm(ep->dst);
2087 set_bit(PEER_CLOSE, &ep->com.history);
2088 mutex_lock(&ep->com.mutex);
2089 switch (ep->com.state) {
2091 __state_set(&ep->com, CLOSING);
2094 __state_set(&ep->com, CLOSING);
2095 connect_reply_upcall(ep, -ECONNRESET);
2100 * We're gonna mark this puppy DEAD, but keep
2101 * the reference on it until the ULP accepts or
2102 * rejects the CR. Also wake up anyone waiting
2103 * in rdma connection migration (see c4iw_accept_cr()).
2105 __state_set(&ep->com, CLOSING);
2106 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2107 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2110 __state_set(&ep->com, CLOSING);
2111 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2112 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2116 __state_set(&ep->com, CLOSING);
2117 attrs.next_state = C4IW_QP_STATE_CLOSING;
2118 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2119 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2120 if (ret != -ECONNRESET) {
2121 peer_close_upcall(ep);
2129 __state_set(&ep->com, MORIBUND);
2134 if (ep->com.cm_id && ep->com.qp) {
2135 attrs.next_state = C4IW_QP_STATE_IDLE;
2136 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2137 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2139 close_complete_upcall(ep);
2140 __state_set(&ep->com, DEAD);
2150 mutex_unlock(&ep->com.mutex);
2152 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2154 release_ep_resources(ep);
2159 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2161 static int is_neg_adv_abort(unsigned int status)
2163 return status == CPL_ERR_RTX_NEG_ADVICE ||
2164 status == CPL_ERR_PERSIST_NEG_ADVICE;
2167 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2169 struct cpl_abort_req_rss *req = cplhdr(skb);
2171 struct cpl_abort_rpl *rpl;
2172 struct sk_buff *rpl_skb;
2173 struct c4iw_qp_attributes attrs;
2176 struct tid_info *t = dev->rdev.lldi.tids;
2177 unsigned int tid = GET_TID(req);
2179 ep = lookup_tid(t, tid);
2180 if (is_neg_adv_abort(req->status)) {
2181 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2185 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2187 set_bit(PEER_ABORT, &ep->com.history);
2190 * Wake up any threads in rdma_init() or rdma_fini().
2191 * However, this is not needed if com state is just
2194 if (ep->com.state != MPA_REQ_SENT)
2195 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2197 mutex_lock(&ep->com.mutex);
2198 switch (ep->com.state) {
2206 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2207 connect_reply_upcall(ep, -ECONNRESET);
2210 * we just don't send notification upwards because we
2211 * want to retry with mpa_v1 without upper layers even
2214 * do some housekeeping so as to re-initiate the
2217 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2219 ep->retry_with_mpa_v1 = 1;
2231 if (ep->com.cm_id && ep->com.qp) {
2232 attrs.next_state = C4IW_QP_STATE_ERROR;
2233 ret = c4iw_modify_qp(ep->com.qp->rhp,
2234 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2238 "%s - qp <- error failed!\n",
2241 peer_abort_upcall(ep);
2246 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2247 mutex_unlock(&ep->com.mutex);
2253 dst_confirm(ep->dst);
2254 if (ep->com.state != ABORTING) {
2255 __state_set(&ep->com, DEAD);
2256 /* we don't release if we want to retry with mpa_v1 */
2257 if (!ep->retry_with_mpa_v1)
2260 mutex_unlock(&ep->com.mutex);
2262 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2264 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2269 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2270 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2271 INIT_TP_WR(rpl, ep->hwtid);
2272 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2273 rpl->cmd = CPL_ABORT_NO_RST;
2274 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2277 release_ep_resources(ep);
2278 else if (ep->retry_with_mpa_v1) {
2279 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
2280 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2281 dst_release(ep->dst);
2282 cxgb4_l2t_release(ep->l2t);
2289 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2292 struct c4iw_qp_attributes attrs;
2293 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2295 struct tid_info *t = dev->rdev.lldi.tids;
2296 unsigned int tid = GET_TID(rpl);
2298 ep = lookup_tid(t, tid);
2300 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2303 /* The cm_id may be null if we failed to connect */
2304 mutex_lock(&ep->com.mutex);
2305 switch (ep->com.state) {
2307 __state_set(&ep->com, MORIBUND);
2311 if ((ep->com.cm_id) && (ep->com.qp)) {
2312 attrs.next_state = C4IW_QP_STATE_IDLE;
2313 c4iw_modify_qp(ep->com.qp->rhp,
2315 C4IW_QP_ATTR_NEXT_STATE,
2318 close_complete_upcall(ep);
2319 __state_set(&ep->com, DEAD);
2329 mutex_unlock(&ep->com.mutex);
2331 release_ep_resources(ep);
2335 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2337 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2338 struct tid_info *t = dev->rdev.lldi.tids;
2339 unsigned int tid = GET_TID(rpl);
2341 struct c4iw_qp_attributes attrs;
2343 ep = lookup_tid(t, tid);
2346 if (ep && ep->com.qp) {
2347 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2348 ep->com.qp->wq.sq.qid);
2349 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2350 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2351 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2353 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2359 * Upcall from the adapter indicating data has been transmitted.
2360 * For us its just the single MPA request or reply. We can now free
2361 * the skb holding the mpa message.
2363 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2366 struct cpl_fw4_ack *hdr = cplhdr(skb);
2367 u8 credits = hdr->credits;
2368 unsigned int tid = GET_TID(hdr);
2369 struct tid_info *t = dev->rdev.lldi.tids;
2372 ep = lookup_tid(t, tid);
2373 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2375 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2376 __func__, ep, ep->hwtid, state_read(&ep->com));
2380 dst_confirm(ep->dst);
2382 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2383 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2384 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2385 kfree_skb(ep->mpa_skb);
2391 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2394 struct c4iw_ep *ep = to_ep(cm_id);
2395 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2397 if (state_read(&ep->com) == DEAD) {
2398 c4iw_put_ep(&ep->com);
2401 set_bit(ULP_REJECT, &ep->com.history);
2402 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2404 abort_connection(ep, NULL, GFP_KERNEL);
2406 err = send_mpa_reject(ep, pdata, pdata_len);
2407 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2409 c4iw_put_ep(&ep->com);
2413 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2416 struct c4iw_qp_attributes attrs;
2417 enum c4iw_qp_attr_mask mask;
2418 struct c4iw_ep *ep = to_ep(cm_id);
2419 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2420 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2422 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2423 if (state_read(&ep->com) == DEAD) {
2428 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2431 set_bit(ULP_ACCEPT, &ep->com.history);
2432 if ((conn_param->ord > c4iw_max_read_depth) ||
2433 (conn_param->ird > c4iw_max_read_depth)) {
2434 abort_connection(ep, NULL, GFP_KERNEL);
2439 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2440 if (conn_param->ord > ep->ird) {
2441 ep->ird = conn_param->ird;
2442 ep->ord = conn_param->ord;
2443 send_mpa_reject(ep, conn_param->private_data,
2444 conn_param->private_data_len);
2445 abort_connection(ep, NULL, GFP_KERNEL);
2449 if (conn_param->ird > ep->ord) {
2451 conn_param->ird = 1;
2453 abort_connection(ep, NULL, GFP_KERNEL);
2460 ep->ird = conn_param->ird;
2461 ep->ord = conn_param->ord;
2463 if (ep->mpa_attr.version != 2)
2464 if (peer2peer && ep->ird == 0)
2467 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2469 cm_id->add_ref(cm_id);
2470 ep->com.cm_id = cm_id;
2474 /* bind QP to EP and move to RTS */
2475 attrs.mpa_attr = ep->mpa_attr;
2476 attrs.max_ird = ep->ird;
2477 attrs.max_ord = ep->ord;
2478 attrs.llp_stream_handle = ep;
2479 attrs.next_state = C4IW_QP_STATE_RTS;
2481 /* bind QP and TID with INIT_WR */
2482 mask = C4IW_QP_ATTR_NEXT_STATE |
2483 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2484 C4IW_QP_ATTR_MPA_ATTR |
2485 C4IW_QP_ATTR_MAX_IRD |
2486 C4IW_QP_ATTR_MAX_ORD;
2488 err = c4iw_modify_qp(ep->com.qp->rhp,
2489 ep->com.qp, mask, &attrs, 1);
2492 err = send_mpa_reply(ep, conn_param->private_data,
2493 conn_param->private_data_len);
2497 state_set(&ep->com, FPDU_MODE);
2498 established_upcall(ep);
2499 c4iw_put_ep(&ep->com);
2502 ep->com.cm_id = NULL;
2503 cm_id->rem_ref(cm_id);
2505 c4iw_put_ep(&ep->com);
2509 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2511 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2516 if ((conn_param->ord > c4iw_max_read_depth) ||
2517 (conn_param->ird > c4iw_max_read_depth)) {
2521 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2523 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2527 init_timer(&ep->timer);
2528 ep->plen = conn_param->private_data_len;
2530 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2531 conn_param->private_data, ep->plen);
2532 ep->ird = conn_param->ird;
2533 ep->ord = conn_param->ord;
2535 if (peer2peer && ep->ord == 0)
2538 cm_id->add_ref(cm_id);
2540 ep->com.cm_id = cm_id;
2541 ep->com.qp = get_qhp(dev, conn_param->qpn);
2542 BUG_ON(!ep->com.qp);
2544 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2548 * Allocate an active TID to initiate a TCP connection.
2550 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2551 if (ep->atid == -1) {
2552 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2556 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2558 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2559 ntohl(cm_id->local_addr.sin_addr.s_addr),
2560 ntohs(cm_id->local_addr.sin_port),
2561 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2562 ntohs(cm_id->remote_addr.sin_port));
2565 rt = find_route(dev,
2566 cm_id->local_addr.sin_addr.s_addr,
2567 cm_id->remote_addr.sin_addr.s_addr,
2568 cm_id->local_addr.sin_port,
2569 cm_id->remote_addr.sin_port, 0);
2571 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2572 err = -EHOSTUNREACH;
2577 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2578 ep->dst, ep->com.dev, true);
2580 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2584 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2585 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2588 state_set(&ep->com, CONNECTING);
2590 ep->com.local_addr = cm_id->local_addr;
2591 ep->com.remote_addr = cm_id->remote_addr;
2593 /* send connect request to rnic */
2594 err = send_connect(ep);
2598 cxgb4_l2t_release(ep->l2t);
2600 dst_release(ep->dst);
2602 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2603 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2605 cm_id->rem_ref(cm_id);
2606 c4iw_put_ep(&ep->com);
2611 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2614 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2615 struct c4iw_listen_ep *ep;
2619 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2621 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2625 PDBG("%s ep %p\n", __func__, ep);
2626 cm_id->add_ref(cm_id);
2627 ep->com.cm_id = cm_id;
2629 ep->backlog = backlog;
2630 ep->com.local_addr = cm_id->local_addr;
2633 * Allocate a server TID.
2635 if (dev->rdev.lldi.enable_fw_ofld_conn)
2636 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2638 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2640 if (ep->stid == -1) {
2641 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
2645 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
2646 state_set(&ep->com, LISTEN);
2647 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2649 err = cxgb4_create_server_filter(
2650 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2651 ep->com.local_addr.sin_addr.s_addr,
2652 ep->com.local_addr.sin_port,
2654 ep->com.dev->rdev.lldi.rxq_ids[0],
2657 if (err == -EBUSY) {
2658 set_current_state(TASK_UNINTERRUPTIBLE);
2659 schedule_timeout(usecs_to_jiffies(100));
2661 } while (err == -EBUSY);
2663 c4iw_init_wr_wait(&ep->com.wr_wait);
2664 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2665 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2666 ep->com.local_addr.sin_port,
2668 ep->com.dev->rdev.lldi.rxq_ids[0]);
2670 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2675 cm_id->provider_data = ep;
2678 pr_err("%s cxgb4_create_server/filter failed err %d " \
2679 "stid %d laddr %08x lport %d\n", \
2680 __func__, err, ep->stid,
2681 ntohl(ep->com.local_addr.sin_addr.s_addr),
2682 ntohs(ep->com.local_addr.sin_port));
2683 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2685 cm_id->rem_ref(cm_id);
2686 c4iw_put_ep(&ep->com);
2692 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2695 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2697 PDBG("%s ep %p\n", __func__, ep);
2700 state_set(&ep->com, DEAD);
2701 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2702 err = cxgb4_remove_server_filter(
2703 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2704 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2706 c4iw_init_wr_wait(&ep->com.wr_wait);
2707 err = listen_stop(ep);
2710 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2713 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
2714 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2716 cm_id->rem_ref(cm_id);
2717 c4iw_put_ep(&ep->com);
2721 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2726 struct c4iw_rdev *rdev;
2728 mutex_lock(&ep->com.mutex);
2730 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2731 states[ep->com.state], abrupt);
2733 rdev = &ep->com.dev->rdev;
2734 if (c4iw_fatal_error(rdev)) {
2736 close_complete_upcall(ep);
2737 ep->com.state = DEAD;
2739 switch (ep->com.state) {
2747 ep->com.state = ABORTING;
2749 ep->com.state = CLOSING;
2752 set_bit(CLOSE_SENT, &ep->com.flags);
2755 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2759 ep->com.state = ABORTING;
2761 ep->com.state = MORIBUND;
2767 PDBG("%s ignoring disconnect ep %p state %u\n",
2768 __func__, ep, ep->com.state);
2777 set_bit(EP_DISC_ABORT, &ep->com.history);
2778 close_complete_upcall(ep);
2779 ret = send_abort(ep, NULL, gfp);
2781 set_bit(EP_DISC_CLOSE, &ep->com.history);
2782 ret = send_halfclose(ep, gfp);
2787 mutex_unlock(&ep->com.mutex);
2789 release_ep_resources(ep);
2793 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2794 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2797 int atid = be32_to_cpu(req->tid);
2799 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
2800 (__force u32) req->tid);
2804 switch (req->retval) {
2806 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2807 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2808 send_fw_act_open_req(ep, atid);
2812 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2813 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2814 send_fw_act_open_req(ep, atid);
2819 pr_info("%s unexpected ofld conn wr retval %d\n",
2820 __func__, req->retval);
2823 pr_err("active ofld_connect_wr failure %d atid %d\n",
2825 mutex_lock(&dev->rdev.stats.lock);
2826 dev->rdev.stats.act_ofld_conn_fails++;
2827 mutex_unlock(&dev->rdev.stats.lock);
2828 connect_reply_upcall(ep, status2errno(req->retval));
2829 state_set(&ep->com, DEAD);
2830 remove_handle(dev, &dev->atid_idr, atid);
2831 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2832 dst_release(ep->dst);
2833 cxgb4_l2t_release(ep->l2t);
2834 c4iw_put_ep(&ep->com);
2837 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2838 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2840 struct sk_buff *rpl_skb;
2841 struct cpl_pass_accept_req *cpl;
2844 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
2847 PDBG("%s passive open failure %d\n", __func__, req->retval);
2848 mutex_lock(&dev->rdev.stats.lock);
2849 dev->rdev.stats.pas_ofld_conn_fails++;
2850 mutex_unlock(&dev->rdev.stats.lock);
2853 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2854 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2855 (__force u32) htonl(
2856 (__force u32) req->tid)));
2857 ret = pass_accept_req(dev, rpl_skb);
2864 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2866 struct cpl_fw6_msg *rpl = cplhdr(skb);
2867 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2869 switch (rpl->type) {
2871 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2873 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2874 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2875 switch (req->t_state) {
2877 active_ofld_conn_reply(dev, skb, req);
2880 passive_ofld_conn_reply(dev, skb, req);
2883 pr_err("%s unexpected ofld conn wr state %d\n",
2884 __func__, req->t_state);
2892 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2895 u16 vlantag, len, hdr_len, eth_hdr_len;
2897 struct cpl_rx_pkt *cpl = cplhdr(skb);
2898 struct cpl_pass_accept_req *req;
2899 struct tcp_options_received tmp_opt;
2900 struct c4iw_dev *dev;
2902 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
2903 /* Store values from cpl_rx_pkt in temporary location. */
2904 vlantag = (__force u16) cpl->vlan;
2905 len = (__force u16) cpl->len;
2906 l2info = (__force u32) cpl->l2info;
2907 hdr_len = (__force u16) cpl->hdr_len;
2910 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2913 * We need to parse the TCP options from SYN packet.
2914 * to generate cpl_pass_accept_req.
2916 memset(&tmp_opt, 0, sizeof(tmp_opt));
2917 tcp_clear_options(&tmp_opt);
2918 tcp_parse_options(skb, &tmp_opt, 0, NULL);
2920 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2921 memset(req, 0, sizeof(*req));
2922 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2923 V_SYN_MAC_IDX(G_RX_MACIDX(
2924 (__force int) htonl(l2info))) |
2926 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
2927 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
2928 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
2929 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
2930 (__force int) htonl(l2info))) |
2931 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
2932 (__force int) htons(hdr_len))) |
2933 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
2934 (__force int) htons(hdr_len))) |
2935 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
2936 req->vlan = (__force __be16) vlantag;
2937 req->len = (__force __be16) len;
2938 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2939 PASS_OPEN_TOS(tos));
2940 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2941 if (tmp_opt.wscale_ok)
2942 req->tcpopt.wsf = tmp_opt.snd_wscale;
2943 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2944 if (tmp_opt.sack_ok)
2945 req->tcpopt.sack = 1;
2946 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2950 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2951 __be32 laddr, __be16 lport,
2952 __be32 raddr, __be16 rport,
2953 u32 rcv_isn, u32 filter, u16 window,
2954 u32 rss_qid, u8 port_id)
2956 struct sk_buff *req_skb;
2957 struct fw_ofld_connection_wr *req;
2958 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2960 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2961 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2962 memset(req, 0, sizeof(*req));
2963 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2964 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2965 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2966 req->le.filter = (__force __be32) filter;
2967 req->le.lport = lport;
2968 req->le.pport = rport;
2969 req->le.u.ipv4.lip = laddr;
2970 req->le.u.ipv4.pip = raddr;
2971 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2972 req->tcb.rcv_adv = htons(window);
2973 req->tcb.t_state_to_astid =
2974 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2975 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2976 V_FW_OFLD_CONNECTION_WR_ASTID(
2977 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2980 * We store the qid in opt2 which will be used by the firmware
2981 * to send us the wr response.
2983 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2986 * We initialize the MSS index in TCB to 0xF.
2987 * So that when driver sends cpl_pass_accept_rpl
2988 * TCB picks up the correct value. If this was 0
2989 * TP will ignore any value > 0 for MSS index.
2991 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2992 req->cookie = (unsigned long)skb;
2994 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2995 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2999 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3000 * messages when a filter is being used instead of server to
3001 * redirect a syn packet. When packets hit filter they are redirected
3002 * to the offload queue and driver tries to establish the connection
3003 * using firmware work request.
3005 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3008 unsigned int filter;
3009 struct ethhdr *eh = NULL;
3010 struct vlan_ethhdr *vlan_eh = NULL;
3012 struct tcphdr *tcph;
3013 struct rss_header *rss = (void *)skb->data;
3014 struct cpl_rx_pkt *cpl = (void *)skb->data;
3015 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3016 struct l2t_entry *e;
3017 struct dst_entry *dst;
3019 struct c4iw_ep *lep;
3021 struct port_info *pi;
3022 struct net_device *pdev;
3023 u16 rss_qid, eth_hdr_len;
3026 struct neighbour *neigh;
3028 /* Drop all non-SYN packets */
3029 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3033 * Drop all packets which did not hit the filter.
3034 * Unlikely to happen.
3036 if (!(rss->filter_hit && rss->filter_tid))
3040 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3042 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
3043 - dev->rdev.lldi.tids->sftid_base
3044 + dev->rdev.lldi.tids->nstids;
3046 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3048 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3052 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3053 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3054 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3055 if (eth_hdr_len == ETH_HLEN) {
3056 eh = (struct ethhdr *)(req + 1);
3057 iph = (struct iphdr *)(eh + 1);
3059 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3060 iph = (struct iphdr *)(vlan_eh + 1);
3061 skb->vlan_tci = ntohs(cpl->vlan);
3064 if (iph->version != 0x4)
3067 tcph = (struct tcphdr *)(iph + 1);
3068 skb_set_network_header(skb, (void *)iph - (void *)rss);
3069 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3072 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3073 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3074 ntohs(tcph->source), iph->tos);
3076 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3079 pr_err("%s - failed to find dst entry!\n",
3084 neigh = dst_neigh_lookup_skb(dst, skb);
3086 if (neigh->dev->flags & IFF_LOOPBACK) {
3087 pdev = ip_dev_find(&init_net, iph->daddr);
3088 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3090 pi = (struct port_info *)netdev_priv(pdev);
3091 tx_chan = cxgb4_port_chan(pdev);
3094 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3096 pi = (struct port_info *)netdev_priv(neigh->dev);
3097 tx_chan = cxgb4_port_chan(neigh->dev);
3100 pr_err("%s - failed to allocate l2t entry!\n",
3105 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3106 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3107 window = (__force u16) htons((__force u16)tcph->window);
3109 /* Calcuate filter portion for LE region. */
3110 filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
3113 * Synthesize the cpl_pass_accept_req. We have everything except the
3114 * TID. Once firmware sends a reply with TID we update the TID field
3115 * in cpl and pass it through the regular cpl_pass_accept_req path.
3117 build_cpl_pass_accept_req(skb, stid, iph->tos);
3118 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3119 tcph->source, ntohl(tcph->seq), filter, window,
3120 rss_qid, pi->port_id);
3121 cxgb4_l2t_release(e);
3129 * These are the real handlers that are called from a
3132 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3133 [CPL_ACT_ESTABLISH] = act_establish,
3134 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3135 [CPL_RX_DATA] = rx_data,
3136 [CPL_ABORT_RPL_RSS] = abort_rpl,
3137 [CPL_ABORT_RPL] = abort_rpl,
3138 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3139 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3140 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3141 [CPL_PASS_ESTABLISH] = pass_establish,
3142 [CPL_PEER_CLOSE] = peer_close,
3143 [CPL_ABORT_REQ_RSS] = peer_abort,
3144 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3145 [CPL_RDMA_TERMINATE] = terminate,
3146 [CPL_FW4_ACK] = fw4_ack,
3147 [CPL_FW6_MSG] = deferred_fw6_msg,
3148 [CPL_RX_PKT] = rx_pkt
3151 static void process_timeout(struct c4iw_ep *ep)
3153 struct c4iw_qp_attributes attrs;
3156 mutex_lock(&ep->com.mutex);
3157 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3159 set_bit(TIMEDOUT, &ep->com.history);
3160 switch (ep->com.state) {
3162 __state_set(&ep->com, ABORTING);
3163 connect_reply_upcall(ep, -ETIMEDOUT);
3166 __state_set(&ep->com, ABORTING);
3170 if (ep->com.cm_id && ep->com.qp) {
3171 attrs.next_state = C4IW_QP_STATE_ERROR;
3172 c4iw_modify_qp(ep->com.qp->rhp,
3173 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3176 __state_set(&ep->com, ABORTING);
3179 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3180 __func__, ep, ep->hwtid, ep->com.state);
3183 mutex_unlock(&ep->com.mutex);
3185 abort_connection(ep, NULL, GFP_KERNEL);
3186 c4iw_put_ep(&ep->com);
3189 static void process_timedout_eps(void)
3193 spin_lock_irq(&timeout_lock);
3194 while (!list_empty(&timeout_list)) {
3195 struct list_head *tmp;
3197 tmp = timeout_list.next;
3199 spin_unlock_irq(&timeout_lock);
3200 ep = list_entry(tmp, struct c4iw_ep, entry);
3201 process_timeout(ep);
3202 spin_lock_irq(&timeout_lock);
3204 spin_unlock_irq(&timeout_lock);
3207 static void process_work(struct work_struct *work)
3209 struct sk_buff *skb = NULL;
3210 struct c4iw_dev *dev;
3211 struct cpl_act_establish *rpl;
3212 unsigned int opcode;
3215 while ((skb = skb_dequeue(&rxq))) {
3217 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3218 opcode = rpl->ot.opcode;
3220 BUG_ON(!work_handlers[opcode]);
3221 ret = work_handlers[opcode](dev, skb);
3225 process_timedout_eps();
3228 static DECLARE_WORK(skb_work, process_work);
3230 static void ep_timeout(unsigned long arg)
3232 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3235 spin_lock(&timeout_lock);
3236 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3237 list_add_tail(&ep->entry, &timeout_list);
3240 spin_unlock(&timeout_lock);
3242 queue_work(workq, &skb_work);
3246 * All the CM events are handled on a work queue to have a safe context.
3248 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3252 * Save dev in the skb->cb area.
3254 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3257 * Queue the skb and schedule the worker thread.
3259 skb_queue_tail(&rxq, skb);
3260 queue_work(workq, &skb_work);
3264 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3266 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3268 if (rpl->status != CPL_ERR_NONE) {
3269 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3270 "for tid %u\n", rpl->status, GET_TID(rpl));
3276 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3278 struct cpl_fw6_msg *rpl = cplhdr(skb);
3279 struct c4iw_wr_wait *wr_waitp;
3282 PDBG("%s type %u\n", __func__, rpl->type);
3284 switch (rpl->type) {
3285 case FW6_TYPE_WR_RPL:
3286 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
3287 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
3288 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
3290 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3294 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3298 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3306 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3308 struct cpl_abort_req_rss *req = cplhdr(skb);
3310 struct tid_info *t = dev->rdev.lldi.tids;
3311 unsigned int tid = GET_TID(req);
3313 ep = lookup_tid(t, tid);
3315 printk(KERN_WARNING MOD
3316 "Abort on non-existent endpoint, tid %d\n", tid);
3320 if (is_neg_adv_abort(req->status)) {
3321 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3326 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3330 * Wake up any threads in rdma_init() or rdma_fini().
3331 * However, if we are on MPAv2 and want to retry with MPAv1
3332 * then, don't wake up yet.
3334 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3335 if (ep->com.state != MPA_REQ_SENT)
3336 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3338 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3344 * Most upcalls from the T4 Core go to sched() to
3345 * schedule the processing on a work queue.
3347 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3348 [CPL_ACT_ESTABLISH] = sched,
3349 [CPL_ACT_OPEN_RPL] = sched,
3350 [CPL_RX_DATA] = sched,
3351 [CPL_ABORT_RPL_RSS] = sched,
3352 [CPL_ABORT_RPL] = sched,
3353 [CPL_PASS_OPEN_RPL] = sched,
3354 [CPL_CLOSE_LISTSRV_RPL] = sched,
3355 [CPL_PASS_ACCEPT_REQ] = sched,
3356 [CPL_PASS_ESTABLISH] = sched,
3357 [CPL_PEER_CLOSE] = sched,
3358 [CPL_CLOSE_CON_RPL] = sched,
3359 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
3360 [CPL_RDMA_TERMINATE] = sched,
3361 [CPL_FW4_ACK] = sched,
3362 [CPL_SET_TCB_RPL] = set_tcb_rpl,
3363 [CPL_FW6_MSG] = fw6_msg,
3364 [CPL_RX_PKT] = sched
3367 int __init c4iw_cm_init(void)
3369 spin_lock_init(&timeout_lock);
3370 skb_queue_head_init(&rxq);
3372 workq = create_singlethread_workqueue("iw_cxgb4");
3379 void __exit c4iw_cm_term(void)
3381 WARN_ON(!list_empty(&timeout_list));
3382 flush_workqueue(workq);
3383 destroy_workqueue(workq);