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 PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
163 del_timer_sync(&ep->timer);
165 c4iw_get_ep(&ep->com);
166 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
167 ep->timer.data = (unsigned long)ep;
168 ep->timer.function = ep_timeout;
169 add_timer(&ep->timer);
172 static void stop_ep_timer(struct c4iw_ep *ep)
174 PDBG("%s ep %p\n", __func__, ep);
175 if (!timer_pending(&ep->timer)) {
176 WARN(1, "%s timer stopped when its not running! "
177 "ep %p state %u\n", __func__, ep, ep->com.state);
180 del_timer_sync(&ep->timer);
181 c4iw_put_ep(&ep->com);
184 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
185 struct l2t_entry *l2e)
189 if (c4iw_fatal_error(rdev)) {
191 PDBG("%s - device in error state - dropping\n", __func__);
194 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
197 return error < 0 ? error : 0;
200 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
204 if (c4iw_fatal_error(rdev)) {
206 PDBG("%s - device in error state - dropping\n", __func__);
209 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
212 return error < 0 ? error : 0;
215 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
217 struct cpl_tid_release *req;
219 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
222 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
223 INIT_TP_WR(req, hwtid);
224 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
225 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
226 c4iw_ofld_send(rdev, skb);
230 static void set_emss(struct c4iw_ep *ep, u16 opt)
232 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
234 if (GET_TCPOPT_TSTAMP(opt))
238 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
242 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
244 enum c4iw_ep_state state;
246 mutex_lock(&epc->mutex);
248 mutex_unlock(&epc->mutex);
252 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
257 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
259 mutex_lock(&epc->mutex);
260 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
261 __state_set(epc, new);
262 mutex_unlock(&epc->mutex);
266 static void *alloc_ep(int size, gfp_t gfp)
268 struct c4iw_ep_common *epc;
270 epc = kzalloc(size, gfp);
272 kref_init(&epc->kref);
273 mutex_init(&epc->mutex);
274 c4iw_init_wr_wait(&epc->wr_wait);
276 PDBG("%s alloc ep %p\n", __func__, epc);
280 void _c4iw_free_ep(struct kref *kref)
284 ep = container_of(kref, struct c4iw_ep, com.kref);
285 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
286 if (test_bit(QP_REFERENCED, &ep->com.flags))
288 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
289 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
290 dst_release(ep->dst);
291 cxgb4_l2t_release(ep->l2t);
292 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
297 static void release_ep_resources(struct c4iw_ep *ep)
299 set_bit(RELEASE_RESOURCES, &ep->com.flags);
300 c4iw_put_ep(&ep->com);
303 static int status2errno(int status)
308 case CPL_ERR_CONN_RESET:
310 case CPL_ERR_ARP_MISS:
311 return -EHOSTUNREACH;
312 case CPL_ERR_CONN_TIMEDOUT:
314 case CPL_ERR_TCAM_FULL:
316 case CPL_ERR_CONN_EXIST:
324 * Try and reuse skbs already allocated...
326 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
328 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
331 skb_reset_transport_header(skb);
333 skb = alloc_skb(len, gfp);
338 static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
339 __be32 peer_ip, __be16 local_port,
340 __be16 peer_port, u8 tos)
345 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
346 peer_port, local_port, IPPROTO_TCP,
353 static void arp_failure_discard(void *handle, struct sk_buff *skb)
355 PDBG("%s c4iw_dev %p\n", __func__, handle);
360 * Handle an ARP failure for an active open.
362 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
364 printk(KERN_ERR MOD "ARP failure duing connect\n");
369 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
372 static void abort_arp_failure(void *handle, struct sk_buff *skb)
374 struct c4iw_rdev *rdev = handle;
375 struct cpl_abort_req *req = cplhdr(skb);
377 PDBG("%s rdev %p\n", __func__, rdev);
378 req->cmd = CPL_ABORT_NO_RST;
379 c4iw_ofld_send(rdev, skb);
382 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
384 unsigned int flowclen = 80;
385 struct fw_flowc_wr *flowc;
388 skb = get_skb(skb, flowclen, GFP_KERNEL);
389 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
391 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
392 FW_FLOWC_WR_NPARAMS(8));
393 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
394 16)) | FW_WR_FLOWID(ep->hwtid));
396 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
397 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
398 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
399 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
400 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
401 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
402 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
403 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
404 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
405 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
406 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
407 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
408 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
409 flowc->mnemval[6].val = cpu_to_be32(snd_win);
410 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
411 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
412 /* Pad WR to 16 byte boundary */
413 flowc->mnemval[8].mnemonic = 0;
414 flowc->mnemval[8].val = 0;
415 for (i = 0; i < 9; i++) {
416 flowc->mnemval[i].r4[0] = 0;
417 flowc->mnemval[i].r4[1] = 0;
418 flowc->mnemval[i].r4[2] = 0;
421 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
422 c4iw_ofld_send(&ep->com.dev->rdev, skb);
425 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
427 struct cpl_close_con_req *req;
429 int wrlen = roundup(sizeof *req, 16);
431 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
432 skb = get_skb(NULL, wrlen, gfp);
434 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
437 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
438 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
439 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
440 memset(req, 0, wrlen);
441 INIT_TP_WR(req, ep->hwtid);
442 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
444 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
447 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
449 struct cpl_abort_req *req;
450 int wrlen = roundup(sizeof *req, 16);
452 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
453 skb = get_skb(skb, wrlen, gfp);
455 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
459 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
460 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
461 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
462 memset(req, 0, wrlen);
463 INIT_TP_WR(req, ep->hwtid);
464 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
465 req->cmd = CPL_ABORT_SEND_RST;
466 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
469 #define VLAN_NONE 0xfff
470 #define FILTER_SEL_VLAN_NONE 0xffff
471 #define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
472 #define FILTER_SEL_WIDTH_VIN_P_FC \
473 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
474 #define FILTER_SEL_WIDTH_TAG_P_FC \
475 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
476 #define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
478 static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
479 struct l2t_entry *l2t)
481 unsigned int ntuple = 0;
484 switch (dev->rdev.lldi.filt_mode) {
486 /* default filter mode */
487 case HW_TPL_FR_MT_PR_IV_P_FC:
488 if (l2t->vlan == VLAN_NONE)
489 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
491 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
492 ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
494 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
495 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
497 case HW_TPL_FR_MT_PR_OV_P_FC: {
498 viid = cxgb4_port_viid(l2t->neigh->dev);
500 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
501 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
502 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
503 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
504 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
513 static int send_connect(struct c4iw_ep *ep)
515 struct cpl_act_open_req *req;
519 unsigned int mtu_idx;
521 int wrlen = roundup(sizeof *req, 16);
523 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
525 skb = get_skb(NULL, wrlen, GFP_KERNEL);
527 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
531 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
533 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
534 wscale = compute_wscale(rcv_win);
535 opt0 = (nocong ? NO_CONG(1) : 0) |
540 L2T_IDX(ep->l2t->idx) |
541 TX_CHAN(ep->tx_chan) |
542 SMAC_SEL(ep->smac_idx) |
544 ULP_MODE(ULP_MODE_TCPDDP) |
545 RCV_BUFSIZ(rcv_win>>10);
546 opt2 = RX_CHANNEL(0) |
547 CCTRL_ECN(enable_ecn) |
548 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
549 if (enable_tcp_timestamps)
550 opt2 |= TSTAMPS_EN(1);
553 if (wscale && enable_tcp_window_scaling)
554 opt2 |= WND_SCALE_EN(1);
555 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
557 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
559 OPCODE_TID(req) = cpu_to_be32(
560 MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
561 req->local_port = ep->com.local_addr.sin_port;
562 req->peer_port = ep->com.remote_addr.sin_port;
563 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
564 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
565 req->opt0 = cpu_to_be64(opt0);
566 req->params = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst, ep->l2t));
567 req->opt2 = cpu_to_be32(opt2);
568 set_bit(ACT_OPEN_REQ, &ep->com.history);
569 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
572 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
576 struct fw_ofld_tx_data_wr *req;
577 struct mpa_message *mpa;
578 struct mpa_v2_conn_params mpa_v2_params;
580 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
582 BUG_ON(skb_cloned(skb));
584 mpalen = sizeof(*mpa) + ep->plen;
585 if (mpa_rev_to_use == 2)
586 mpalen += sizeof(struct mpa_v2_conn_params);
587 wrlen = roundup(mpalen + sizeof *req, 16);
588 skb = get_skb(skb, wrlen, GFP_KERNEL);
590 connect_reply_upcall(ep, -ENOMEM);
593 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
595 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
596 memset(req, 0, wrlen);
597 req->op_to_immdlen = cpu_to_be32(
598 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
600 FW_WR_IMMDLEN(mpalen));
601 req->flowid_len16 = cpu_to_be32(
602 FW_WR_FLOWID(ep->hwtid) |
603 FW_WR_LEN16(wrlen >> 4));
604 req->plen = cpu_to_be32(mpalen);
605 req->tunnel_to_proxy = cpu_to_be32(
606 FW_OFLD_TX_DATA_WR_FLUSH(1) |
607 FW_OFLD_TX_DATA_WR_SHOVE(1));
609 mpa = (struct mpa_message *)(req + 1);
610 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
611 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
612 (markers_enabled ? MPA_MARKERS : 0) |
613 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
614 mpa->private_data_size = htons(ep->plen);
615 mpa->revision = mpa_rev_to_use;
616 if (mpa_rev_to_use == 1) {
617 ep->tried_with_mpa_v1 = 1;
618 ep->retry_with_mpa_v1 = 0;
621 if (mpa_rev_to_use == 2) {
622 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
623 sizeof (struct mpa_v2_conn_params));
624 mpa_v2_params.ird = htons((u16)ep->ird);
625 mpa_v2_params.ord = htons((u16)ep->ord);
628 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
629 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
631 htons(MPA_V2_RDMA_WRITE_RTR);
632 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
634 htons(MPA_V2_RDMA_READ_RTR);
636 memcpy(mpa->private_data, &mpa_v2_params,
637 sizeof(struct mpa_v2_conn_params));
640 memcpy(mpa->private_data +
641 sizeof(struct mpa_v2_conn_params),
642 ep->mpa_pkt + sizeof(*mpa), ep->plen);
645 memcpy(mpa->private_data,
646 ep->mpa_pkt + sizeof(*mpa), ep->plen);
649 * Reference the mpa skb. This ensures the data area
650 * will remain in memory until the hw acks the tx.
651 * Function fw4_ack() will deref it.
654 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
657 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
659 state_set(&ep->com, MPA_REQ_SENT);
660 ep->mpa_attr.initiator = 1;
664 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
667 struct fw_ofld_tx_data_wr *req;
668 struct mpa_message *mpa;
670 struct mpa_v2_conn_params mpa_v2_params;
672 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
674 mpalen = sizeof(*mpa) + plen;
675 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
676 mpalen += sizeof(struct mpa_v2_conn_params);
677 wrlen = roundup(mpalen + sizeof *req, 16);
679 skb = get_skb(NULL, wrlen, GFP_KERNEL);
681 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
684 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
686 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
687 memset(req, 0, wrlen);
688 req->op_to_immdlen = cpu_to_be32(
689 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
691 FW_WR_IMMDLEN(mpalen));
692 req->flowid_len16 = cpu_to_be32(
693 FW_WR_FLOWID(ep->hwtid) |
694 FW_WR_LEN16(wrlen >> 4));
695 req->plen = cpu_to_be32(mpalen);
696 req->tunnel_to_proxy = cpu_to_be32(
697 FW_OFLD_TX_DATA_WR_FLUSH(1) |
698 FW_OFLD_TX_DATA_WR_SHOVE(1));
700 mpa = (struct mpa_message *)(req + 1);
701 memset(mpa, 0, sizeof(*mpa));
702 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
703 mpa->flags = MPA_REJECT;
704 mpa->revision = mpa_rev;
705 mpa->private_data_size = htons(plen);
707 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
708 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
709 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
710 sizeof (struct mpa_v2_conn_params));
711 mpa_v2_params.ird = htons(((u16)ep->ird) |
712 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
714 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
716 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
717 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
718 FW_RI_INIT_P2PTYPE_READ_REQ ?
719 MPA_V2_RDMA_READ_RTR : 0) : 0));
720 memcpy(mpa->private_data, &mpa_v2_params,
721 sizeof(struct mpa_v2_conn_params));
724 memcpy(mpa->private_data +
725 sizeof(struct mpa_v2_conn_params), pdata, plen);
728 memcpy(mpa->private_data, pdata, plen);
731 * Reference the mpa skb again. This ensures the data area
732 * will remain in memory until the hw acks the tx.
733 * Function fw4_ack() will deref it.
736 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
737 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
740 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
743 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
746 struct fw_ofld_tx_data_wr *req;
747 struct mpa_message *mpa;
749 struct mpa_v2_conn_params mpa_v2_params;
751 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
753 mpalen = sizeof(*mpa) + plen;
754 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
755 mpalen += sizeof(struct mpa_v2_conn_params);
756 wrlen = roundup(mpalen + sizeof *req, 16);
758 skb = get_skb(NULL, wrlen, GFP_KERNEL);
760 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
763 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
765 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
766 memset(req, 0, wrlen);
767 req->op_to_immdlen = cpu_to_be32(
768 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
770 FW_WR_IMMDLEN(mpalen));
771 req->flowid_len16 = cpu_to_be32(
772 FW_WR_FLOWID(ep->hwtid) |
773 FW_WR_LEN16(wrlen >> 4));
774 req->plen = cpu_to_be32(mpalen);
775 req->tunnel_to_proxy = cpu_to_be32(
776 FW_OFLD_TX_DATA_WR_FLUSH(1) |
777 FW_OFLD_TX_DATA_WR_SHOVE(1));
779 mpa = (struct mpa_message *)(req + 1);
780 memset(mpa, 0, sizeof(*mpa));
781 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
782 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
783 (markers_enabled ? MPA_MARKERS : 0);
784 mpa->revision = ep->mpa_attr.version;
785 mpa->private_data_size = htons(plen);
787 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
788 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
789 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
790 sizeof (struct mpa_v2_conn_params));
791 mpa_v2_params.ird = htons((u16)ep->ird);
792 mpa_v2_params.ord = htons((u16)ep->ord);
793 if (peer2peer && (ep->mpa_attr.p2p_type !=
794 FW_RI_INIT_P2PTYPE_DISABLED)) {
795 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
797 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
799 htons(MPA_V2_RDMA_WRITE_RTR);
800 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
802 htons(MPA_V2_RDMA_READ_RTR);
805 memcpy(mpa->private_data, &mpa_v2_params,
806 sizeof(struct mpa_v2_conn_params));
809 memcpy(mpa->private_data +
810 sizeof(struct mpa_v2_conn_params), pdata, plen);
813 memcpy(mpa->private_data, pdata, plen);
816 * Reference the mpa skb. This ensures the data area
817 * will remain in memory until the hw acks the tx.
818 * Function fw4_ack() will deref it.
821 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
823 state_set(&ep->com, MPA_REP_SENT);
824 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
827 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
830 struct cpl_act_establish *req = cplhdr(skb);
831 unsigned int tid = GET_TID(req);
832 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
833 struct tid_info *t = dev->rdev.lldi.tids;
835 ep = lookup_atid(t, atid);
837 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
838 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
840 dst_confirm(ep->dst);
842 /* setup the hwtid for this connection */
844 cxgb4_insert_tid(t, ep, tid);
845 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
847 ep->snd_seq = be32_to_cpu(req->snd_isn);
848 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
850 set_emss(ep, ntohs(req->tcp_opt));
852 /* dealloc the atid */
853 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
854 cxgb4_free_atid(t, atid);
855 set_bit(ACT_ESTAB, &ep->com.history);
857 /* start MPA negotiation */
858 send_flowc(ep, NULL);
859 if (ep->retry_with_mpa_v1)
860 send_mpa_req(ep, skb, 1);
862 send_mpa_req(ep, skb, mpa_rev);
867 static void close_complete_upcall(struct c4iw_ep *ep)
869 struct iw_cm_event event;
871 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
872 memset(&event, 0, sizeof(event));
873 event.event = IW_CM_EVENT_CLOSE;
875 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
876 ep, ep->com.cm_id, ep->hwtid);
877 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
878 ep->com.cm_id->rem_ref(ep->com.cm_id);
879 ep->com.cm_id = NULL;
880 set_bit(CLOSE_UPCALL, &ep->com.history);
884 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
886 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
887 close_complete_upcall(ep);
888 state_set(&ep->com, ABORTING);
889 set_bit(ABORT_CONN, &ep->com.history);
890 return send_abort(ep, skb, gfp);
893 static void peer_close_upcall(struct c4iw_ep *ep)
895 struct iw_cm_event event;
897 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
898 memset(&event, 0, sizeof(event));
899 event.event = IW_CM_EVENT_DISCONNECT;
901 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
902 ep, ep->com.cm_id, ep->hwtid);
903 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
904 set_bit(DISCONN_UPCALL, &ep->com.history);
908 static void peer_abort_upcall(struct c4iw_ep *ep)
910 struct iw_cm_event event;
912 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
913 memset(&event, 0, sizeof(event));
914 event.event = IW_CM_EVENT_CLOSE;
915 event.status = -ECONNRESET;
917 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
918 ep->com.cm_id, ep->hwtid);
919 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
920 ep->com.cm_id->rem_ref(ep->com.cm_id);
921 ep->com.cm_id = NULL;
922 set_bit(ABORT_UPCALL, &ep->com.history);
926 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
928 struct iw_cm_event event;
930 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
931 memset(&event, 0, sizeof(event));
932 event.event = IW_CM_EVENT_CONNECT_REPLY;
933 event.status = status;
934 event.local_addr = ep->com.local_addr;
935 event.remote_addr = ep->com.remote_addr;
937 if ((status == 0) || (status == -ECONNREFUSED)) {
938 if (!ep->tried_with_mpa_v1) {
939 /* this means MPA_v2 is used */
940 event.private_data_len = ep->plen -
941 sizeof(struct mpa_v2_conn_params);
942 event.private_data = ep->mpa_pkt +
943 sizeof(struct mpa_message) +
944 sizeof(struct mpa_v2_conn_params);
946 /* this means MPA_v1 is used */
947 event.private_data_len = ep->plen;
948 event.private_data = ep->mpa_pkt +
949 sizeof(struct mpa_message);
953 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
955 set_bit(CONN_RPL_UPCALL, &ep->com.history);
956 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
959 ep->com.cm_id->rem_ref(ep->com.cm_id);
960 ep->com.cm_id = NULL;
964 static void connect_request_upcall(struct c4iw_ep *ep)
966 struct iw_cm_event event;
968 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
969 memset(&event, 0, sizeof(event));
970 event.event = IW_CM_EVENT_CONNECT_REQUEST;
971 event.local_addr = ep->com.local_addr;
972 event.remote_addr = ep->com.remote_addr;
973 event.provider_data = ep;
974 if (!ep->tried_with_mpa_v1) {
975 /* this means MPA_v2 is used */
978 event.private_data_len = ep->plen -
979 sizeof(struct mpa_v2_conn_params);
980 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
981 sizeof(struct mpa_v2_conn_params);
983 /* this means MPA_v1 is used. Send max supported */
984 event.ord = c4iw_max_read_depth;
985 event.ird = c4iw_max_read_depth;
986 event.private_data_len = ep->plen;
987 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
989 if (state_read(&ep->parent_ep->com) != DEAD) {
990 c4iw_get_ep(&ep->com);
991 ep->parent_ep->com.cm_id->event_handler(
992 ep->parent_ep->com.cm_id,
995 set_bit(CONNREQ_UPCALL, &ep->com.history);
996 c4iw_put_ep(&ep->parent_ep->com);
997 ep->parent_ep = NULL;
1000 static void established_upcall(struct c4iw_ep *ep)
1002 struct iw_cm_event event;
1004 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1005 memset(&event, 0, sizeof(event));
1006 event.event = IW_CM_EVENT_ESTABLISHED;
1007 event.ird = ep->ird;
1008 event.ord = ep->ord;
1009 if (ep->com.cm_id) {
1010 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1011 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1012 set_bit(ESTAB_UPCALL, &ep->com.history);
1016 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1018 struct cpl_rx_data_ack *req;
1019 struct sk_buff *skb;
1020 int wrlen = roundup(sizeof *req, 16);
1022 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1023 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1025 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1029 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1030 memset(req, 0, wrlen);
1031 INIT_TP_WR(req, ep->hwtid);
1032 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1034 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1036 V_RX_DACK_MODE(dack_mode));
1037 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
1038 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1042 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1044 struct mpa_message *mpa;
1045 struct mpa_v2_conn_params *mpa_v2_params;
1047 u16 resp_ird, resp_ord;
1048 u8 rtr_mismatch = 0, insuff_ird = 0;
1049 struct c4iw_qp_attributes attrs;
1050 enum c4iw_qp_attr_mask mask;
1053 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1056 * Stop mpa timer. If it expired, then the state has
1057 * changed and we bail since ep_timeout already aborted
1061 if (state_read(&ep->com) != MPA_REQ_SENT)
1065 * If we get more than the supported amount of private data
1066 * then we must fail this connection.
1068 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1074 * copy the new data into our accumulation buffer.
1076 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1078 ep->mpa_pkt_len += skb->len;
1081 * if we don't even have the mpa message, then bail.
1083 if (ep->mpa_pkt_len < sizeof(*mpa))
1085 mpa = (struct mpa_message *) ep->mpa_pkt;
1087 /* Validate MPA header. */
1088 if (mpa->revision > mpa_rev) {
1089 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1090 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1094 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1099 plen = ntohs(mpa->private_data_size);
1102 * Fail if there's too much private data.
1104 if (plen > MPA_MAX_PRIVATE_DATA) {
1110 * If plen does not account for pkt size
1112 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1117 ep->plen = (u8) plen;
1120 * If we don't have all the pdata yet, then bail.
1121 * We'll continue process when more data arrives.
1123 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1126 if (mpa->flags & MPA_REJECT) {
1127 err = -ECONNREFUSED;
1132 * If we get here we have accumulated the entire mpa
1133 * start reply message including private data. And
1134 * the MPA header is valid.
1136 state_set(&ep->com, FPDU_MODE);
1137 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1138 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1139 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1140 ep->mpa_attr.version = mpa->revision;
1141 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1143 if (mpa->revision == 2) {
1144 ep->mpa_attr.enhanced_rdma_conn =
1145 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1146 if (ep->mpa_attr.enhanced_rdma_conn) {
1147 mpa_v2_params = (struct mpa_v2_conn_params *)
1148 (ep->mpa_pkt + sizeof(*mpa));
1149 resp_ird = ntohs(mpa_v2_params->ird) &
1150 MPA_V2_IRD_ORD_MASK;
1151 resp_ord = ntohs(mpa_v2_params->ord) &
1152 MPA_V2_IRD_ORD_MASK;
1155 * This is a double-check. Ideally, below checks are
1156 * not required since ird/ord stuff has been taken
1157 * care of in c4iw_accept_cr
1159 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1166 if (ntohs(mpa_v2_params->ird) &
1167 MPA_V2_PEER2PEER_MODEL) {
1168 if (ntohs(mpa_v2_params->ord) &
1169 MPA_V2_RDMA_WRITE_RTR)
1170 ep->mpa_attr.p2p_type =
1171 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1172 else if (ntohs(mpa_v2_params->ord) &
1173 MPA_V2_RDMA_READ_RTR)
1174 ep->mpa_attr.p2p_type =
1175 FW_RI_INIT_P2PTYPE_READ_REQ;
1178 } else if (mpa->revision == 1)
1180 ep->mpa_attr.p2p_type = p2p_type;
1182 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1183 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1184 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1185 ep->mpa_attr.recv_marker_enabled,
1186 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1187 ep->mpa_attr.p2p_type, p2p_type);
1190 * If responder's RTR does not match with that of initiator, assign
1191 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1192 * generated when moving QP to RTS state.
1193 * A TERM message will be sent after QP has moved to RTS state
1195 if ((ep->mpa_attr.version == 2) && peer2peer &&
1196 (ep->mpa_attr.p2p_type != p2p_type)) {
1197 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1201 attrs.mpa_attr = ep->mpa_attr;
1202 attrs.max_ird = ep->ird;
1203 attrs.max_ord = ep->ord;
1204 attrs.llp_stream_handle = ep;
1205 attrs.next_state = C4IW_QP_STATE_RTS;
1207 mask = C4IW_QP_ATTR_NEXT_STATE |
1208 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1209 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1211 /* bind QP and TID with INIT_WR */
1212 err = c4iw_modify_qp(ep->com.qp->rhp,
1213 ep->com.qp, mask, &attrs, 1);
1218 * If responder's RTR requirement did not match with what initiator
1219 * supports, generate TERM message
1222 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1223 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1224 attrs.ecode = MPA_NOMATCH_RTR;
1225 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1226 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1227 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1233 * Generate TERM if initiator IRD is not sufficient for responder
1234 * provided ORD. Currently, we do the same behaviour even when
1235 * responder provided IRD is also not sufficient as regards to
1239 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1241 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1242 attrs.ecode = MPA_INSUFF_IRD;
1243 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1244 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1245 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1251 state_set(&ep->com, ABORTING);
1252 send_abort(ep, skb, GFP_KERNEL);
1254 connect_reply_upcall(ep, err);
1258 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1260 struct mpa_message *mpa;
1261 struct mpa_v2_conn_params *mpa_v2_params;
1264 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1266 if (state_read(&ep->com) != MPA_REQ_WAIT)
1270 * If we get more than the supported amount of private data
1271 * then we must fail this connection.
1273 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1275 abort_connection(ep, skb, GFP_KERNEL);
1279 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1282 * Copy the new data into our accumulation buffer.
1284 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1286 ep->mpa_pkt_len += skb->len;
1289 * If we don't even have the mpa message, then bail.
1290 * We'll continue process when more data arrives.
1292 if (ep->mpa_pkt_len < sizeof(*mpa))
1295 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1297 mpa = (struct mpa_message *) ep->mpa_pkt;
1300 * Validate MPA Header.
1302 if (mpa->revision > mpa_rev) {
1303 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1304 " Received = %d\n", __func__, mpa_rev, mpa->revision);
1305 abort_connection(ep, skb, GFP_KERNEL);
1309 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1310 abort_connection(ep, skb, GFP_KERNEL);
1314 plen = ntohs(mpa->private_data_size);
1317 * Fail if there's too much private data.
1319 if (plen > MPA_MAX_PRIVATE_DATA) {
1320 abort_connection(ep, skb, GFP_KERNEL);
1325 * If plen does not account for pkt size
1327 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1328 abort_connection(ep, skb, GFP_KERNEL);
1331 ep->plen = (u8) plen;
1334 * If we don't have all the pdata yet, then bail.
1336 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1340 * If we get here we have accumulated the entire mpa
1341 * start reply message including private data.
1343 ep->mpa_attr.initiator = 0;
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 if (mpa->revision == 1)
1349 ep->tried_with_mpa_v1 = 1;
1350 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1352 if (mpa->revision == 2) {
1353 ep->mpa_attr.enhanced_rdma_conn =
1354 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1355 if (ep->mpa_attr.enhanced_rdma_conn) {
1356 mpa_v2_params = (struct mpa_v2_conn_params *)
1357 (ep->mpa_pkt + sizeof(*mpa));
1358 ep->ird = ntohs(mpa_v2_params->ird) &
1359 MPA_V2_IRD_ORD_MASK;
1360 ep->ord = ntohs(mpa_v2_params->ord) &
1361 MPA_V2_IRD_ORD_MASK;
1362 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1364 if (ntohs(mpa_v2_params->ord) &
1365 MPA_V2_RDMA_WRITE_RTR)
1366 ep->mpa_attr.p2p_type =
1367 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1368 else if (ntohs(mpa_v2_params->ord) &
1369 MPA_V2_RDMA_READ_RTR)
1370 ep->mpa_attr.p2p_type =
1371 FW_RI_INIT_P2PTYPE_READ_REQ;
1374 } else if (mpa->revision == 1)
1376 ep->mpa_attr.p2p_type = p2p_type;
1378 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1379 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1380 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1381 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1382 ep->mpa_attr.p2p_type);
1384 state_set(&ep->com, MPA_REQ_RCVD);
1387 connect_request_upcall(ep);
1391 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1394 struct cpl_rx_data *hdr = cplhdr(skb);
1395 unsigned int dlen = ntohs(hdr->len);
1396 unsigned int tid = GET_TID(hdr);
1397 struct tid_info *t = dev->rdev.lldi.tids;
1398 __u8 status = hdr->status;
1400 ep = lookup_tid(t, tid);
1401 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1402 skb_pull(skb, sizeof(*hdr));
1403 skb_trim(skb, dlen);
1405 /* update RX credits */
1406 update_rx_credits(ep, dlen);
1408 switch (state_read(&ep->com)) {
1410 ep->rcv_seq += dlen;
1411 process_mpa_reply(ep, skb);
1414 ep->rcv_seq += dlen;
1415 process_mpa_request(ep, skb);
1418 struct c4iw_qp_attributes attrs;
1419 BUG_ON(!ep->com.qp);
1420 if (ep->com.qp->attr.state == C4IW_QP_STATE_RTS)
1421 pr_err("%s Unexpected streaming data." \
1422 " qpid %u ep %p state %d tid %u status %d\n",
1423 __func__, ep->com.qp->wq.sq.qid, ep,
1424 state_read(&ep->com), ep->hwtid, status);
1425 attrs.next_state = C4IW_QP_STATE_ERROR;
1426 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1427 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1428 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
1437 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1440 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1442 unsigned int tid = GET_TID(rpl);
1443 struct tid_info *t = dev->rdev.lldi.tids;
1445 ep = lookup_tid(t, tid);
1447 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1450 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1451 mutex_lock(&ep->com.mutex);
1452 switch (ep->com.state) {
1454 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1455 __state_set(&ep->com, DEAD);
1459 printk(KERN_ERR "%s ep %p state %d\n",
1460 __func__, ep, ep->com.state);
1463 mutex_unlock(&ep->com.mutex);
1466 release_ep_resources(ep);
1470 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1472 struct sk_buff *skb;
1473 struct fw_ofld_connection_wr *req;
1474 unsigned int mtu_idx;
1477 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1478 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1479 memset(req, 0, sizeof(*req));
1480 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1481 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1482 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1484 req->le.lport = ep->com.local_addr.sin_port;
1485 req->le.pport = ep->com.remote_addr.sin_port;
1486 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1487 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1488 req->tcb.t_state_to_astid =
1489 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1490 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1491 req->tcb.cplrxdataack_cplpassacceptrpl =
1492 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1493 req->tcb.tx_max = jiffies;
1494 req->tcb.rcv_adv = htons(1);
1495 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1496 wscale = compute_wscale(rcv_win);
1497 req->tcb.opt0 = TCAM_BYPASS(1) |
1498 (nocong ? NO_CONG(1) : 0) |
1503 L2T_IDX(ep->l2t->idx) |
1504 TX_CHAN(ep->tx_chan) |
1505 SMAC_SEL(ep->smac_idx) |
1507 ULP_MODE(ULP_MODE_TCPDDP) |
1508 RCV_BUFSIZ(rcv_win >> 10);
1509 req->tcb.opt2 = PACE(1) |
1510 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1512 CCTRL_ECN(enable_ecn) |
1513 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1514 if (enable_tcp_timestamps)
1515 req->tcb.opt2 |= TSTAMPS_EN(1);
1516 if (enable_tcp_sack)
1517 req->tcb.opt2 |= SACK_EN(1);
1518 if (wscale && enable_tcp_window_scaling)
1519 req->tcb.opt2 |= WND_SCALE_EN(1);
1520 req->tcb.opt0 = cpu_to_be64(req->tcb.opt0);
1521 req->tcb.opt2 = cpu_to_be32(req->tcb.opt2);
1522 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1523 set_bit(ACT_OFLD_CONN, &ep->com.history);
1524 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1528 * Return whether a failed active open has allocated a TID
1530 static inline int act_open_has_tid(int status)
1532 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1533 status != CPL_ERR_ARP_MISS;
1536 #define ACT_OPEN_RETRY_COUNT 2
1538 static int c4iw_reconnect(struct c4iw_ep *ep)
1542 struct port_info *pi;
1543 struct net_device *pdev;
1545 struct neighbour *neigh;
1547 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1548 init_timer(&ep->timer);
1551 * Allocate an active TID to initiate a TCP connection.
1553 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1554 if (ep->atid == -1) {
1555 pr_err("%s - cannot alloc atid.\n", __func__);
1559 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1562 rt = find_route(ep->com.dev,
1563 ep->com.cm_id->local_addr.sin_addr.s_addr,
1564 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1565 ep->com.cm_id->local_addr.sin_port,
1566 ep->com.cm_id->remote_addr.sin_port, 0);
1568 pr_err("%s - cannot find route.\n", __func__);
1569 err = -EHOSTUNREACH;
1574 neigh = dst_neigh_lookup(ep->dst,
1575 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1576 /* get a l2t entry */
1577 if (neigh->dev->flags & IFF_LOOPBACK) {
1578 PDBG("%s LOOPBACK\n", __func__);
1579 pdev = ip_dev_find(&init_net,
1580 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1581 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1583 pi = (struct port_info *)netdev_priv(pdev);
1584 ep->mtu = pdev->mtu;
1585 ep->tx_chan = cxgb4_port_chan(pdev);
1586 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1589 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1590 neigh, neigh->dev, 0);
1591 pi = (struct port_info *)netdev_priv(neigh->dev);
1592 ep->mtu = dst_mtu(ep->dst);
1593 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1594 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1598 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1599 ep->txq_idx = pi->port_id * step;
1600 ep->ctrlq_idx = pi->port_id;
1601 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1602 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1605 pr_err("%s - cannot alloc l2e.\n", __func__);
1610 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1611 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1614 state_set(&ep->com, CONNECTING);
1617 /* send connect request to rnic */
1618 err = send_connect(ep);
1622 cxgb4_l2t_release(ep->l2t);
1624 dst_release(ep->dst);
1626 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1627 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1630 * remember to send notification to upper layer.
1631 * We are in here so the upper layer is not aware that this is
1632 * re-connect attempt and so, upper layer is still waiting for
1633 * response of 1st connect request.
1635 connect_reply_upcall(ep, -ECONNRESET);
1636 c4iw_put_ep(&ep->com);
1641 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1644 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1645 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1646 ntohl(rpl->atid_status)));
1647 struct tid_info *t = dev->rdev.lldi.tids;
1648 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1650 ep = lookup_atid(t, atid);
1652 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1653 status, status2errno(status));
1655 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1656 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1661 set_bit(ACT_OPEN_RPL, &ep->com.history);
1664 * Log interesting failures.
1667 case CPL_ERR_CONN_RESET:
1668 case CPL_ERR_CONN_TIMEDOUT:
1670 case CPL_ERR_TCAM_FULL:
1671 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1672 mutex_lock(&dev->rdev.stats.lock);
1673 dev->rdev.stats.tcam_full++;
1674 mutex_unlock(&dev->rdev.stats.lock);
1675 send_fw_act_open_req(ep,
1676 GET_TID_TID(GET_AOPEN_ATID(
1677 ntohl(rpl->atid_status))));
1681 case CPL_ERR_CONN_EXIST:
1682 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1683 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1684 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1686 cxgb4_free_atid(t, atid);
1687 dst_release(ep->dst);
1688 cxgb4_l2t_release(ep->l2t);
1694 printk(KERN_INFO MOD "Active open failure - "
1695 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1696 atid, status, status2errno(status),
1697 &ep->com.local_addr.sin_addr.s_addr,
1698 ntohs(ep->com.local_addr.sin_port),
1699 &ep->com.remote_addr.sin_addr.s_addr,
1700 ntohs(ep->com.remote_addr.sin_port));
1704 connect_reply_upcall(ep, status2errno(status));
1705 state_set(&ep->com, DEAD);
1707 if (status && act_open_has_tid(status))
1708 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1710 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
1711 cxgb4_free_atid(t, atid);
1712 dst_release(ep->dst);
1713 cxgb4_l2t_release(ep->l2t);
1714 c4iw_put_ep(&ep->com);
1719 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1721 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1722 struct tid_info *t = dev->rdev.lldi.tids;
1723 unsigned int stid = GET_TID(rpl);
1724 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1727 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1730 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1731 rpl->status, status2errno(rpl->status));
1732 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1738 static int listen_stop(struct c4iw_listen_ep *ep)
1740 struct sk_buff *skb;
1741 struct cpl_close_listsvr_req *req;
1743 PDBG("%s ep %p\n", __func__, ep);
1744 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1746 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1749 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1751 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1753 req->reply_ctrl = cpu_to_be16(
1754 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1755 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1756 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1759 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1761 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1762 struct tid_info *t = dev->rdev.lldi.tids;
1763 unsigned int stid = GET_TID(rpl);
1764 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1766 PDBG("%s ep %p\n", __func__, ep);
1767 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1771 static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1772 struct cpl_pass_accept_req *req)
1774 struct cpl_pass_accept_rpl *rpl;
1775 unsigned int mtu_idx;
1780 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1781 BUG_ON(skb_cloned(skb));
1782 skb_trim(skb, sizeof(*rpl));
1784 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1785 wscale = compute_wscale(rcv_win);
1786 opt0 = (nocong ? NO_CONG(1) : 0) |
1791 L2T_IDX(ep->l2t->idx) |
1792 TX_CHAN(ep->tx_chan) |
1793 SMAC_SEL(ep->smac_idx) |
1794 DSCP(ep->tos >> 2) |
1795 ULP_MODE(ULP_MODE_TCPDDP) |
1796 RCV_BUFSIZ(rcv_win>>10);
1797 opt2 = RX_CHANNEL(0) |
1798 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1800 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1801 opt2 |= TSTAMPS_EN(1);
1802 if (enable_tcp_sack && req->tcpopt.sack)
1804 if (wscale && enable_tcp_window_scaling)
1805 opt2 |= WND_SCALE_EN(1);
1807 const struct tcphdr *tcph;
1808 u32 hlen = ntohl(req->hdr_len);
1810 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1812 if (tcph->ece && tcph->cwr)
1813 opt2 |= CCTRL_ECN(1);
1817 INIT_TP_WR(rpl, ep->hwtid);
1818 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1820 rpl->opt0 = cpu_to_be64(opt0);
1821 rpl->opt2 = cpu_to_be32(opt2);
1822 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
1823 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1828 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1829 struct sk_buff *skb)
1831 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1833 BUG_ON(skb_cloned(skb));
1834 skb_trim(skb, sizeof(struct cpl_tid_release));
1836 release_tid(&dev->rdev, hwtid, skb);
1840 static void get_4tuple(struct cpl_pass_accept_req *req,
1841 __be32 *local_ip, __be32 *peer_ip,
1842 __be16 *local_port, __be16 *peer_port)
1844 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1845 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1846 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1847 struct tcphdr *tcp = (struct tcphdr *)
1848 ((u8 *)(req + 1) + eth_len + ip_len);
1850 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1851 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1854 *peer_ip = ip->saddr;
1855 *local_ip = ip->daddr;
1856 *peer_port = tcp->source;
1857 *local_port = tcp->dest;
1862 static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1863 struct c4iw_dev *cdev, bool clear_mpa_v1)
1865 struct neighbour *n;
1868 n = dst_neigh_lookup(dst, &peer_ip);
1874 if (n->dev->flags & IFF_LOOPBACK) {
1875 struct net_device *pdev;
1877 pdev = ip_dev_find(&init_net, peer_ip);
1882 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1886 ep->mtu = pdev->mtu;
1887 ep->tx_chan = cxgb4_port_chan(pdev);
1888 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1889 step = cdev->rdev.lldi.ntxq /
1890 cdev->rdev.lldi.nchan;
1891 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1892 step = cdev->rdev.lldi.nrxq /
1893 cdev->rdev.lldi.nchan;
1894 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1895 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1896 cxgb4_port_idx(pdev) * step];
1899 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1903 ep->mtu = dst_mtu(dst);
1904 ep->tx_chan = cxgb4_port_chan(n->dev);
1905 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1906 step = cdev->rdev.lldi.ntxq /
1907 cdev->rdev.lldi.nchan;
1908 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1909 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1910 step = cdev->rdev.lldi.nrxq /
1911 cdev->rdev.lldi.nchan;
1912 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1913 cxgb4_port_idx(n->dev) * step];
1916 ep->retry_with_mpa_v1 = 0;
1917 ep->tried_with_mpa_v1 = 0;
1929 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1931 struct c4iw_ep *child_ep = NULL, *parent_ep;
1932 struct cpl_pass_accept_req *req = cplhdr(skb);
1933 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1934 struct tid_info *t = dev->rdev.lldi.tids;
1935 unsigned int hwtid = GET_TID(req);
1936 struct dst_entry *dst;
1938 __be32 local_ip, peer_ip = 0;
1939 __be16 local_port, peer_port;
1941 u16 peer_mss = ntohs(req->tcpopt.mss);
1943 parent_ep = lookup_stid(t, stid);
1945 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1948 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1950 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1951 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1952 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1953 ntohs(peer_port), peer_mss);
1955 if (state_read(&parent_ep->com) != LISTEN) {
1956 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1961 /* Find output route */
1962 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1963 GET_POPEN_TOS(ntohl(req->tos_stid)));
1965 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1971 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1973 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1979 err = import_ep(child_ep, peer_ip, dst, dev, false);
1981 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1988 if (peer_mss && child_ep->mtu > (peer_mss + 40))
1989 child_ep->mtu = peer_mss + 40;
1991 state_set(&child_ep->com, CONNECTING);
1992 child_ep->com.dev = dev;
1993 child_ep->com.cm_id = NULL;
1994 child_ep->com.local_addr.sin_family = PF_INET;
1995 child_ep->com.local_addr.sin_port = local_port;
1996 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1997 child_ep->com.remote_addr.sin_family = PF_INET;
1998 child_ep->com.remote_addr.sin_port = peer_port;
1999 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
2000 c4iw_get_ep(&parent_ep->com);
2001 child_ep->parent_ep = parent_ep;
2002 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
2003 child_ep->dst = dst;
2004 child_ep->hwtid = hwtid;
2006 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2007 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
2009 init_timer(&child_ep->timer);
2010 cxgb4_insert_tid(t, child_ep, hwtid);
2011 accept_cr(child_ep, peer_ip, skb, req);
2012 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2015 reject_cr(dev, hwtid, peer_ip, skb);
2020 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2023 struct cpl_pass_establish *req = cplhdr(skb);
2024 struct tid_info *t = dev->rdev.lldi.tids;
2025 unsigned int tid = GET_TID(req);
2027 ep = lookup_tid(t, tid);
2028 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2029 ep->snd_seq = be32_to_cpu(req->snd_isn);
2030 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2032 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2033 ntohs(req->tcp_opt));
2035 set_emss(ep, ntohs(req->tcp_opt));
2036 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
2038 dst_confirm(ep->dst);
2039 state_set(&ep->com, MPA_REQ_WAIT);
2041 send_flowc(ep, skb);
2042 set_bit(PASS_ESTAB, &ep->com.history);
2047 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2049 struct cpl_peer_close *hdr = cplhdr(skb);
2051 struct c4iw_qp_attributes attrs;
2054 struct tid_info *t = dev->rdev.lldi.tids;
2055 unsigned int tid = GET_TID(hdr);
2058 ep = lookup_tid(t, tid);
2059 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2060 dst_confirm(ep->dst);
2062 set_bit(PEER_CLOSE, &ep->com.history);
2063 mutex_lock(&ep->com.mutex);
2064 switch (ep->com.state) {
2066 __state_set(&ep->com, CLOSING);
2069 __state_set(&ep->com, CLOSING);
2070 connect_reply_upcall(ep, -ECONNRESET);
2075 * We're gonna mark this puppy DEAD, but keep
2076 * the reference on it until the ULP accepts or
2077 * rejects the CR. Also wake up anyone waiting
2078 * in rdma connection migration (see c4iw_accept_cr()).
2080 __state_set(&ep->com, CLOSING);
2081 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2082 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2085 __state_set(&ep->com, CLOSING);
2086 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
2087 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2091 __state_set(&ep->com, CLOSING);
2092 attrs.next_state = C4IW_QP_STATE_CLOSING;
2093 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2094 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2095 if (ret != -ECONNRESET) {
2096 peer_close_upcall(ep);
2104 __state_set(&ep->com, MORIBUND);
2109 if (ep->com.cm_id && ep->com.qp) {
2110 attrs.next_state = C4IW_QP_STATE_IDLE;
2111 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2112 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2114 close_complete_upcall(ep);
2115 __state_set(&ep->com, DEAD);
2125 mutex_unlock(&ep->com.mutex);
2127 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2129 release_ep_resources(ep);
2134 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2136 static int is_neg_adv_abort(unsigned int status)
2138 return status == CPL_ERR_RTX_NEG_ADVICE ||
2139 status == CPL_ERR_PERSIST_NEG_ADVICE;
2142 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2144 struct cpl_abort_req_rss *req = cplhdr(skb);
2146 struct cpl_abort_rpl *rpl;
2147 struct sk_buff *rpl_skb;
2148 struct c4iw_qp_attributes attrs;
2151 struct tid_info *t = dev->rdev.lldi.tids;
2152 unsigned int tid = GET_TID(req);
2154 ep = lookup_tid(t, tid);
2155 if (is_neg_adv_abort(req->status)) {
2156 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2160 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2162 set_bit(PEER_ABORT, &ep->com.history);
2165 * Wake up any threads in rdma_init() or rdma_fini().
2166 * However, this is not needed if com state is just
2169 if (ep->com.state != MPA_REQ_SENT)
2170 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2172 mutex_lock(&ep->com.mutex);
2173 switch (ep->com.state) {
2181 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
2182 connect_reply_upcall(ep, -ECONNRESET);
2185 * we just don't send notification upwards because we
2186 * want to retry with mpa_v1 without upper layers even
2189 * do some housekeeping so as to re-initiate the
2192 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2194 ep->retry_with_mpa_v1 = 1;
2206 if (ep->com.cm_id && ep->com.qp) {
2207 attrs.next_state = C4IW_QP_STATE_ERROR;
2208 ret = c4iw_modify_qp(ep->com.qp->rhp,
2209 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2213 "%s - qp <- error failed!\n",
2216 peer_abort_upcall(ep);
2221 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2222 mutex_unlock(&ep->com.mutex);
2228 dst_confirm(ep->dst);
2229 if (ep->com.state != ABORTING) {
2230 __state_set(&ep->com, DEAD);
2231 /* we don't release if we want to retry with mpa_v1 */
2232 if (!ep->retry_with_mpa_v1)
2235 mutex_unlock(&ep->com.mutex);
2237 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2239 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2244 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2245 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2246 INIT_TP_WR(rpl, ep->hwtid);
2247 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2248 rpl->cmd = CPL_ABORT_NO_RST;
2249 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2252 release_ep_resources(ep);
2254 /* retry with mpa-v1 */
2255 if (ep && ep->retry_with_mpa_v1) {
2256 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2257 dst_release(ep->dst);
2258 cxgb4_l2t_release(ep->l2t);
2265 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2268 struct c4iw_qp_attributes attrs;
2269 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2271 struct tid_info *t = dev->rdev.lldi.tids;
2272 unsigned int tid = GET_TID(rpl);
2274 ep = lookup_tid(t, tid);
2276 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2279 /* The cm_id may be null if we failed to connect */
2280 mutex_lock(&ep->com.mutex);
2281 switch (ep->com.state) {
2283 __state_set(&ep->com, MORIBUND);
2287 if ((ep->com.cm_id) && (ep->com.qp)) {
2288 attrs.next_state = C4IW_QP_STATE_IDLE;
2289 c4iw_modify_qp(ep->com.qp->rhp,
2291 C4IW_QP_ATTR_NEXT_STATE,
2294 close_complete_upcall(ep);
2295 __state_set(&ep->com, DEAD);
2305 mutex_unlock(&ep->com.mutex);
2307 release_ep_resources(ep);
2311 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2313 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2314 struct tid_info *t = dev->rdev.lldi.tids;
2315 unsigned int tid = GET_TID(rpl);
2317 struct c4iw_qp_attributes attrs;
2319 ep = lookup_tid(t, tid);
2322 if (ep && ep->com.qp) {
2323 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2324 ep->com.qp->wq.sq.qid);
2325 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2326 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2327 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2329 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2335 * Upcall from the adapter indicating data has been transmitted.
2336 * For us its just the single MPA request or reply. We can now free
2337 * the skb holding the mpa message.
2339 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2342 struct cpl_fw4_ack *hdr = cplhdr(skb);
2343 u8 credits = hdr->credits;
2344 unsigned int tid = GET_TID(hdr);
2345 struct tid_info *t = dev->rdev.lldi.tids;
2348 ep = lookup_tid(t, tid);
2349 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2351 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2352 __func__, ep, ep->hwtid, state_read(&ep->com));
2356 dst_confirm(ep->dst);
2358 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2359 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2360 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2361 kfree_skb(ep->mpa_skb);
2367 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2370 struct c4iw_ep *ep = to_ep(cm_id);
2371 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2373 if (state_read(&ep->com) == DEAD) {
2374 c4iw_put_ep(&ep->com);
2377 set_bit(ULP_REJECT, &ep->com.history);
2378 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2380 abort_connection(ep, NULL, GFP_KERNEL);
2382 err = send_mpa_reject(ep, pdata, pdata_len);
2383 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2385 c4iw_put_ep(&ep->com);
2389 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2392 struct c4iw_qp_attributes attrs;
2393 enum c4iw_qp_attr_mask mask;
2394 struct c4iw_ep *ep = to_ep(cm_id);
2395 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2396 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2398 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2399 if (state_read(&ep->com) == DEAD) {
2404 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2407 set_bit(ULP_ACCEPT, &ep->com.history);
2408 if ((conn_param->ord > c4iw_max_read_depth) ||
2409 (conn_param->ird > c4iw_max_read_depth)) {
2410 abort_connection(ep, NULL, GFP_KERNEL);
2415 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2416 if (conn_param->ord > ep->ird) {
2417 ep->ird = conn_param->ird;
2418 ep->ord = conn_param->ord;
2419 send_mpa_reject(ep, conn_param->private_data,
2420 conn_param->private_data_len);
2421 abort_connection(ep, NULL, GFP_KERNEL);
2425 if (conn_param->ird > ep->ord) {
2427 conn_param->ird = 1;
2429 abort_connection(ep, NULL, GFP_KERNEL);
2436 ep->ird = conn_param->ird;
2437 ep->ord = conn_param->ord;
2439 if (ep->mpa_attr.version != 2)
2440 if (peer2peer && ep->ird == 0)
2443 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2445 cm_id->add_ref(cm_id);
2446 ep->com.cm_id = cm_id;
2450 /* bind QP to EP and move to RTS */
2451 attrs.mpa_attr = ep->mpa_attr;
2452 attrs.max_ird = ep->ird;
2453 attrs.max_ord = ep->ord;
2454 attrs.llp_stream_handle = ep;
2455 attrs.next_state = C4IW_QP_STATE_RTS;
2457 /* bind QP and TID with INIT_WR */
2458 mask = C4IW_QP_ATTR_NEXT_STATE |
2459 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2460 C4IW_QP_ATTR_MPA_ATTR |
2461 C4IW_QP_ATTR_MAX_IRD |
2462 C4IW_QP_ATTR_MAX_ORD;
2464 err = c4iw_modify_qp(ep->com.qp->rhp,
2465 ep->com.qp, mask, &attrs, 1);
2468 err = send_mpa_reply(ep, conn_param->private_data,
2469 conn_param->private_data_len);
2473 state_set(&ep->com, FPDU_MODE);
2474 established_upcall(ep);
2475 c4iw_put_ep(&ep->com);
2478 ep->com.cm_id = NULL;
2479 cm_id->rem_ref(cm_id);
2481 c4iw_put_ep(&ep->com);
2485 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2487 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2492 if ((conn_param->ord > c4iw_max_read_depth) ||
2493 (conn_param->ird > c4iw_max_read_depth)) {
2497 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2499 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2503 init_timer(&ep->timer);
2504 ep->plen = conn_param->private_data_len;
2506 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2507 conn_param->private_data, ep->plen);
2508 ep->ird = conn_param->ird;
2509 ep->ord = conn_param->ord;
2511 if (peer2peer && ep->ord == 0)
2514 cm_id->add_ref(cm_id);
2516 ep->com.cm_id = cm_id;
2517 ep->com.qp = get_qhp(dev, conn_param->qpn);
2518 BUG_ON(!ep->com.qp);
2520 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2524 * Allocate an active TID to initiate a TCP connection.
2526 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2527 if (ep->atid == -1) {
2528 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2532 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2534 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2535 ntohl(cm_id->local_addr.sin_addr.s_addr),
2536 ntohs(cm_id->local_addr.sin_port),
2537 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2538 ntohs(cm_id->remote_addr.sin_port));
2541 rt = find_route(dev,
2542 cm_id->local_addr.sin_addr.s_addr,
2543 cm_id->remote_addr.sin_addr.s_addr,
2544 cm_id->local_addr.sin_port,
2545 cm_id->remote_addr.sin_port, 0);
2547 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2548 err = -EHOSTUNREACH;
2553 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2554 ep->dst, ep->com.dev, true);
2556 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2560 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2561 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2564 state_set(&ep->com, CONNECTING);
2566 ep->com.local_addr = cm_id->local_addr;
2567 ep->com.remote_addr = cm_id->remote_addr;
2569 /* send connect request to rnic */
2570 err = send_connect(ep);
2574 cxgb4_l2t_release(ep->l2t);
2576 dst_release(ep->dst);
2578 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2579 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2581 cm_id->rem_ref(cm_id);
2582 c4iw_put_ep(&ep->com);
2587 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2590 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2591 struct c4iw_listen_ep *ep;
2595 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2597 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2601 PDBG("%s ep %p\n", __func__, ep);
2602 cm_id->add_ref(cm_id);
2603 ep->com.cm_id = cm_id;
2605 ep->backlog = backlog;
2606 ep->com.local_addr = cm_id->local_addr;
2609 * Allocate a server TID.
2611 if (dev->rdev.lldi.enable_fw_ofld_conn)
2612 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2614 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2616 if (ep->stid == -1) {
2617 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
2621 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
2622 state_set(&ep->com, LISTEN);
2623 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2625 err = cxgb4_create_server_filter(
2626 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2627 ep->com.local_addr.sin_addr.s_addr,
2628 ep->com.local_addr.sin_port,
2630 ep->com.dev->rdev.lldi.rxq_ids[0],
2633 if (err == -EBUSY) {
2634 set_current_state(TASK_UNINTERRUPTIBLE);
2635 schedule_timeout(usecs_to_jiffies(100));
2637 } while (err == -EBUSY);
2639 c4iw_init_wr_wait(&ep->com.wr_wait);
2640 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2641 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2642 ep->com.local_addr.sin_port,
2644 ep->com.dev->rdev.lldi.rxq_ids[0]);
2646 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2651 cm_id->provider_data = ep;
2654 pr_err("%s cxgb4_create_server/filter failed err %d " \
2655 "stid %d laddr %08x lport %d\n", \
2656 __func__, err, ep->stid,
2657 ntohl(ep->com.local_addr.sin_addr.s_addr),
2658 ntohs(ep->com.local_addr.sin_port));
2659 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2661 cm_id->rem_ref(cm_id);
2662 c4iw_put_ep(&ep->com);
2668 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2671 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2673 PDBG("%s ep %p\n", __func__, ep);
2676 state_set(&ep->com, DEAD);
2677 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2678 err = cxgb4_remove_server_filter(
2679 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2680 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2682 c4iw_init_wr_wait(&ep->com.wr_wait);
2683 err = listen_stop(ep);
2686 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2689 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
2690 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2692 cm_id->rem_ref(cm_id);
2693 c4iw_put_ep(&ep->com);
2697 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2702 struct c4iw_rdev *rdev;
2704 mutex_lock(&ep->com.mutex);
2706 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2707 states[ep->com.state], abrupt);
2709 rdev = &ep->com.dev->rdev;
2710 if (c4iw_fatal_error(rdev)) {
2712 close_complete_upcall(ep);
2713 ep->com.state = DEAD;
2715 switch (ep->com.state) {
2723 ep->com.state = ABORTING;
2725 ep->com.state = CLOSING;
2728 set_bit(CLOSE_SENT, &ep->com.flags);
2731 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2735 ep->com.state = ABORTING;
2737 ep->com.state = MORIBUND;
2743 PDBG("%s ignoring disconnect ep %p state %u\n",
2744 __func__, ep, ep->com.state);
2753 set_bit(EP_DISC_ABORT, &ep->com.history);
2754 close_complete_upcall(ep);
2755 ret = send_abort(ep, NULL, gfp);
2757 set_bit(EP_DISC_CLOSE, &ep->com.history);
2758 ret = send_halfclose(ep, gfp);
2763 mutex_unlock(&ep->com.mutex);
2765 release_ep_resources(ep);
2769 static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2770 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2773 int atid = be32_to_cpu(req->tid);
2775 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, req->tid);
2779 switch (req->retval) {
2781 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2782 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2783 send_fw_act_open_req(ep, atid);
2787 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2788 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2789 send_fw_act_open_req(ep, atid);
2794 pr_info("%s unexpected ofld conn wr retval %d\n",
2795 __func__, req->retval);
2798 pr_err("active ofld_connect_wr failure %d atid %d\n",
2800 mutex_lock(&dev->rdev.stats.lock);
2801 dev->rdev.stats.act_ofld_conn_fails++;
2802 mutex_unlock(&dev->rdev.stats.lock);
2803 connect_reply_upcall(ep, status2errno(req->retval));
2804 state_set(&ep->com, DEAD);
2805 remove_handle(dev, &dev->atid_idr, atid);
2806 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2807 dst_release(ep->dst);
2808 cxgb4_l2t_release(ep->l2t);
2809 c4iw_put_ep(&ep->com);
2812 static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2813 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2815 struct sk_buff *rpl_skb;
2816 struct cpl_pass_accept_req *cpl;
2819 rpl_skb = (struct sk_buff *)cpu_to_be64(req->cookie);
2822 PDBG("%s passive open failure %d\n", __func__, req->retval);
2823 mutex_lock(&dev->rdev.stats.lock);
2824 dev->rdev.stats.pas_ofld_conn_fails++;
2825 mutex_unlock(&dev->rdev.stats.lock);
2828 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2829 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2831 ret = pass_accept_req(dev, rpl_skb);
2838 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2840 struct cpl_fw6_msg *rpl = cplhdr(skb);
2841 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2843 switch (rpl->type) {
2845 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2847 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2848 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2849 switch (req->t_state) {
2851 active_ofld_conn_reply(dev, skb, req);
2854 passive_ofld_conn_reply(dev, skb, req);
2857 pr_err("%s unexpected ofld conn wr state %d\n",
2858 __func__, req->t_state);
2866 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2869 u16 vlantag, len, hdr_len;
2871 struct cpl_rx_pkt *cpl = cplhdr(skb);
2872 struct cpl_pass_accept_req *req;
2873 struct tcp_options_received tmp_opt;
2875 /* Store values from cpl_rx_pkt in temporary location. */
2876 vlantag = cpl->vlan;
2878 l2info = cpl->l2info;
2879 hdr_len = cpl->hdr_len;
2882 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2885 * We need to parse the TCP options from SYN packet.
2886 * to generate cpl_pass_accept_req.
2888 memset(&tmp_opt, 0, sizeof(tmp_opt));
2889 tcp_clear_options(&tmp_opt);
2890 tcp_parse_options(skb, &tmp_opt, 0, 0, NULL);
2892 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2893 memset(req, 0, sizeof(*req));
2894 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2895 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info))) |
2897 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info))) |
2898 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len))) |
2899 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len))) |
2900 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info))));
2901 req->vlan = vlantag;
2903 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2904 PASS_OPEN_TOS(tos));
2905 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2906 if (tmp_opt.wscale_ok)
2907 req->tcpopt.wsf = tmp_opt.snd_wscale;
2908 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2909 if (tmp_opt.sack_ok)
2910 req->tcpopt.sack = 1;
2911 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2915 static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2916 __be32 laddr, __be16 lport,
2917 __be32 raddr, __be16 rport,
2918 u32 rcv_isn, u32 filter, u16 window,
2919 u32 rss_qid, u8 port_id)
2921 struct sk_buff *req_skb;
2922 struct fw_ofld_connection_wr *req;
2923 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2925 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2926 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2927 memset(req, 0, sizeof(*req));
2928 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2929 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2930 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2931 req->le.filter = filter;
2932 req->le.lport = lport;
2933 req->le.pport = rport;
2934 req->le.u.ipv4.lip = laddr;
2935 req->le.u.ipv4.pip = raddr;
2936 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2937 req->tcb.rcv_adv = htons(window);
2938 req->tcb.t_state_to_astid =
2939 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2940 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2941 V_FW_OFLD_CONNECTION_WR_ASTID(
2942 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2945 * We store the qid in opt2 which will be used by the firmware
2946 * to send us the wr response.
2948 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2951 * We initialize the MSS index in TCB to 0xF.
2952 * So that when driver sends cpl_pass_accept_rpl
2953 * TCB picks up the correct value. If this was 0
2954 * TP will ignore any value > 0 for MSS index.
2956 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2957 req->cookie = cpu_to_be64((u64)skb);
2959 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2960 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2964 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2965 * messages when a filter is being used instead of server to
2966 * redirect a syn packet. When packets hit filter they are redirected
2967 * to the offload queue and driver tries to establish the connection
2968 * using firmware work request.
2970 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
2973 unsigned int filter;
2974 struct ethhdr *eh = NULL;
2975 struct vlan_ethhdr *vlan_eh = NULL;
2977 struct tcphdr *tcph;
2978 struct rss_header *rss = (void *)skb->data;
2979 struct cpl_rx_pkt *cpl = (void *)skb->data;
2980 struct cpl_pass_accept_req *req = (void *)(rss + 1);
2981 struct l2t_entry *e;
2982 struct dst_entry *dst;
2984 struct c4iw_ep *lep;
2986 struct port_info *pi;
2987 struct net_device *pdev;
2991 struct neighbour *neigh;
2993 /* Drop all non-SYN packets */
2994 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
2998 * Drop all packets which did not hit the filter.
2999 * Unlikely to happen.
3001 if (!(rss->filter_hit && rss->filter_tid))
3005 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3007 stid = cpu_to_be32(rss->hash_val) - dev->rdev.lldi.tids->sftid_base
3008 + dev->rdev.lldi.tids->nstids;
3010 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3012 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3016 if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
3017 eh = (struct ethhdr *)(req + 1);
3018 iph = (struct iphdr *)(eh + 1);
3020 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3021 iph = (struct iphdr *)(vlan_eh + 1);
3022 skb->vlan_tci = ntohs(cpl->vlan);
3025 if (iph->version != 0x4)
3028 tcph = (struct tcphdr *)(iph + 1);
3029 skb_set_network_header(skb, (void *)iph - (void *)rss);
3030 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3033 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3034 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3035 ntohs(tcph->source), iph->tos);
3037 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3040 pr_err("%s - failed to find dst entry!\n",
3045 neigh = dst_neigh_lookup_skb(dst, skb);
3047 if (neigh->dev->flags & IFF_LOOPBACK) {
3048 pdev = ip_dev_find(&init_net, iph->daddr);
3049 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3051 pi = (struct port_info *)netdev_priv(pdev);
3052 tx_chan = cxgb4_port_chan(pdev);
3055 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3057 pi = (struct port_info *)netdev_priv(neigh->dev);
3058 tx_chan = cxgb4_port_chan(neigh->dev);
3061 pr_err("%s - failed to allocate l2t entry!\n",
3066 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3067 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3068 window = htons(tcph->window);
3070 /* Calcuate filter portion for LE region. */
3071 filter = cpu_to_be32(select_ntuple(dev, dst, e));
3074 * Synthesize the cpl_pass_accept_req. We have everything except the
3075 * TID. Once firmware sends a reply with TID we update the TID field
3076 * in cpl and pass it through the regular cpl_pass_accept_req path.
3078 build_cpl_pass_accept_req(skb, stid, iph->tos);
3079 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3080 tcph->source, ntohl(tcph->seq), filter, window,
3081 rss_qid, pi->port_id);
3082 cxgb4_l2t_release(e);
3090 * These are the real handlers that are called from a
3093 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3094 [CPL_ACT_ESTABLISH] = act_establish,
3095 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3096 [CPL_RX_DATA] = rx_data,
3097 [CPL_ABORT_RPL_RSS] = abort_rpl,
3098 [CPL_ABORT_RPL] = abort_rpl,
3099 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3100 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3101 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3102 [CPL_PASS_ESTABLISH] = pass_establish,
3103 [CPL_PEER_CLOSE] = peer_close,
3104 [CPL_ABORT_REQ_RSS] = peer_abort,
3105 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3106 [CPL_RDMA_TERMINATE] = terminate,
3107 [CPL_FW4_ACK] = fw4_ack,
3108 [CPL_FW6_MSG] = deferred_fw6_msg,
3109 [CPL_RX_PKT] = rx_pkt
3112 static void process_timeout(struct c4iw_ep *ep)
3114 struct c4iw_qp_attributes attrs;
3117 mutex_lock(&ep->com.mutex);
3118 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3120 set_bit(TIMEDOUT, &ep->com.history);
3121 switch (ep->com.state) {
3123 __state_set(&ep->com, ABORTING);
3124 connect_reply_upcall(ep, -ETIMEDOUT);
3127 __state_set(&ep->com, ABORTING);
3131 if (ep->com.cm_id && ep->com.qp) {
3132 attrs.next_state = C4IW_QP_STATE_ERROR;
3133 c4iw_modify_qp(ep->com.qp->rhp,
3134 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3137 __state_set(&ep->com, ABORTING);
3140 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3141 __func__, ep, ep->hwtid, ep->com.state);
3144 mutex_unlock(&ep->com.mutex);
3146 abort_connection(ep, NULL, GFP_KERNEL);
3147 c4iw_put_ep(&ep->com);
3150 static void process_timedout_eps(void)
3154 spin_lock_irq(&timeout_lock);
3155 while (!list_empty(&timeout_list)) {
3156 struct list_head *tmp;
3158 tmp = timeout_list.next;
3160 spin_unlock_irq(&timeout_lock);
3161 ep = list_entry(tmp, struct c4iw_ep, entry);
3162 process_timeout(ep);
3163 spin_lock_irq(&timeout_lock);
3165 spin_unlock_irq(&timeout_lock);
3168 static void process_work(struct work_struct *work)
3170 struct sk_buff *skb = NULL;
3171 struct c4iw_dev *dev;
3172 struct cpl_act_establish *rpl;
3173 unsigned int opcode;
3176 while ((skb = skb_dequeue(&rxq))) {
3178 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3179 opcode = rpl->ot.opcode;
3181 BUG_ON(!work_handlers[opcode]);
3182 ret = work_handlers[opcode](dev, skb);
3186 process_timedout_eps();
3189 static DECLARE_WORK(skb_work, process_work);
3191 static void ep_timeout(unsigned long arg)
3193 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3195 spin_lock(&timeout_lock);
3196 list_add_tail(&ep->entry, &timeout_list);
3197 spin_unlock(&timeout_lock);
3198 queue_work(workq, &skb_work);
3202 * All the CM events are handled on a work queue to have a safe context.
3204 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3208 * Save dev in the skb->cb area.
3210 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3213 * Queue the skb and schedule the worker thread.
3215 skb_queue_tail(&rxq, skb);
3216 queue_work(workq, &skb_work);
3220 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3222 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3224 if (rpl->status != CPL_ERR_NONE) {
3225 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3226 "for tid %u\n", rpl->status, GET_TID(rpl));
3232 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3234 struct cpl_fw6_msg *rpl = cplhdr(skb);
3235 struct c4iw_wr_wait *wr_waitp;
3238 PDBG("%s type %u\n", __func__, rpl->type);
3240 switch (rpl->type) {
3241 case FW6_TYPE_WR_RPL:
3242 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
3243 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
3244 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
3246 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3250 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3254 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3262 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3264 struct cpl_abort_req_rss *req = cplhdr(skb);
3266 struct tid_info *t = dev->rdev.lldi.tids;
3267 unsigned int tid = GET_TID(req);
3269 ep = lookup_tid(t, tid);
3271 printk(KERN_WARNING MOD
3272 "Abort on non-existent endpoint, tid %d\n", tid);
3276 if (is_neg_adv_abort(req->status)) {
3277 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3282 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3286 * Wake up any threads in rdma_init() or rdma_fini().
3288 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3294 * Most upcalls from the T4 Core go to sched() to
3295 * schedule the processing on a work queue.
3297 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3298 [CPL_ACT_ESTABLISH] = sched,
3299 [CPL_ACT_OPEN_RPL] = sched,
3300 [CPL_RX_DATA] = sched,
3301 [CPL_ABORT_RPL_RSS] = sched,
3302 [CPL_ABORT_RPL] = sched,
3303 [CPL_PASS_OPEN_RPL] = sched,
3304 [CPL_CLOSE_LISTSRV_RPL] = sched,
3305 [CPL_PASS_ACCEPT_REQ] = sched,
3306 [CPL_PASS_ESTABLISH] = sched,
3307 [CPL_PEER_CLOSE] = sched,
3308 [CPL_CLOSE_CON_RPL] = sched,
3309 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
3310 [CPL_RDMA_TERMINATE] = sched,
3311 [CPL_FW4_ACK] = sched,
3312 [CPL_SET_TCB_RPL] = set_tcb_rpl,
3313 [CPL_FW6_MSG] = fw6_msg,
3314 [CPL_RX_PKT] = sched
3317 int __init c4iw_cm_init(void)
3319 spin_lock_init(&timeout_lock);
3320 skb_queue_head_init(&rxq);
3322 workq = create_singlethread_workqueue("iw_cxgb4");
3329 void __exit c4iw_cm_term(void)
3331 WARN_ON(!list_empty(&timeout_list));
3332 flush_workqueue(workq);
3333 destroy_workqueue(workq);