]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/infiniband/hw/cxgb4/cm.c
ipv4: Create and use route lookup helpers.
[mirror_ubuntu-jammy-kernel.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
42 #include <net/neighbour.h>
43 #include <net/netevent.h>
44 #include <net/route.h>
45
46 #include "iw_cxgb4.h"
47
48 static char *states[] = {
49 "idle",
50 "listen",
51 "connecting",
52 "mpa_wait_req",
53 "mpa_req_sent",
54 "mpa_req_rcvd",
55 "mpa_rep_sent",
56 "fpdu_mode",
57 "aborting",
58 "closing",
59 "moribund",
60 "dead",
61 NULL,
62 };
63
64 static int dack_mode;
65 module_param(dack_mode, int, 0644);
66 MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=0)");
67
68 int c4iw_max_read_depth = 8;
69 module_param(c4iw_max_read_depth, int, 0644);
70 MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
71
72 static int enable_tcp_timestamps;
73 module_param(enable_tcp_timestamps, int, 0644);
74 MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
75
76 static int enable_tcp_sack;
77 module_param(enable_tcp_sack, int, 0644);
78 MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
79
80 static int enable_tcp_window_scaling = 1;
81 module_param(enable_tcp_window_scaling, int, 0644);
82 MODULE_PARM_DESC(enable_tcp_window_scaling,
83 "Enable tcp window scaling (default=1)");
84
85 int c4iw_debug;
86 module_param(c4iw_debug, int, 0644);
87 MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
88
89 static int peer2peer;
90 module_param(peer2peer, int, 0644);
91 MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
92
93 static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
94 module_param(p2p_type, int, 0644);
95 MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
96 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
97
98 static int ep_timeout_secs = 60;
99 module_param(ep_timeout_secs, int, 0644);
100 MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
101 "in seconds (default=60)");
102
103 static int mpa_rev = 1;
104 module_param(mpa_rev, int, 0644);
105 MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
106 "1 is spec compliant. (default=1)");
107
108 static int markers_enabled;
109 module_param(markers_enabled, int, 0644);
110 MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
111
112 static int crc_enabled = 1;
113 module_param(crc_enabled, int, 0644);
114 MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
115
116 static int rcv_win = 256 * 1024;
117 module_param(rcv_win, int, 0644);
118 MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
119
120 static int snd_win = 128 * 1024;
121 module_param(snd_win, int, 0644);
122 MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
123
124 static struct workqueue_struct *workq;
125
126 static struct sk_buff_head rxq;
127
128 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
129 static void ep_timeout(unsigned long arg);
130 static void connect_reply_upcall(struct c4iw_ep *ep, int status);
131
132 static LIST_HEAD(timeout_list);
133 static spinlock_t timeout_lock;
134
135 static void start_ep_timer(struct c4iw_ep *ep)
136 {
137 PDBG("%s ep %p\n", __func__, ep);
138 if (timer_pending(&ep->timer)) {
139 PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
140 del_timer_sync(&ep->timer);
141 } else
142 c4iw_get_ep(&ep->com);
143 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
144 ep->timer.data = (unsigned long)ep;
145 ep->timer.function = ep_timeout;
146 add_timer(&ep->timer);
147 }
148
149 static void stop_ep_timer(struct c4iw_ep *ep)
150 {
151 PDBG("%s ep %p\n", __func__, ep);
152 if (!timer_pending(&ep->timer)) {
153 printk(KERN_ERR "%s timer stopped when its not running! "
154 "ep %p state %u\n", __func__, ep, ep->com.state);
155 WARN_ON(1);
156 return;
157 }
158 del_timer_sync(&ep->timer);
159 c4iw_put_ep(&ep->com);
160 }
161
162 static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
163 struct l2t_entry *l2e)
164 {
165 int error = 0;
166
167 if (c4iw_fatal_error(rdev)) {
168 kfree_skb(skb);
169 PDBG("%s - device in error state - dropping\n", __func__);
170 return -EIO;
171 }
172 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
173 if (error < 0)
174 kfree_skb(skb);
175 return error < 0 ? error : 0;
176 }
177
178 int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
179 {
180 int error = 0;
181
182 if (c4iw_fatal_error(rdev)) {
183 kfree_skb(skb);
184 PDBG("%s - device in error state - dropping\n", __func__);
185 return -EIO;
186 }
187 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
188 if (error < 0)
189 kfree_skb(skb);
190 return error < 0 ? error : 0;
191 }
192
193 static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
194 {
195 struct cpl_tid_release *req;
196
197 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
198 if (!skb)
199 return;
200 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
201 INIT_TP_WR(req, hwtid);
202 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
203 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
204 c4iw_ofld_send(rdev, skb);
205 return;
206 }
207
208 static void set_emss(struct c4iw_ep *ep, u16 opt)
209 {
210 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
211 ep->mss = ep->emss;
212 if (GET_TCPOPT_TSTAMP(opt))
213 ep->emss -= 12;
214 if (ep->emss < 128)
215 ep->emss = 128;
216 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
217 ep->mss, ep->emss);
218 }
219
220 static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
221 {
222 enum c4iw_ep_state state;
223
224 mutex_lock(&epc->mutex);
225 state = epc->state;
226 mutex_unlock(&epc->mutex);
227 return state;
228 }
229
230 static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
231 {
232 epc->state = new;
233 }
234
235 static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
236 {
237 mutex_lock(&epc->mutex);
238 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
239 __state_set(epc, new);
240 mutex_unlock(&epc->mutex);
241 return;
242 }
243
244 static void *alloc_ep(int size, gfp_t gfp)
245 {
246 struct c4iw_ep_common *epc;
247
248 epc = kzalloc(size, gfp);
249 if (epc) {
250 kref_init(&epc->kref);
251 mutex_init(&epc->mutex);
252 c4iw_init_wr_wait(&epc->wr_wait);
253 }
254 PDBG("%s alloc ep %p\n", __func__, epc);
255 return epc;
256 }
257
258 void _c4iw_free_ep(struct kref *kref)
259 {
260 struct c4iw_ep *ep;
261
262 ep = container_of(kref, struct c4iw_ep, com.kref);
263 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
264 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
265 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
266 dst_release(ep->dst);
267 cxgb4_l2t_release(ep->l2t);
268 }
269 kfree(ep);
270 }
271
272 static void release_ep_resources(struct c4iw_ep *ep)
273 {
274 set_bit(RELEASE_RESOURCES, &ep->com.flags);
275 c4iw_put_ep(&ep->com);
276 }
277
278 static int status2errno(int status)
279 {
280 switch (status) {
281 case CPL_ERR_NONE:
282 return 0;
283 case CPL_ERR_CONN_RESET:
284 return -ECONNRESET;
285 case CPL_ERR_ARP_MISS:
286 return -EHOSTUNREACH;
287 case CPL_ERR_CONN_TIMEDOUT:
288 return -ETIMEDOUT;
289 case CPL_ERR_TCAM_FULL:
290 return -ENOMEM;
291 case CPL_ERR_CONN_EXIST:
292 return -EADDRINUSE;
293 default:
294 return -EIO;
295 }
296 }
297
298 /*
299 * Try and reuse skbs already allocated...
300 */
301 static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
302 {
303 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
304 skb_trim(skb, 0);
305 skb_get(skb);
306 skb_reset_transport_header(skb);
307 } else {
308 skb = alloc_skb(len, gfp);
309 }
310 return skb;
311 }
312
313 static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
314 __be32 peer_ip, __be16 local_port,
315 __be16 peer_port, u8 tos)
316 {
317 struct rtable *rt;
318
319 rt = ip_route_output_ports(&init_net, NULL, peer_ip, local_ip,
320 peer_port, local_port, IPPROTO_TCP,
321 tos, 0);
322 if (IS_ERR(rt))
323 return NULL;
324 return rt;
325 }
326
327 static void arp_failure_discard(void *handle, struct sk_buff *skb)
328 {
329 PDBG("%s c4iw_dev %p\n", __func__, handle);
330 kfree_skb(skb);
331 }
332
333 /*
334 * Handle an ARP failure for an active open.
335 */
336 static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
337 {
338 printk(KERN_ERR MOD "ARP failure duing connect\n");
339 kfree_skb(skb);
340 }
341
342 /*
343 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
344 * and send it along.
345 */
346 static void abort_arp_failure(void *handle, struct sk_buff *skb)
347 {
348 struct c4iw_rdev *rdev = handle;
349 struct cpl_abort_req *req = cplhdr(skb);
350
351 PDBG("%s rdev %p\n", __func__, rdev);
352 req->cmd = CPL_ABORT_NO_RST;
353 c4iw_ofld_send(rdev, skb);
354 }
355
356 static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
357 {
358 unsigned int flowclen = 80;
359 struct fw_flowc_wr *flowc;
360 int i;
361
362 skb = get_skb(skb, flowclen, GFP_KERNEL);
363 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
364
365 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
366 FW_FLOWC_WR_NPARAMS(8));
367 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
368 16)) | FW_WR_FLOWID(ep->hwtid));
369
370 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
371 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
372 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
373 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
374 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
375 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
376 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
377 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
378 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
379 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
380 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
381 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
382 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
383 flowc->mnemval[6].val = cpu_to_be32(snd_win);
384 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
385 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
386 /* Pad WR to 16 byte boundary */
387 flowc->mnemval[8].mnemonic = 0;
388 flowc->mnemval[8].val = 0;
389 for (i = 0; i < 9; i++) {
390 flowc->mnemval[i].r4[0] = 0;
391 flowc->mnemval[i].r4[1] = 0;
392 flowc->mnemval[i].r4[2] = 0;
393 }
394
395 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
396 c4iw_ofld_send(&ep->com.dev->rdev, skb);
397 }
398
399 static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
400 {
401 struct cpl_close_con_req *req;
402 struct sk_buff *skb;
403 int wrlen = roundup(sizeof *req, 16);
404
405 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
406 skb = get_skb(NULL, wrlen, gfp);
407 if (!skb) {
408 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
409 return -ENOMEM;
410 }
411 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
412 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
413 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
414 memset(req, 0, wrlen);
415 INIT_TP_WR(req, ep->hwtid);
416 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
417 ep->hwtid));
418 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
419 }
420
421 static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
422 {
423 struct cpl_abort_req *req;
424 int wrlen = roundup(sizeof *req, 16);
425
426 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
427 skb = get_skb(skb, wrlen, gfp);
428 if (!skb) {
429 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
430 __func__);
431 return -ENOMEM;
432 }
433 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
434 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
435 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
436 memset(req, 0, wrlen);
437 INIT_TP_WR(req, ep->hwtid);
438 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
439 req->cmd = CPL_ABORT_SEND_RST;
440 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
441 }
442
443 static int send_connect(struct c4iw_ep *ep)
444 {
445 struct cpl_act_open_req *req;
446 struct sk_buff *skb;
447 u64 opt0;
448 u32 opt2;
449 unsigned int mtu_idx;
450 int wscale;
451 int wrlen = roundup(sizeof *req, 16);
452
453 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
454
455 skb = get_skb(NULL, wrlen, GFP_KERNEL);
456 if (!skb) {
457 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
458 __func__);
459 return -ENOMEM;
460 }
461 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
462
463 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
464 wscale = compute_wscale(rcv_win);
465 opt0 = KEEP_ALIVE(1) |
466 DELACK(1) |
467 WND_SCALE(wscale) |
468 MSS_IDX(mtu_idx) |
469 L2T_IDX(ep->l2t->idx) |
470 TX_CHAN(ep->tx_chan) |
471 SMAC_SEL(ep->smac_idx) |
472 DSCP(ep->tos) |
473 RCV_BUFSIZ(rcv_win>>10);
474 opt2 = RX_CHANNEL(0) |
475 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
476 if (enable_tcp_timestamps)
477 opt2 |= TSTAMPS_EN(1);
478 if (enable_tcp_sack)
479 opt2 |= SACK_EN(1);
480 if (wscale && enable_tcp_window_scaling)
481 opt2 |= WND_SCALE_EN(1);
482 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
483
484 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
485 INIT_TP_WR(req, 0);
486 OPCODE_TID(req) = cpu_to_be32(
487 MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
488 req->local_port = ep->com.local_addr.sin_port;
489 req->peer_port = ep->com.remote_addr.sin_port;
490 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
491 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
492 req->opt0 = cpu_to_be64(opt0);
493 req->params = 0;
494 req->opt2 = cpu_to_be32(opt2);
495 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
496 }
497
498 static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb)
499 {
500 int mpalen, wrlen;
501 struct fw_ofld_tx_data_wr *req;
502 struct mpa_message *mpa;
503
504 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
505
506 BUG_ON(skb_cloned(skb));
507
508 mpalen = sizeof(*mpa) + ep->plen;
509 wrlen = roundup(mpalen + sizeof *req, 16);
510 skb = get_skb(skb, wrlen, GFP_KERNEL);
511 if (!skb) {
512 connect_reply_upcall(ep, -ENOMEM);
513 return;
514 }
515 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
516
517 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
518 memset(req, 0, wrlen);
519 req->op_to_immdlen = cpu_to_be32(
520 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
521 FW_WR_COMPL(1) |
522 FW_WR_IMMDLEN(mpalen));
523 req->flowid_len16 = cpu_to_be32(
524 FW_WR_FLOWID(ep->hwtid) |
525 FW_WR_LEN16(wrlen >> 4));
526 req->plen = cpu_to_be32(mpalen);
527 req->tunnel_to_proxy = cpu_to_be32(
528 FW_OFLD_TX_DATA_WR_FLUSH(1) |
529 FW_OFLD_TX_DATA_WR_SHOVE(1));
530
531 mpa = (struct mpa_message *)(req + 1);
532 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
533 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
534 (markers_enabled ? MPA_MARKERS : 0);
535 mpa->private_data_size = htons(ep->plen);
536 mpa->revision = mpa_rev;
537
538 if (ep->plen)
539 memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
540
541 /*
542 * Reference the mpa skb. This ensures the data area
543 * will remain in memory until the hw acks the tx.
544 * Function fw4_ack() will deref it.
545 */
546 skb_get(skb);
547 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
548 BUG_ON(ep->mpa_skb);
549 ep->mpa_skb = skb;
550 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
551 start_ep_timer(ep);
552 state_set(&ep->com, MPA_REQ_SENT);
553 ep->mpa_attr.initiator = 1;
554 return;
555 }
556
557 static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
558 {
559 int mpalen, wrlen;
560 struct fw_ofld_tx_data_wr *req;
561 struct mpa_message *mpa;
562 struct sk_buff *skb;
563
564 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
565
566 mpalen = sizeof(*mpa) + plen;
567 wrlen = roundup(mpalen + sizeof *req, 16);
568
569 skb = get_skb(NULL, wrlen, GFP_KERNEL);
570 if (!skb) {
571 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
572 return -ENOMEM;
573 }
574 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
575
576 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
577 memset(req, 0, wrlen);
578 req->op_to_immdlen = cpu_to_be32(
579 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
580 FW_WR_COMPL(1) |
581 FW_WR_IMMDLEN(mpalen));
582 req->flowid_len16 = cpu_to_be32(
583 FW_WR_FLOWID(ep->hwtid) |
584 FW_WR_LEN16(wrlen >> 4));
585 req->plen = cpu_to_be32(mpalen);
586 req->tunnel_to_proxy = cpu_to_be32(
587 FW_OFLD_TX_DATA_WR_FLUSH(1) |
588 FW_OFLD_TX_DATA_WR_SHOVE(1));
589
590 mpa = (struct mpa_message *)(req + 1);
591 memset(mpa, 0, sizeof(*mpa));
592 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
593 mpa->flags = MPA_REJECT;
594 mpa->revision = mpa_rev;
595 mpa->private_data_size = htons(plen);
596 if (plen)
597 memcpy(mpa->private_data, pdata, plen);
598
599 /*
600 * Reference the mpa skb again. This ensures the data area
601 * will remain in memory until the hw acks the tx.
602 * Function fw4_ack() will deref it.
603 */
604 skb_get(skb);
605 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
606 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
607 BUG_ON(ep->mpa_skb);
608 ep->mpa_skb = skb;
609 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
610 }
611
612 static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
613 {
614 int mpalen, wrlen;
615 struct fw_ofld_tx_data_wr *req;
616 struct mpa_message *mpa;
617 struct sk_buff *skb;
618
619 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
620
621 mpalen = sizeof(*mpa) + plen;
622 wrlen = roundup(mpalen + sizeof *req, 16);
623
624 skb = get_skb(NULL, wrlen, GFP_KERNEL);
625 if (!skb) {
626 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
627 return -ENOMEM;
628 }
629 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
630
631 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
632 memset(req, 0, wrlen);
633 req->op_to_immdlen = cpu_to_be32(
634 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
635 FW_WR_COMPL(1) |
636 FW_WR_IMMDLEN(mpalen));
637 req->flowid_len16 = cpu_to_be32(
638 FW_WR_FLOWID(ep->hwtid) |
639 FW_WR_LEN16(wrlen >> 4));
640 req->plen = cpu_to_be32(mpalen);
641 req->tunnel_to_proxy = cpu_to_be32(
642 FW_OFLD_TX_DATA_WR_FLUSH(1) |
643 FW_OFLD_TX_DATA_WR_SHOVE(1));
644
645 mpa = (struct mpa_message *)(req + 1);
646 memset(mpa, 0, sizeof(*mpa));
647 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
648 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
649 (markers_enabled ? MPA_MARKERS : 0);
650 mpa->revision = mpa_rev;
651 mpa->private_data_size = htons(plen);
652 if (plen)
653 memcpy(mpa->private_data, pdata, plen);
654
655 /*
656 * Reference the mpa skb. This ensures the data area
657 * will remain in memory until the hw acks the tx.
658 * Function fw4_ack() will deref it.
659 */
660 skb_get(skb);
661 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
662 ep->mpa_skb = skb;
663 state_set(&ep->com, MPA_REP_SENT);
664 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
665 }
666
667 static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
668 {
669 struct c4iw_ep *ep;
670 struct cpl_act_establish *req = cplhdr(skb);
671 unsigned int tid = GET_TID(req);
672 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
673 struct tid_info *t = dev->rdev.lldi.tids;
674
675 ep = lookup_atid(t, atid);
676
677 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
678 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
679
680 dst_confirm(ep->dst);
681
682 /* setup the hwtid for this connection */
683 ep->hwtid = tid;
684 cxgb4_insert_tid(t, ep, tid);
685
686 ep->snd_seq = be32_to_cpu(req->snd_isn);
687 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
688
689 set_emss(ep, ntohs(req->tcp_opt));
690
691 /* dealloc the atid */
692 cxgb4_free_atid(t, atid);
693
694 /* start MPA negotiation */
695 send_flowc(ep, NULL);
696 send_mpa_req(ep, skb);
697
698 return 0;
699 }
700
701 static void close_complete_upcall(struct c4iw_ep *ep)
702 {
703 struct iw_cm_event event;
704
705 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
706 memset(&event, 0, sizeof(event));
707 event.event = IW_CM_EVENT_CLOSE;
708 if (ep->com.cm_id) {
709 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
710 ep, ep->com.cm_id, ep->hwtid);
711 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
712 ep->com.cm_id->rem_ref(ep->com.cm_id);
713 ep->com.cm_id = NULL;
714 ep->com.qp = NULL;
715 }
716 }
717
718 static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
719 {
720 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
721 close_complete_upcall(ep);
722 state_set(&ep->com, ABORTING);
723 return send_abort(ep, skb, gfp);
724 }
725
726 static void peer_close_upcall(struct c4iw_ep *ep)
727 {
728 struct iw_cm_event event;
729
730 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
731 memset(&event, 0, sizeof(event));
732 event.event = IW_CM_EVENT_DISCONNECT;
733 if (ep->com.cm_id) {
734 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
735 ep, ep->com.cm_id, ep->hwtid);
736 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
737 }
738 }
739
740 static void peer_abort_upcall(struct c4iw_ep *ep)
741 {
742 struct iw_cm_event event;
743
744 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
745 memset(&event, 0, sizeof(event));
746 event.event = IW_CM_EVENT_CLOSE;
747 event.status = -ECONNRESET;
748 if (ep->com.cm_id) {
749 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
750 ep->com.cm_id, ep->hwtid);
751 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
752 ep->com.cm_id->rem_ref(ep->com.cm_id);
753 ep->com.cm_id = NULL;
754 ep->com.qp = NULL;
755 }
756 }
757
758 static void connect_reply_upcall(struct c4iw_ep *ep, int status)
759 {
760 struct iw_cm_event event;
761
762 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
763 memset(&event, 0, sizeof(event));
764 event.event = IW_CM_EVENT_CONNECT_REPLY;
765 event.status = status;
766 event.local_addr = ep->com.local_addr;
767 event.remote_addr = ep->com.remote_addr;
768
769 if ((status == 0) || (status == -ECONNREFUSED)) {
770 event.private_data_len = ep->plen;
771 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
772 }
773
774 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
775 ep->hwtid, status);
776 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
777
778 if (status < 0) {
779 ep->com.cm_id->rem_ref(ep->com.cm_id);
780 ep->com.cm_id = NULL;
781 ep->com.qp = NULL;
782 }
783 }
784
785 static void connect_request_upcall(struct c4iw_ep *ep)
786 {
787 struct iw_cm_event event;
788
789 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
790 memset(&event, 0, sizeof(event));
791 event.event = IW_CM_EVENT_CONNECT_REQUEST;
792 event.local_addr = ep->com.local_addr;
793 event.remote_addr = ep->com.remote_addr;
794 event.private_data_len = ep->plen;
795 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
796 event.provider_data = ep;
797 if (state_read(&ep->parent_ep->com) != DEAD) {
798 c4iw_get_ep(&ep->com);
799 ep->parent_ep->com.cm_id->event_handler(
800 ep->parent_ep->com.cm_id,
801 &event);
802 }
803 c4iw_put_ep(&ep->parent_ep->com);
804 ep->parent_ep = NULL;
805 }
806
807 static void established_upcall(struct c4iw_ep *ep)
808 {
809 struct iw_cm_event event;
810
811 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
812 memset(&event, 0, sizeof(event));
813 event.event = IW_CM_EVENT_ESTABLISHED;
814 if (ep->com.cm_id) {
815 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
816 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
817 }
818 }
819
820 static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
821 {
822 struct cpl_rx_data_ack *req;
823 struct sk_buff *skb;
824 int wrlen = roundup(sizeof *req, 16);
825
826 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
827 skb = get_skb(NULL, wrlen, GFP_KERNEL);
828 if (!skb) {
829 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
830 return 0;
831 }
832
833 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
834 memset(req, 0, wrlen);
835 INIT_TP_WR(req, ep->hwtid);
836 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
837 ep->hwtid));
838 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
839 F_RX_DACK_CHANGE |
840 V_RX_DACK_MODE(dack_mode));
841 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
842 c4iw_ofld_send(&ep->com.dev->rdev, skb);
843 return credits;
844 }
845
846 static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
847 {
848 struct mpa_message *mpa;
849 u16 plen;
850 struct c4iw_qp_attributes attrs;
851 enum c4iw_qp_attr_mask mask;
852 int err;
853
854 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
855
856 /*
857 * Stop mpa timer. If it expired, then the state has
858 * changed and we bail since ep_timeout already aborted
859 * the connection.
860 */
861 stop_ep_timer(ep);
862 if (state_read(&ep->com) != MPA_REQ_SENT)
863 return;
864
865 /*
866 * If we get more than the supported amount of private data
867 * then we must fail this connection.
868 */
869 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
870 err = -EINVAL;
871 goto err;
872 }
873
874 /*
875 * copy the new data into our accumulation buffer.
876 */
877 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
878 skb->len);
879 ep->mpa_pkt_len += skb->len;
880
881 /*
882 * if we don't even have the mpa message, then bail.
883 */
884 if (ep->mpa_pkt_len < sizeof(*mpa))
885 return;
886 mpa = (struct mpa_message *) ep->mpa_pkt;
887
888 /* Validate MPA header. */
889 if (mpa->revision != mpa_rev) {
890 err = -EPROTO;
891 goto err;
892 }
893 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
894 err = -EPROTO;
895 goto err;
896 }
897
898 plen = ntohs(mpa->private_data_size);
899
900 /*
901 * Fail if there's too much private data.
902 */
903 if (plen > MPA_MAX_PRIVATE_DATA) {
904 err = -EPROTO;
905 goto err;
906 }
907
908 /*
909 * If plen does not account for pkt size
910 */
911 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
912 err = -EPROTO;
913 goto err;
914 }
915
916 ep->plen = (u8) plen;
917
918 /*
919 * If we don't have all the pdata yet, then bail.
920 * We'll continue process when more data arrives.
921 */
922 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
923 return;
924
925 if (mpa->flags & MPA_REJECT) {
926 err = -ECONNREFUSED;
927 goto err;
928 }
929
930 /*
931 * If we get here we have accumulated the entire mpa
932 * start reply message including private data. And
933 * the MPA header is valid.
934 */
935 state_set(&ep->com, FPDU_MODE);
936 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
937 ep->mpa_attr.recv_marker_enabled = markers_enabled;
938 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
939 ep->mpa_attr.version = mpa_rev;
940 ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
941 FW_RI_INIT_P2PTYPE_DISABLED;
942 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
943 "xmit_marker_enabled=%d, version=%d\n", __func__,
944 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
945 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
946
947 attrs.mpa_attr = ep->mpa_attr;
948 attrs.max_ird = ep->ird;
949 attrs.max_ord = ep->ord;
950 attrs.llp_stream_handle = ep;
951 attrs.next_state = C4IW_QP_STATE_RTS;
952
953 mask = C4IW_QP_ATTR_NEXT_STATE |
954 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
955 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
956
957 /* bind QP and TID with INIT_WR */
958 err = c4iw_modify_qp(ep->com.qp->rhp,
959 ep->com.qp, mask, &attrs, 1);
960 if (err)
961 goto err;
962 goto out;
963 err:
964 state_set(&ep->com, ABORTING);
965 send_abort(ep, skb, GFP_KERNEL);
966 out:
967 connect_reply_upcall(ep, err);
968 return;
969 }
970
971 static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
972 {
973 struct mpa_message *mpa;
974 u16 plen;
975
976 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
977
978 if (state_read(&ep->com) != MPA_REQ_WAIT)
979 return;
980
981 /*
982 * If we get more than the supported amount of private data
983 * then we must fail this connection.
984 */
985 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
986 stop_ep_timer(ep);
987 abort_connection(ep, skb, GFP_KERNEL);
988 return;
989 }
990
991 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
992
993 /*
994 * Copy the new data into our accumulation buffer.
995 */
996 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
997 skb->len);
998 ep->mpa_pkt_len += skb->len;
999
1000 /*
1001 * If we don't even have the mpa message, then bail.
1002 * We'll continue process when more data arrives.
1003 */
1004 if (ep->mpa_pkt_len < sizeof(*mpa))
1005 return;
1006
1007 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1008 stop_ep_timer(ep);
1009 mpa = (struct mpa_message *) ep->mpa_pkt;
1010
1011 /*
1012 * Validate MPA Header.
1013 */
1014 if (mpa->revision != mpa_rev) {
1015 abort_connection(ep, skb, GFP_KERNEL);
1016 return;
1017 }
1018
1019 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1020 abort_connection(ep, skb, GFP_KERNEL);
1021 return;
1022 }
1023
1024 plen = ntohs(mpa->private_data_size);
1025
1026 /*
1027 * Fail if there's too much private data.
1028 */
1029 if (plen > MPA_MAX_PRIVATE_DATA) {
1030 abort_connection(ep, skb, GFP_KERNEL);
1031 return;
1032 }
1033
1034 /*
1035 * If plen does not account for pkt size
1036 */
1037 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1038 abort_connection(ep, skb, GFP_KERNEL);
1039 return;
1040 }
1041 ep->plen = (u8) plen;
1042
1043 /*
1044 * If we don't have all the pdata yet, then bail.
1045 */
1046 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1047 return;
1048
1049 /*
1050 * If we get here we have accumulated the entire mpa
1051 * start reply message including private data.
1052 */
1053 ep->mpa_attr.initiator = 0;
1054 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1055 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1056 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1057 ep->mpa_attr.version = mpa_rev;
1058 ep->mpa_attr.p2p_type = peer2peer ? p2p_type :
1059 FW_RI_INIT_P2PTYPE_DISABLED;
1060 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1061 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1062 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1063 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1064 ep->mpa_attr.p2p_type);
1065
1066 state_set(&ep->com, MPA_REQ_RCVD);
1067
1068 /* drive upcall */
1069 connect_request_upcall(ep);
1070 return;
1071 }
1072
1073 static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1074 {
1075 struct c4iw_ep *ep;
1076 struct cpl_rx_data *hdr = cplhdr(skb);
1077 unsigned int dlen = ntohs(hdr->len);
1078 unsigned int tid = GET_TID(hdr);
1079 struct tid_info *t = dev->rdev.lldi.tids;
1080
1081 ep = lookup_tid(t, tid);
1082 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1083 skb_pull(skb, sizeof(*hdr));
1084 skb_trim(skb, dlen);
1085
1086 ep->rcv_seq += dlen;
1087 BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
1088
1089 /* update RX credits */
1090 update_rx_credits(ep, dlen);
1091
1092 switch (state_read(&ep->com)) {
1093 case MPA_REQ_SENT:
1094 process_mpa_reply(ep, skb);
1095 break;
1096 case MPA_REQ_WAIT:
1097 process_mpa_request(ep, skb);
1098 break;
1099 case MPA_REP_SENT:
1100 break;
1101 default:
1102 printk(KERN_ERR MOD "%s Unexpected streaming data."
1103 " ep %p state %d tid %u\n",
1104 __func__, ep, state_read(&ep->com), ep->hwtid);
1105
1106 /*
1107 * The ep will timeout and inform the ULP of the failure.
1108 * See ep_timeout().
1109 */
1110 break;
1111 }
1112 return 0;
1113 }
1114
1115 static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1116 {
1117 struct c4iw_ep *ep;
1118 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
1119 int release = 0;
1120 unsigned int tid = GET_TID(rpl);
1121 struct tid_info *t = dev->rdev.lldi.tids;
1122
1123 ep = lookup_tid(t, tid);
1124 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1125 BUG_ON(!ep);
1126 mutex_lock(&ep->com.mutex);
1127 switch (ep->com.state) {
1128 case ABORTING:
1129 __state_set(&ep->com, DEAD);
1130 release = 1;
1131 break;
1132 default:
1133 printk(KERN_ERR "%s ep %p state %d\n",
1134 __func__, ep, ep->com.state);
1135 break;
1136 }
1137 mutex_unlock(&ep->com.mutex);
1138
1139 if (release)
1140 release_ep_resources(ep);
1141 return 0;
1142 }
1143
1144 /*
1145 * Return whether a failed active open has allocated a TID
1146 */
1147 static inline int act_open_has_tid(int status)
1148 {
1149 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1150 status != CPL_ERR_ARP_MISS;
1151 }
1152
1153 static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1154 {
1155 struct c4iw_ep *ep;
1156 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1157 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1158 ntohl(rpl->atid_status)));
1159 struct tid_info *t = dev->rdev.lldi.tids;
1160 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1161
1162 ep = lookup_atid(t, atid);
1163
1164 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1165 status, status2errno(status));
1166
1167 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1168 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1169 atid);
1170 return 0;
1171 }
1172
1173 connect_reply_upcall(ep, status2errno(status));
1174 state_set(&ep->com, DEAD);
1175
1176 if (status && act_open_has_tid(status))
1177 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1178
1179 cxgb4_free_atid(t, atid);
1180 dst_release(ep->dst);
1181 cxgb4_l2t_release(ep->l2t);
1182 c4iw_put_ep(&ep->com);
1183
1184 return 0;
1185 }
1186
1187 static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1188 {
1189 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1190 struct tid_info *t = dev->rdev.lldi.tids;
1191 unsigned int stid = GET_TID(rpl);
1192 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1193
1194 if (!ep) {
1195 printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
1196 return 0;
1197 }
1198 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1199 rpl->status, status2errno(rpl->status));
1200 ep->com.wr_wait.ret = status2errno(rpl->status);
1201 ep->com.wr_wait.done = 1;
1202 wake_up(&ep->com.wr_wait.wait);
1203
1204 return 0;
1205 }
1206
1207 static int listen_stop(struct c4iw_listen_ep *ep)
1208 {
1209 struct sk_buff *skb;
1210 struct cpl_close_listsvr_req *req;
1211
1212 PDBG("%s ep %p\n", __func__, ep);
1213 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1214 if (!skb) {
1215 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1216 return -ENOMEM;
1217 }
1218 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1219 INIT_TP_WR(req, 0);
1220 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1221 ep->stid));
1222 req->reply_ctrl = cpu_to_be16(
1223 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1224 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1225 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1226 }
1227
1228 static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1229 {
1230 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1231 struct tid_info *t = dev->rdev.lldi.tids;
1232 unsigned int stid = GET_TID(rpl);
1233 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1234
1235 PDBG("%s ep %p\n", __func__, ep);
1236 ep->com.wr_wait.ret = status2errno(rpl->status);
1237 ep->com.wr_wait.done = 1;
1238 wake_up(&ep->com.wr_wait.wait);
1239 return 0;
1240 }
1241
1242 static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1243 struct cpl_pass_accept_req *req)
1244 {
1245 struct cpl_pass_accept_rpl *rpl;
1246 unsigned int mtu_idx;
1247 u64 opt0;
1248 u32 opt2;
1249 int wscale;
1250
1251 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1252 BUG_ON(skb_cloned(skb));
1253 skb_trim(skb, sizeof(*rpl));
1254 skb_get(skb);
1255 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1256 wscale = compute_wscale(rcv_win);
1257 opt0 = KEEP_ALIVE(1) |
1258 DELACK(1) |
1259 WND_SCALE(wscale) |
1260 MSS_IDX(mtu_idx) |
1261 L2T_IDX(ep->l2t->idx) |
1262 TX_CHAN(ep->tx_chan) |
1263 SMAC_SEL(ep->smac_idx) |
1264 DSCP(ep->tos) |
1265 RCV_BUFSIZ(rcv_win>>10);
1266 opt2 = RX_CHANNEL(0) |
1267 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1268
1269 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1270 opt2 |= TSTAMPS_EN(1);
1271 if (enable_tcp_sack && req->tcpopt.sack)
1272 opt2 |= SACK_EN(1);
1273 if (wscale && enable_tcp_window_scaling)
1274 opt2 |= WND_SCALE_EN(1);
1275
1276 rpl = cplhdr(skb);
1277 INIT_TP_WR(rpl, ep->hwtid);
1278 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1279 ep->hwtid));
1280 rpl->opt0 = cpu_to_be64(opt0);
1281 rpl->opt2 = cpu_to_be32(opt2);
1282 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
1283 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1284
1285 return;
1286 }
1287
1288 static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1289 struct sk_buff *skb)
1290 {
1291 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1292 peer_ip);
1293 BUG_ON(skb_cloned(skb));
1294 skb_trim(skb, sizeof(struct cpl_tid_release));
1295 skb_get(skb);
1296 release_tid(&dev->rdev, hwtid, skb);
1297 return;
1298 }
1299
1300 static void get_4tuple(struct cpl_pass_accept_req *req,
1301 __be32 *local_ip, __be32 *peer_ip,
1302 __be16 *local_port, __be16 *peer_port)
1303 {
1304 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1305 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1306 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1307 struct tcphdr *tcp = (struct tcphdr *)
1308 ((u8 *)(req + 1) + eth_len + ip_len);
1309
1310 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1311 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1312 ntohs(tcp->dest));
1313
1314 *peer_ip = ip->saddr;
1315 *local_ip = ip->daddr;
1316 *peer_port = tcp->source;
1317 *local_port = tcp->dest;
1318
1319 return;
1320 }
1321
1322 static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1323 {
1324 struct c4iw_ep *child_ep, *parent_ep;
1325 struct cpl_pass_accept_req *req = cplhdr(skb);
1326 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1327 struct tid_info *t = dev->rdev.lldi.tids;
1328 unsigned int hwtid = GET_TID(req);
1329 struct dst_entry *dst;
1330 struct l2t_entry *l2t;
1331 struct rtable *rt;
1332 __be32 local_ip, peer_ip;
1333 __be16 local_port, peer_port;
1334 struct net_device *pdev;
1335 u32 tx_chan, smac_idx;
1336 u16 rss_qid;
1337 u32 mtu;
1338 int step;
1339 int txq_idx, ctrlq_idx;
1340
1341 parent_ep = lookup_stid(t, stid);
1342 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
1343
1344 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1345
1346 if (state_read(&parent_ep->com) != LISTEN) {
1347 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1348 __func__);
1349 goto reject;
1350 }
1351
1352 /* Find output route */
1353 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1354 GET_POPEN_TOS(ntohl(req->tos_stid)));
1355 if (!rt) {
1356 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1357 __func__);
1358 goto reject;
1359 }
1360 dst = &rt->dst;
1361 if (dst->neighbour->dev->flags & IFF_LOOPBACK) {
1362 pdev = ip_dev_find(&init_net, peer_ip);
1363 BUG_ON(!pdev);
1364 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
1365 pdev, 0);
1366 mtu = pdev->mtu;
1367 tx_chan = cxgb4_port_chan(pdev);
1368 smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1369 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
1370 txq_idx = cxgb4_port_idx(pdev) * step;
1371 ctrlq_idx = cxgb4_port_idx(pdev);
1372 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1373 rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
1374 dev_put(pdev);
1375 } else {
1376 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, dst->neighbour,
1377 dst->neighbour->dev, 0);
1378 mtu = dst_mtu(dst);
1379 tx_chan = cxgb4_port_chan(dst->neighbour->dev);
1380 smac_idx = (cxgb4_port_viid(dst->neighbour->dev) & 0x7F) << 1;
1381 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
1382 txq_idx = cxgb4_port_idx(dst->neighbour->dev) * step;
1383 ctrlq_idx = cxgb4_port_idx(dst->neighbour->dev);
1384 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1385 rss_qid = dev->rdev.lldi.rxq_ids[
1386 cxgb4_port_idx(dst->neighbour->dev) * step];
1387 }
1388 if (!l2t) {
1389 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1390 __func__);
1391 dst_release(dst);
1392 goto reject;
1393 }
1394
1395 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1396 if (!child_ep) {
1397 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1398 __func__);
1399 cxgb4_l2t_release(l2t);
1400 dst_release(dst);
1401 goto reject;
1402 }
1403 state_set(&child_ep->com, CONNECTING);
1404 child_ep->com.dev = dev;
1405 child_ep->com.cm_id = NULL;
1406 child_ep->com.local_addr.sin_family = PF_INET;
1407 child_ep->com.local_addr.sin_port = local_port;
1408 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1409 child_ep->com.remote_addr.sin_family = PF_INET;
1410 child_ep->com.remote_addr.sin_port = peer_port;
1411 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1412 c4iw_get_ep(&parent_ep->com);
1413 child_ep->parent_ep = parent_ep;
1414 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
1415 child_ep->l2t = l2t;
1416 child_ep->dst = dst;
1417 child_ep->hwtid = hwtid;
1418 child_ep->tx_chan = tx_chan;
1419 child_ep->smac_idx = smac_idx;
1420 child_ep->rss_qid = rss_qid;
1421 child_ep->mtu = mtu;
1422 child_ep->txq_idx = txq_idx;
1423 child_ep->ctrlq_idx = ctrlq_idx;
1424
1425 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
1426 tx_chan, smac_idx, rss_qid);
1427
1428 init_timer(&child_ep->timer);
1429 cxgb4_insert_tid(t, child_ep, hwtid);
1430 accept_cr(child_ep, peer_ip, skb, req);
1431 goto out;
1432 reject:
1433 reject_cr(dev, hwtid, peer_ip, skb);
1434 out:
1435 return 0;
1436 }
1437
1438 static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1439 {
1440 struct c4iw_ep *ep;
1441 struct cpl_pass_establish *req = cplhdr(skb);
1442 struct tid_info *t = dev->rdev.lldi.tids;
1443 unsigned int tid = GET_TID(req);
1444
1445 ep = lookup_tid(t, tid);
1446 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1447 ep->snd_seq = be32_to_cpu(req->snd_isn);
1448 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1449
1450 set_emss(ep, ntohs(req->tcp_opt));
1451
1452 dst_confirm(ep->dst);
1453 state_set(&ep->com, MPA_REQ_WAIT);
1454 start_ep_timer(ep);
1455 send_flowc(ep, skb);
1456
1457 return 0;
1458 }
1459
1460 static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
1461 {
1462 struct cpl_peer_close *hdr = cplhdr(skb);
1463 struct c4iw_ep *ep;
1464 struct c4iw_qp_attributes attrs;
1465 int disconnect = 1;
1466 int release = 0;
1467 int closing = 0;
1468 struct tid_info *t = dev->rdev.lldi.tids;
1469 unsigned int tid = GET_TID(hdr);
1470
1471 ep = lookup_tid(t, tid);
1472 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1473 dst_confirm(ep->dst);
1474
1475 mutex_lock(&ep->com.mutex);
1476 switch (ep->com.state) {
1477 case MPA_REQ_WAIT:
1478 __state_set(&ep->com, CLOSING);
1479 break;
1480 case MPA_REQ_SENT:
1481 __state_set(&ep->com, CLOSING);
1482 connect_reply_upcall(ep, -ECONNRESET);
1483 break;
1484 case MPA_REQ_RCVD:
1485
1486 /*
1487 * We're gonna mark this puppy DEAD, but keep
1488 * the reference on it until the ULP accepts or
1489 * rejects the CR. Also wake up anyone waiting
1490 * in rdma connection migration (see c4iw_accept_cr()).
1491 */
1492 __state_set(&ep->com, CLOSING);
1493 ep->com.wr_wait.done = 1;
1494 ep->com.wr_wait.ret = -ECONNRESET;
1495 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
1496 wake_up(&ep->com.wr_wait.wait);
1497 break;
1498 case MPA_REP_SENT:
1499 __state_set(&ep->com, CLOSING);
1500 ep->com.wr_wait.done = 1;
1501 ep->com.wr_wait.ret = -ECONNRESET;
1502 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
1503 wake_up(&ep->com.wr_wait.wait);
1504 break;
1505 case FPDU_MODE:
1506 start_ep_timer(ep);
1507 __state_set(&ep->com, CLOSING);
1508 closing = 1;
1509 peer_close_upcall(ep);
1510 break;
1511 case ABORTING:
1512 disconnect = 0;
1513 break;
1514 case CLOSING:
1515 __state_set(&ep->com, MORIBUND);
1516 disconnect = 0;
1517 break;
1518 case MORIBUND:
1519 stop_ep_timer(ep);
1520 if (ep->com.cm_id && ep->com.qp) {
1521 attrs.next_state = C4IW_QP_STATE_IDLE;
1522 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1523 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1524 }
1525 close_complete_upcall(ep);
1526 __state_set(&ep->com, DEAD);
1527 release = 1;
1528 disconnect = 0;
1529 break;
1530 case DEAD:
1531 disconnect = 0;
1532 break;
1533 default:
1534 BUG_ON(1);
1535 }
1536 mutex_unlock(&ep->com.mutex);
1537 if (closing) {
1538 attrs.next_state = C4IW_QP_STATE_CLOSING;
1539 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1540 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1541 }
1542 if (disconnect)
1543 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1544 if (release)
1545 release_ep_resources(ep);
1546 return 0;
1547 }
1548
1549 /*
1550 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1551 */
1552 static int is_neg_adv_abort(unsigned int status)
1553 {
1554 return status == CPL_ERR_RTX_NEG_ADVICE ||
1555 status == CPL_ERR_PERSIST_NEG_ADVICE;
1556 }
1557
1558 static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
1559 {
1560 struct cpl_abort_req_rss *req = cplhdr(skb);
1561 struct c4iw_ep *ep;
1562 struct cpl_abort_rpl *rpl;
1563 struct sk_buff *rpl_skb;
1564 struct c4iw_qp_attributes attrs;
1565 int ret;
1566 int release = 0;
1567 struct tid_info *t = dev->rdev.lldi.tids;
1568 unsigned int tid = GET_TID(req);
1569
1570 ep = lookup_tid(t, tid);
1571 if (is_neg_adv_abort(req->status)) {
1572 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
1573 ep->hwtid);
1574 return 0;
1575 }
1576 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
1577 ep->com.state);
1578
1579 /*
1580 * Wake up any threads in rdma_init() or rdma_fini().
1581 */
1582 ep->com.wr_wait.done = 1;
1583 ep->com.wr_wait.ret = -ECONNRESET;
1584 wake_up(&ep->com.wr_wait.wait);
1585
1586 mutex_lock(&ep->com.mutex);
1587 switch (ep->com.state) {
1588 case CONNECTING:
1589 break;
1590 case MPA_REQ_WAIT:
1591 stop_ep_timer(ep);
1592 break;
1593 case MPA_REQ_SENT:
1594 stop_ep_timer(ep);
1595 connect_reply_upcall(ep, -ECONNRESET);
1596 break;
1597 case MPA_REP_SENT:
1598 break;
1599 case MPA_REQ_RCVD:
1600 break;
1601 case MORIBUND:
1602 case CLOSING:
1603 stop_ep_timer(ep);
1604 /*FALLTHROUGH*/
1605 case FPDU_MODE:
1606 if (ep->com.cm_id && ep->com.qp) {
1607 attrs.next_state = C4IW_QP_STATE_ERROR;
1608 ret = c4iw_modify_qp(ep->com.qp->rhp,
1609 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
1610 &attrs, 1);
1611 if (ret)
1612 printk(KERN_ERR MOD
1613 "%s - qp <- error failed!\n",
1614 __func__);
1615 }
1616 peer_abort_upcall(ep);
1617 break;
1618 case ABORTING:
1619 break;
1620 case DEAD:
1621 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
1622 mutex_unlock(&ep->com.mutex);
1623 return 0;
1624 default:
1625 BUG_ON(1);
1626 break;
1627 }
1628 dst_confirm(ep->dst);
1629 if (ep->com.state != ABORTING) {
1630 __state_set(&ep->com, DEAD);
1631 release = 1;
1632 }
1633 mutex_unlock(&ep->com.mutex);
1634
1635 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
1636 if (!rpl_skb) {
1637 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
1638 __func__);
1639 release = 1;
1640 goto out;
1641 }
1642 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1643 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
1644 INIT_TP_WR(rpl, ep->hwtid);
1645 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
1646 rpl->cmd = CPL_ABORT_NO_RST;
1647 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
1648 out:
1649 if (release)
1650 release_ep_resources(ep);
1651 return 0;
1652 }
1653
1654 static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1655 {
1656 struct c4iw_ep *ep;
1657 struct c4iw_qp_attributes attrs;
1658 struct cpl_close_con_rpl *rpl = cplhdr(skb);
1659 int release = 0;
1660 struct tid_info *t = dev->rdev.lldi.tids;
1661 unsigned int tid = GET_TID(rpl);
1662
1663 ep = lookup_tid(t, tid);
1664
1665 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1666 BUG_ON(!ep);
1667
1668 /* The cm_id may be null if we failed to connect */
1669 mutex_lock(&ep->com.mutex);
1670 switch (ep->com.state) {
1671 case CLOSING:
1672 __state_set(&ep->com, MORIBUND);
1673 break;
1674 case MORIBUND:
1675 stop_ep_timer(ep);
1676 if ((ep->com.cm_id) && (ep->com.qp)) {
1677 attrs.next_state = C4IW_QP_STATE_IDLE;
1678 c4iw_modify_qp(ep->com.qp->rhp,
1679 ep->com.qp,
1680 C4IW_QP_ATTR_NEXT_STATE,
1681 &attrs, 1);
1682 }
1683 close_complete_upcall(ep);
1684 __state_set(&ep->com, DEAD);
1685 release = 1;
1686 break;
1687 case ABORTING:
1688 case DEAD:
1689 break;
1690 default:
1691 BUG_ON(1);
1692 break;
1693 }
1694 mutex_unlock(&ep->com.mutex);
1695 if (release)
1696 release_ep_resources(ep);
1697 return 0;
1698 }
1699
1700 static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
1701 {
1702 struct cpl_rdma_terminate *rpl = cplhdr(skb);
1703 struct tid_info *t = dev->rdev.lldi.tids;
1704 unsigned int tid = GET_TID(rpl);
1705 struct c4iw_ep *ep;
1706 struct c4iw_qp_attributes attrs;
1707
1708 ep = lookup_tid(t, tid);
1709 BUG_ON(!ep);
1710
1711 if (ep->com.qp) {
1712 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
1713 ep->com.qp->wq.sq.qid);
1714 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1715 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1716 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1717 } else
1718 printk(KERN_WARNING MOD "TERM received tid %u no qp\n", tid);
1719
1720 return 0;
1721 }
1722
1723 /*
1724 * Upcall from the adapter indicating data has been transmitted.
1725 * For us its just the single MPA request or reply. We can now free
1726 * the skb holding the mpa message.
1727 */
1728 static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
1729 {
1730 struct c4iw_ep *ep;
1731 struct cpl_fw4_ack *hdr = cplhdr(skb);
1732 u8 credits = hdr->credits;
1733 unsigned int tid = GET_TID(hdr);
1734 struct tid_info *t = dev->rdev.lldi.tids;
1735
1736
1737 ep = lookup_tid(t, tid);
1738 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1739 if (credits == 0) {
1740 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
1741 __func__, ep, ep->hwtid, state_read(&ep->com));
1742 return 0;
1743 }
1744
1745 dst_confirm(ep->dst);
1746 if (ep->mpa_skb) {
1747 PDBG("%s last streaming msg ack ep %p tid %u state %u "
1748 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
1749 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
1750 kfree_skb(ep->mpa_skb);
1751 ep->mpa_skb = NULL;
1752 }
1753 return 0;
1754 }
1755
1756 int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
1757 {
1758 int err;
1759 struct c4iw_ep *ep = to_ep(cm_id);
1760 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1761
1762 if (state_read(&ep->com) == DEAD) {
1763 c4iw_put_ep(&ep->com);
1764 return -ECONNRESET;
1765 }
1766 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
1767 if (mpa_rev == 0)
1768 abort_connection(ep, NULL, GFP_KERNEL);
1769 else {
1770 err = send_mpa_reject(ep, pdata, pdata_len);
1771 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1772 }
1773 c4iw_put_ep(&ep->com);
1774 return 0;
1775 }
1776
1777 int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
1778 {
1779 int err;
1780 struct c4iw_qp_attributes attrs;
1781 enum c4iw_qp_attr_mask mask;
1782 struct c4iw_ep *ep = to_ep(cm_id);
1783 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
1784 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
1785
1786 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1787 if (state_read(&ep->com) == DEAD) {
1788 err = -ECONNRESET;
1789 goto err;
1790 }
1791
1792 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
1793 BUG_ON(!qp);
1794
1795 if ((conn_param->ord > c4iw_max_read_depth) ||
1796 (conn_param->ird > c4iw_max_read_depth)) {
1797 abort_connection(ep, NULL, GFP_KERNEL);
1798 err = -EINVAL;
1799 goto err;
1800 }
1801
1802 cm_id->add_ref(cm_id);
1803 ep->com.cm_id = cm_id;
1804 ep->com.qp = qp;
1805
1806 ep->ird = conn_param->ird;
1807 ep->ord = conn_param->ord;
1808
1809 if (peer2peer && ep->ird == 0)
1810 ep->ird = 1;
1811
1812 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
1813
1814 /* bind QP to EP and move to RTS */
1815 attrs.mpa_attr = ep->mpa_attr;
1816 attrs.max_ird = ep->ird;
1817 attrs.max_ord = ep->ord;
1818 attrs.llp_stream_handle = ep;
1819 attrs.next_state = C4IW_QP_STATE_RTS;
1820
1821 /* bind QP and TID with INIT_WR */
1822 mask = C4IW_QP_ATTR_NEXT_STATE |
1823 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
1824 C4IW_QP_ATTR_MPA_ATTR |
1825 C4IW_QP_ATTR_MAX_IRD |
1826 C4IW_QP_ATTR_MAX_ORD;
1827
1828 err = c4iw_modify_qp(ep->com.qp->rhp,
1829 ep->com.qp, mask, &attrs, 1);
1830 if (err)
1831 goto err1;
1832 err = send_mpa_reply(ep, conn_param->private_data,
1833 conn_param->private_data_len);
1834 if (err)
1835 goto err1;
1836
1837 state_set(&ep->com, FPDU_MODE);
1838 established_upcall(ep);
1839 c4iw_put_ep(&ep->com);
1840 return 0;
1841 err1:
1842 ep->com.cm_id = NULL;
1843 ep->com.qp = NULL;
1844 cm_id->rem_ref(cm_id);
1845 err:
1846 c4iw_put_ep(&ep->com);
1847 return err;
1848 }
1849
1850 int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
1851 {
1852 int err = 0;
1853 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
1854 struct c4iw_ep *ep;
1855 struct rtable *rt;
1856 struct net_device *pdev;
1857 int step;
1858
1859 if ((conn_param->ord > c4iw_max_read_depth) ||
1860 (conn_param->ird > c4iw_max_read_depth)) {
1861 err = -EINVAL;
1862 goto out;
1863 }
1864 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
1865 if (!ep) {
1866 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
1867 err = -ENOMEM;
1868 goto out;
1869 }
1870 init_timer(&ep->timer);
1871 ep->plen = conn_param->private_data_len;
1872 if (ep->plen)
1873 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
1874 conn_param->private_data, ep->plen);
1875 ep->ird = conn_param->ird;
1876 ep->ord = conn_param->ord;
1877
1878 if (peer2peer && ep->ord == 0)
1879 ep->ord = 1;
1880
1881 cm_id->add_ref(cm_id);
1882 ep->com.dev = dev;
1883 ep->com.cm_id = cm_id;
1884 ep->com.qp = get_qhp(dev, conn_param->qpn);
1885 BUG_ON(!ep->com.qp);
1886 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
1887 ep->com.qp, cm_id);
1888
1889 /*
1890 * Allocate an active TID to initiate a TCP connection.
1891 */
1892 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
1893 if (ep->atid == -1) {
1894 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
1895 err = -ENOMEM;
1896 goto fail2;
1897 }
1898
1899 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
1900 ntohl(cm_id->local_addr.sin_addr.s_addr),
1901 ntohs(cm_id->local_addr.sin_port),
1902 ntohl(cm_id->remote_addr.sin_addr.s_addr),
1903 ntohs(cm_id->remote_addr.sin_port));
1904
1905 /* find a route */
1906 rt = find_route(dev,
1907 cm_id->local_addr.sin_addr.s_addr,
1908 cm_id->remote_addr.sin_addr.s_addr,
1909 cm_id->local_addr.sin_port,
1910 cm_id->remote_addr.sin_port, 0);
1911 if (!rt) {
1912 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
1913 err = -EHOSTUNREACH;
1914 goto fail3;
1915 }
1916 ep->dst = &rt->dst;
1917
1918 /* get a l2t entry */
1919 if (ep->dst->neighbour->dev->flags & IFF_LOOPBACK) {
1920 PDBG("%s LOOPBACK\n", __func__);
1921 pdev = ip_dev_find(&init_net,
1922 cm_id->remote_addr.sin_addr.s_addr);
1923 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1924 ep->dst->neighbour,
1925 pdev, 0);
1926 ep->mtu = pdev->mtu;
1927 ep->tx_chan = cxgb4_port_chan(pdev);
1928 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1929 step = ep->com.dev->rdev.lldi.ntxq /
1930 ep->com.dev->rdev.lldi.nchan;
1931 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1932 step = ep->com.dev->rdev.lldi.nrxq /
1933 ep->com.dev->rdev.lldi.nchan;
1934 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1935 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1936 cxgb4_port_idx(pdev) * step];
1937 dev_put(pdev);
1938 } else {
1939 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1940 ep->dst->neighbour,
1941 ep->dst->neighbour->dev, 0);
1942 ep->mtu = dst_mtu(ep->dst);
1943 ep->tx_chan = cxgb4_port_chan(ep->dst->neighbour->dev);
1944 ep->smac_idx = (cxgb4_port_viid(ep->dst->neighbour->dev) &
1945 0x7F) << 1;
1946 step = ep->com.dev->rdev.lldi.ntxq /
1947 ep->com.dev->rdev.lldi.nchan;
1948 ep->txq_idx = cxgb4_port_idx(ep->dst->neighbour->dev) * step;
1949 ep->ctrlq_idx = cxgb4_port_idx(ep->dst->neighbour->dev);
1950 step = ep->com.dev->rdev.lldi.nrxq /
1951 ep->com.dev->rdev.lldi.nchan;
1952 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1953 cxgb4_port_idx(ep->dst->neighbour->dev) * step];
1954 }
1955 if (!ep->l2t) {
1956 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
1957 err = -ENOMEM;
1958 goto fail4;
1959 }
1960
1961 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1962 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1963 ep->l2t->idx);
1964
1965 state_set(&ep->com, CONNECTING);
1966 ep->tos = 0;
1967 ep->com.local_addr = cm_id->local_addr;
1968 ep->com.remote_addr = cm_id->remote_addr;
1969
1970 /* send connect request to rnic */
1971 err = send_connect(ep);
1972 if (!err)
1973 goto out;
1974
1975 cxgb4_l2t_release(ep->l2t);
1976 fail4:
1977 dst_release(ep->dst);
1978 fail3:
1979 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1980 fail2:
1981 cm_id->rem_ref(cm_id);
1982 c4iw_put_ep(&ep->com);
1983 out:
1984 return err;
1985 }
1986
1987 int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
1988 {
1989 int err = 0;
1990 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
1991 struct c4iw_listen_ep *ep;
1992
1993
1994 might_sleep();
1995
1996 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
1997 if (!ep) {
1998 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
1999 err = -ENOMEM;
2000 goto fail1;
2001 }
2002 PDBG("%s ep %p\n", __func__, ep);
2003 cm_id->add_ref(cm_id);
2004 ep->com.cm_id = cm_id;
2005 ep->com.dev = dev;
2006 ep->backlog = backlog;
2007 ep->com.local_addr = cm_id->local_addr;
2008
2009 /*
2010 * Allocate a server TID.
2011 */
2012 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2013 if (ep->stid == -1) {
2014 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
2015 err = -ENOMEM;
2016 goto fail2;
2017 }
2018
2019 state_set(&ep->com, LISTEN);
2020 c4iw_init_wr_wait(&ep->com.wr_wait);
2021 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
2022 ep->com.local_addr.sin_addr.s_addr,
2023 ep->com.local_addr.sin_port,
2024 ep->com.dev->rdev.lldi.rxq_ids[0]);
2025 if (err)
2026 goto fail3;
2027
2028 /* wait for pass_open_rpl */
2029 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2030 __func__);
2031 if (!err) {
2032 cm_id->provider_data = ep;
2033 goto out;
2034 }
2035 fail3:
2036 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2037 fail2:
2038 cm_id->rem_ref(cm_id);
2039 c4iw_put_ep(&ep->com);
2040 fail1:
2041 out:
2042 return err;
2043 }
2044
2045 int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2046 {
2047 int err;
2048 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2049
2050 PDBG("%s ep %p\n", __func__, ep);
2051
2052 might_sleep();
2053 state_set(&ep->com, DEAD);
2054 c4iw_init_wr_wait(&ep->com.wr_wait);
2055 err = listen_stop(ep);
2056 if (err)
2057 goto done;
2058 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2059 __func__);
2060 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2061 done:
2062 cm_id->rem_ref(cm_id);
2063 c4iw_put_ep(&ep->com);
2064 return err;
2065 }
2066
2067 int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2068 {
2069 int ret = 0;
2070 int close = 0;
2071 int fatal = 0;
2072 struct c4iw_rdev *rdev;
2073
2074 mutex_lock(&ep->com.mutex);
2075
2076 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2077 states[ep->com.state], abrupt);
2078
2079 rdev = &ep->com.dev->rdev;
2080 if (c4iw_fatal_error(rdev)) {
2081 fatal = 1;
2082 close_complete_upcall(ep);
2083 ep->com.state = DEAD;
2084 }
2085 switch (ep->com.state) {
2086 case MPA_REQ_WAIT:
2087 case MPA_REQ_SENT:
2088 case MPA_REQ_RCVD:
2089 case MPA_REP_SENT:
2090 case FPDU_MODE:
2091 close = 1;
2092 if (abrupt)
2093 ep->com.state = ABORTING;
2094 else {
2095 ep->com.state = CLOSING;
2096 start_ep_timer(ep);
2097 }
2098 set_bit(CLOSE_SENT, &ep->com.flags);
2099 break;
2100 case CLOSING:
2101 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2102 close = 1;
2103 if (abrupt) {
2104 stop_ep_timer(ep);
2105 ep->com.state = ABORTING;
2106 } else
2107 ep->com.state = MORIBUND;
2108 }
2109 break;
2110 case MORIBUND:
2111 case ABORTING:
2112 case DEAD:
2113 PDBG("%s ignoring disconnect ep %p state %u\n",
2114 __func__, ep, ep->com.state);
2115 break;
2116 default:
2117 BUG();
2118 break;
2119 }
2120
2121 mutex_unlock(&ep->com.mutex);
2122 if (close) {
2123 if (abrupt)
2124 ret = abort_connection(ep, NULL, gfp);
2125 else
2126 ret = send_halfclose(ep, gfp);
2127 if (ret)
2128 fatal = 1;
2129 }
2130 if (fatal)
2131 release_ep_resources(ep);
2132 return ret;
2133 }
2134
2135 static int async_event(struct c4iw_dev *dev, struct sk_buff *skb)
2136 {
2137 struct cpl_fw6_msg *rpl = cplhdr(skb);
2138 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2139 return 0;
2140 }
2141
2142 /*
2143 * These are the real handlers that are called from a
2144 * work queue.
2145 */
2146 static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
2147 [CPL_ACT_ESTABLISH] = act_establish,
2148 [CPL_ACT_OPEN_RPL] = act_open_rpl,
2149 [CPL_RX_DATA] = rx_data,
2150 [CPL_ABORT_RPL_RSS] = abort_rpl,
2151 [CPL_ABORT_RPL] = abort_rpl,
2152 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
2153 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
2154 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
2155 [CPL_PASS_ESTABLISH] = pass_establish,
2156 [CPL_PEER_CLOSE] = peer_close,
2157 [CPL_ABORT_REQ_RSS] = peer_abort,
2158 [CPL_CLOSE_CON_RPL] = close_con_rpl,
2159 [CPL_RDMA_TERMINATE] = terminate,
2160 [CPL_FW4_ACK] = fw4_ack,
2161 [CPL_FW6_MSG] = async_event
2162 };
2163
2164 static void process_timeout(struct c4iw_ep *ep)
2165 {
2166 struct c4iw_qp_attributes attrs;
2167 int abort = 1;
2168
2169 mutex_lock(&ep->com.mutex);
2170 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
2171 ep->com.state);
2172 switch (ep->com.state) {
2173 case MPA_REQ_SENT:
2174 __state_set(&ep->com, ABORTING);
2175 connect_reply_upcall(ep, -ETIMEDOUT);
2176 break;
2177 case MPA_REQ_WAIT:
2178 __state_set(&ep->com, ABORTING);
2179 break;
2180 case CLOSING:
2181 case MORIBUND:
2182 if (ep->com.cm_id && ep->com.qp) {
2183 attrs.next_state = C4IW_QP_STATE_ERROR;
2184 c4iw_modify_qp(ep->com.qp->rhp,
2185 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2186 &attrs, 1);
2187 }
2188 __state_set(&ep->com, ABORTING);
2189 break;
2190 default:
2191 printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
2192 __func__, ep, ep->hwtid, ep->com.state);
2193 WARN_ON(1);
2194 abort = 0;
2195 }
2196 mutex_unlock(&ep->com.mutex);
2197 if (abort)
2198 abort_connection(ep, NULL, GFP_KERNEL);
2199 c4iw_put_ep(&ep->com);
2200 }
2201
2202 static void process_timedout_eps(void)
2203 {
2204 struct c4iw_ep *ep;
2205
2206 spin_lock_irq(&timeout_lock);
2207 while (!list_empty(&timeout_list)) {
2208 struct list_head *tmp;
2209
2210 tmp = timeout_list.next;
2211 list_del(tmp);
2212 spin_unlock_irq(&timeout_lock);
2213 ep = list_entry(tmp, struct c4iw_ep, entry);
2214 process_timeout(ep);
2215 spin_lock_irq(&timeout_lock);
2216 }
2217 spin_unlock_irq(&timeout_lock);
2218 }
2219
2220 static void process_work(struct work_struct *work)
2221 {
2222 struct sk_buff *skb = NULL;
2223 struct c4iw_dev *dev;
2224 struct cpl_act_establish *rpl;
2225 unsigned int opcode;
2226 int ret;
2227
2228 while ((skb = skb_dequeue(&rxq))) {
2229 rpl = cplhdr(skb);
2230 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
2231 opcode = rpl->ot.opcode;
2232
2233 BUG_ON(!work_handlers[opcode]);
2234 ret = work_handlers[opcode](dev, skb);
2235 if (!ret)
2236 kfree_skb(skb);
2237 }
2238 process_timedout_eps();
2239 }
2240
2241 static DECLARE_WORK(skb_work, process_work);
2242
2243 static void ep_timeout(unsigned long arg)
2244 {
2245 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
2246
2247 spin_lock(&timeout_lock);
2248 list_add_tail(&ep->entry, &timeout_list);
2249 spin_unlock(&timeout_lock);
2250 queue_work(workq, &skb_work);
2251 }
2252
2253 /*
2254 * All the CM events are handled on a work queue to have a safe context.
2255 */
2256 static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
2257 {
2258
2259 /*
2260 * Save dev in the skb->cb area.
2261 */
2262 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
2263
2264 /*
2265 * Queue the skb and schedule the worker thread.
2266 */
2267 skb_queue_tail(&rxq, skb);
2268 queue_work(workq, &skb_work);
2269 return 0;
2270 }
2271
2272 static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2273 {
2274 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
2275
2276 if (rpl->status != CPL_ERR_NONE) {
2277 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
2278 "for tid %u\n", rpl->status, GET_TID(rpl));
2279 }
2280 kfree_skb(skb);
2281 return 0;
2282 }
2283
2284 static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2285 {
2286 struct cpl_fw6_msg *rpl = cplhdr(skb);
2287 struct c4iw_wr_wait *wr_waitp;
2288 int ret;
2289
2290 PDBG("%s type %u\n", __func__, rpl->type);
2291
2292 switch (rpl->type) {
2293 case 1:
2294 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
2295 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
2296 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
2297 if (wr_waitp) {
2298 if (ret)
2299 wr_waitp->ret = -ret;
2300 else
2301 wr_waitp->ret = 0;
2302 wr_waitp->done = 1;
2303 wake_up(&wr_waitp->wait);
2304 }
2305 kfree_skb(skb);
2306 break;
2307 case 2:
2308 sched(dev, skb);
2309 break;
2310 default:
2311 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
2312 rpl->type);
2313 kfree_skb(skb);
2314 break;
2315 }
2316 return 0;
2317 }
2318
2319 /*
2320 * Most upcalls from the T4 Core go to sched() to
2321 * schedule the processing on a work queue.
2322 */
2323 c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
2324 [CPL_ACT_ESTABLISH] = sched,
2325 [CPL_ACT_OPEN_RPL] = sched,
2326 [CPL_RX_DATA] = sched,
2327 [CPL_ABORT_RPL_RSS] = sched,
2328 [CPL_ABORT_RPL] = sched,
2329 [CPL_PASS_OPEN_RPL] = sched,
2330 [CPL_CLOSE_LISTSRV_RPL] = sched,
2331 [CPL_PASS_ACCEPT_REQ] = sched,
2332 [CPL_PASS_ESTABLISH] = sched,
2333 [CPL_PEER_CLOSE] = sched,
2334 [CPL_CLOSE_CON_RPL] = sched,
2335 [CPL_ABORT_REQ_RSS] = sched,
2336 [CPL_RDMA_TERMINATE] = sched,
2337 [CPL_FW4_ACK] = sched,
2338 [CPL_SET_TCB_RPL] = set_tcb_rpl,
2339 [CPL_FW6_MSG] = fw6_msg
2340 };
2341
2342 int __init c4iw_cm_init(void)
2343 {
2344 spin_lock_init(&timeout_lock);
2345 skb_queue_head_init(&rxq);
2346
2347 workq = create_singlethread_workqueue("iw_cxgb4");
2348 if (!workq)
2349 return -ENOMEM;
2350
2351 return 0;
2352 }
2353
2354 void __exit c4iw_cm_term(void)
2355 {
2356 WARN_ON(!list_empty(&timeout_list));
2357 flush_workqueue(workq);
2358 destroy_workqueue(workq);
2359 }