Commit | Line | Data |
---|---|---|
b038ced7 SW |
1 | /* |
2 | * Copyright (c) 2006 Chelsio, Inc. All rights reserved. | |
b038ced7 SW |
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 | ||
39 | #include <net/neighbour.h> | |
40 | #include <net/netevent.h> | |
41 | #include <net/route.h> | |
42 | ||
43 | #include "tcb.h" | |
44 | #include "cxgb3_offload.h" | |
45 | #include "iwch.h" | |
46 | #include "iwch_provider.h" | |
47 | #include "iwch_cm.h" | |
48 | ||
49 | static char *states[] = { | |
50 | "idle", | |
51 | "listen", | |
52 | "connecting", | |
53 | "mpa_wait_req", | |
54 | "mpa_req_sent", | |
55 | "mpa_req_rcvd", | |
56 | "mpa_rep_sent", | |
57 | "fpdu_mode", | |
58 | "aborting", | |
59 | "closing", | |
60 | "moribund", | |
61 | "dead", | |
62 | NULL, | |
63 | }; | |
64 | ||
65 | static int ep_timeout_secs = 10; | |
66 | module_param(ep_timeout_secs, int, 0444); | |
67 | MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout " | |
68 | "in seconds (default=10)"); | |
69 | ||
70 | static int mpa_rev = 1; | |
71 | module_param(mpa_rev, int, 0444); | |
72 | MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, " | |
73 | "1 is spec compliant. (default=1)"); | |
74 | ||
75 | static int markers_enabled = 0; | |
76 | module_param(markers_enabled, int, 0444); | |
77 | MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)"); | |
78 | ||
79 | static int crc_enabled = 1; | |
80 | module_param(crc_enabled, int, 0444); | |
81 | MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)"); | |
82 | ||
83 | static int rcv_win = 256 * 1024; | |
84 | module_param(rcv_win, int, 0444); | |
85 | MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256)"); | |
86 | ||
87 | static int snd_win = 32 * 1024; | |
88 | module_param(snd_win, int, 0444); | |
89 | MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=32KB)"); | |
90 | ||
91 | static unsigned int nocong = 0; | |
92 | module_param(nocong, uint, 0444); | |
93 | MODULE_PARM_DESC(nocong, "Turn off congestion control (default=0)"); | |
94 | ||
95 | static unsigned int cong_flavor = 1; | |
96 | module_param(cong_flavor, uint, 0444); | |
97 | MODULE_PARM_DESC(cong_flavor, "TCP Congestion control flavor (default=1)"); | |
98 | ||
99 | static void process_work(struct work_struct *work); | |
100 | static struct workqueue_struct *workq; | |
101 | static DECLARE_WORK(skb_work, process_work); | |
102 | ||
103 | static struct sk_buff_head rxq; | |
104 | static cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS]; | |
105 | ||
106 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp); | |
107 | static void ep_timeout(unsigned long arg); | |
108 | static void connect_reply_upcall(struct iwch_ep *ep, int status); | |
109 | ||
110 | static void start_ep_timer(struct iwch_ep *ep) | |
111 | { | |
112 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
113 | if (timer_pending(&ep->timer)) { | |
114 | PDBG("%s stopped / restarted timer ep %p\n", __FUNCTION__, ep); | |
115 | del_timer_sync(&ep->timer); | |
116 | } else | |
117 | get_ep(&ep->com); | |
118 | ep->timer.expires = jiffies + ep_timeout_secs * HZ; | |
119 | ep->timer.data = (unsigned long)ep; | |
120 | ep->timer.function = ep_timeout; | |
121 | add_timer(&ep->timer); | |
122 | } | |
123 | ||
124 | static void stop_ep_timer(struct iwch_ep *ep) | |
125 | { | |
126 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
127 | del_timer_sync(&ep->timer); | |
128 | put_ep(&ep->com); | |
129 | } | |
130 | ||
131 | static void release_tid(struct t3cdev *tdev, u32 hwtid, struct sk_buff *skb) | |
132 | { | |
133 | struct cpl_tid_release *req; | |
134 | ||
135 | skb = get_skb(skb, sizeof *req, GFP_KERNEL); | |
136 | if (!skb) | |
137 | return; | |
138 | req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req)); | |
139 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
140 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid)); | |
141 | skb->priority = CPL_PRIORITY_SETUP; | |
142 | tdev->send(tdev, skb); | |
143 | return; | |
144 | } | |
145 | ||
146 | int iwch_quiesce_tid(struct iwch_ep *ep) | |
147 | { | |
148 | struct cpl_set_tcb_field *req; | |
149 | struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
150 | ||
151 | if (!skb) | |
152 | return -ENOMEM; | |
153 | req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req)); | |
154 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
155 | req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
156 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid)); | |
157 | req->reply = 0; | |
158 | req->cpu_idx = 0; | |
159 | req->word = htons(W_TCB_RX_QUIESCE); | |
160 | req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE); | |
161 | req->val = cpu_to_be64(1 << S_TCB_RX_QUIESCE); | |
162 | ||
163 | skb->priority = CPL_PRIORITY_DATA; | |
164 | ep->com.tdev->send(ep->com.tdev, skb); | |
165 | return 0; | |
166 | } | |
167 | ||
168 | int iwch_resume_tid(struct iwch_ep *ep) | |
169 | { | |
170 | struct cpl_set_tcb_field *req; | |
171 | struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
172 | ||
173 | if (!skb) | |
174 | return -ENOMEM; | |
175 | req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req)); | |
176 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
177 | req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
178 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid)); | |
179 | req->reply = 0; | |
180 | req->cpu_idx = 0; | |
181 | req->word = htons(W_TCB_RX_QUIESCE); | |
182 | req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE); | |
183 | req->val = 0; | |
184 | ||
185 | skb->priority = CPL_PRIORITY_DATA; | |
186 | ep->com.tdev->send(ep->com.tdev, skb); | |
187 | return 0; | |
188 | } | |
189 | ||
190 | static void set_emss(struct iwch_ep *ep, u16 opt) | |
191 | { | |
192 | PDBG("%s ep %p opt %u\n", __FUNCTION__, ep, opt); | |
193 | ep->emss = T3C_DATA(ep->com.tdev)->mtus[G_TCPOPT_MSS(opt)] - 40; | |
194 | if (G_TCPOPT_TSTAMP(opt)) | |
195 | ep->emss -= 12; | |
196 | if (ep->emss < 128) | |
197 | ep->emss = 128; | |
198 | PDBG("emss=%d\n", ep->emss); | |
199 | } | |
200 | ||
201 | static enum iwch_ep_state state_read(struct iwch_ep_common *epc) | |
202 | { | |
203 | unsigned long flags; | |
204 | enum iwch_ep_state state; | |
205 | ||
206 | spin_lock_irqsave(&epc->lock, flags); | |
207 | state = epc->state; | |
208 | spin_unlock_irqrestore(&epc->lock, flags); | |
209 | return state; | |
210 | } | |
211 | ||
2b540355 | 212 | static void __state_set(struct iwch_ep_common *epc, enum iwch_ep_state new) |
b038ced7 SW |
213 | { |
214 | epc->state = new; | |
215 | } | |
216 | ||
217 | static void state_set(struct iwch_ep_common *epc, enum iwch_ep_state new) | |
218 | { | |
219 | unsigned long flags; | |
220 | ||
221 | spin_lock_irqsave(&epc->lock, flags); | |
222 | PDBG("%s - %s -> %s\n", __FUNCTION__, states[epc->state], states[new]); | |
223 | __state_set(epc, new); | |
224 | spin_unlock_irqrestore(&epc->lock, flags); | |
225 | return; | |
226 | } | |
227 | ||
228 | static void *alloc_ep(int size, gfp_t gfp) | |
229 | { | |
230 | struct iwch_ep_common *epc; | |
231 | ||
232 | epc = kmalloc(size, gfp); | |
233 | if (epc) { | |
234 | memset(epc, 0, size); | |
235 | kref_init(&epc->kref); | |
236 | spin_lock_init(&epc->lock); | |
237 | init_waitqueue_head(&epc->waitq); | |
238 | } | |
239 | PDBG("%s alloc ep %p\n", __FUNCTION__, epc); | |
240 | return epc; | |
241 | } | |
242 | ||
243 | void __free_ep(struct kref *kref) | |
244 | { | |
245 | struct iwch_ep_common *epc; | |
246 | epc = container_of(kref, struct iwch_ep_common, kref); | |
247 | PDBG("%s ep %p state %s\n", __FUNCTION__, epc, states[state_read(epc)]); | |
248 | kfree(epc); | |
249 | } | |
250 | ||
251 | static void release_ep_resources(struct iwch_ep *ep) | |
252 | { | |
253 | PDBG("%s ep %p tid %d\n", __FUNCTION__, ep, ep->hwtid); | |
254 | cxgb3_remove_tid(ep->com.tdev, (void *)ep, ep->hwtid); | |
255 | dst_release(ep->dst); | |
256 | l2t_release(L2DATA(ep->com.tdev), ep->l2t); | |
257 | if (ep->com.tdev->type == T3B) | |
258 | release_tid(ep->com.tdev, ep->hwtid, NULL); | |
259 | put_ep(&ep->com); | |
260 | } | |
261 | ||
262 | static void process_work(struct work_struct *work) | |
263 | { | |
264 | struct sk_buff *skb = NULL; | |
265 | void *ep; | |
266 | struct t3cdev *tdev; | |
267 | int ret; | |
268 | ||
269 | while ((skb = skb_dequeue(&rxq))) { | |
270 | ep = *((void **) (skb->cb)); | |
271 | tdev = *((struct t3cdev **) (skb->cb + sizeof(void *))); | |
272 | ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep); | |
273 | if (ret & CPL_RET_BUF_DONE) | |
274 | kfree_skb(skb); | |
275 | ||
276 | /* | |
277 | * ep was referenced in sched(), and is freed here. | |
278 | */ | |
279 | put_ep((struct iwch_ep_common *)ep); | |
280 | } | |
281 | } | |
282 | ||
283 | static int status2errno(int status) | |
284 | { | |
285 | switch (status) { | |
286 | case CPL_ERR_NONE: | |
287 | return 0; | |
288 | case CPL_ERR_CONN_RESET: | |
289 | return -ECONNRESET; | |
290 | case CPL_ERR_ARP_MISS: | |
291 | return -EHOSTUNREACH; | |
292 | case CPL_ERR_CONN_TIMEDOUT: | |
293 | return -ETIMEDOUT; | |
294 | case CPL_ERR_TCAM_FULL: | |
295 | return -ENOMEM; | |
296 | case CPL_ERR_CONN_EXIST: | |
297 | return -EADDRINUSE; | |
298 | default: | |
299 | return -EIO; | |
300 | } | |
301 | } | |
302 | ||
303 | /* | |
304 | * Try and reuse skbs already allocated... | |
305 | */ | |
306 | static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp) | |
307 | { | |
308 | if (skb) { | |
309 | BUG_ON(skb_cloned(skb)); | |
310 | skb_trim(skb, 0); | |
311 | skb_get(skb); | |
312 | } else { | |
313 | skb = alloc_skb(len, gfp); | |
314 | } | |
315 | return skb; | |
316 | } | |
317 | ||
318 | static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip, | |
319 | __be32 peer_ip, __be16 local_port, | |
320 | __be16 peer_port, u8 tos) | |
321 | { | |
322 | struct rtable *rt; | |
323 | struct flowi fl = { | |
324 | .oif = 0, | |
325 | .nl_u = { | |
326 | .ip4_u = { | |
327 | .daddr = peer_ip, | |
328 | .saddr = local_ip, | |
329 | .tos = tos} | |
330 | }, | |
331 | .proto = IPPROTO_TCP, | |
332 | .uli_u = { | |
333 | .ports = { | |
334 | .sport = local_port, | |
335 | .dport = peer_port} | |
336 | } | |
337 | }; | |
338 | ||
339 | if (ip_route_output_flow(&rt, &fl, NULL, 0)) | |
340 | return NULL; | |
341 | return rt; | |
342 | } | |
343 | ||
344 | static unsigned int find_best_mtu(const struct t3c_data *d, unsigned short mtu) | |
345 | { | |
346 | int i = 0; | |
347 | ||
348 | while (i < d->nmtus - 1 && d->mtus[i + 1] <= mtu) | |
349 | ++i; | |
350 | return i; | |
351 | } | |
352 | ||
353 | static void arp_failure_discard(struct t3cdev *dev, struct sk_buff *skb) | |
354 | { | |
355 | PDBG("%s t3cdev %p\n", __FUNCTION__, dev); | |
356 | kfree_skb(skb); | |
357 | } | |
358 | ||
359 | /* | |
360 | * Handle an ARP failure for an active open. | |
361 | */ | |
362 | static void act_open_req_arp_failure(struct t3cdev *dev, struct sk_buff *skb) | |
363 | { | |
364 | printk(KERN_ERR MOD "ARP failure duing connect\n"); | |
365 | kfree_skb(skb); | |
366 | } | |
367 | ||
368 | /* | |
369 | * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant | |
370 | * and send it along. | |
371 | */ | |
372 | static void abort_arp_failure(struct t3cdev *dev, struct sk_buff *skb) | |
373 | { | |
374 | struct cpl_abort_req *req = cplhdr(skb); | |
375 | ||
376 | PDBG("%s t3cdev %p\n", __FUNCTION__, dev); | |
377 | req->cmd = CPL_ABORT_NO_RST; | |
378 | cxgb3_ofld_send(dev, skb); | |
379 | } | |
380 | ||
381 | static int send_halfclose(struct iwch_ep *ep, gfp_t gfp) | |
382 | { | |
383 | struct cpl_close_con_req *req; | |
384 | struct sk_buff *skb; | |
385 | ||
386 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
387 | skb = get_skb(NULL, sizeof(*req), gfp); | |
388 | if (!skb) { | |
389 | printk(KERN_ERR MOD "%s - failed to alloc skb\n", __FUNCTION__); | |
390 | return -ENOMEM; | |
391 | } | |
392 | skb->priority = CPL_PRIORITY_DATA; | |
393 | set_arp_failure_handler(skb, arp_failure_discard); | |
394 | req = (struct cpl_close_con_req *) skb_put(skb, sizeof(*req)); | |
395 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON)); | |
396 | req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
397 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, ep->hwtid)); | |
398 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
399 | return 0; | |
400 | } | |
401 | ||
402 | static int send_abort(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp) | |
403 | { | |
404 | struct cpl_abort_req *req; | |
405 | ||
406 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
407 | skb = get_skb(skb, sizeof(*req), gfp); | |
408 | if (!skb) { | |
409 | printk(KERN_ERR MOD "%s - failed to alloc skb.\n", | |
410 | __FUNCTION__); | |
411 | return -ENOMEM; | |
412 | } | |
413 | skb->priority = CPL_PRIORITY_DATA; | |
414 | set_arp_failure_handler(skb, abort_arp_failure); | |
415 | req = (struct cpl_abort_req *) skb_put(skb, sizeof(*req)); | |
416 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ)); | |
417 | req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
418 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid)); | |
419 | req->cmd = CPL_ABORT_SEND_RST; | |
420 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
421 | return 0; | |
422 | } | |
423 | ||
424 | static int send_connect(struct iwch_ep *ep) | |
425 | { | |
426 | struct cpl_act_open_req *req; | |
427 | struct sk_buff *skb; | |
428 | u32 opt0h, opt0l, opt2; | |
429 | unsigned int mtu_idx; | |
430 | int wscale; | |
431 | ||
432 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
433 | ||
434 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
435 | if (!skb) { | |
436 | printk(KERN_ERR MOD "%s - failed to alloc skb.\n", | |
437 | __FUNCTION__); | |
438 | return -ENOMEM; | |
439 | } | |
440 | mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst)); | |
441 | wscale = compute_wscale(rcv_win); | |
442 | opt0h = V_NAGLE(0) | | |
443 | V_NO_CONG(nocong) | | |
444 | V_KEEP_ALIVE(1) | | |
445 | F_TCAM_BYPASS | | |
446 | V_WND_SCALE(wscale) | | |
447 | V_MSS_IDX(mtu_idx) | | |
448 | V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx); | |
449 | opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10); | |
450 | opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor); | |
451 | skb->priority = CPL_PRIORITY_SETUP; | |
452 | set_arp_failure_handler(skb, act_open_req_arp_failure); | |
453 | ||
454 | req = (struct cpl_act_open_req *) skb_put(skb, sizeof(*req)); | |
455 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
456 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ep->atid)); | |
457 | req->local_port = ep->com.local_addr.sin_port; | |
458 | req->peer_port = ep->com.remote_addr.sin_port; | |
459 | req->local_ip = ep->com.local_addr.sin_addr.s_addr; | |
460 | req->peer_ip = ep->com.remote_addr.sin_addr.s_addr; | |
461 | req->opt0h = htonl(opt0h); | |
462 | req->opt0l = htonl(opt0l); | |
463 | req->params = 0; | |
464 | req->opt2 = htonl(opt2); | |
465 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
466 | return 0; | |
467 | } | |
468 | ||
469 | static void send_mpa_req(struct iwch_ep *ep, struct sk_buff *skb) | |
470 | { | |
471 | int mpalen; | |
472 | struct tx_data_wr *req; | |
473 | struct mpa_message *mpa; | |
474 | int len; | |
475 | ||
476 | PDBG("%s ep %p pd_len %d\n", __FUNCTION__, ep, ep->plen); | |
477 | ||
478 | BUG_ON(skb_cloned(skb)); | |
479 | ||
480 | mpalen = sizeof(*mpa) + ep->plen; | |
481 | if (skb->data + mpalen + sizeof(*req) > skb->end) { | |
482 | kfree_skb(skb); | |
483 | skb=alloc_skb(mpalen + sizeof(*req), GFP_KERNEL); | |
484 | if (!skb) { | |
485 | connect_reply_upcall(ep, -ENOMEM); | |
486 | return; | |
487 | } | |
488 | } | |
489 | skb_trim(skb, 0); | |
490 | skb_reserve(skb, sizeof(*req)); | |
491 | skb_put(skb, mpalen); | |
492 | skb->priority = CPL_PRIORITY_DATA; | |
493 | mpa = (struct mpa_message *) skb->data; | |
494 | memset(mpa, 0, sizeof(*mpa)); | |
495 | memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)); | |
496 | mpa->flags = (crc_enabled ? MPA_CRC : 0) | | |
497 | (markers_enabled ? MPA_MARKERS : 0); | |
498 | mpa->private_data_size = htons(ep->plen); | |
499 | mpa->revision = mpa_rev; | |
500 | ||
501 | if (ep->plen) | |
502 | memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen); | |
503 | ||
504 | /* | |
505 | * Reference the mpa skb. This ensures the data area | |
506 | * will remain in memory until the hw acks the tx. | |
507 | * Function tx_ack() will deref it. | |
508 | */ | |
509 | skb_get(skb); | |
510 | set_arp_failure_handler(skb, arp_failure_discard); | |
511 | skb->h.raw = skb->data; | |
512 | len = skb->len; | |
513 | req = (struct tx_data_wr *) skb_push(skb, sizeof(*req)); | |
514 | req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)); | |
515 | req->wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
516 | req->len = htonl(len); | |
517 | req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) | | |
518 | V_TX_SNDBUF(snd_win>>15)); | |
519 | req->flags = htonl(F_TX_IMM_ACK|F_TX_INIT); | |
520 | req->sndseq = htonl(ep->snd_seq); | |
521 | BUG_ON(ep->mpa_skb); | |
522 | ep->mpa_skb = skb; | |
523 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
524 | start_ep_timer(ep); | |
525 | state_set(&ep->com, MPA_REQ_SENT); | |
526 | return; | |
527 | } | |
528 | ||
529 | static int send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen) | |
530 | { | |
531 | int mpalen; | |
532 | struct tx_data_wr *req; | |
533 | struct mpa_message *mpa; | |
534 | struct sk_buff *skb; | |
535 | ||
536 | PDBG("%s ep %p plen %d\n", __FUNCTION__, ep, plen); | |
537 | ||
538 | mpalen = sizeof(*mpa) + plen; | |
539 | ||
540 | skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL); | |
541 | if (!skb) { | |
542 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __FUNCTION__); | |
543 | return -ENOMEM; | |
544 | } | |
545 | skb_reserve(skb, sizeof(*req)); | |
546 | mpa = (struct mpa_message *) skb_put(skb, mpalen); | |
547 | memset(mpa, 0, sizeof(*mpa)); | |
548 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); | |
549 | mpa->flags = MPA_REJECT; | |
550 | mpa->revision = mpa_rev; | |
551 | mpa->private_data_size = htons(plen); | |
552 | if (plen) | |
553 | memcpy(mpa->private_data, pdata, plen); | |
554 | ||
555 | /* | |
556 | * Reference the mpa skb again. This ensures the data area | |
557 | * will remain in memory until the hw acks the tx. | |
558 | * Function tx_ack() will deref it. | |
559 | */ | |
560 | skb_get(skb); | |
561 | skb->priority = CPL_PRIORITY_DATA; | |
562 | set_arp_failure_handler(skb, arp_failure_discard); | |
563 | skb->h.raw = skb->data; | |
564 | req = (struct tx_data_wr *) skb_push(skb, sizeof(*req)); | |
565 | req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)); | |
566 | req->wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
567 | req->len = htonl(mpalen); | |
568 | req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) | | |
569 | V_TX_SNDBUF(snd_win>>15)); | |
570 | req->flags = htonl(F_TX_IMM_ACK|F_TX_INIT); | |
571 | req->sndseq = htonl(ep->snd_seq); | |
572 | BUG_ON(ep->mpa_skb); | |
573 | ep->mpa_skb = skb; | |
574 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
575 | return 0; | |
576 | } | |
577 | ||
578 | static int send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen) | |
579 | { | |
580 | int mpalen; | |
581 | struct tx_data_wr *req; | |
582 | struct mpa_message *mpa; | |
583 | int len; | |
584 | struct sk_buff *skb; | |
585 | ||
586 | PDBG("%s ep %p plen %d\n", __FUNCTION__, ep, plen); | |
587 | ||
588 | mpalen = sizeof(*mpa) + plen; | |
589 | ||
590 | skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL); | |
591 | if (!skb) { | |
592 | printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __FUNCTION__); | |
593 | return -ENOMEM; | |
594 | } | |
595 | skb->priority = CPL_PRIORITY_DATA; | |
596 | skb_reserve(skb, sizeof(*req)); | |
597 | mpa = (struct mpa_message *) skb_put(skb, mpalen); | |
598 | memset(mpa, 0, sizeof(*mpa)); | |
599 | memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key)); | |
600 | mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) | | |
601 | (markers_enabled ? MPA_MARKERS : 0); | |
602 | mpa->revision = mpa_rev; | |
603 | mpa->private_data_size = htons(plen); | |
604 | if (plen) | |
605 | memcpy(mpa->private_data, pdata, plen); | |
606 | ||
607 | /* | |
608 | * Reference the mpa skb. This ensures the data area | |
609 | * will remain in memory until the hw acks the tx. | |
610 | * Function tx_ack() will deref it. | |
611 | */ | |
612 | skb_get(skb); | |
613 | set_arp_failure_handler(skb, arp_failure_discard); | |
614 | skb->h.raw = skb->data; | |
615 | len = skb->len; | |
616 | req = (struct tx_data_wr *) skb_push(skb, sizeof(*req)); | |
617 | req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)); | |
618 | req->wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
619 | req->len = htonl(len); | |
620 | req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) | | |
621 | V_TX_SNDBUF(snd_win>>15)); | |
622 | req->flags = htonl(F_TX_MORE | F_TX_IMM_ACK | F_TX_INIT); | |
623 | req->sndseq = htonl(ep->snd_seq); | |
624 | ep->mpa_skb = skb; | |
625 | state_set(&ep->com, MPA_REP_SENT); | |
626 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
627 | return 0; | |
628 | } | |
629 | ||
630 | static int act_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
631 | { | |
632 | struct iwch_ep *ep = ctx; | |
633 | struct cpl_act_establish *req = cplhdr(skb); | |
634 | unsigned int tid = GET_TID(req); | |
635 | ||
636 | PDBG("%s ep %p tid %d\n", __FUNCTION__, ep, tid); | |
637 | ||
638 | dst_confirm(ep->dst); | |
639 | ||
640 | /* setup the hwtid for this connection */ | |
641 | ep->hwtid = tid; | |
642 | cxgb3_insert_tid(ep->com.tdev, &t3c_client, ep, tid); | |
643 | ||
644 | ep->snd_seq = ntohl(req->snd_isn); | |
645 | ||
646 | set_emss(ep, ntohs(req->tcp_opt)); | |
647 | ||
648 | /* dealloc the atid */ | |
649 | cxgb3_free_atid(ep->com.tdev, ep->atid); | |
650 | ||
651 | /* start MPA negotiation */ | |
652 | send_mpa_req(ep, skb); | |
653 | ||
654 | return 0; | |
655 | } | |
656 | ||
657 | static void abort_connection(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp) | |
658 | { | |
659 | PDBG("%s ep %p\n", __FILE__, ep); | |
660 | state_set(&ep->com, ABORTING); | |
661 | send_abort(ep, skb, gfp); | |
662 | } | |
663 | ||
664 | static void close_complete_upcall(struct iwch_ep *ep) | |
665 | { | |
666 | struct iw_cm_event event; | |
667 | ||
668 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
669 | memset(&event, 0, sizeof(event)); | |
670 | event.event = IW_CM_EVENT_CLOSE; | |
671 | if (ep->com.cm_id) { | |
672 | PDBG("close complete delivered ep %p cm_id %p tid %d\n", | |
673 | ep, ep->com.cm_id, ep->hwtid); | |
674 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); | |
675 | ep->com.cm_id->rem_ref(ep->com.cm_id); | |
676 | ep->com.cm_id = NULL; | |
677 | ep->com.qp = NULL; | |
678 | } | |
679 | } | |
680 | ||
681 | static void peer_close_upcall(struct iwch_ep *ep) | |
682 | { | |
683 | struct iw_cm_event event; | |
684 | ||
685 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
686 | memset(&event, 0, sizeof(event)); | |
687 | event.event = IW_CM_EVENT_DISCONNECT; | |
688 | if (ep->com.cm_id) { | |
689 | PDBG("peer close delivered ep %p cm_id %p tid %d\n", | |
690 | ep, ep->com.cm_id, ep->hwtid); | |
691 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); | |
692 | } | |
693 | } | |
694 | ||
695 | static void peer_abort_upcall(struct iwch_ep *ep) | |
696 | { | |
697 | struct iw_cm_event event; | |
698 | ||
699 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
700 | memset(&event, 0, sizeof(event)); | |
701 | event.event = IW_CM_EVENT_CLOSE; | |
702 | event.status = -ECONNRESET; | |
703 | if (ep->com.cm_id) { | |
704 | PDBG("abort delivered ep %p cm_id %p tid %d\n", ep, | |
705 | ep->com.cm_id, ep->hwtid); | |
706 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); | |
707 | ep->com.cm_id->rem_ref(ep->com.cm_id); | |
708 | ep->com.cm_id = NULL; | |
709 | ep->com.qp = NULL; | |
710 | } | |
711 | } | |
712 | ||
713 | static void connect_reply_upcall(struct iwch_ep *ep, int status) | |
714 | { | |
715 | struct iw_cm_event event; | |
716 | ||
717 | PDBG("%s ep %p status %d\n", __FUNCTION__, ep, status); | |
718 | memset(&event, 0, sizeof(event)); | |
719 | event.event = IW_CM_EVENT_CONNECT_REPLY; | |
720 | event.status = status; | |
721 | event.local_addr = ep->com.local_addr; | |
722 | event.remote_addr = ep->com.remote_addr; | |
723 | ||
724 | if ((status == 0) || (status == -ECONNREFUSED)) { | |
725 | event.private_data_len = ep->plen; | |
726 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); | |
727 | } | |
728 | if (ep->com.cm_id) { | |
729 | PDBG("%s ep %p tid %d status %d\n", __FUNCTION__, ep, | |
730 | ep->hwtid, status); | |
731 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); | |
732 | } | |
733 | if (status < 0) { | |
734 | ep->com.cm_id->rem_ref(ep->com.cm_id); | |
735 | ep->com.cm_id = NULL; | |
736 | ep->com.qp = NULL; | |
737 | } | |
738 | } | |
739 | ||
740 | static void connect_request_upcall(struct iwch_ep *ep) | |
741 | { | |
742 | struct iw_cm_event event; | |
743 | ||
744 | PDBG("%s ep %p tid %d\n", __FUNCTION__, ep, ep->hwtid); | |
745 | memset(&event, 0, sizeof(event)); | |
746 | event.event = IW_CM_EVENT_CONNECT_REQUEST; | |
747 | event.local_addr = ep->com.local_addr; | |
748 | event.remote_addr = ep->com.remote_addr; | |
749 | event.private_data_len = ep->plen; | |
750 | event.private_data = ep->mpa_pkt + sizeof(struct mpa_message); | |
751 | event.provider_data = ep; | |
752 | if (state_read(&ep->parent_ep->com) != DEAD) | |
753 | ep->parent_ep->com.cm_id->event_handler( | |
754 | ep->parent_ep->com.cm_id, | |
755 | &event); | |
756 | put_ep(&ep->parent_ep->com); | |
757 | ep->parent_ep = NULL; | |
758 | } | |
759 | ||
760 | static void established_upcall(struct iwch_ep *ep) | |
761 | { | |
762 | struct iw_cm_event event; | |
763 | ||
764 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
765 | memset(&event, 0, sizeof(event)); | |
766 | event.event = IW_CM_EVENT_ESTABLISHED; | |
767 | if (ep->com.cm_id) { | |
768 | PDBG("%s ep %p tid %d\n", __FUNCTION__, ep, ep->hwtid); | |
769 | ep->com.cm_id->event_handler(ep->com.cm_id, &event); | |
770 | } | |
771 | } | |
772 | ||
773 | static int update_rx_credits(struct iwch_ep *ep, u32 credits) | |
774 | { | |
775 | struct cpl_rx_data_ack *req; | |
776 | struct sk_buff *skb; | |
777 | ||
778 | PDBG("%s ep %p credits %u\n", __FUNCTION__, ep, credits); | |
779 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
780 | if (!skb) { | |
781 | printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n"); | |
782 | return 0; | |
783 | } | |
784 | ||
785 | req = (struct cpl_rx_data_ack *) skb_put(skb, sizeof(*req)); | |
786 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
787 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK, ep->hwtid)); | |
788 | req->credit_dack = htonl(V_RX_CREDITS(credits) | V_RX_FORCE_ACK(1)); | |
789 | skb->priority = CPL_PRIORITY_ACK; | |
790 | ep->com.tdev->send(ep->com.tdev, skb); | |
791 | return credits; | |
792 | } | |
793 | ||
794 | static void process_mpa_reply(struct iwch_ep *ep, struct sk_buff *skb) | |
795 | { | |
796 | struct mpa_message *mpa; | |
797 | u16 plen; | |
798 | struct iwch_qp_attributes attrs; | |
799 | enum iwch_qp_attr_mask mask; | |
800 | int err; | |
801 | ||
802 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
803 | ||
804 | /* | |
805 | * Stop mpa timer. If it expired, then the state has | |
806 | * changed and we bail since ep_timeout already aborted | |
807 | * the connection. | |
808 | */ | |
809 | stop_ep_timer(ep); | |
810 | if (state_read(&ep->com) != MPA_REQ_SENT) | |
811 | return; | |
812 | ||
813 | /* | |
814 | * If we get more than the supported amount of private data | |
815 | * then we must fail this connection. | |
816 | */ | |
817 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { | |
818 | err = -EINVAL; | |
819 | goto err; | |
820 | } | |
821 | ||
822 | /* | |
823 | * copy the new data into our accumulation buffer. | |
824 | */ | |
825 | memcpy(&(ep->mpa_pkt[ep->mpa_pkt_len]), skb->data, skb->len); | |
826 | ep->mpa_pkt_len += skb->len; | |
827 | ||
828 | /* | |
829 | * if we don't even have the mpa message, then bail. | |
830 | */ | |
831 | if (ep->mpa_pkt_len < sizeof(*mpa)) | |
832 | return; | |
833 | mpa = (struct mpa_message *) ep->mpa_pkt; | |
834 | ||
835 | /* Validate MPA header. */ | |
836 | if (mpa->revision != mpa_rev) { | |
837 | err = -EPROTO; | |
838 | goto err; | |
839 | } | |
840 | if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) { | |
841 | err = -EPROTO; | |
842 | goto err; | |
843 | } | |
844 | ||
845 | plen = ntohs(mpa->private_data_size); | |
846 | ||
847 | /* | |
848 | * Fail if there's too much private data. | |
849 | */ | |
850 | if (plen > MPA_MAX_PRIVATE_DATA) { | |
851 | err = -EPROTO; | |
852 | goto err; | |
853 | } | |
854 | ||
855 | /* | |
856 | * If plen does not account for pkt size | |
857 | */ | |
858 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { | |
859 | err = -EPROTO; | |
860 | goto err; | |
861 | } | |
862 | ||
863 | ep->plen = (u8) plen; | |
864 | ||
865 | /* | |
866 | * If we don't have all the pdata yet, then bail. | |
867 | * We'll continue process when more data arrives. | |
868 | */ | |
869 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) | |
870 | return; | |
871 | ||
872 | if (mpa->flags & MPA_REJECT) { | |
873 | err = -ECONNREFUSED; | |
874 | goto err; | |
875 | } | |
876 | ||
877 | /* | |
878 | * If we get here we have accumulated the entire mpa | |
879 | * start reply message including private data. And | |
880 | * the MPA header is valid. | |
881 | */ | |
882 | state_set(&ep->com, FPDU_MODE); | |
883 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; | |
884 | ep->mpa_attr.recv_marker_enabled = markers_enabled; | |
885 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; | |
886 | ep->mpa_attr.version = mpa_rev; | |
887 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " | |
888 | "xmit_marker_enabled=%d, version=%d\n", __FUNCTION__, | |
889 | ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, | |
890 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version); | |
891 | ||
892 | attrs.mpa_attr = ep->mpa_attr; | |
893 | attrs.max_ird = ep->ird; | |
894 | attrs.max_ord = ep->ord; | |
895 | attrs.llp_stream_handle = ep; | |
896 | attrs.next_state = IWCH_QP_STATE_RTS; | |
897 | ||
898 | mask = IWCH_QP_ATTR_NEXT_STATE | | |
899 | IWCH_QP_ATTR_LLP_STREAM_HANDLE | IWCH_QP_ATTR_MPA_ATTR | | |
900 | IWCH_QP_ATTR_MAX_IRD | IWCH_QP_ATTR_MAX_ORD; | |
901 | ||
902 | /* bind QP and TID with INIT_WR */ | |
903 | err = iwch_modify_qp(ep->com.qp->rhp, | |
904 | ep->com.qp, mask, &attrs, 1); | |
905 | if (!err) | |
906 | goto out; | |
907 | err: | |
908 | abort_connection(ep, skb, GFP_KERNEL); | |
909 | out: | |
910 | connect_reply_upcall(ep, err); | |
911 | return; | |
912 | } | |
913 | ||
914 | static void process_mpa_request(struct iwch_ep *ep, struct sk_buff *skb) | |
915 | { | |
916 | struct mpa_message *mpa; | |
917 | u16 plen; | |
918 | ||
919 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
920 | ||
921 | /* | |
922 | * Stop mpa timer. If it expired, then the state has | |
923 | * changed and we bail since ep_timeout already aborted | |
924 | * the connection. | |
925 | */ | |
926 | stop_ep_timer(ep); | |
927 | if (state_read(&ep->com) != MPA_REQ_WAIT) | |
928 | return; | |
929 | ||
930 | /* | |
931 | * If we get more than the supported amount of private data | |
932 | * then we must fail this connection. | |
933 | */ | |
934 | if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) { | |
935 | abort_connection(ep, skb, GFP_KERNEL); | |
936 | return; | |
937 | } | |
938 | ||
939 | PDBG("%s enter (%s line %u)\n", __FUNCTION__, __FILE__, __LINE__); | |
940 | ||
941 | /* | |
942 | * Copy the new data into our accumulation buffer. | |
943 | */ | |
944 | memcpy(&(ep->mpa_pkt[ep->mpa_pkt_len]), skb->data, skb->len); | |
945 | ep->mpa_pkt_len += skb->len; | |
946 | ||
947 | /* | |
948 | * If we don't even have the mpa message, then bail. | |
949 | * We'll continue process when more data arrives. | |
950 | */ | |
951 | if (ep->mpa_pkt_len < sizeof(*mpa)) | |
952 | return; | |
953 | PDBG("%s enter (%s line %u)\n", __FUNCTION__, __FILE__, __LINE__); | |
954 | mpa = (struct mpa_message *) ep->mpa_pkt; | |
955 | ||
956 | /* | |
957 | * Validate MPA Header. | |
958 | */ | |
959 | if (mpa->revision != mpa_rev) { | |
960 | abort_connection(ep, skb, GFP_KERNEL); | |
961 | return; | |
962 | } | |
963 | ||
964 | if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) { | |
965 | abort_connection(ep, skb, GFP_KERNEL); | |
966 | return; | |
967 | } | |
968 | ||
969 | plen = ntohs(mpa->private_data_size); | |
970 | ||
971 | /* | |
972 | * Fail if there's too much private data. | |
973 | */ | |
974 | if (plen > MPA_MAX_PRIVATE_DATA) { | |
975 | abort_connection(ep, skb, GFP_KERNEL); | |
976 | return; | |
977 | } | |
978 | ||
979 | /* | |
980 | * If plen does not account for pkt size | |
981 | */ | |
982 | if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) { | |
983 | abort_connection(ep, skb, GFP_KERNEL); | |
984 | return; | |
985 | } | |
986 | ep->plen = (u8) plen; | |
987 | ||
988 | /* | |
989 | * If we don't have all the pdata yet, then bail. | |
990 | */ | |
991 | if (ep->mpa_pkt_len < (sizeof(*mpa) + plen)) | |
992 | return; | |
993 | ||
994 | /* | |
995 | * If we get here we have accumulated the entire mpa | |
996 | * start reply message including private data. | |
997 | */ | |
998 | ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0; | |
999 | ep->mpa_attr.recv_marker_enabled = markers_enabled; | |
1000 | ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0; | |
1001 | ep->mpa_attr.version = mpa_rev; | |
1002 | PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, " | |
1003 | "xmit_marker_enabled=%d, version=%d\n", __FUNCTION__, | |
1004 | ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled, | |
1005 | ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version); | |
1006 | ||
1007 | state_set(&ep->com, MPA_REQ_RCVD); | |
1008 | ||
1009 | /* drive upcall */ | |
1010 | connect_request_upcall(ep); | |
1011 | return; | |
1012 | } | |
1013 | ||
1014 | static int rx_data(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1015 | { | |
1016 | struct iwch_ep *ep = ctx; | |
1017 | struct cpl_rx_data *hdr = cplhdr(skb); | |
1018 | unsigned int dlen = ntohs(hdr->len); | |
1019 | ||
1020 | PDBG("%s ep %p dlen %u\n", __FUNCTION__, ep, dlen); | |
1021 | ||
1022 | skb_pull(skb, sizeof(*hdr)); | |
1023 | skb_trim(skb, dlen); | |
1024 | ||
1025 | switch (state_read(&ep->com)) { | |
1026 | case MPA_REQ_SENT: | |
1027 | process_mpa_reply(ep, skb); | |
1028 | break; | |
1029 | case MPA_REQ_WAIT: | |
1030 | process_mpa_request(ep, skb); | |
1031 | break; | |
1032 | case MPA_REP_SENT: | |
1033 | break; | |
1034 | default: | |
1035 | printk(KERN_ERR MOD "%s Unexpected streaming data." | |
1036 | " ep %p state %d tid %d\n", | |
1037 | __FUNCTION__, ep, state_read(&ep->com), ep->hwtid); | |
1038 | ||
1039 | /* | |
1040 | * The ep will timeout and inform the ULP of the failure. | |
1041 | * See ep_timeout(). | |
1042 | */ | |
1043 | break; | |
1044 | } | |
1045 | ||
1046 | /* update RX credits */ | |
1047 | update_rx_credits(ep, dlen); | |
1048 | ||
1049 | return CPL_RET_BUF_DONE; | |
1050 | } | |
1051 | ||
1052 | /* | |
1053 | * Upcall from the adapter indicating data has been transmitted. | |
1054 | * For us its just the single MPA request or reply. We can now free | |
1055 | * the skb holding the mpa message. | |
1056 | */ | |
1057 | static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1058 | { | |
1059 | struct iwch_ep *ep = ctx; | |
1060 | struct cpl_wr_ack *hdr = cplhdr(skb); | |
1061 | unsigned int credits = ntohs(hdr->credits); | |
1062 | enum iwch_qp_attr_mask mask; | |
1063 | ||
1064 | PDBG("%s ep %p credits %u\n", __FUNCTION__, ep, credits); | |
1065 | ||
1066 | if (credits == 0) | |
1067 | return CPL_RET_BUF_DONE; | |
1068 | BUG_ON(credits != 1); | |
1069 | BUG_ON(ep->mpa_skb == NULL); | |
1070 | kfree_skb(ep->mpa_skb); | |
1071 | ep->mpa_skb = NULL; | |
1072 | dst_confirm(ep->dst); | |
1073 | if (state_read(&ep->com) == MPA_REP_SENT) { | |
1074 | struct iwch_qp_attributes attrs; | |
1075 | ||
1076 | /* bind QP to EP and move to RTS */ | |
1077 | attrs.mpa_attr = ep->mpa_attr; | |
1078 | attrs.max_ird = ep->ord; | |
1079 | attrs.max_ord = ep->ord; | |
1080 | attrs.llp_stream_handle = ep; | |
1081 | attrs.next_state = IWCH_QP_STATE_RTS; | |
1082 | ||
1083 | /* bind QP and TID with INIT_WR */ | |
1084 | mask = IWCH_QP_ATTR_NEXT_STATE | | |
1085 | IWCH_QP_ATTR_LLP_STREAM_HANDLE | | |
1086 | IWCH_QP_ATTR_MPA_ATTR | | |
1087 | IWCH_QP_ATTR_MAX_IRD | | |
1088 | IWCH_QP_ATTR_MAX_ORD; | |
1089 | ||
1090 | ep->com.rpl_err = iwch_modify_qp(ep->com.qp->rhp, | |
1091 | ep->com.qp, mask, &attrs, 1); | |
1092 | ||
1093 | if (!ep->com.rpl_err) { | |
1094 | state_set(&ep->com, FPDU_MODE); | |
1095 | established_upcall(ep); | |
1096 | } | |
1097 | ||
1098 | ep->com.rpl_done = 1; | |
1099 | PDBG("waking up ep %p\n", ep); | |
1100 | wake_up(&ep->com.waitq); | |
1101 | } | |
1102 | return CPL_RET_BUF_DONE; | |
1103 | } | |
1104 | ||
1105 | static int abort_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1106 | { | |
1107 | struct iwch_ep *ep = ctx; | |
1108 | ||
1109 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1110 | ||
1111 | close_complete_upcall(ep); | |
1112 | state_set(&ep->com, DEAD); | |
1113 | release_ep_resources(ep); | |
1114 | return CPL_RET_BUF_DONE; | |
1115 | } | |
1116 | ||
1117 | static int act_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1118 | { | |
1119 | struct iwch_ep *ep = ctx; | |
1120 | struct cpl_act_open_rpl *rpl = cplhdr(skb); | |
1121 | ||
1122 | PDBG("%s ep %p status %u errno %d\n", __FUNCTION__, ep, rpl->status, | |
1123 | status2errno(rpl->status)); | |
1124 | connect_reply_upcall(ep, status2errno(rpl->status)); | |
1125 | state_set(&ep->com, DEAD); | |
1126 | if (ep->com.tdev->type == T3B) | |
1127 | release_tid(ep->com.tdev, GET_TID(rpl), NULL); | |
1128 | cxgb3_free_atid(ep->com.tdev, ep->atid); | |
1129 | dst_release(ep->dst); | |
1130 | l2t_release(L2DATA(ep->com.tdev), ep->l2t); | |
1131 | put_ep(&ep->com); | |
1132 | return CPL_RET_BUF_DONE; | |
1133 | } | |
1134 | ||
1135 | static int listen_start(struct iwch_listen_ep *ep) | |
1136 | { | |
1137 | struct sk_buff *skb; | |
1138 | struct cpl_pass_open_req *req; | |
1139 | ||
1140 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1141 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
1142 | if (!skb) { | |
1143 | printk(KERN_ERR MOD "t3c_listen_start failed to alloc skb!\n"); | |
1144 | return -ENOMEM; | |
1145 | } | |
1146 | ||
1147 | req = (struct cpl_pass_open_req *) skb_put(skb, sizeof(*req)); | |
1148 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
1149 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, ep->stid)); | |
1150 | req->local_port = ep->com.local_addr.sin_port; | |
1151 | req->local_ip = ep->com.local_addr.sin_addr.s_addr; | |
1152 | req->peer_port = 0; | |
1153 | req->peer_ip = 0; | |
1154 | req->peer_netmask = 0; | |
1155 | req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS); | |
1156 | req->opt0l = htonl(V_RCV_BUFSIZ(rcv_win>>10)); | |
1157 | req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK)); | |
1158 | ||
1159 | skb->priority = 1; | |
1160 | ep->com.tdev->send(ep->com.tdev, skb); | |
1161 | return 0; | |
1162 | } | |
1163 | ||
1164 | static int pass_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1165 | { | |
1166 | struct iwch_listen_ep *ep = ctx; | |
1167 | struct cpl_pass_open_rpl *rpl = cplhdr(skb); | |
1168 | ||
1169 | PDBG("%s ep %p status %d error %d\n", __FUNCTION__, ep, | |
1170 | rpl->status, status2errno(rpl->status)); | |
1171 | ep->com.rpl_err = status2errno(rpl->status); | |
1172 | ep->com.rpl_done = 1; | |
1173 | wake_up(&ep->com.waitq); | |
1174 | ||
1175 | return CPL_RET_BUF_DONE; | |
1176 | } | |
1177 | ||
1178 | static int listen_stop(struct iwch_listen_ep *ep) | |
1179 | { | |
1180 | struct sk_buff *skb; | |
1181 | struct cpl_close_listserv_req *req; | |
1182 | ||
1183 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1184 | skb = get_skb(NULL, sizeof(*req), GFP_KERNEL); | |
1185 | if (!skb) { | |
1186 | printk(KERN_ERR MOD "%s - failed to alloc skb\n", __FUNCTION__); | |
1187 | return -ENOMEM; | |
1188 | } | |
1189 | req = (struct cpl_close_listserv_req *) skb_put(skb, sizeof(*req)); | |
1190 | req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
1191 | OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, ep->stid)); | |
1192 | skb->priority = 1; | |
1193 | ep->com.tdev->send(ep->com.tdev, skb); | |
1194 | return 0; | |
1195 | } | |
1196 | ||
1197 | static int close_listsrv_rpl(struct t3cdev *tdev, struct sk_buff *skb, | |
1198 | void *ctx) | |
1199 | { | |
1200 | struct iwch_listen_ep *ep = ctx; | |
1201 | struct cpl_close_listserv_rpl *rpl = cplhdr(skb); | |
1202 | ||
1203 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1204 | ep->com.rpl_err = status2errno(rpl->status); | |
1205 | ep->com.rpl_done = 1; | |
1206 | wake_up(&ep->com.waitq); | |
1207 | return CPL_RET_BUF_DONE; | |
1208 | } | |
1209 | ||
1210 | static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb) | |
1211 | { | |
1212 | struct cpl_pass_accept_rpl *rpl; | |
1213 | unsigned int mtu_idx; | |
1214 | u32 opt0h, opt0l, opt2; | |
1215 | int wscale; | |
1216 | ||
1217 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1218 | BUG_ON(skb_cloned(skb)); | |
1219 | skb_trim(skb, sizeof(*rpl)); | |
1220 | skb_get(skb); | |
1221 | mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst)); | |
1222 | wscale = compute_wscale(rcv_win); | |
1223 | opt0h = V_NAGLE(0) | | |
1224 | V_NO_CONG(nocong) | | |
1225 | V_KEEP_ALIVE(1) | | |
1226 | F_TCAM_BYPASS | | |
1227 | V_WND_SCALE(wscale) | | |
1228 | V_MSS_IDX(mtu_idx) | | |
1229 | V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx); | |
1230 | opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10); | |
1231 | opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor); | |
1232 | ||
1233 | rpl = cplhdr(skb); | |
1234 | rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
1235 | OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, ep->hwtid)); | |
1236 | rpl->peer_ip = peer_ip; | |
1237 | rpl->opt0h = htonl(opt0h); | |
1238 | rpl->opt0l_status = htonl(opt0l | CPL_PASS_OPEN_ACCEPT); | |
1239 | rpl->opt2 = htonl(opt2); | |
1240 | rpl->rsvd = rpl->opt2; /* workaround for HW bug */ | |
1241 | skb->priority = CPL_PRIORITY_SETUP; | |
1242 | l2t_send(ep->com.tdev, skb, ep->l2t); | |
1243 | ||
1244 | return; | |
1245 | } | |
1246 | ||
1247 | static void reject_cr(struct t3cdev *tdev, u32 hwtid, __be32 peer_ip, | |
1248 | struct sk_buff *skb) | |
1249 | { | |
1250 | PDBG("%s t3cdev %p tid %u peer_ip %x\n", __FUNCTION__, tdev, hwtid, | |
1251 | peer_ip); | |
1252 | BUG_ON(skb_cloned(skb)); | |
1253 | skb_trim(skb, sizeof(struct cpl_tid_release)); | |
1254 | skb_get(skb); | |
1255 | ||
1256 | if (tdev->type == T3B) | |
1257 | release_tid(tdev, hwtid, skb); | |
1258 | else { | |
1259 | struct cpl_pass_accept_rpl *rpl; | |
1260 | ||
1261 | rpl = cplhdr(skb); | |
1262 | skb->priority = CPL_PRIORITY_SETUP; | |
1263 | rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD)); | |
1264 | OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, | |
1265 | hwtid)); | |
1266 | rpl->peer_ip = peer_ip; | |
1267 | rpl->opt0h = htonl(F_TCAM_BYPASS); | |
1268 | rpl->opt0l_status = htonl(CPL_PASS_OPEN_REJECT); | |
1269 | rpl->opt2 = 0; | |
1270 | rpl->rsvd = rpl->opt2; | |
1271 | tdev->send(tdev, skb); | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1276 | { | |
1277 | struct iwch_ep *child_ep, *parent_ep = ctx; | |
1278 | struct cpl_pass_accept_req *req = cplhdr(skb); | |
1279 | unsigned int hwtid = GET_TID(req); | |
1280 | struct dst_entry *dst; | |
1281 | struct l2t_entry *l2t; | |
1282 | struct rtable *rt; | |
1283 | struct iff_mac tim; | |
1284 | ||
1285 | PDBG("%s parent ep %p tid %u\n", __FUNCTION__, parent_ep, hwtid); | |
1286 | ||
1287 | if (state_read(&parent_ep->com) != LISTEN) { | |
1288 | printk(KERN_ERR "%s - listening ep not in LISTEN\n", | |
1289 | __FUNCTION__); | |
1290 | goto reject; | |
1291 | } | |
1292 | ||
1293 | /* | |
1294 | * Find the netdev for this connection request. | |
1295 | */ | |
1296 | tim.mac_addr = req->dst_mac; | |
1297 | tim.vlan_tag = ntohs(req->vlan_tag); | |
1298 | if (tdev->ctl(tdev, GET_IFF_FROM_MAC, &tim) < 0 || !tim.dev) { | |
1299 | printk(KERN_ERR | |
1300 | "%s bad dst mac %02x %02x %02x %02x %02x %02x\n", | |
1301 | __FUNCTION__, | |
1302 | req->dst_mac[0], | |
1303 | req->dst_mac[1], | |
1304 | req->dst_mac[2], | |
1305 | req->dst_mac[3], | |
1306 | req->dst_mac[4], | |
1307 | req->dst_mac[5]); | |
1308 | goto reject; | |
1309 | } | |
1310 | ||
1311 | /* Find output route */ | |
1312 | rt = find_route(tdev, | |
1313 | req->local_ip, | |
1314 | req->peer_ip, | |
1315 | req->local_port, | |
1316 | req->peer_port, G_PASS_OPEN_TOS(ntohl(req->tos_tid))); | |
1317 | if (!rt) { | |
1318 | printk(KERN_ERR MOD "%s - failed to find dst entry!\n", | |
1319 | __FUNCTION__); | |
1320 | goto reject; | |
1321 | } | |
1322 | dst = &rt->u.dst; | |
1323 | l2t = t3_l2t_get(tdev, dst->neighbour, dst->neighbour->dev); | |
1324 | if (!l2t) { | |
1325 | printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n", | |
1326 | __FUNCTION__); | |
1327 | dst_release(dst); | |
1328 | goto reject; | |
1329 | } | |
1330 | child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL); | |
1331 | if (!child_ep) { | |
1332 | printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n", | |
1333 | __FUNCTION__); | |
1334 | l2t_release(L2DATA(tdev), l2t); | |
1335 | dst_release(dst); | |
1336 | goto reject; | |
1337 | } | |
1338 | state_set(&child_ep->com, CONNECTING); | |
1339 | child_ep->com.tdev = tdev; | |
1340 | child_ep->com.cm_id = NULL; | |
1341 | child_ep->com.local_addr.sin_family = PF_INET; | |
1342 | child_ep->com.local_addr.sin_port = req->local_port; | |
1343 | child_ep->com.local_addr.sin_addr.s_addr = req->local_ip; | |
1344 | child_ep->com.remote_addr.sin_family = PF_INET; | |
1345 | child_ep->com.remote_addr.sin_port = req->peer_port; | |
1346 | child_ep->com.remote_addr.sin_addr.s_addr = req->peer_ip; | |
1347 | get_ep(&parent_ep->com); | |
1348 | child_ep->parent_ep = parent_ep; | |
1349 | child_ep->tos = G_PASS_OPEN_TOS(ntohl(req->tos_tid)); | |
1350 | child_ep->l2t = l2t; | |
1351 | child_ep->dst = dst; | |
1352 | child_ep->hwtid = hwtid; | |
1353 | init_timer(&child_ep->timer); | |
1354 | cxgb3_insert_tid(tdev, &t3c_client, child_ep, hwtid); | |
1355 | accept_cr(child_ep, req->peer_ip, skb); | |
1356 | goto out; | |
1357 | reject: | |
1358 | reject_cr(tdev, hwtid, req->peer_ip, skb); | |
1359 | out: | |
1360 | return CPL_RET_BUF_DONE; | |
1361 | } | |
1362 | ||
1363 | static int pass_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1364 | { | |
1365 | struct iwch_ep *ep = ctx; | |
1366 | struct cpl_pass_establish *req = cplhdr(skb); | |
1367 | ||
1368 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1369 | ep->snd_seq = ntohl(req->snd_isn); | |
1370 | ||
1371 | set_emss(ep, ntohs(req->tcp_opt)); | |
1372 | ||
1373 | dst_confirm(ep->dst); | |
1374 | state_set(&ep->com, MPA_REQ_WAIT); | |
1375 | start_ep_timer(ep); | |
1376 | ||
1377 | return CPL_RET_BUF_DONE; | |
1378 | } | |
1379 | ||
1380 | static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1381 | { | |
1382 | struct iwch_ep *ep = ctx; | |
1383 | struct iwch_qp_attributes attrs; | |
1384 | unsigned long flags; | |
1385 | int disconnect = 1; | |
1386 | int release = 0; | |
1387 | ||
1388 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1389 | dst_confirm(ep->dst); | |
1390 | ||
1391 | spin_lock_irqsave(&ep->com.lock, flags); | |
1392 | switch (ep->com.state) { | |
1393 | case MPA_REQ_WAIT: | |
1394 | __state_set(&ep->com, CLOSING); | |
1395 | break; | |
1396 | case MPA_REQ_SENT: | |
1397 | __state_set(&ep->com, CLOSING); | |
1398 | connect_reply_upcall(ep, -ECONNRESET); | |
1399 | break; | |
1400 | case MPA_REQ_RCVD: | |
1401 | ||
1402 | /* | |
1403 | * We're gonna mark this puppy DEAD, but keep | |
1404 | * the reference on it until the ULP accepts or | |
1405 | * rejects the CR. | |
1406 | */ | |
1407 | __state_set(&ep->com, CLOSING); | |
1408 | get_ep(&ep->com); | |
1409 | break; | |
1410 | case MPA_REP_SENT: | |
1411 | __state_set(&ep->com, CLOSING); | |
1412 | ep->com.rpl_done = 1; | |
1413 | ep->com.rpl_err = -ECONNRESET; | |
1414 | PDBG("waking up ep %p\n", ep); | |
1415 | wake_up(&ep->com.waitq); | |
1416 | break; | |
1417 | case FPDU_MODE: | |
42e31753 | 1418 | start_ep_timer(ep); |
b038ced7 SW |
1419 | __state_set(&ep->com, CLOSING); |
1420 | attrs.next_state = IWCH_QP_STATE_CLOSING; | |
1421 | iwch_modify_qp(ep->com.qp->rhp, ep->com.qp, | |
1422 | IWCH_QP_ATTR_NEXT_STATE, &attrs, 1); | |
1423 | peer_close_upcall(ep); | |
1424 | break; | |
1425 | case ABORTING: | |
1426 | disconnect = 0; | |
1427 | break; | |
1428 | case CLOSING: | |
b038ced7 SW |
1429 | __state_set(&ep->com, MORIBUND); |
1430 | disconnect = 0; | |
1431 | break; | |
1432 | case MORIBUND: | |
1433 | stop_ep_timer(ep); | |
1434 | if (ep->com.cm_id && ep->com.qp) { | |
1435 | attrs.next_state = IWCH_QP_STATE_IDLE; | |
1436 | iwch_modify_qp(ep->com.qp->rhp, ep->com.qp, | |
1437 | IWCH_QP_ATTR_NEXT_STATE, &attrs, 1); | |
1438 | } | |
1439 | close_complete_upcall(ep); | |
1440 | __state_set(&ep->com, DEAD); | |
1441 | release = 1; | |
1442 | disconnect = 0; | |
1443 | break; | |
1444 | case DEAD: | |
1445 | disconnect = 0; | |
1446 | break; | |
1447 | default: | |
1448 | BUG_ON(1); | |
1449 | } | |
1450 | spin_unlock_irqrestore(&ep->com.lock, flags); | |
1451 | if (disconnect) | |
1452 | iwch_ep_disconnect(ep, 0, GFP_KERNEL); | |
1453 | if (release) | |
1454 | release_ep_resources(ep); | |
1455 | return CPL_RET_BUF_DONE; | |
1456 | } | |
1457 | ||
1458 | /* | |
1459 | * Returns whether an ABORT_REQ_RSS message is a negative advice. | |
1460 | */ | |
2b540355 | 1461 | static int is_neg_adv_abort(unsigned int status) |
b038ced7 SW |
1462 | { |
1463 | return status == CPL_ERR_RTX_NEG_ADVICE || | |
1464 | status == CPL_ERR_PERSIST_NEG_ADVICE; | |
1465 | } | |
1466 | ||
1467 | static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1468 | { | |
1469 | struct cpl_abort_req_rss *req = cplhdr(skb); | |
1470 | struct iwch_ep *ep = ctx; | |
1471 | struct cpl_abort_rpl *rpl; | |
1472 | struct sk_buff *rpl_skb; | |
1473 | struct iwch_qp_attributes attrs; | |
1474 | int ret; | |
1475 | int state; | |
1476 | ||
1477 | if (is_neg_adv_abort(req->status)) { | |
1478 | PDBG("%s neg_adv_abort ep %p tid %d\n", __FUNCTION__, ep, | |
1479 | ep->hwtid); | |
1480 | t3_l2t_send_event(ep->com.tdev, ep->l2t); | |
1481 | return CPL_RET_BUF_DONE; | |
1482 | } | |
1483 | ||
1484 | state = state_read(&ep->com); | |
1485 | PDBG("%s ep %p state %u\n", __FUNCTION__, ep, state); | |
1486 | switch (state) { | |
1487 | case CONNECTING: | |
1488 | break; | |
1489 | case MPA_REQ_WAIT: | |
1490 | break; | |
1491 | case MPA_REQ_SENT: | |
1492 | connect_reply_upcall(ep, -ECONNRESET); | |
1493 | break; | |
1494 | case MPA_REP_SENT: | |
1495 | ep->com.rpl_done = 1; | |
1496 | ep->com.rpl_err = -ECONNRESET; | |
1497 | PDBG("waking up ep %p\n", ep); | |
1498 | wake_up(&ep->com.waitq); | |
1499 | break; | |
1500 | case MPA_REQ_RCVD: | |
1501 | ||
1502 | /* | |
1503 | * We're gonna mark this puppy DEAD, but keep | |
1504 | * the reference on it until the ULP accepts or | |
1505 | * rejects the CR. | |
1506 | */ | |
1507 | get_ep(&ep->com); | |
1508 | break; | |
1509 | case MORIBUND: | |
42e31753 | 1510 | case CLOSING: |
b038ced7 | 1511 | stop_ep_timer(ep); |
42e31753 | 1512 | /*FALLTHROUGH*/ |
b038ced7 | 1513 | case FPDU_MODE: |
b038ced7 SW |
1514 | if (ep->com.cm_id && ep->com.qp) { |
1515 | attrs.next_state = IWCH_QP_STATE_ERROR; | |
1516 | ret = iwch_modify_qp(ep->com.qp->rhp, | |
1517 | ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, | |
1518 | &attrs, 1); | |
1519 | if (ret) | |
1520 | printk(KERN_ERR MOD | |
1521 | "%s - qp <- error failed!\n", | |
1522 | __FUNCTION__); | |
1523 | } | |
1524 | peer_abort_upcall(ep); | |
1525 | break; | |
1526 | case ABORTING: | |
1527 | break; | |
1528 | case DEAD: | |
1529 | PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __FUNCTION__); | |
1530 | return CPL_RET_BUF_DONE; | |
1531 | default: | |
1532 | BUG_ON(1); | |
1533 | break; | |
1534 | } | |
1535 | dst_confirm(ep->dst); | |
1536 | ||
1537 | rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL); | |
1538 | if (!rpl_skb) { | |
1539 | printk(KERN_ERR MOD "%s - cannot allocate skb!\n", | |
1540 | __FUNCTION__); | |
1541 | dst_release(ep->dst); | |
1542 | l2t_release(L2DATA(ep->com.tdev), ep->l2t); | |
1543 | put_ep(&ep->com); | |
1544 | return CPL_RET_BUF_DONE; | |
1545 | } | |
1546 | rpl_skb->priority = CPL_PRIORITY_DATA; | |
1547 | rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl)); | |
1548 | rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL)); | |
1549 | rpl->wr.wr_lo = htonl(V_WR_TID(ep->hwtid)); | |
1550 | OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid)); | |
1551 | rpl->cmd = CPL_ABORT_NO_RST; | |
1552 | ep->com.tdev->send(ep->com.tdev, rpl_skb); | |
1553 | if (state != ABORTING) { | |
1554 | state_set(&ep->com, DEAD); | |
1555 | release_ep_resources(ep); | |
1556 | } | |
1557 | return CPL_RET_BUF_DONE; | |
1558 | } | |
1559 | ||
1560 | static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1561 | { | |
1562 | struct iwch_ep *ep = ctx; | |
1563 | struct iwch_qp_attributes attrs; | |
1564 | unsigned long flags; | |
1565 | int release = 0; | |
1566 | ||
1567 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1568 | BUG_ON(!ep); | |
1569 | ||
1570 | /* The cm_id may be null if we failed to connect */ | |
1571 | spin_lock_irqsave(&ep->com.lock, flags); | |
1572 | switch (ep->com.state) { | |
1573 | case CLOSING: | |
b038ced7 SW |
1574 | __state_set(&ep->com, MORIBUND); |
1575 | break; | |
1576 | case MORIBUND: | |
1577 | stop_ep_timer(ep); | |
1578 | if ((ep->com.cm_id) && (ep->com.qp)) { | |
1579 | attrs.next_state = IWCH_QP_STATE_IDLE; | |
1580 | iwch_modify_qp(ep->com.qp->rhp, | |
1581 | ep->com.qp, | |
1582 | IWCH_QP_ATTR_NEXT_STATE, | |
1583 | &attrs, 1); | |
1584 | } | |
1585 | close_complete_upcall(ep); | |
1586 | __state_set(&ep->com, DEAD); | |
1587 | release = 1; | |
1588 | break; | |
42e31753 SW |
1589 | case ABORTING: |
1590 | break; | |
b038ced7 SW |
1591 | case DEAD: |
1592 | default: | |
1593 | BUG_ON(1); | |
1594 | break; | |
1595 | } | |
1596 | spin_unlock_irqrestore(&ep->com.lock, flags); | |
1597 | if (release) | |
1598 | release_ep_resources(ep); | |
1599 | return CPL_RET_BUF_DONE; | |
1600 | } | |
1601 | ||
1602 | /* | |
1603 | * T3A does 3 things when a TERM is received: | |
1604 | * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet | |
1605 | * 2) generate an async event on the QP with the TERMINATE opcode | |
1606 | * 3) post a TERMINATE opcde cqe into the associated CQ. | |
1607 | * | |
1608 | * For (1), we save the message in the qp for later consumer consumption. | |
1609 | * For (2), we move the QP into TERMINATE, post a QP event and disconnect. | |
1610 | * For (3), we toss the CQE in cxio_poll_cq(). | |
1611 | * | |
1612 | * terminate() handles case (1)... | |
1613 | */ | |
1614 | static int terminate(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1615 | { | |
1616 | struct iwch_ep *ep = ctx; | |
1617 | ||
1618 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1619 | skb_pull(skb, sizeof(struct cpl_rdma_terminate)); | |
1620 | PDBG("%s saving %d bytes of term msg\n", __FUNCTION__, skb->len); | |
1621 | memcpy(ep->com.qp->attr.terminate_buffer, skb->data, skb->len); | |
1622 | ep->com.qp->attr.terminate_msg_len = skb->len; | |
1623 | ep->com.qp->attr.is_terminate_local = 0; | |
1624 | return CPL_RET_BUF_DONE; | |
1625 | } | |
1626 | ||
1627 | static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
1628 | { | |
1629 | struct cpl_rdma_ec_status *rep = cplhdr(skb); | |
1630 | struct iwch_ep *ep = ctx; | |
1631 | ||
1632 | PDBG("%s ep %p tid %u status %d\n", __FUNCTION__, ep, ep->hwtid, | |
1633 | rep->status); | |
1634 | if (rep->status) { | |
1635 | struct iwch_qp_attributes attrs; | |
1636 | ||
1637 | printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n", | |
1638 | __FUNCTION__, ep->hwtid); | |
2f236735 | 1639 | stop_ep_timer(ep); |
b038ced7 SW |
1640 | attrs.next_state = IWCH_QP_STATE_ERROR; |
1641 | iwch_modify_qp(ep->com.qp->rhp, | |
1642 | ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, | |
1643 | &attrs, 1); | |
1644 | abort_connection(ep, NULL, GFP_KERNEL); | |
1645 | } | |
1646 | return CPL_RET_BUF_DONE; | |
1647 | } | |
1648 | ||
1649 | static void ep_timeout(unsigned long arg) | |
1650 | { | |
1651 | struct iwch_ep *ep = (struct iwch_ep *)arg; | |
1652 | struct iwch_qp_attributes attrs; | |
1653 | unsigned long flags; | |
1654 | ||
1655 | spin_lock_irqsave(&ep->com.lock, flags); | |
1656 | PDBG("%s ep %p tid %u state %d\n", __FUNCTION__, ep, ep->hwtid, | |
1657 | ep->com.state); | |
1658 | switch (ep->com.state) { | |
1659 | case MPA_REQ_SENT: | |
1660 | connect_reply_upcall(ep, -ETIMEDOUT); | |
1661 | break; | |
1662 | case MPA_REQ_WAIT: | |
1663 | break; | |
42e31753 | 1664 | case CLOSING: |
b038ced7 SW |
1665 | case MORIBUND: |
1666 | if (ep->com.cm_id && ep->com.qp) { | |
1667 | attrs.next_state = IWCH_QP_STATE_ERROR; | |
1668 | iwch_modify_qp(ep->com.qp->rhp, | |
1669 | ep->com.qp, IWCH_QP_ATTR_NEXT_STATE, | |
1670 | &attrs, 1); | |
1671 | } | |
1672 | break; | |
1673 | default: | |
1674 | BUG(); | |
1675 | } | |
1676 | __state_set(&ep->com, CLOSING); | |
1677 | spin_unlock_irqrestore(&ep->com.lock, flags); | |
1678 | abort_connection(ep, NULL, GFP_ATOMIC); | |
1679 | put_ep(&ep->com); | |
1680 | } | |
1681 | ||
1682 | int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len) | |
1683 | { | |
1684 | int err; | |
1685 | struct iwch_ep *ep = to_ep(cm_id); | |
1686 | PDBG("%s ep %p tid %u\n", __FUNCTION__, ep, ep->hwtid); | |
1687 | ||
1688 | if (state_read(&ep->com) == DEAD) { | |
1689 | put_ep(&ep->com); | |
1690 | return -ECONNRESET; | |
1691 | } | |
1692 | BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD); | |
b038ced7 SW |
1693 | if (mpa_rev == 0) |
1694 | abort_connection(ep, NULL, GFP_KERNEL); | |
1695 | else { | |
1696 | err = send_mpa_reject(ep, pdata, pdata_len); | |
7d526e6b | 1697 | err = iwch_ep_disconnect(ep, 0, GFP_KERNEL); |
b038ced7 SW |
1698 | } |
1699 | return 0; | |
1700 | } | |
1701 | ||
1702 | int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) | |
1703 | { | |
1704 | int err; | |
1705 | struct iwch_qp_attributes attrs; | |
1706 | enum iwch_qp_attr_mask mask; | |
1707 | struct iwch_ep *ep = to_ep(cm_id); | |
1708 | struct iwch_dev *h = to_iwch_dev(cm_id->device); | |
1709 | struct iwch_qp *qp = get_qhp(h, conn_param->qpn); | |
1710 | ||
1711 | PDBG("%s ep %p tid %u\n", __FUNCTION__, ep, ep->hwtid); | |
1712 | if (state_read(&ep->com) == DEAD) { | |
1713 | put_ep(&ep->com); | |
1714 | return -ECONNRESET; | |
1715 | } | |
1716 | ||
1717 | BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD); | |
1718 | BUG_ON(!qp); | |
1719 | ||
1720 | if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) || | |
1721 | (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) { | |
1722 | abort_connection(ep, NULL, GFP_KERNEL); | |
1723 | return -EINVAL; | |
1724 | } | |
1725 | ||
1726 | cm_id->add_ref(cm_id); | |
1727 | ep->com.cm_id = cm_id; | |
1728 | ep->com.qp = qp; | |
1729 | ||
1730 | ep->com.rpl_done = 0; | |
1731 | ep->com.rpl_err = 0; | |
1732 | ep->ird = conn_param->ird; | |
1733 | ep->ord = conn_param->ord; | |
1734 | PDBG("%s %d ird %d ord %d\n", __FUNCTION__, __LINE__, ep->ird, ep->ord); | |
1735 | get_ep(&ep->com); | |
1736 | err = send_mpa_reply(ep, conn_param->private_data, | |
1737 | conn_param->private_data_len); | |
1738 | if (err) { | |
1739 | ep->com.cm_id = NULL; | |
1740 | ep->com.qp = NULL; | |
1741 | cm_id->rem_ref(cm_id); | |
1742 | abort_connection(ep, NULL, GFP_KERNEL); | |
1743 | put_ep(&ep->com); | |
1744 | return err; | |
1745 | } | |
1746 | ||
1747 | /* bind QP to EP and move to RTS */ | |
1748 | attrs.mpa_attr = ep->mpa_attr; | |
1749 | attrs.max_ird = ep->ord; | |
1750 | attrs.max_ord = ep->ord; | |
1751 | attrs.llp_stream_handle = ep; | |
1752 | attrs.next_state = IWCH_QP_STATE_RTS; | |
1753 | ||
1754 | /* bind QP and TID with INIT_WR */ | |
1755 | mask = IWCH_QP_ATTR_NEXT_STATE | | |
1756 | IWCH_QP_ATTR_LLP_STREAM_HANDLE | | |
1757 | IWCH_QP_ATTR_MPA_ATTR | | |
1758 | IWCH_QP_ATTR_MAX_IRD | | |
1759 | IWCH_QP_ATTR_MAX_ORD; | |
1760 | ||
1761 | err = iwch_modify_qp(ep->com.qp->rhp, | |
1762 | ep->com.qp, mask, &attrs, 1); | |
1763 | ||
1764 | if (err) { | |
1765 | ep->com.cm_id = NULL; | |
1766 | ep->com.qp = NULL; | |
1767 | cm_id->rem_ref(cm_id); | |
1768 | abort_connection(ep, NULL, GFP_KERNEL); | |
1769 | } else { | |
1770 | state_set(&ep->com, FPDU_MODE); | |
1771 | established_upcall(ep); | |
1772 | } | |
1773 | put_ep(&ep->com); | |
1774 | return err; | |
1775 | } | |
1776 | ||
1777 | int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) | |
1778 | { | |
1779 | int err = 0; | |
1780 | struct iwch_dev *h = to_iwch_dev(cm_id->device); | |
1781 | struct iwch_ep *ep; | |
1782 | struct rtable *rt; | |
1783 | ||
1784 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); | |
1785 | if (!ep) { | |
1786 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __FUNCTION__); | |
1787 | err = -ENOMEM; | |
1788 | goto out; | |
1789 | } | |
1790 | init_timer(&ep->timer); | |
1791 | ep->plen = conn_param->private_data_len; | |
1792 | if (ep->plen) | |
1793 | memcpy(ep->mpa_pkt + sizeof(struct mpa_message), | |
1794 | conn_param->private_data, ep->plen); | |
1795 | ep->ird = conn_param->ird; | |
1796 | ep->ord = conn_param->ord; | |
1797 | ep->com.tdev = h->rdev.t3cdev_p; | |
1798 | ||
1799 | cm_id->add_ref(cm_id); | |
1800 | ep->com.cm_id = cm_id; | |
1801 | ep->com.qp = get_qhp(h, conn_param->qpn); | |
1802 | BUG_ON(!ep->com.qp); | |
1803 | PDBG("%s qpn 0x%x qp %p cm_id %p\n", __FUNCTION__, conn_param->qpn, | |
1804 | ep->com.qp, cm_id); | |
1805 | ||
1806 | /* | |
1807 | * Allocate an active TID to initiate a TCP connection. | |
1808 | */ | |
1809 | ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep); | |
1810 | if (ep->atid == -1) { | |
1811 | printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __FUNCTION__); | |
1812 | err = -ENOMEM; | |
1813 | goto fail2; | |
1814 | } | |
1815 | ||
1816 | /* find a route */ | |
1817 | rt = find_route(h->rdev.t3cdev_p, | |
1818 | cm_id->local_addr.sin_addr.s_addr, | |
1819 | cm_id->remote_addr.sin_addr.s_addr, | |
1820 | cm_id->local_addr.sin_port, | |
1821 | cm_id->remote_addr.sin_port, IPTOS_LOWDELAY); | |
1822 | if (!rt) { | |
1823 | printk(KERN_ERR MOD "%s - cannot find route.\n", __FUNCTION__); | |
1824 | err = -EHOSTUNREACH; | |
1825 | goto fail3; | |
1826 | } | |
1827 | ep->dst = &rt->u.dst; | |
1828 | ||
1829 | /* get a l2t entry */ | |
1830 | ep->l2t = t3_l2t_get(ep->com.tdev, ep->dst->neighbour, | |
1831 | ep->dst->neighbour->dev); | |
1832 | if (!ep->l2t) { | |
1833 | printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __FUNCTION__); | |
1834 | err = -ENOMEM; | |
1835 | goto fail4; | |
1836 | } | |
1837 | ||
1838 | state_set(&ep->com, CONNECTING); | |
1839 | ep->tos = IPTOS_LOWDELAY; | |
1840 | ep->com.local_addr = cm_id->local_addr; | |
1841 | ep->com.remote_addr = cm_id->remote_addr; | |
1842 | ||
1843 | /* send connect request to rnic */ | |
1844 | err = send_connect(ep); | |
1845 | if (!err) | |
1846 | goto out; | |
1847 | ||
1848 | l2t_release(L2DATA(h->rdev.t3cdev_p), ep->l2t); | |
1849 | fail4: | |
1850 | dst_release(ep->dst); | |
1851 | fail3: | |
1852 | cxgb3_free_atid(ep->com.tdev, ep->atid); | |
1853 | fail2: | |
1854 | put_ep(&ep->com); | |
1855 | out: | |
1856 | return err; | |
1857 | } | |
1858 | ||
1859 | int iwch_create_listen(struct iw_cm_id *cm_id, int backlog) | |
1860 | { | |
1861 | int err = 0; | |
1862 | struct iwch_dev *h = to_iwch_dev(cm_id->device); | |
1863 | struct iwch_listen_ep *ep; | |
1864 | ||
1865 | ||
1866 | might_sleep(); | |
1867 | ||
1868 | ep = alloc_ep(sizeof(*ep), GFP_KERNEL); | |
1869 | if (!ep) { | |
1870 | printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __FUNCTION__); | |
1871 | err = -ENOMEM; | |
1872 | goto fail1; | |
1873 | } | |
1874 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1875 | ep->com.tdev = h->rdev.t3cdev_p; | |
1876 | cm_id->add_ref(cm_id); | |
1877 | ep->com.cm_id = cm_id; | |
1878 | ep->backlog = backlog; | |
1879 | ep->com.local_addr = cm_id->local_addr; | |
1880 | ||
1881 | /* | |
1882 | * Allocate a server TID. | |
1883 | */ | |
1884 | ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep); | |
1885 | if (ep->stid == -1) { | |
1886 | printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __FUNCTION__); | |
1887 | err = -ENOMEM; | |
1888 | goto fail2; | |
1889 | } | |
1890 | ||
1891 | state_set(&ep->com, LISTEN); | |
1892 | err = listen_start(ep); | |
1893 | if (err) | |
1894 | goto fail3; | |
1895 | ||
1896 | /* wait for pass_open_rpl */ | |
1897 | wait_event(ep->com.waitq, ep->com.rpl_done); | |
1898 | err = ep->com.rpl_err; | |
1899 | if (!err) { | |
1900 | cm_id->provider_data = ep; | |
1901 | goto out; | |
1902 | } | |
1903 | fail3: | |
1904 | cxgb3_free_stid(ep->com.tdev, ep->stid); | |
1905 | fail2: | |
1906 | put_ep(&ep->com); | |
1907 | fail1: | |
1908 | out: | |
1909 | return err; | |
1910 | } | |
1911 | ||
1912 | int iwch_destroy_listen(struct iw_cm_id *cm_id) | |
1913 | { | |
1914 | int err; | |
1915 | struct iwch_listen_ep *ep = to_listen_ep(cm_id); | |
1916 | ||
1917 | PDBG("%s ep %p\n", __FUNCTION__, ep); | |
1918 | ||
1919 | might_sleep(); | |
1920 | state_set(&ep->com, DEAD); | |
1921 | ep->com.rpl_done = 0; | |
1922 | ep->com.rpl_err = 0; | |
1923 | err = listen_stop(ep); | |
1924 | wait_event(ep->com.waitq, ep->com.rpl_done); | |
1925 | cxgb3_free_stid(ep->com.tdev, ep->stid); | |
1926 | err = ep->com.rpl_err; | |
1927 | cm_id->rem_ref(cm_id); | |
1928 | put_ep(&ep->com); | |
1929 | return err; | |
1930 | } | |
1931 | ||
1932 | int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp) | |
1933 | { | |
1934 | int ret=0; | |
1935 | unsigned long flags; | |
1936 | int close = 0; | |
1937 | ||
1938 | spin_lock_irqsave(&ep->com.lock, flags); | |
1939 | ||
1940 | PDBG("%s ep %p state %s, abrupt %d\n", __FUNCTION__, ep, | |
1941 | states[ep->com.state], abrupt); | |
1942 | ||
1943 | if (ep->com.state == DEAD) { | |
1944 | PDBG("%s already dead ep %p\n", __FUNCTION__, ep); | |
1945 | goto out; | |
1946 | } | |
1947 | ||
1948 | if (abrupt) { | |
1949 | if (ep->com.state != ABORTING) { | |
1950 | ep->com.state = ABORTING; | |
1951 | close = 1; | |
1952 | } | |
1953 | goto out; | |
1954 | } | |
1955 | ||
1956 | switch (ep->com.state) { | |
1957 | case MPA_REQ_WAIT: | |
1958 | case MPA_REQ_SENT: | |
1959 | case MPA_REQ_RCVD: | |
1960 | case MPA_REP_SENT: | |
1961 | case FPDU_MODE: | |
42e31753 | 1962 | start_ep_timer(ep); |
b038ced7 SW |
1963 | ep->com.state = CLOSING; |
1964 | close = 1; | |
1965 | break; | |
1966 | case CLOSING: | |
b038ced7 SW |
1967 | ep->com.state = MORIBUND; |
1968 | close = 1; | |
1969 | break; | |
1970 | case MORIBUND: | |
1971 | break; | |
1972 | default: | |
1973 | BUG(); | |
1974 | break; | |
1975 | } | |
1976 | out: | |
1977 | spin_unlock_irqrestore(&ep->com.lock, flags); | |
1978 | if (close) { | |
1979 | if (abrupt) | |
1980 | ret = send_abort(ep, NULL, gfp); | |
1981 | else | |
1982 | ret = send_halfclose(ep, gfp); | |
1983 | } | |
1984 | return ret; | |
1985 | } | |
1986 | ||
1987 | int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new, | |
1988 | struct l2t_entry *l2t) | |
1989 | { | |
1990 | struct iwch_ep *ep = ctx; | |
1991 | ||
1992 | if (ep->dst != old) | |
1993 | return 0; | |
1994 | ||
1995 | PDBG("%s ep %p redirect to dst %p l2t %p\n", __FUNCTION__, ep, new, | |
1996 | l2t); | |
1997 | dst_hold(new); | |
1998 | l2t_release(L2DATA(ep->com.tdev), ep->l2t); | |
1999 | ep->l2t = l2t; | |
2000 | dst_release(old); | |
2001 | ep->dst = new; | |
2002 | return 1; | |
2003 | } | |
2004 | ||
2005 | /* | |
2006 | * All the CM events are handled on a work queue to have a safe context. | |
2007 | */ | |
2008 | static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx) | |
2009 | { | |
2010 | struct iwch_ep_common *epc = ctx; | |
2011 | ||
2012 | get_ep(epc); | |
2013 | ||
2014 | /* | |
2015 | * Save ctx and tdev in the skb->cb area. | |
2016 | */ | |
2017 | *((void **) skb->cb) = ctx; | |
2018 | *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev; | |
2019 | ||
2020 | /* | |
2021 | * Queue the skb and schedule the worker thread. | |
2022 | */ | |
2023 | skb_queue_tail(&rxq, skb); | |
2024 | queue_work(workq, &skb_work); | |
2025 | return 0; | |
2026 | } | |
2027 | ||
2028 | int __init iwch_cm_init(void) | |
2029 | { | |
2030 | skb_queue_head_init(&rxq); | |
2031 | ||
2032 | workq = create_singlethread_workqueue("iw_cxgb3"); | |
2033 | if (!workq) | |
2034 | return -ENOMEM; | |
2035 | ||
2036 | /* | |
2037 | * All upcalls from the T3 Core go to sched() to | |
2038 | * schedule the processing on a work queue. | |
2039 | */ | |
2040 | t3c_handlers[CPL_ACT_ESTABLISH] = sched; | |
2041 | t3c_handlers[CPL_ACT_OPEN_RPL] = sched; | |
2042 | t3c_handlers[CPL_RX_DATA] = sched; | |
2043 | t3c_handlers[CPL_TX_DMA_ACK] = sched; | |
2044 | t3c_handlers[CPL_ABORT_RPL_RSS] = sched; | |
2045 | t3c_handlers[CPL_ABORT_RPL] = sched; | |
2046 | t3c_handlers[CPL_PASS_OPEN_RPL] = sched; | |
2047 | t3c_handlers[CPL_CLOSE_LISTSRV_RPL] = sched; | |
2048 | t3c_handlers[CPL_PASS_ACCEPT_REQ] = sched; | |
2049 | t3c_handlers[CPL_PASS_ESTABLISH] = sched; | |
2050 | t3c_handlers[CPL_PEER_CLOSE] = sched; | |
2051 | t3c_handlers[CPL_CLOSE_CON_RPL] = sched; | |
2052 | t3c_handlers[CPL_ABORT_REQ_RSS] = sched; | |
2053 | t3c_handlers[CPL_RDMA_TERMINATE] = sched; | |
2054 | t3c_handlers[CPL_RDMA_EC_STATUS] = sched; | |
2055 | ||
2056 | /* | |
2057 | * These are the real handlers that are called from a | |
2058 | * work queue. | |
2059 | */ | |
2060 | work_handlers[CPL_ACT_ESTABLISH] = act_establish; | |
2061 | work_handlers[CPL_ACT_OPEN_RPL] = act_open_rpl; | |
2062 | work_handlers[CPL_RX_DATA] = rx_data; | |
2063 | work_handlers[CPL_TX_DMA_ACK] = tx_ack; | |
2064 | work_handlers[CPL_ABORT_RPL_RSS] = abort_rpl; | |
2065 | work_handlers[CPL_ABORT_RPL] = abort_rpl; | |
2066 | work_handlers[CPL_PASS_OPEN_RPL] = pass_open_rpl; | |
2067 | work_handlers[CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl; | |
2068 | work_handlers[CPL_PASS_ACCEPT_REQ] = pass_accept_req; | |
2069 | work_handlers[CPL_PASS_ESTABLISH] = pass_establish; | |
2070 | work_handlers[CPL_PEER_CLOSE] = peer_close; | |
2071 | work_handlers[CPL_ABORT_REQ_RSS] = peer_abort; | |
2072 | work_handlers[CPL_CLOSE_CON_RPL] = close_con_rpl; | |
2073 | work_handlers[CPL_RDMA_TERMINATE] = terminate; | |
2074 | work_handlers[CPL_RDMA_EC_STATUS] = ec_status; | |
2075 | return 0; | |
2076 | } | |
2077 | ||
2078 | void __exit iwch_cm_term(void) | |
2079 | { | |
2080 | flush_workqueue(workq); | |
2081 | destroy_workqueue(workq); | |
2082 | } |