tcp: Remove TCPCT
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / infiniband / hw / cxgb4 / cm.c
1 /*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
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:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
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.
22 *
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
30 * SOFTWARE.
31 */
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>
39 #include <linux/ip.h>
40 #include <linux/tcp.h>
41 #include <linux/if_vlan.h>
42
43 #include <net/neighbour.h>
44 #include <net/netevent.h>
45 #include <net/route.h>
46 #include <net/tcp.h>
47
48 #include "iw_cxgb4.h"
49
50 static char *states[] = {
51 "idle",
52 "listen",
53 "connecting",
54 "mpa_wait_req",
55 "mpa_req_sent",
56 "mpa_req_rcvd",
57 "mpa_rep_sent",
58 "fpdu_mode",
59 "aborting",
60 "closing",
61 "moribund",
62 "dead",
63 NULL,
64 };
65
66 static int nocong;
67 module_param(nocong, int, 0644);
68 MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
69
70 static int enable_ecn;
71 module_param(enable_ecn, int, 0644);
72 MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
73
74 static int dack_mode = 1;
75 module_param(dack_mode, int, 0644);
76 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
77
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)");
81
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)");
85
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)");
89
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)");
94
95 int c4iw_debug;
96 module_param(c4iw_debug, int, 0644);
97 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
98
99 static int peer2peer;
100 module_param(peer2peer, int, 0644);
101 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
102
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)");
107
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)");
112
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)");
118
119 static int markers_enabled;
120 module_param(markers_enabled, int, 0644);
121 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
122
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)");
126
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)");
130
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)");
134
135 static struct workqueue_struct *workq;
136
137 static struct sk_buff_head rxq;
138
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);
142
143 static LIST_HEAD(timeout_list);
144 static spinlock_t timeout_lock;
145
146 static void deref_qp(struct c4iw_ep *ep)
147 {
148 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
149 clear_bit(QP_REFERENCED, &ep->com.flags);
150 }
151
152 static void ref_qp(struct c4iw_ep *ep)
153 {
154 set_bit(QP_REFERENCED, &ep->com.flags);
155 c4iw_qp_add_ref(&ep->com.qp->ibqp);
156 }
157
158 static void start_ep_timer(struct c4iw_ep *ep)
159 {
160 PDBG("%s ep %p\n", __func__, ep);
161 if (timer_pending(&ep->timer)) {
162 pr_err("%s timer already started! ep %p\n",
163 __func__, ep);
164 return;
165 }
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);
172 }
173
174 static void stop_ep_timer(struct c4iw_ep *ep)
175 {
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);
180 }
181
182 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
183 struct l2t_entry *l2e)
184 {
185 int error = 0;
186
187 if (c4iw_fatal_error(rdev)) {
188 kfree_skb(skb);
189 PDBG("%s - device in error state - dropping\n", __func__);
190 return -EIO;
191 }
192 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
193 if (error < 0)
194 kfree_skb(skb);
195 return error < 0 ? error : 0;
196 }
197
198 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
199 {
200 int error = 0;
201
202 if (c4iw_fatal_error(rdev)) {
203 kfree_skb(skb);
204 PDBG("%s - device in error state - dropping\n", __func__);
205 return -EIO;
206 }
207 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
208 if (error < 0)
209 kfree_skb(skb);
210 return error < 0 ? error : 0;
211 }
212
213 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
214 {
215 struct cpl_tid_release *req;
216
217 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
218 if (!skb)
219 return;
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);
225 return;
226 }
227
228 static void set_emss(struct c4iw_ep *ep, u16 opt)
229 {
230 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
231 ep->mss = ep->emss;
232 if (GET_TCPOPT_TSTAMP(opt))
233 ep->emss -= 12;
234 if (ep->emss < 128)
235 ep->emss = 128;
236 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
237 ep->mss, ep->emss);
238 }
239
240 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
241 {
242 enum c4iw_ep_state state;
243
244 mutex_lock(&epc->mutex);
245 state = epc->state;
246 mutex_unlock(&epc->mutex);
247 return state;
248 }
249
250 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
251 {
252 epc->state = new;
253 }
254
255 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
256 {
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);
261 return;
262 }
263
264 static void *alloc_ep(int size, gfp_t gfp)
265 {
266 struct c4iw_ep_common *epc;
267
268 epc = kzalloc(size, gfp);
269 if (epc) {
270 kref_init(&epc->kref);
271 mutex_init(&epc->mutex);
272 c4iw_init_wr_wait(&epc->wr_wait);
273 }
274 PDBG("%s alloc ep %p\n", __func__, epc);
275 return epc;
276 }
277
278 void _c4iw_free_ep(struct kref *kref)
279 {
280 struct c4iw_ep *ep;
281
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))
285 deref_qp(ep);
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);
291 }
292 kfree(ep);
293 }
294
295 static void release_ep_resources(struct c4iw_ep *ep)
296 {
297 set_bit(RELEASE_RESOURCES, &ep->com.flags);
298 c4iw_put_ep(&ep->com);
299 }
300
301 static int status2errno(int status)
302 {
303 switch (status) {
304 case CPL_ERR_NONE:
305 return 0;
306 case CPL_ERR_CONN_RESET:
307 return -ECONNRESET;
308 case CPL_ERR_ARP_MISS:
309 return -EHOSTUNREACH;
310 case CPL_ERR_CONN_TIMEDOUT:
311 return -ETIMEDOUT;
312 case CPL_ERR_TCAM_FULL:
313 return -ENOMEM;
314 case CPL_ERR_CONN_EXIST:
315 return -EADDRINUSE;
316 default:
317 return -EIO;
318 }
319 }
320
321 /*
322 * Try and reuse skbs already allocated...
323 */
324 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
325 {
326 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
327 skb_trim(skb, 0);
328 skb_get(skb);
329 skb_reset_transport_header(skb);
330 } else {
331 skb = alloc_skb(len, gfp);
332 }
333 return skb;
334 }
335
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)
339 {
340 struct rtable *rt;
341 struct flowi4 fl4;
342
343 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
344 peer_port, local_port, IPPROTO_TCP,
345 tos, 0);
346 if (IS_ERR(rt))
347 return NULL;
348 return rt;
349 }
350
351 static void arp_failure_discard(void *handle, struct sk_buff *skb)
352 {
353 PDBG("%s c4iw_dev %p\n", __func__, handle);
354 kfree_skb(skb);
355 }
356
357 /*
358 * Handle an ARP failure for an active open.
359 */
360 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
361 {
362 printk(KERN_ERR MOD "ARP failure duing connect\n");
363 kfree_skb(skb);
364 }
365
366 /*
367 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
368 * and send it along.
369 */
370 static void abort_arp_failure(void *handle, struct sk_buff *skb)
371 {
372 struct c4iw_rdev *rdev = handle;
373 struct cpl_abort_req *req = cplhdr(skb);
374
375 PDBG("%s rdev %p\n", __func__, rdev);
376 req->cmd = CPL_ABORT_NO_RST;
377 c4iw_ofld_send(rdev, skb);
378 }
379
380 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
381 {
382 unsigned int flowclen = 80;
383 struct fw_flowc_wr *flowc;
384 int i;
385
386 skb = get_skb(skb, flowclen, GFP_KERNEL);
387 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
388
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));
393
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;
417 }
418
419 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
420 c4iw_ofld_send(&ep->com.dev->rdev, skb);
421 }
422
423 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
424 {
425 struct cpl_close_con_req *req;
426 struct sk_buff *skb;
427 int wrlen = roundup(sizeof *req, 16);
428
429 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
430 skb = get_skb(NULL, wrlen, gfp);
431 if (!skb) {
432 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
433 return -ENOMEM;
434 }
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,
441 ep->hwtid));
442 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
443 }
444
445 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
446 {
447 struct cpl_abort_req *req;
448 int wrlen = roundup(sizeof *req, 16);
449
450 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
451 skb = get_skb(skb, wrlen, gfp);
452 if (!skb) {
453 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
454 __func__);
455 return -ENOMEM;
456 }
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);
465 }
466
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)
475
476 static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
477 struct l2t_entry *l2t)
478 {
479 unsigned int ntuple = 0;
480 u32 viid;
481
482 switch (dev->rdev.lldi.filt_mode) {
483
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;
488 else {
489 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
490 ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
491 }
492 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
493 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
494 break;
495 case HW_TPL_FR_MT_PR_OV_P_FC: {
496 viid = cxgb4_port_viid(l2t->neigh->dev);
497
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;
503 break;
504 }
505 default:
506 break;
507 }
508 return ntuple;
509 }
510
511 static int send_connect(struct c4iw_ep *ep)
512 {
513 struct cpl_act_open_req *req;
514 struct cpl_t5_act_open_req *t5_req;
515 struct sk_buff *skb;
516 u64 opt0;
517 u32 opt2;
518 unsigned int mtu_idx;
519 int wscale;
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);
524
525 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
526
527 skb = get_skb(NULL, wrlen, GFP_KERNEL);
528 if (!skb) {
529 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
530 __func__);
531 return -ENOMEM;
532 }
533 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
534
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) |
538 KEEP_ALIVE(1) |
539 DELACK(1) |
540 WND_SCALE(wscale) |
541 MSS_IDX(mtu_idx) |
542 L2T_IDX(ep->l2t->idx) |
543 TX_CHAN(ep->tx_chan) |
544 SMAC_SEL(ep->smac_idx) |
545 DSCP(ep->tos) |
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);
553 if (enable_tcp_sack)
554 opt2 |= SACK_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);
558
559 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
560 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
561 INIT_TP_WR(req, 0);
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,
571 ep->dst, ep->l2t));
572 req->opt2 = cpu_to_be32(opt2);
573 } else {
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);
587 }
588
589 set_bit(ACT_OPEN_REQ, &ep->com.history);
590 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
591 }
592
593 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
594 u8 mpa_rev_to_use)
595 {
596 int mpalen, wrlen;
597 struct fw_ofld_tx_data_wr *req;
598 struct mpa_message *mpa;
599 struct mpa_v2_conn_params mpa_v2_params;
600
601 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
602
603 BUG_ON(skb_cloned(skb));
604
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);
610 if (!skb) {
611 connect_reply_upcall(ep, -ENOMEM);
612 return;
613 }
614 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
615
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) |
620 FW_WR_COMPL(1) |
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));
629
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;
640 }
641
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);
647
648 if (peer2peer) {
649 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
650 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
651 mpa_v2_params.ord |=
652 htons(MPA_V2_RDMA_WRITE_RTR);
653 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
654 mpa_v2_params.ord |=
655 htons(MPA_V2_RDMA_READ_RTR);
656 }
657 memcpy(mpa->private_data, &mpa_v2_params,
658 sizeof(struct mpa_v2_conn_params));
659
660 if (ep->plen)
661 memcpy(mpa->private_data +
662 sizeof(struct mpa_v2_conn_params),
663 ep->mpa_pkt + sizeof(*mpa), ep->plen);
664 } else
665 if (ep->plen)
666 memcpy(mpa->private_data,
667 ep->mpa_pkt + sizeof(*mpa), ep->plen);
668
669 /*
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.
673 */
674 skb_get(skb);
675 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
676 BUG_ON(ep->mpa_skb);
677 ep->mpa_skb = skb;
678 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
679 start_ep_timer(ep);
680 state_set(&ep->com, MPA_REQ_SENT);
681 ep->mpa_attr.initiator = 1;
682 return;
683 }
684
685 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
686 {
687 int mpalen, wrlen;
688 struct fw_ofld_tx_data_wr *req;
689 struct mpa_message *mpa;
690 struct sk_buff *skb;
691 struct mpa_v2_conn_params mpa_v2_params;
692
693 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
694
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);
699
700 skb = get_skb(NULL, wrlen, GFP_KERNEL);
701 if (!skb) {
702 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
703 return -ENOMEM;
704 }
705 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
706
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) |
711 FW_WR_COMPL(1) |
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));
720
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);
727
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 :
734 0));
735 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
736 (p2p_type ==
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));
743
744 if (ep->plen)
745 memcpy(mpa->private_data +
746 sizeof(struct mpa_v2_conn_params), pdata, plen);
747 } else
748 if (plen)
749 memcpy(mpa->private_data, pdata, plen);
750
751 /*
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.
755 */
756 skb_get(skb);
757 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
758 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
759 BUG_ON(ep->mpa_skb);
760 ep->mpa_skb = skb;
761 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
762 }
763
764 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
765 {
766 int mpalen, wrlen;
767 struct fw_ofld_tx_data_wr *req;
768 struct mpa_message *mpa;
769 struct sk_buff *skb;
770 struct mpa_v2_conn_params mpa_v2_params;
771
772 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
773
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);
778
779 skb = get_skb(NULL, wrlen, GFP_KERNEL);
780 if (!skb) {
781 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
782 return -ENOMEM;
783 }
784 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
785
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) |
790 FW_WR_COMPL(1) |
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));
799
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);
807
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);
817
818 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
819 mpa_v2_params.ord |=
820 htons(MPA_V2_RDMA_WRITE_RTR);
821 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
822 mpa_v2_params.ord |=
823 htons(MPA_V2_RDMA_READ_RTR);
824 }
825
826 memcpy(mpa->private_data, &mpa_v2_params,
827 sizeof(struct mpa_v2_conn_params));
828
829 if (ep->plen)
830 memcpy(mpa->private_data +
831 sizeof(struct mpa_v2_conn_params), pdata, plen);
832 } else
833 if (plen)
834 memcpy(mpa->private_data, pdata, plen);
835
836 /*
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.
840 */
841 skb_get(skb);
842 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
843 ep->mpa_skb = skb;
844 state_set(&ep->com, MPA_REP_SENT);
845 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
846 }
847
848 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
849 {
850 struct c4iw_ep *ep;
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;
855
856 ep = lookup_atid(t, atid);
857
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));
860
861 dst_confirm(ep->dst);
862
863 /* setup the hwtid for this connection */
864 ep->hwtid = tid;
865 cxgb4_insert_tid(t, ep, tid);
866 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
867
868 ep->snd_seq = be32_to_cpu(req->snd_isn);
869 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
870
871 set_emss(ep, ntohs(req->tcp_opt));
872
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);
877
878 /* start MPA negotiation */
879 send_flowc(ep, NULL);
880 if (ep->retry_with_mpa_v1)
881 send_mpa_req(ep, skb, 1);
882 else
883 send_mpa_req(ep, skb, mpa_rev);
884
885 return 0;
886 }
887
888 static void close_complete_upcall(struct c4iw_ep *ep)
889 {
890 struct iw_cm_event event;
891
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;
895 if (ep->com.cm_id) {
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);
902 }
903 }
904
905 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
906 {
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);
912 }
913
914 static void peer_close_upcall(struct c4iw_ep *ep)
915 {
916 struct iw_cm_event event;
917
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;
921 if (ep->com.cm_id) {
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);
926 }
927 }
928
929 static void peer_abort_upcall(struct c4iw_ep *ep)
930 {
931 struct iw_cm_event event;
932
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;
937 if (ep->com.cm_id) {
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);
944 }
945 }
946
947 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
948 {
949 struct iw_cm_event event;
950
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;
957
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);
966 } else {
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);
971 }
972 }
973
974 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
975 ep->hwtid, status);
976 set_bit(CONN_RPL_UPCALL, &ep->com.history);
977 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
978
979 if (status < 0) {
980 ep->com.cm_id->rem_ref(ep->com.cm_id);
981 ep->com.cm_id = NULL;
982 }
983 }
984
985 static void connect_request_upcall(struct c4iw_ep *ep)
986 {
987 struct iw_cm_event event;
988
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 */
997 event.ord = ep->ord;
998 event.ird = ep->ird;
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);
1003 } else {
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);
1009 }
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,
1014 &event);
1015 }
1016 set_bit(CONNREQ_UPCALL, &ep->com.history);
1017 c4iw_put_ep(&ep->parent_ep->com);
1018 ep->parent_ep = NULL;
1019 }
1020
1021 static void established_upcall(struct c4iw_ep *ep)
1022 {
1023 struct iw_cm_event event;
1024
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);
1034 }
1035 }
1036
1037 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1038 {
1039 struct cpl_rx_data_ack *req;
1040 struct sk_buff *skb;
1041 int wrlen = roundup(sizeof *req, 16);
1042
1043 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1044 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1045 if (!skb) {
1046 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1047 return 0;
1048 }
1049
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,
1054 ep->hwtid));
1055 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1056 F_RX_DACK_CHANGE |
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);
1060 return credits;
1061 }
1062
1063 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1064 {
1065 struct mpa_message *mpa;
1066 struct mpa_v2_conn_params *mpa_v2_params;
1067 u16 plen;
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;
1072 int err;
1073
1074 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1075
1076 /*
1077 * Stop mpa timer. If it expired, then the state has
1078 * changed and we bail since ep_timeout already aborted
1079 * the connection.
1080 */
1081 stop_ep_timer(ep);
1082 if (state_read(&ep->com) != MPA_REQ_SENT)
1083 return;
1084
1085 /*
1086 * If we get more than the supported amount of private data
1087 * then we must fail this connection.
1088 */
1089 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1090 err = -EINVAL;
1091 goto err;
1092 }
1093
1094 /*
1095 * copy the new data into our accumulation buffer.
1096 */
1097 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1098 skb->len);
1099 ep->mpa_pkt_len += skb->len;
1100
1101 /*
1102 * if we don't even have the mpa message, then bail.
1103 */
1104 if (ep->mpa_pkt_len < sizeof(*mpa))
1105 return;
1106 mpa = (struct mpa_message *) ep->mpa_pkt;
1107
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);
1112 err = -EPROTO;
1113 goto err;
1114 }
1115 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1116 err = -EPROTO;
1117 goto err;
1118 }
1119
1120 plen = ntohs(mpa->private_data_size);
1121
1122 /*
1123 * Fail if there's too much private data.
1124 */
1125 if (plen > MPA_MAX_PRIVATE_DATA) {
1126 err = -EPROTO;
1127 goto err;
1128 }
1129
1130 /*
1131 * If plen does not account for pkt size
1132 */
1133 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1134 err = -EPROTO;
1135 goto err;
1136 }
1137
1138 ep->plen = (u8) plen;
1139
1140 /*
1141 * If we don't have all the pdata yet, then bail.
1142 * We'll continue process when more data arrives.
1143 */
1144 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1145 return;
1146
1147 if (mpa->flags & MPA_REJECT) {
1148 err = -ECONNREFUSED;
1149 goto err;
1150 }
1151
1152 /*
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.
1156 */
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;
1163
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;
1174
1175 /*
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
1179 */
1180 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1181 err = -ENOMEM;
1182 ep->ird = resp_ord;
1183 ep->ord = resp_ird;
1184 insuff_ird = 1;
1185 }
1186
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;
1197 }
1198 }
1199 } else if (mpa->revision == 1)
1200 if (peer2peer)
1201 ep->mpa_attr.p2p_type = p2p_type;
1202
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);
1209
1210 /*
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
1215 */
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;
1219 rtr_mismatch = 1;
1220 }
1221
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;
1227
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;
1231
1232 /* bind QP and TID with INIT_WR */
1233 err = c4iw_modify_qp(ep->com.qp->rhp,
1234 ep->com.qp, mask, &attrs, 1);
1235 if (err)
1236 goto err;
1237
1238 /*
1239 * If responder's RTR requirement did not match with what initiator
1240 * supports, generate TERM message
1241 */
1242 if (rtr_mismatch) {
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);
1249 err = -ENOMEM;
1250 goto out;
1251 }
1252
1253 /*
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
1257 * initiator ORD.
1258 */
1259 if (insuff_ird) {
1260 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1261 __func__);
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);
1267 err = -ENOMEM;
1268 goto out;
1269 }
1270 goto out;
1271 err:
1272 state_set(&ep->com, ABORTING);
1273 send_abort(ep, skb, GFP_KERNEL);
1274 out:
1275 connect_reply_upcall(ep, err);
1276 return;
1277 }
1278
1279 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1280 {
1281 struct mpa_message *mpa;
1282 struct mpa_v2_conn_params *mpa_v2_params;
1283 u16 plen;
1284
1285 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1286
1287 if (state_read(&ep->com) != MPA_REQ_WAIT)
1288 return;
1289
1290 /*
1291 * If we get more than the supported amount of private data
1292 * then we must fail this connection.
1293 */
1294 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1295 stop_ep_timer(ep);
1296 abort_connection(ep, skb, GFP_KERNEL);
1297 return;
1298 }
1299
1300 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1301
1302 /*
1303 * Copy the new data into our accumulation buffer.
1304 */
1305 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1306 skb->len);
1307 ep->mpa_pkt_len += skb->len;
1308
1309 /*
1310 * If we don't even have the mpa message, then bail.
1311 * We'll continue process when more data arrives.
1312 */
1313 if (ep->mpa_pkt_len < sizeof(*mpa))
1314 return;
1315
1316 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1317 stop_ep_timer(ep);
1318 mpa = (struct mpa_message *) ep->mpa_pkt;
1319
1320 /*
1321 * Validate MPA Header.
1322 */
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);
1326 stop_ep_timer(ep);
1327 abort_connection(ep, skb, GFP_KERNEL);
1328 return;
1329 }
1330
1331 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1332 stop_ep_timer(ep);
1333 abort_connection(ep, skb, GFP_KERNEL);
1334 return;
1335 }
1336
1337 plen = ntohs(mpa->private_data_size);
1338
1339 /*
1340 * Fail if there's too much private data.
1341 */
1342 if (plen > MPA_MAX_PRIVATE_DATA) {
1343 stop_ep_timer(ep);
1344 abort_connection(ep, skb, GFP_KERNEL);
1345 return;
1346 }
1347
1348 /*
1349 * If plen does not account for pkt size
1350 */
1351 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1352 stop_ep_timer(ep);
1353 abort_connection(ep, skb, GFP_KERNEL);
1354 return;
1355 }
1356 ep->plen = (u8) plen;
1357
1358 /*
1359 * If we don't have all the pdata yet, then bail.
1360 */
1361 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1362 return;
1363
1364 /*
1365 * If we get here we have accumulated the entire mpa
1366 * start reply message including private data.
1367 */
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;
1376
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)
1388 if (peer2peer) {
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;
1397 }
1398 }
1399 } else if (mpa->revision == 1)
1400 if (peer2peer)
1401 ep->mpa_attr.p2p_type = p2p_type;
1402
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);
1408
1409 state_set(&ep->com, MPA_REQ_RCVD);
1410
1411 /* drive upcall */
1412 connect_request_upcall(ep);
1413 return;
1414 }
1415
1416 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1417 {
1418 struct c4iw_ep *ep;
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;
1424
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);
1429
1430 /* update RX credits */
1431 update_rx_credits(ep, dlen);
1432
1433 switch (state_read(&ep->com)) {
1434 case MPA_REQ_SENT:
1435 ep->rcv_seq += dlen;
1436 process_mpa_reply(ep, skb);
1437 break;
1438 case MPA_REQ_WAIT:
1439 ep->rcv_seq += dlen;
1440 process_mpa_request(ep, skb);
1441 break;
1442 case FPDU_MODE: {
1443 struct c4iw_qp_attributes attrs;
1444 BUG_ON(!ep->com.qp);
1445 if (status)
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);
1454 break;
1455 }
1456 default:
1457 break;
1458 }
1459 return 0;
1460 }
1461
1462 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1463 {
1464 struct c4iw_ep *ep;
1465 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1466 int release = 0;
1467 unsigned int tid = GET_TID(rpl);
1468 struct tid_info *t = dev->rdev.lldi.tids;
1469
1470 ep = lookup_tid(t, tid);
1471 if (!ep) {
1472 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1473 return 0;
1474 }
1475 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1476 mutex_lock(&ep->com.mutex);
1477 switch (ep->com.state) {
1478 case ABORTING:
1479 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
1480 __state_set(&ep->com, DEAD);
1481 release = 1;
1482 break;
1483 default:
1484 printk(KERN_ERR "%s ep %p state %d\n",
1485 __func__, ep, ep->com.state);
1486 break;
1487 }
1488 mutex_unlock(&ep->com.mutex);
1489
1490 if (release)
1491 release_ep_resources(ep);
1492 return 0;
1493 }
1494
1495 static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1496 {
1497 struct sk_buff *skb;
1498 struct fw_ofld_connection_wr *req;
1499 unsigned int mtu_idx;
1500 int wscale;
1501
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,
1508 ep->l2t));
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) |
1524 KEEP_ALIVE(1) |
1525 DELACK(1) |
1526 WND_SCALE(wscale) |
1527 MSS_IDX(mtu_idx) |
1528 L2T_IDX(ep->l2t->idx) |
1529 TX_CHAN(ep->tx_chan) |
1530 SMAC_SEL(ep->smac_idx) |
1531 DSCP(ep->tos) |
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]) |
1536 RX_CHANNEL(0) |
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);
1550 }
1551
1552 /*
1553 * Return whether a failed active open has allocated a TID
1554 */
1555 static inline int act_open_has_tid(int status)
1556 {
1557 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1558 status != CPL_ERR_ARP_MISS;
1559 }
1560
1561 #define ACT_OPEN_RETRY_COUNT 2
1562
1563 static int c4iw_reconnect(struct c4iw_ep *ep)
1564 {
1565 int err = 0;
1566 struct rtable *rt;
1567 struct port_info *pi;
1568 struct net_device *pdev;
1569 int step;
1570 struct neighbour *neigh;
1571
1572 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1573 init_timer(&ep->timer);
1574
1575 /*
1576 * Allocate an active TID to initiate a TCP connection.
1577 */
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__);
1581 err = -ENOMEM;
1582 goto fail2;
1583 }
1584 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1585
1586 /* find a route */
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);
1592 if (!rt) {
1593 pr_err("%s - cannot find route.\n", __func__);
1594 err = -EHOSTUNREACH;
1595 goto fail3;
1596 }
1597 ep->dst = &rt->dst;
1598
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,
1607 neigh, pdev, 0);
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;
1612 dev_put(pdev);
1613 } else {
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) &
1620 0x7F) << 1;
1621 }
1622
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];
1628
1629 if (!ep->l2t) {
1630 pr_err("%s - cannot alloc l2e.\n", __func__);
1631 err = -ENOMEM;
1632 goto fail4;
1633 }
1634
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,
1637 ep->l2t->idx);
1638
1639 state_set(&ep->com, CONNECTING);
1640 ep->tos = 0;
1641
1642 /* send connect request to rnic */
1643 err = send_connect(ep);
1644 if (!err)
1645 goto out;
1646
1647 cxgb4_l2t_release(ep->l2t);
1648 fail4:
1649 dst_release(ep->dst);
1650 fail3:
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);
1653 fail2:
1654 /*
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.
1659 */
1660 connect_reply_upcall(ep, -ECONNRESET);
1661 c4iw_put_ep(&ep->com);
1662 out:
1663 return err;
1664 }
1665
1666 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1667 {
1668 struct c4iw_ep *ep;
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));
1674
1675 ep = lookup_atid(t, atid);
1676
1677 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1678 status, status2errno(status));
1679
1680 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1681 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1682 atid);
1683 return 0;
1684 }
1685
1686 set_bit(ACT_OPEN_RPL, &ep->com.history);
1687
1688 /*
1689 * Log interesting failures.
1690 */
1691 switch (status) {
1692 case CPL_ERR_CONN_RESET:
1693 case CPL_ERR_CONN_TIMEDOUT:
1694 break;
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))));
1703 return 0;
1704 }
1705 break;
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,
1710 atid);
1711 cxgb4_free_atid(t, atid);
1712 dst_release(ep->dst);
1713 cxgb4_l2t_release(ep->l2t);
1714 c4iw_reconnect(ep);
1715 return 0;
1716 }
1717 break;
1718 default:
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));
1726 break;
1727 }
1728
1729 connect_reply_upcall(ep, status2errno(status));
1730 state_set(&ep->com, DEAD);
1731
1732 if (status && act_open_has_tid(status))
1733 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1734
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);
1740
1741 return 0;
1742 }
1743
1744 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1745 {
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);
1750
1751 if (!ep) {
1752 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1753 goto out;
1754 }
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));
1758
1759 out:
1760 return 0;
1761 }
1762
1763 static int listen_stop(struct c4iw_listen_ep *ep)
1764 {
1765 struct sk_buff *skb;
1766 struct cpl_close_listsvr_req *req;
1767
1768 PDBG("%s ep %p\n", __func__, ep);
1769 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1770 if (!skb) {
1771 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1772 return -ENOMEM;
1773 }
1774 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1775 INIT_TP_WR(req, 0);
1776 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1777 ep->stid));
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);
1782 }
1783
1784 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1785 {
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);
1790
1791 PDBG("%s ep %p\n", __func__, ep);
1792 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
1793 return 0;
1794 }
1795
1796 static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1797 struct cpl_pass_accept_req *req)
1798 {
1799 struct cpl_pass_accept_rpl *rpl;
1800 unsigned int mtu_idx;
1801 u64 opt0;
1802 u32 opt2;
1803 int wscale;
1804
1805 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1806 BUG_ON(skb_cloned(skb));
1807 skb_trim(skb, sizeof(*rpl));
1808 skb_get(skb);
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) |
1812 KEEP_ALIVE(1) |
1813 DELACK(1) |
1814 WND_SCALE(wscale) |
1815 MSS_IDX(mtu_idx) |
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);
1824
1825 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1826 opt2 |= TSTAMPS_EN(1);
1827 if (enable_tcp_sack && req->tcpopt.sack)
1828 opt2 |= SACK_EN(1);
1829 if (wscale && enable_tcp_window_scaling)
1830 opt2 |= WND_SCALE_EN(1);
1831 if (enable_ecn) {
1832 const struct tcphdr *tcph;
1833 u32 hlen = ntohl(req->hdr_len);
1834
1835 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1836 G_IP_HDR_LEN(hlen);
1837 if (tcph->ece && tcph->cwr)
1838 opt2 |= CCTRL_ECN(1);
1839 }
1840
1841 rpl = cplhdr(skb);
1842 INIT_TP_WR(rpl, ep->hwtid);
1843 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1844 ep->hwtid));
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);
1849
1850 return;
1851 }
1852
1853 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1854 struct sk_buff *skb)
1855 {
1856 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1857 peer_ip);
1858 BUG_ON(skb_cloned(skb));
1859 skb_trim(skb, sizeof(struct cpl_tid_release));
1860 skb_get(skb);
1861 release_tid(&dev->rdev, hwtid, skb);
1862 return;
1863 }
1864
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)
1868 {
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);
1874
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),
1877 ntohs(tcp->dest));
1878
1879 *peer_ip = ip->saddr;
1880 *local_ip = ip->daddr;
1881 *peer_port = tcp->source;
1882 *local_port = tcp->dest;
1883
1884 return;
1885 }
1886
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)
1889 {
1890 struct neighbour *n;
1891 int err, step;
1892
1893 n = dst_neigh_lookup(dst, &peer_ip);
1894 if (!n)
1895 return -ENODEV;
1896
1897 rcu_read_lock();
1898 err = -ENOMEM;
1899 if (n->dev->flags & IFF_LOOPBACK) {
1900 struct net_device *pdev;
1901
1902 pdev = ip_dev_find(&init_net, peer_ip);
1903 if (!pdev) {
1904 err = -ENODEV;
1905 goto out;
1906 }
1907 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1908 n, pdev, 0);
1909 if (!ep->l2t)
1910 goto out;
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];
1922 dev_put(pdev);
1923 } else {
1924 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1925 n, n->dev, 0);
1926 if (!ep->l2t)
1927 goto out;
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];
1939
1940 if (clear_mpa_v1) {
1941 ep->retry_with_mpa_v1 = 0;
1942 ep->tried_with_mpa_v1 = 0;
1943 }
1944 }
1945 err = 0;
1946 out:
1947 rcu_read_unlock();
1948
1949 neigh_release(n);
1950
1951 return err;
1952 }
1953
1954 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1955 {
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;
1962 struct rtable *rt;
1963 __be32 local_ip, peer_ip = 0;
1964 __be16 local_port, peer_port;
1965 int err;
1966 u16 peer_mss = ntohs(req->tcpopt.mss);
1967
1968 parent_ep = lookup_stid(t, stid);
1969 if (!parent_ep) {
1970 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1971 goto reject;
1972 }
1973 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1974
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);
1979
1980 if (state_read(&parent_ep->com) != LISTEN) {
1981 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1982 __func__);
1983 goto reject;
1984 }
1985
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)));
1989 if (!rt) {
1990 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1991 __func__);
1992 goto reject;
1993 }
1994 dst = &rt->dst;
1995
1996 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1997 if (!child_ep) {
1998 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1999 __func__);
2000 dst_release(dst);
2001 goto reject;
2002 }
2003
2004 err = import_ep(child_ep, peer_ip, dst, dev, false);
2005 if (err) {
2006 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2007 __func__);
2008 dst_release(dst);
2009 kfree(child_ep);
2010 goto reject;
2011 }
2012
2013 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2014 child_ep->mtu = peer_mss + 40;
2015
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;
2030
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);
2033
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);
2039 goto out;
2040 reject:
2041 reject_cr(dev, hwtid, peer_ip, skb);
2042 out:
2043 return 0;
2044 }
2045
2046 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2047 {
2048 struct c4iw_ep *ep;
2049 struct cpl_pass_establish *req = cplhdr(skb);
2050 struct tid_info *t = dev->rdev.lldi.tids;
2051 unsigned int tid = GET_TID(req);
2052
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);
2057
2058 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2059 ntohs(req->tcp_opt));
2060
2061 set_emss(ep, ntohs(req->tcp_opt));
2062
2063 dst_confirm(ep->dst);
2064 state_set(&ep->com, MPA_REQ_WAIT);
2065 start_ep_timer(ep);
2066 send_flowc(ep, skb);
2067 set_bit(PASS_ESTAB, &ep->com.history);
2068
2069 return 0;
2070 }
2071
2072 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2073 {
2074 struct cpl_peer_close *hdr = cplhdr(skb);
2075 struct c4iw_ep *ep;
2076 struct c4iw_qp_attributes attrs;
2077 int disconnect = 1;
2078 int release = 0;
2079 struct tid_info *t = dev->rdev.lldi.tids;
2080 unsigned int tid = GET_TID(hdr);
2081 int ret;
2082
2083 ep = lookup_tid(t, tid);
2084 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2085 dst_confirm(ep->dst);
2086
2087 set_bit(PEER_CLOSE, &ep->com.history);
2088 mutex_lock(&ep->com.mutex);
2089 switch (ep->com.state) {
2090 case MPA_REQ_WAIT:
2091 __state_set(&ep->com, CLOSING);
2092 break;
2093 case MPA_REQ_SENT:
2094 __state_set(&ep->com, CLOSING);
2095 connect_reply_upcall(ep, -ECONNRESET);
2096 break;
2097 case MPA_REQ_RCVD:
2098
2099 /*
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()).
2104 */
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);
2108 break;
2109 case MPA_REP_SENT:
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);
2113 break;
2114 case FPDU_MODE:
2115 start_ep_timer(ep);
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);
2122 disconnect = 1;
2123 }
2124 break;
2125 case ABORTING:
2126 disconnect = 0;
2127 break;
2128 case CLOSING:
2129 __state_set(&ep->com, MORIBUND);
2130 disconnect = 0;
2131 break;
2132 case MORIBUND:
2133 stop_ep_timer(ep);
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);
2138 }
2139 close_complete_upcall(ep);
2140 __state_set(&ep->com, DEAD);
2141 release = 1;
2142 disconnect = 0;
2143 break;
2144 case DEAD:
2145 disconnect = 0;
2146 break;
2147 default:
2148 BUG_ON(1);
2149 }
2150 mutex_unlock(&ep->com.mutex);
2151 if (disconnect)
2152 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2153 if (release)
2154 release_ep_resources(ep);
2155 return 0;
2156 }
2157
2158 /*
2159 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2160 */
2161 static int is_neg_adv_abort(unsigned int status)
2162 {
2163 return status == CPL_ERR_RTX_NEG_ADVICE ||
2164 status == CPL_ERR_PERSIST_NEG_ADVICE;
2165 }
2166
2167 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2168 {
2169 struct cpl_abort_req_rss *req = cplhdr(skb);
2170 struct c4iw_ep *ep;
2171 struct cpl_abort_rpl *rpl;
2172 struct sk_buff *rpl_skb;
2173 struct c4iw_qp_attributes attrs;
2174 int ret;
2175 int release = 0;
2176 struct tid_info *t = dev->rdev.lldi.tids;
2177 unsigned int tid = GET_TID(req);
2178
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,
2182 ep->hwtid);
2183 return 0;
2184 }
2185 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2186 ep->com.state);
2187 set_bit(PEER_ABORT, &ep->com.history);
2188
2189 /*
2190 * Wake up any threads in rdma_init() or rdma_fini().
2191 * However, this is not needed if com state is just
2192 * MPA_REQ_SENT
2193 */
2194 if (ep->com.state != MPA_REQ_SENT)
2195 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
2196
2197 mutex_lock(&ep->com.mutex);
2198 switch (ep->com.state) {
2199 case CONNECTING:
2200 break;
2201 case MPA_REQ_WAIT:
2202 stop_ep_timer(ep);
2203 break;
2204 case MPA_REQ_SENT:
2205 stop_ep_timer(ep);
2206 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
2207 connect_reply_upcall(ep, -ECONNRESET);
2208 else {
2209 /*
2210 * we just don't send notification upwards because we
2211 * want to retry with mpa_v1 without upper layers even
2212 * knowing it.
2213 *
2214 * do some housekeeping so as to re-initiate the
2215 * connection
2216 */
2217 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2218 mpa_rev);
2219 ep->retry_with_mpa_v1 = 1;
2220 }
2221 break;
2222 case MPA_REP_SENT:
2223 break;
2224 case MPA_REQ_RCVD:
2225 break;
2226 case MORIBUND:
2227 case CLOSING:
2228 stop_ep_timer(ep);
2229 /*FALLTHROUGH*/
2230 case FPDU_MODE:
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,
2235 &attrs, 1);
2236 if (ret)
2237 printk(KERN_ERR MOD
2238 "%s - qp <- error failed!\n",
2239 __func__);
2240 }
2241 peer_abort_upcall(ep);
2242 break;
2243 case ABORTING:
2244 break;
2245 case DEAD:
2246 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
2247 mutex_unlock(&ep->com.mutex);
2248 return 0;
2249 default:
2250 BUG_ON(1);
2251 break;
2252 }
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)
2258 release = 1;
2259 }
2260 mutex_unlock(&ep->com.mutex);
2261
2262 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2263 if (!rpl_skb) {
2264 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2265 __func__);
2266 release = 1;
2267 goto out;
2268 }
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);
2275 out:
2276 if (release)
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);
2283 c4iw_reconnect(ep);
2284 }
2285
2286 return 0;
2287 }
2288
2289 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2290 {
2291 struct c4iw_ep *ep;
2292 struct c4iw_qp_attributes attrs;
2293 struct cpl_close_con_rpl *rpl = cplhdr(skb);
2294 int release = 0;
2295 struct tid_info *t = dev->rdev.lldi.tids;
2296 unsigned int tid = GET_TID(rpl);
2297
2298 ep = lookup_tid(t, tid);
2299
2300 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2301 BUG_ON(!ep);
2302
2303 /* The cm_id may be null if we failed to connect */
2304 mutex_lock(&ep->com.mutex);
2305 switch (ep->com.state) {
2306 case CLOSING:
2307 __state_set(&ep->com, MORIBUND);
2308 break;
2309 case MORIBUND:
2310 stop_ep_timer(ep);
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,
2314 ep->com.qp,
2315 C4IW_QP_ATTR_NEXT_STATE,
2316 &attrs, 1);
2317 }
2318 close_complete_upcall(ep);
2319 __state_set(&ep->com, DEAD);
2320 release = 1;
2321 break;
2322 case ABORTING:
2323 case DEAD:
2324 break;
2325 default:
2326 BUG_ON(1);
2327 break;
2328 }
2329 mutex_unlock(&ep->com.mutex);
2330 if (release)
2331 release_ep_resources(ep);
2332 return 0;
2333 }
2334
2335 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2336 {
2337 struct cpl_rdma_terminate *rpl = cplhdr(skb);
2338 struct tid_info *t = dev->rdev.lldi.tids;
2339 unsigned int tid = GET_TID(rpl);
2340 struct c4iw_ep *ep;
2341 struct c4iw_qp_attributes attrs;
2342
2343 ep = lookup_tid(t, tid);
2344 BUG_ON(!ep);
2345
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);
2352 } else
2353 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
2354
2355 return 0;
2356 }
2357
2358 /*
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.
2362 */
2363 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2364 {
2365 struct c4iw_ep *ep;
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;
2370
2371
2372 ep = lookup_tid(t, tid);
2373 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2374 if (credits == 0) {
2375 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2376 __func__, ep, ep->hwtid, state_read(&ep->com));
2377 return 0;
2378 }
2379
2380 dst_confirm(ep->dst);
2381 if (ep->mpa_skb) {
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);
2386 ep->mpa_skb = NULL;
2387 }
2388 return 0;
2389 }
2390
2391 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2392 {
2393 int err;
2394 struct c4iw_ep *ep = to_ep(cm_id);
2395 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2396
2397 if (state_read(&ep->com) == DEAD) {
2398 c4iw_put_ep(&ep->com);
2399 return -ECONNRESET;
2400 }
2401 set_bit(ULP_REJECT, &ep->com.history);
2402 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2403 if (mpa_rev == 0)
2404 abort_connection(ep, NULL, GFP_KERNEL);
2405 else {
2406 err = send_mpa_reject(ep, pdata, pdata_len);
2407 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2408 }
2409 c4iw_put_ep(&ep->com);
2410 return 0;
2411 }
2412
2413 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2414 {
2415 int err;
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);
2421
2422 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2423 if (state_read(&ep->com) == DEAD) {
2424 err = -ECONNRESET;
2425 goto err;
2426 }
2427
2428 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2429 BUG_ON(!qp);
2430
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);
2435 err = -EINVAL;
2436 goto err;
2437 }
2438
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);
2446 err = -ENOMEM;
2447 goto err;
2448 }
2449 if (conn_param->ird > ep->ord) {
2450 if (!ep->ord)
2451 conn_param->ird = 1;
2452 else {
2453 abort_connection(ep, NULL, GFP_KERNEL);
2454 err = -ENOMEM;
2455 goto err;
2456 }
2457 }
2458
2459 }
2460 ep->ird = conn_param->ird;
2461 ep->ord = conn_param->ord;
2462
2463 if (ep->mpa_attr.version != 2)
2464 if (peer2peer && ep->ird == 0)
2465 ep->ird = 1;
2466
2467 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2468
2469 cm_id->add_ref(cm_id);
2470 ep->com.cm_id = cm_id;
2471 ep->com.qp = qp;
2472 ref_qp(ep);
2473
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;
2480
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;
2487
2488 err = c4iw_modify_qp(ep->com.qp->rhp,
2489 ep->com.qp, mask, &attrs, 1);
2490 if (err)
2491 goto err1;
2492 err = send_mpa_reply(ep, conn_param->private_data,
2493 conn_param->private_data_len);
2494 if (err)
2495 goto err1;
2496
2497 state_set(&ep->com, FPDU_MODE);
2498 established_upcall(ep);
2499 c4iw_put_ep(&ep->com);
2500 return 0;
2501 err1:
2502 ep->com.cm_id = NULL;
2503 cm_id->rem_ref(cm_id);
2504 err:
2505 c4iw_put_ep(&ep->com);
2506 return err;
2507 }
2508
2509 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2510 {
2511 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2512 struct c4iw_ep *ep;
2513 struct rtable *rt;
2514 int err = 0;
2515
2516 if ((conn_param->ord > c4iw_max_read_depth) ||
2517 (conn_param->ird > c4iw_max_read_depth)) {
2518 err = -EINVAL;
2519 goto out;
2520 }
2521 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2522 if (!ep) {
2523 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2524 err = -ENOMEM;
2525 goto out;
2526 }
2527 init_timer(&ep->timer);
2528 ep->plen = conn_param->private_data_len;
2529 if (ep->plen)
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;
2534
2535 if (peer2peer && ep->ord == 0)
2536 ep->ord = 1;
2537
2538 cm_id->add_ref(cm_id);
2539 ep->com.dev = dev;
2540 ep->com.cm_id = cm_id;
2541 ep->com.qp = get_qhp(dev, conn_param->qpn);
2542 BUG_ON(!ep->com.qp);
2543 ref_qp(ep);
2544 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2545 ep->com.qp, cm_id);
2546
2547 /*
2548 * Allocate an active TID to initiate a TCP connection.
2549 */
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__);
2553 err = -ENOMEM;
2554 goto fail2;
2555 }
2556 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
2557
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));
2563
2564 /* find a route */
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);
2570 if (!rt) {
2571 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2572 err = -EHOSTUNREACH;
2573 goto fail3;
2574 }
2575 ep->dst = &rt->dst;
2576
2577 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2578 ep->dst, ep->com.dev, true);
2579 if (err) {
2580 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2581 goto fail4;
2582 }
2583
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,
2586 ep->l2t->idx);
2587
2588 state_set(&ep->com, CONNECTING);
2589 ep->tos = 0;
2590 ep->com.local_addr = cm_id->local_addr;
2591 ep->com.remote_addr = cm_id->remote_addr;
2592
2593 /* send connect request to rnic */
2594 err = send_connect(ep);
2595 if (!err)
2596 goto out;
2597
2598 cxgb4_l2t_release(ep->l2t);
2599 fail4:
2600 dst_release(ep->dst);
2601 fail3:
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);
2604 fail2:
2605 cm_id->rem_ref(cm_id);
2606 c4iw_put_ep(&ep->com);
2607 out:
2608 return err;
2609 }
2610
2611 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2612 {
2613 int err = 0;
2614 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2615 struct c4iw_listen_ep *ep;
2616
2617 might_sleep();
2618
2619 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2620 if (!ep) {
2621 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2622 err = -ENOMEM;
2623 goto fail1;
2624 }
2625 PDBG("%s ep %p\n", __func__, ep);
2626 cm_id->add_ref(cm_id);
2627 ep->com.cm_id = cm_id;
2628 ep->com.dev = dev;
2629 ep->backlog = backlog;
2630 ep->com.local_addr = cm_id->local_addr;
2631
2632 /*
2633 * Allocate a server TID.
2634 */
2635 if (dev->rdev.lldi.enable_fw_ofld_conn)
2636 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2637 else
2638 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2639
2640 if (ep->stid == -1) {
2641 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
2642 err = -ENOMEM;
2643 goto fail2;
2644 }
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) {
2648 do {
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,
2653 0,
2654 ep->com.dev->rdev.lldi.rxq_ids[0],
2655 0,
2656 0);
2657 if (err == -EBUSY) {
2658 set_current_state(TASK_UNINTERRUPTIBLE);
2659 schedule_timeout(usecs_to_jiffies(100));
2660 }
2661 } while (err == -EBUSY);
2662 } else {
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,
2667 0,
2668 ep->com.dev->rdev.lldi.rxq_ids[0]);
2669 if (!err)
2670 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2671 &ep->com.wr_wait,
2672 0, 0, __func__);
2673 }
2674 if (!err) {
2675 cm_id->provider_data = ep;
2676 goto out;
2677 }
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);
2684 fail2:
2685 cm_id->rem_ref(cm_id);
2686 c4iw_put_ep(&ep->com);
2687 fail1:
2688 out:
2689 return err;
2690 }
2691
2692 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2693 {
2694 int err;
2695 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2696
2697 PDBG("%s ep %p\n", __func__, ep);
2698
2699 might_sleep();
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);
2705 } else {
2706 c4iw_init_wr_wait(&ep->com.wr_wait);
2707 err = listen_stop(ep);
2708 if (err)
2709 goto done;
2710 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2711 0, 0, __func__);
2712 }
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);
2715 done:
2716 cm_id->rem_ref(cm_id);
2717 c4iw_put_ep(&ep->com);
2718 return err;
2719 }
2720
2721 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2722 {
2723 int ret = 0;
2724 int close = 0;
2725 int fatal = 0;
2726 struct c4iw_rdev *rdev;
2727
2728 mutex_lock(&ep->com.mutex);
2729
2730 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2731 states[ep->com.state], abrupt);
2732
2733 rdev = &ep->com.dev->rdev;
2734 if (c4iw_fatal_error(rdev)) {
2735 fatal = 1;
2736 close_complete_upcall(ep);
2737 ep->com.state = DEAD;
2738 }
2739 switch (ep->com.state) {
2740 case MPA_REQ_WAIT:
2741 case MPA_REQ_SENT:
2742 case MPA_REQ_RCVD:
2743 case MPA_REP_SENT:
2744 case FPDU_MODE:
2745 close = 1;
2746 if (abrupt)
2747 ep->com.state = ABORTING;
2748 else {
2749 ep->com.state = CLOSING;
2750 start_ep_timer(ep);
2751 }
2752 set_bit(CLOSE_SENT, &ep->com.flags);
2753 break;
2754 case CLOSING:
2755 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2756 close = 1;
2757 if (abrupt) {
2758 stop_ep_timer(ep);
2759 ep->com.state = ABORTING;
2760 } else
2761 ep->com.state = MORIBUND;
2762 }
2763 break;
2764 case MORIBUND:
2765 case ABORTING:
2766 case DEAD:
2767 PDBG("%s ignoring disconnect ep %p state %u\n",
2768 __func__, ep, ep->com.state);
2769 break;
2770 default:
2771 BUG();
2772 break;
2773 }
2774
2775 if (close) {
2776 if (abrupt) {
2777 set_bit(EP_DISC_ABORT, &ep->com.history);
2778 close_complete_upcall(ep);
2779 ret = send_abort(ep, NULL, gfp);
2780 } else {
2781 set_bit(EP_DISC_CLOSE, &ep->com.history);
2782 ret = send_halfclose(ep, gfp);
2783 }
2784 if (ret)
2785 fatal = 1;
2786 }
2787 mutex_unlock(&ep->com.mutex);
2788 if (fatal)
2789 release_ep_resources(ep);
2790 return ret;
2791 }
2792
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)
2795 {
2796 struct c4iw_ep *ep;
2797 int atid = be32_to_cpu(req->tid);
2798
2799 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
2800 (__force u32) req->tid);
2801 if (!ep)
2802 return;
2803
2804 switch (req->retval) {
2805 case FW_ENOMEM:
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);
2809 return;
2810 }
2811 case FW_EADDRINUSE:
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);
2815 return;
2816 }
2817 break;
2818 default:
2819 pr_info("%s unexpected ofld conn wr retval %d\n",
2820 __func__, req->retval);
2821 break;
2822 }
2823 pr_err("active ofld_connect_wr failure %d atid %d\n",
2824 req->retval, atid);
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);
2835 }
2836
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)
2839 {
2840 struct sk_buff *rpl_skb;
2841 struct cpl_pass_accept_req *cpl;
2842 int ret;
2843
2844 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
2845 BUG_ON(!rpl_skb);
2846 if (req->retval) {
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);
2851 kfree_skb(rpl_skb);
2852 } else {
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);
2858 if (!ret)
2859 kfree_skb(rpl_skb);
2860 }
2861 return;
2862 }
2863
2864 static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2865 {
2866 struct cpl_fw6_msg *rpl = cplhdr(skb);
2867 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2868
2869 switch (rpl->type) {
2870 case FW6_TYPE_CQE:
2871 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2872 break;
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) {
2876 case TCP_SYN_SENT:
2877 active_ofld_conn_reply(dev, skb, req);
2878 break;
2879 case TCP_SYN_RECV:
2880 passive_ofld_conn_reply(dev, skb, req);
2881 break;
2882 default:
2883 pr_err("%s unexpected ofld conn wr state %d\n",
2884 __func__, req->t_state);
2885 break;
2886 }
2887 break;
2888 }
2889 return 0;
2890 }
2891
2892 static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2893 {
2894 u32 l2info;
2895 u16 vlantag, len, hdr_len, eth_hdr_len;
2896 u8 intf;
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;
2901
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;
2908 intf = cpl->iff;
2909
2910 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2911
2912 /*
2913 * We need to parse the TCP options from SYN packet.
2914 * to generate cpl_pass_accept_req.
2915 */
2916 memset(&tmp_opt, 0, sizeof(tmp_opt));
2917 tcp_clear_options(&tmp_opt);
2918 tcp_parse_options(skb, &tmp_opt, 0, NULL);
2919
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))) |
2925 F_SYN_XACT_MATCH);
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));
2947 return;
2948 }
2949
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)
2955 {
2956 struct sk_buff *req_skb;
2957 struct fw_ofld_connection_wr *req;
2958 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2959
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))));
2978
2979 /*
2980 * We store the qid in opt2 which will be used by the firmware
2981 * to send us the wr response.
2982 */
2983 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2984
2985 /*
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.
2990 */
2991 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2992 req->cookie = (unsigned long)skb;
2993
2994 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2995 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2996 }
2997
2998 /*
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.
3004 */
3005 static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3006 {
3007 int stid;
3008 unsigned int filter;
3009 struct ethhdr *eh = NULL;
3010 struct vlan_ethhdr *vlan_eh = NULL;
3011 struct iphdr *iph;
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;
3018 struct rtable *rt;
3019 struct c4iw_ep *lep;
3020 u16 window;
3021 struct port_info *pi;
3022 struct net_device *pdev;
3023 u16 rss_qid, eth_hdr_len;
3024 int step;
3025 u32 tx_chan;
3026 struct neighbour *neigh;
3027
3028 /* Drop all non-SYN packets */
3029 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3030 goto reject;
3031
3032 /*
3033 * Drop all packets which did not hit the filter.
3034 * Unlikely to happen.
3035 */
3036 if (!(rss->filter_hit && rss->filter_tid))
3037 goto reject;
3038
3039 /*
3040 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3041 */
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;
3045
3046 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3047 if (!lep) {
3048 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3049 goto reject;
3050 }
3051
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);
3058 } else {
3059 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3060 iph = (struct iphdr *)(vlan_eh + 1);
3061 skb->vlan_tci = ntohs(cpl->vlan);
3062 }
3063
3064 if (iph->version != 0x4)
3065 goto reject;
3066
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);
3070 skb_get(skb);
3071
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);
3075
3076 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3077 iph->tos);
3078 if (!rt) {
3079 pr_err("%s - failed to find dst entry!\n",
3080 __func__);
3081 goto reject;
3082 }
3083 dst = &rt->dst;
3084 neigh = dst_neigh_lookup_skb(dst, skb);
3085
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,
3089 pdev, 0);
3090 pi = (struct port_info *)netdev_priv(pdev);
3091 tx_chan = cxgb4_port_chan(pdev);
3092 dev_put(pdev);
3093 } else {
3094 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3095 neigh->dev, 0);
3096 pi = (struct port_info *)netdev_priv(neigh->dev);
3097 tx_chan = cxgb4_port_chan(neigh->dev);
3098 }
3099 if (!e) {
3100 pr_err("%s - failed to allocate l2t entry!\n",
3101 __func__);
3102 goto free_dst;
3103 }
3104
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);
3108
3109 /* Calcuate filter portion for LE region. */
3110 filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
3111
3112 /*
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.
3116 */
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);
3122 free_dst:
3123 dst_release(dst);
3124 reject:
3125 return 0;
3126 }
3127
3128 /*
3129 * These are the real handlers that are called from a
3130 * work queue.
3131 */
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
3149 };
3150
3151 static void process_timeout(struct c4iw_ep *ep)
3152 {
3153 struct c4iw_qp_attributes attrs;
3154 int abort = 1;
3155
3156 mutex_lock(&ep->com.mutex);
3157 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3158 ep->com.state);
3159 set_bit(TIMEDOUT, &ep->com.history);
3160 switch (ep->com.state) {
3161 case MPA_REQ_SENT:
3162 __state_set(&ep->com, ABORTING);
3163 connect_reply_upcall(ep, -ETIMEDOUT);
3164 break;
3165 case MPA_REQ_WAIT:
3166 __state_set(&ep->com, ABORTING);
3167 break;
3168 case CLOSING:
3169 case MORIBUND:
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,
3174 &attrs, 1);
3175 }
3176 __state_set(&ep->com, ABORTING);
3177 break;
3178 default:
3179 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
3180 __func__, ep, ep->hwtid, ep->com.state);
3181 abort = 0;
3182 }
3183 mutex_unlock(&ep->com.mutex);
3184 if (abort)
3185 abort_connection(ep, NULL, GFP_KERNEL);
3186 c4iw_put_ep(&ep->com);
3187 }
3188
3189 static void process_timedout_eps(void)
3190 {
3191 struct c4iw_ep *ep;
3192
3193 spin_lock_irq(&timeout_lock);
3194 while (!list_empty(&timeout_list)) {
3195 struct list_head *tmp;
3196
3197 tmp = timeout_list.next;
3198 list_del(tmp);
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);
3203 }
3204 spin_unlock_irq(&timeout_lock);
3205 }
3206
3207 static void process_work(struct work_struct *work)
3208 {
3209 struct sk_buff *skb = NULL;
3210 struct c4iw_dev *dev;
3211 struct cpl_act_establish *rpl;
3212 unsigned int opcode;
3213 int ret;
3214
3215 while ((skb = skb_dequeue(&rxq))) {
3216 rpl = cplhdr(skb);
3217 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3218 opcode = rpl->ot.opcode;
3219
3220 BUG_ON(!work_handlers[opcode]);
3221 ret = work_handlers[opcode](dev, skb);
3222 if (!ret)
3223 kfree_skb(skb);
3224 }
3225 process_timedout_eps();
3226 }
3227
3228 static DECLARE_WORK(skb_work, process_work);
3229
3230 static void ep_timeout(unsigned long arg)
3231 {
3232 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3233 int kickit = 0;
3234
3235 spin_lock(&timeout_lock);
3236 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3237 list_add_tail(&ep->entry, &timeout_list);
3238 kickit = 1;
3239 }
3240 spin_unlock(&timeout_lock);
3241 if (kickit)
3242 queue_work(workq, &skb_work);
3243 }
3244
3245 /*
3246 * All the CM events are handled on a work queue to have a safe context.
3247 */
3248 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3249 {
3250
3251 /*
3252 * Save dev in the skb->cb area.
3253 */
3254 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3255
3256 /*
3257 * Queue the skb and schedule the worker thread.
3258 */
3259 skb_queue_tail(&rxq, skb);
3260 queue_work(workq, &skb_work);
3261 return 0;
3262 }
3263
3264 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3265 {
3266 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3267
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));
3271 }
3272 kfree_skb(skb);
3273 return 0;
3274 }
3275
3276 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3277 {
3278 struct cpl_fw6_msg *rpl = cplhdr(skb);
3279 struct c4iw_wr_wait *wr_waitp;
3280 int ret;
3281
3282 PDBG("%s type %u\n", __func__, rpl->type);
3283
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);
3289 if (wr_waitp)
3290 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
3291 kfree_skb(skb);
3292 break;
3293 case FW6_TYPE_CQE:
3294 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3295 sched(dev, skb);
3296 break;
3297 default:
3298 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3299 rpl->type);
3300 kfree_skb(skb);
3301 break;
3302 }
3303 return 0;
3304 }
3305
3306 static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3307 {
3308 struct cpl_abort_req_rss *req = cplhdr(skb);
3309 struct c4iw_ep *ep;
3310 struct tid_info *t = dev->rdev.lldi.tids;
3311 unsigned int tid = GET_TID(req);
3312
3313 ep = lookup_tid(t, tid);
3314 if (!ep) {
3315 printk(KERN_WARNING MOD
3316 "Abort on non-existent endpoint, tid %d\n", tid);
3317 kfree_skb(skb);
3318 return 0;
3319 }
3320 if (is_neg_adv_abort(req->status)) {
3321 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3322 ep->hwtid);
3323 kfree_skb(skb);
3324 return 0;
3325 }
3326 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3327 ep->com.state);
3328
3329 /*
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.
3333 */
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);
3337 } else
3338 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3339 sched(dev, skb);
3340 return 0;
3341 }
3342
3343 /*
3344 * Most upcalls from the T4 Core go to sched() to
3345 * schedule the processing on a work queue.
3346 */
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
3365 };
3366
3367 int __init c4iw_cm_init(void)
3368 {
3369 spin_lock_init(&timeout_lock);
3370 skb_queue_head_init(&rxq);
3371
3372 workq = create_singlethread_workqueue("iw_cxgb4");
3373 if (!workq)
3374 return -ENOMEM;
3375
3376 return 0;
3377 }
3378
3379 void __exit c4iw_cm_term(void)
3380 {
3381 WARN_ON(!list_empty(&timeout_list));
3382 flush_workqueue(workq);
3383 destroy_workqueue(workq);
3384 }