blob: abd683ea326d4746622057708050f38cedca9b3d [file] [log] [blame]
Steve Wiseb038ced2007-02-12 16:16:18 -08001/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
Steve Wiseb038ced2007-02-12 16:16:18 -08003 *
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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090034#include <linux/slab.h>
Steve Wiseb038ced2007-02-12 16:16:18 -080035#include <linux/workqueue.h>
36#include <linux/skbuff.h>
37#include <linux/timer.h>
38#include <linux/notifier.h>
Steve Wise8704e9a2008-02-12 16:09:29 -060039#include <linux/inetdevice.h>
Steve Wiseb038ced2007-02-12 16:16:18 -080040
41#include <net/neighbour.h>
42#include <net/netevent.h>
43#include <net/route.h>
44
45#include "tcb.h"
46#include "cxgb3_offload.h"
47#include "iwch.h"
48#include "iwch_provider.h"
49#include "iwch_cm.h"
50
51static char *states[] = {
52 "idle",
53 "listen",
54 "connecting",
55 "mpa_wait_req",
56 "mpa_req_sent",
57 "mpa_req_rcvd",
58 "mpa_rep_sent",
59 "fpdu_mode",
60 "aborting",
61 "closing",
62 "moribund",
63 "dead",
64 NULL,
65};
66
Steve Wisef8b0dfd2008-04-29 13:46:52 -070067int peer2peer = 0;
68module_param(peer2peer, int, 0644);
69MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
70
Steve Wise77a8d572008-05-02 10:57:09 -070071static int ep_timeout_secs = 60;
Steve Wisee54664c2007-07-29 15:12:26 -050072module_param(ep_timeout_secs, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080073MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
Steve Wise77a8d572008-05-02 10:57:09 -070074 "in seconds (default=60)");
Steve Wiseb038ced2007-02-12 16:16:18 -080075
76static int mpa_rev = 1;
Steve Wisee54664c2007-07-29 15:12:26 -050077module_param(mpa_rev, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080078MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
79 "1 is spec compliant. (default=1)");
80
81static int markers_enabled = 0;
Steve Wisee54664c2007-07-29 15:12:26 -050082module_param(markers_enabled, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080083MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
84
85static int crc_enabled = 1;
Steve Wisee54664c2007-07-29 15:12:26 -050086module_param(crc_enabled, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080087MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
88
89static int rcv_win = 256 * 1024;
Steve Wisee54664c2007-07-29 15:12:26 -050090module_param(rcv_win, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080091MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256)");
92
93static int snd_win = 32 * 1024;
Steve Wisee54664c2007-07-29 15:12:26 -050094module_param(snd_win, int, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080095MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=32KB)");
96
97static unsigned int nocong = 0;
Steve Wisee54664c2007-07-29 15:12:26 -050098module_param(nocong, uint, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -080099MODULE_PARM_DESC(nocong, "Turn off congestion control (default=0)");
100
101static unsigned int cong_flavor = 1;
Steve Wisee54664c2007-07-29 15:12:26 -0500102module_param(cong_flavor, uint, 0644);
Steve Wiseb038ced2007-02-12 16:16:18 -0800103MODULE_PARM_DESC(cong_flavor, "TCP Congestion control flavor (default=1)");
104
Steve Wiseb038ced2007-02-12 16:16:18 -0800105static struct workqueue_struct *workq;
Steve Wiseb038ced2007-02-12 16:16:18 -0800106
107static struct sk_buff_head rxq;
Steve Wiseb038ced2007-02-12 16:16:18 -0800108
109static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
110static void ep_timeout(unsigned long arg);
111static void connect_reply_upcall(struct iwch_ep *ep, int status);
112
113static void start_ep_timer(struct iwch_ep *ep)
114{
Harvey Harrison33718362008-04-16 21:01:10 -0700115 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800116 if (timer_pending(&ep->timer)) {
Harvey Harrison33718362008-04-16 21:01:10 -0700117 PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800118 del_timer_sync(&ep->timer);
119 } else
120 get_ep(&ep->com);
121 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
122 ep->timer.data = (unsigned long)ep;
123 ep->timer.function = ep_timeout;
124 add_timer(&ep->timer);
125}
126
127static void stop_ep_timer(struct iwch_ep *ep)
128{
Harvey Harrison33718362008-04-16 21:01:10 -0700129 PDBG("%s ep %p\n", __func__, ep);
Steve Wise989a1782008-04-29 13:46:51 -0700130 if (!timer_pending(&ep->timer)) {
131 printk(KERN_ERR "%s timer stopped when its not running! ep %p state %u\n",
132 __func__, ep, ep->com.state);
133 WARN_ON(1);
134 return;
135 }
Steve Wiseb038ced2007-02-12 16:16:18 -0800136 del_timer_sync(&ep->timer);
137 put_ep(&ep->com);
138}
139
Steve Wise04b5d022009-03-30 08:37:56 -0700140int iwch_l2t_send(struct t3cdev *tdev, struct sk_buff *skb, struct l2t_entry *l2e)
141{
142 int error = 0;
143 struct cxio_rdev *rdev;
144
145 rdev = (struct cxio_rdev *)tdev->ulp;
146 if (cxio_fatal_error(rdev)) {
147 kfree_skb(skb);
148 return -EIO;
149 }
150 error = l2t_send(tdev, skb, l2e);
Steve Wise73a203d2010-04-05 19:59:57 +0000151 if (error < 0)
Steve Wise04b5d022009-03-30 08:37:56 -0700152 kfree_skb(skb);
153 return error;
154}
155
156int iwch_cxgb3_ofld_send(struct t3cdev *tdev, struct sk_buff *skb)
157{
158 int error = 0;
159 struct cxio_rdev *rdev;
160
161 rdev = (struct cxio_rdev *)tdev->ulp;
162 if (cxio_fatal_error(rdev)) {
163 kfree_skb(skb);
164 return -EIO;
165 }
166 error = cxgb3_ofld_send(tdev, skb);
Steve Wise73a203d2010-04-05 19:59:57 +0000167 if (error < 0)
Steve Wise04b5d022009-03-30 08:37:56 -0700168 kfree_skb(skb);
169 return error;
170}
171
Steve Wiseb038ced2007-02-12 16:16:18 -0800172static void release_tid(struct t3cdev *tdev, u32 hwtid, struct sk_buff *skb)
173{
174 struct cpl_tid_release *req;
175
176 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
177 if (!skb)
178 return;
179 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
180 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
181 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
182 skb->priority = CPL_PRIORITY_SETUP;
Steve Wise04b5d022009-03-30 08:37:56 -0700183 iwch_cxgb3_ofld_send(tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800184 return;
185}
186
187int iwch_quiesce_tid(struct iwch_ep *ep)
188{
189 struct cpl_set_tcb_field *req;
190 struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
191
192 if (!skb)
193 return -ENOMEM;
194 req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req));
195 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
196 req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
197 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid));
198 req->reply = 0;
199 req->cpu_idx = 0;
200 req->word = htons(W_TCB_RX_QUIESCE);
201 req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE);
202 req->val = cpu_to_be64(1 << S_TCB_RX_QUIESCE);
203
204 skb->priority = CPL_PRIORITY_DATA;
Steve Wise04b5d022009-03-30 08:37:56 -0700205 return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800206}
207
208int iwch_resume_tid(struct iwch_ep *ep)
209{
210 struct cpl_set_tcb_field *req;
211 struct sk_buff *skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
212
213 if (!skb)
214 return -ENOMEM;
215 req = (struct cpl_set_tcb_field *) skb_put(skb, sizeof(*req));
216 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
217 req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
218 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_SET_TCB_FIELD, ep->hwtid));
219 req->reply = 0;
220 req->cpu_idx = 0;
221 req->word = htons(W_TCB_RX_QUIESCE);
222 req->mask = cpu_to_be64(1ULL << S_TCB_RX_QUIESCE);
223 req->val = 0;
224
225 skb->priority = CPL_PRIORITY_DATA;
Steve Wise04b5d022009-03-30 08:37:56 -0700226 return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800227}
228
229static void set_emss(struct iwch_ep *ep, u16 opt)
230{
Harvey Harrison33718362008-04-16 21:01:10 -0700231 PDBG("%s ep %p opt %u\n", __func__, ep, opt);
Steve Wiseb038ced2007-02-12 16:16:18 -0800232 ep->emss = T3C_DATA(ep->com.tdev)->mtus[G_TCPOPT_MSS(opt)] - 40;
233 if (G_TCPOPT_TSTAMP(opt))
234 ep->emss -= 12;
235 if (ep->emss < 128)
236 ep->emss = 128;
237 PDBG("emss=%d\n", ep->emss);
238}
239
240static enum iwch_ep_state state_read(struct iwch_ep_common *epc)
241{
242 unsigned long flags;
243 enum iwch_ep_state state;
244
245 spin_lock_irqsave(&epc->lock, flags);
246 state = epc->state;
247 spin_unlock_irqrestore(&epc->lock, flags);
248 return state;
249}
250
Adrian Bunk2b540352007-02-21 11:52:49 +0100251static void __state_set(struct iwch_ep_common *epc, enum iwch_ep_state new)
Steve Wiseb038ced2007-02-12 16:16:18 -0800252{
253 epc->state = new;
254}
255
256static void state_set(struct iwch_ep_common *epc, enum iwch_ep_state new)
257{
258 unsigned long flags;
259
260 spin_lock_irqsave(&epc->lock, flags);
Harvey Harrison33718362008-04-16 21:01:10 -0700261 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
Steve Wiseb038ced2007-02-12 16:16:18 -0800262 __state_set(epc, new);
263 spin_unlock_irqrestore(&epc->lock, flags);
264 return;
265}
266
267static void *alloc_ep(int size, gfp_t gfp)
268{
269 struct iwch_ep_common *epc;
270
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700271 epc = kzalloc(size, gfp);
Steve Wiseb038ced2007-02-12 16:16:18 -0800272 if (epc) {
Steve Wiseb038ced2007-02-12 16:16:18 -0800273 kref_init(&epc->kref);
274 spin_lock_init(&epc->lock);
275 init_waitqueue_head(&epc->waitq);
276 }
Harvey Harrison33718362008-04-16 21:01:10 -0700277 PDBG("%s alloc ep %p\n", __func__, epc);
Steve Wiseb038ced2007-02-12 16:16:18 -0800278 return epc;
279}
280
281void __free_ep(struct kref *kref)
282{
Steve Wise874d8df2009-03-30 08:37:59 -0700283 struct iwch_ep *ep;
284 ep = container_of(container_of(kref, struct iwch_ep_common, kref),
285 struct iwch_ep, com);
286 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Steve Wise6e47fe42009-09-05 20:22:38 -0700287 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Steve Wise874d8df2009-03-30 08:37:59 -0700288 cxgb3_remove_tid(ep->com.tdev, (void *)ep, ep->hwtid);
289 dst_release(ep->dst);
290 l2t_release(L2DATA(ep->com.tdev), ep->l2t);
291 }
292 kfree(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800293}
294
295static void release_ep_resources(struct iwch_ep *ep)
296{
Harvey Harrison33718362008-04-16 21:01:10 -0700297 PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
Steve Wise6e47fe42009-09-05 20:22:38 -0700298 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Steve Wiseb038ced2007-02-12 16:16:18 -0800299 put_ep(&ep->com);
300}
301
Steve Wiseb038ced2007-02-12 16:16:18 -0800302static int status2errno(int status)
303{
304 switch (status) {
305 case CPL_ERR_NONE:
306 return 0;
307 case CPL_ERR_CONN_RESET:
308 return -ECONNRESET;
309 case CPL_ERR_ARP_MISS:
310 return -EHOSTUNREACH;
311 case CPL_ERR_CONN_TIMEDOUT:
312 return -ETIMEDOUT;
313 case CPL_ERR_TCAM_FULL:
314 return -ENOMEM;
315 case CPL_ERR_CONN_EXIST:
316 return -EADDRINUSE;
317 default:
318 return -EIO;
319 }
320}
321
322/*
323 * Try and reuse skbs already allocated...
324 */
325static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
326{
Steve Wise1f6a8492007-03-06 14:44:05 -0600327 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
Steve Wiseb038ced2007-02-12 16:16:18 -0800328 skb_trim(skb, 0);
329 skb_get(skb);
330 } else {
331 skb = alloc_skb(len, gfp);
332 }
333 return skb;
334}
335
336static struct rtable *find_route(struct t3cdev *dev, __be32 local_ip,
337 __be32 peer_ip, __be16 local_port,
338 __be16 peer_port, u8 tos)
339{
340 struct rtable *rt;
341 struct flowi fl = {
342 .oif = 0,
343 .nl_u = {
344 .ip4_u = {
345 .daddr = peer_ip,
346 .saddr = local_ip,
347 .tos = tos}
348 },
349 .proto = IPPROTO_TCP,
350 .uli_u = {
351 .ports = {
352 .sport = local_port,
353 .dport = peer_port}
354 }
355 };
356
Denis V. Lunevf1b050b2008-01-22 22:07:10 -0800357 if (ip_route_output_flow(&init_net, &rt, &fl, NULL, 0))
Steve Wiseb038ced2007-02-12 16:16:18 -0800358 return NULL;
359 return rt;
360}
361
362static unsigned int find_best_mtu(const struct t3c_data *d, unsigned short mtu)
363{
364 int i = 0;
365
366 while (i < d->nmtus - 1 && d->mtus[i + 1] <= mtu)
367 ++i;
368 return i;
369}
370
371static void arp_failure_discard(struct t3cdev *dev, struct sk_buff *skb)
372{
Harvey Harrison33718362008-04-16 21:01:10 -0700373 PDBG("%s t3cdev %p\n", __func__, dev);
Steve Wiseb038ced2007-02-12 16:16:18 -0800374 kfree_skb(skb);
375}
376
377/*
378 * Handle an ARP failure for an active open.
379 */
380static void act_open_req_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
381{
382 printk(KERN_ERR MOD "ARP failure duing connect\n");
383 kfree_skb(skb);
384}
385
386/*
387 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
388 * and send it along.
389 */
390static void abort_arp_failure(struct t3cdev *dev, struct sk_buff *skb)
391{
392 struct cpl_abort_req *req = cplhdr(skb);
393
Harvey Harrison33718362008-04-16 21:01:10 -0700394 PDBG("%s t3cdev %p\n", __func__, dev);
Steve Wiseb038ced2007-02-12 16:16:18 -0800395 req->cmd = CPL_ABORT_NO_RST;
Steve Wise04b5d022009-03-30 08:37:56 -0700396 iwch_cxgb3_ofld_send(dev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800397}
398
399static int send_halfclose(struct iwch_ep *ep, gfp_t gfp)
400{
401 struct cpl_close_con_req *req;
402 struct sk_buff *skb;
403
Harvey Harrison33718362008-04-16 21:01:10 -0700404 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800405 skb = get_skb(NULL, sizeof(*req), gfp);
406 if (!skb) {
Harvey Harrison33718362008-04-16 21:01:10 -0700407 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800408 return -ENOMEM;
409 }
410 skb->priority = CPL_PRIORITY_DATA;
411 set_arp_failure_handler(skb, arp_failure_discard);
412 req = (struct cpl_close_con_req *) skb_put(skb, sizeof(*req));
413 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_CLOSE_CON));
414 req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
415 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_CON_REQ, ep->hwtid));
Steve Wise04b5d022009-03-30 08:37:56 -0700416 return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800417}
418
419static int send_abort(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
420{
421 struct cpl_abort_req *req;
422
Harvey Harrison33718362008-04-16 21:01:10 -0700423 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800424 skb = get_skb(skb, sizeof(*req), gfp);
425 if (!skb) {
426 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
Harvey Harrison33718362008-04-16 21:01:10 -0700427 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800428 return -ENOMEM;
429 }
430 skb->priority = CPL_PRIORITY_DATA;
431 set_arp_failure_handler(skb, abort_arp_failure);
432 req = (struct cpl_abort_req *) skb_put(skb, sizeof(*req));
433 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_REQ));
434 req->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
435 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
436 req->cmd = CPL_ABORT_SEND_RST;
Steve Wise04b5d022009-03-30 08:37:56 -0700437 return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800438}
439
440static int send_connect(struct iwch_ep *ep)
441{
442 struct cpl_act_open_req *req;
443 struct sk_buff *skb;
444 u32 opt0h, opt0l, opt2;
445 unsigned int mtu_idx;
446 int wscale;
447
Harvey Harrison33718362008-04-16 21:01:10 -0700448 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800449
450 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
451 if (!skb) {
452 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
Harvey Harrison33718362008-04-16 21:01:10 -0700453 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800454 return -ENOMEM;
455 }
456 mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
457 wscale = compute_wscale(rcv_win);
458 opt0h = V_NAGLE(0) |
459 V_NO_CONG(nocong) |
460 V_KEEP_ALIVE(1) |
461 F_TCAM_BYPASS |
462 V_WND_SCALE(wscale) |
463 V_MSS_IDX(mtu_idx) |
464 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
465 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
466 opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor);
467 skb->priority = CPL_PRIORITY_SETUP;
468 set_arp_failure_handler(skb, act_open_req_arp_failure);
469
470 req = (struct cpl_act_open_req *) skb_put(skb, sizeof(*req));
471 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
472 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ep->atid));
473 req->local_port = ep->com.local_addr.sin_port;
474 req->peer_port = ep->com.remote_addr.sin_port;
475 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
476 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
477 req->opt0h = htonl(opt0h);
478 req->opt0l = htonl(opt0l);
479 req->params = 0;
480 req->opt2 = htonl(opt2);
Steve Wise04b5d022009-03-30 08:37:56 -0700481 return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800482}
483
484static void send_mpa_req(struct iwch_ep *ep, struct sk_buff *skb)
485{
486 int mpalen;
487 struct tx_data_wr *req;
488 struct mpa_message *mpa;
489 int len;
490
Harvey Harrison33718362008-04-16 21:01:10 -0700491 PDBG("%s ep %p pd_len %d\n", __func__, ep, ep->plen);
Steve Wiseb038ced2007-02-12 16:16:18 -0800492
493 BUG_ON(skb_cloned(skb));
494
495 mpalen = sizeof(*mpa) + ep->plen;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -0700496 if (skb->data + mpalen + sizeof(*req) > skb_end_pointer(skb)) {
Steve Wiseb038ced2007-02-12 16:16:18 -0800497 kfree_skb(skb);
498 skb=alloc_skb(mpalen + sizeof(*req), GFP_KERNEL);
499 if (!skb) {
500 connect_reply_upcall(ep, -ENOMEM);
501 return;
502 }
503 }
504 skb_trim(skb, 0);
505 skb_reserve(skb, sizeof(*req));
506 skb_put(skb, mpalen);
507 skb->priority = CPL_PRIORITY_DATA;
508 mpa = (struct mpa_message *) skb->data;
509 memset(mpa, 0, sizeof(*mpa));
510 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
511 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
512 (markers_enabled ? MPA_MARKERS : 0);
513 mpa->private_data_size = htons(ep->plen);
514 mpa->revision = mpa_rev;
515
516 if (ep->plen)
517 memcpy(mpa->private_data, ep->mpa_pkt + sizeof(*mpa), ep->plen);
518
519 /*
520 * Reference the mpa skb. This ensures the data area
521 * will remain in memory until the hw acks the tx.
522 * Function tx_ack() will deref it.
523 */
524 skb_get(skb);
525 set_arp_failure_handler(skb, arp_failure_discard);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300526 skb_reset_transport_header(skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800527 len = skb->len;
528 req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700529 req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
Steve Wiseb038ced2007-02-12 16:16:18 -0800530 req->wr_lo = htonl(V_WR_TID(ep->hwtid));
531 req->len = htonl(len);
532 req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
533 V_TX_SNDBUF(snd_win>>15));
Steve Wisede3d3532007-05-14 13:27:27 -0500534 req->flags = htonl(F_TX_INIT);
Steve Wiseb038ced2007-02-12 16:16:18 -0800535 req->sndseq = htonl(ep->snd_seq);
536 BUG_ON(ep->mpa_skb);
537 ep->mpa_skb = skb;
Steve Wise04b5d022009-03-30 08:37:56 -0700538 iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800539 start_ep_timer(ep);
540 state_set(&ep->com, MPA_REQ_SENT);
541 return;
542}
543
544static int send_mpa_reject(struct iwch_ep *ep, const void *pdata, u8 plen)
545{
546 int mpalen;
547 struct tx_data_wr *req;
548 struct mpa_message *mpa;
549 struct sk_buff *skb;
550
Harvey Harrison33718362008-04-16 21:01:10 -0700551 PDBG("%s ep %p plen %d\n", __func__, ep, plen);
Steve Wiseb038ced2007-02-12 16:16:18 -0800552
553 mpalen = sizeof(*mpa) + plen;
554
555 skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
556 if (!skb) {
Harvey Harrison33718362008-04-16 21:01:10 -0700557 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800558 return -ENOMEM;
559 }
560 skb_reserve(skb, sizeof(*req));
561 mpa = (struct mpa_message *) skb_put(skb, mpalen);
562 memset(mpa, 0, sizeof(*mpa));
563 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
564 mpa->flags = MPA_REJECT;
565 mpa->revision = mpa_rev;
566 mpa->private_data_size = htons(plen);
567 if (plen)
568 memcpy(mpa->private_data, pdata, plen);
569
570 /*
571 * Reference the mpa skb again. This ensures the data area
572 * will remain in memory until the hw acks the tx.
573 * Function tx_ack() will deref it.
574 */
575 skb_get(skb);
576 skb->priority = CPL_PRIORITY_DATA;
577 set_arp_failure_handler(skb, arp_failure_discard);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300578 skb_reset_transport_header(skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800579 req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700580 req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
Steve Wiseb038ced2007-02-12 16:16:18 -0800581 req->wr_lo = htonl(V_WR_TID(ep->hwtid));
582 req->len = htonl(mpalen);
583 req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
584 V_TX_SNDBUF(snd_win>>15));
Steve Wisede3d3532007-05-14 13:27:27 -0500585 req->flags = htonl(F_TX_INIT);
Steve Wiseb038ced2007-02-12 16:16:18 -0800586 req->sndseq = htonl(ep->snd_seq);
587 BUG_ON(ep->mpa_skb);
588 ep->mpa_skb = skb;
Steve Wise04b5d022009-03-30 08:37:56 -0700589 return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800590}
591
592static int send_mpa_reply(struct iwch_ep *ep, const void *pdata, u8 plen)
593{
594 int mpalen;
595 struct tx_data_wr *req;
596 struct mpa_message *mpa;
597 int len;
598 struct sk_buff *skb;
599
Harvey Harrison33718362008-04-16 21:01:10 -0700600 PDBG("%s ep %p plen %d\n", __func__, ep, plen);
Steve Wiseb038ced2007-02-12 16:16:18 -0800601
602 mpalen = sizeof(*mpa) + plen;
603
604 skb = get_skb(NULL, mpalen + sizeof(*req), GFP_KERNEL);
605 if (!skb) {
Harvey Harrison33718362008-04-16 21:01:10 -0700606 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800607 return -ENOMEM;
608 }
609 skb->priority = CPL_PRIORITY_DATA;
610 skb_reserve(skb, sizeof(*req));
611 mpa = (struct mpa_message *) skb_put(skb, mpalen);
612 memset(mpa, 0, sizeof(*mpa));
613 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
614 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
615 (markers_enabled ? MPA_MARKERS : 0);
616 mpa->revision = mpa_rev;
617 mpa->private_data_size = htons(plen);
618 if (plen)
619 memcpy(mpa->private_data, pdata, plen);
620
621 /*
622 * Reference the mpa skb. This ensures the data area
623 * will remain in memory until the hw acks the tx.
624 * Function tx_ack() will deref it.
625 */
626 skb_get(skb);
627 set_arp_failure_handler(skb, arp_failure_discard);
Arnaldo Carvalho de Melobadff6d2007-03-13 13:06:52 -0300628 skb_reset_transport_header(skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800629 len = skb->len;
630 req = (struct tx_data_wr *) skb_push(skb, sizeof(*req));
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700631 req->wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_TX_DATA)|F_WR_COMPL);
Steve Wiseb038ced2007-02-12 16:16:18 -0800632 req->wr_lo = htonl(V_WR_TID(ep->hwtid));
633 req->len = htonl(len);
634 req->param = htonl(V_TX_PORT(ep->l2t->smt_idx) |
635 V_TX_SNDBUF(snd_win>>15));
Steve Wisede3d3532007-05-14 13:27:27 -0500636 req->flags = htonl(F_TX_INIT);
Steve Wiseb038ced2007-02-12 16:16:18 -0800637 req->sndseq = htonl(ep->snd_seq);
638 ep->mpa_skb = skb;
639 state_set(&ep->com, MPA_REP_SENT);
Steve Wise04b5d022009-03-30 08:37:56 -0700640 return iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -0800641}
642
643static int act_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
644{
645 struct iwch_ep *ep = ctx;
646 struct cpl_act_establish *req = cplhdr(skb);
647 unsigned int tid = GET_TID(req);
648
Harvey Harrison33718362008-04-16 21:01:10 -0700649 PDBG("%s ep %p tid %d\n", __func__, ep, tid);
Steve Wiseb038ced2007-02-12 16:16:18 -0800650
651 dst_confirm(ep->dst);
652
653 /* setup the hwtid for this connection */
654 ep->hwtid = tid;
655 cxgb3_insert_tid(ep->com.tdev, &t3c_client, ep, tid);
656
657 ep->snd_seq = ntohl(req->snd_isn);
Steve Wisede3d3532007-05-14 13:27:27 -0500658 ep->rcv_seq = ntohl(req->rcv_isn);
Steve Wiseb038ced2007-02-12 16:16:18 -0800659
660 set_emss(ep, ntohs(req->tcp_opt));
661
662 /* dealloc the atid */
663 cxgb3_free_atid(ep->com.tdev, ep->atid);
664
665 /* start MPA negotiation */
666 send_mpa_req(ep, skb);
667
668 return 0;
669}
670
671static void abort_connection(struct iwch_ep *ep, struct sk_buff *skb, gfp_t gfp)
672{
673 PDBG("%s ep %p\n", __FILE__, ep);
674 state_set(&ep->com, ABORTING);
675 send_abort(ep, skb, gfp);
676}
677
678static void close_complete_upcall(struct iwch_ep *ep)
679{
680 struct iw_cm_event event;
681
Harvey Harrison33718362008-04-16 21:01:10 -0700682 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800683 memset(&event, 0, sizeof(event));
684 event.event = IW_CM_EVENT_CLOSE;
685 if (ep->com.cm_id) {
686 PDBG("close complete delivered ep %p cm_id %p tid %d\n",
687 ep, ep->com.cm_id, ep->hwtid);
688 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
689 ep->com.cm_id->rem_ref(ep->com.cm_id);
690 ep->com.cm_id = NULL;
691 ep->com.qp = NULL;
692 }
693}
694
695static void peer_close_upcall(struct iwch_ep *ep)
696{
697 struct iw_cm_event event;
698
Harvey Harrison33718362008-04-16 21:01:10 -0700699 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800700 memset(&event, 0, sizeof(event));
701 event.event = IW_CM_EVENT_DISCONNECT;
702 if (ep->com.cm_id) {
703 PDBG("peer close delivered ep %p cm_id %p tid %d\n",
704 ep, ep->com.cm_id, ep->hwtid);
705 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
706 }
707}
708
709static void peer_abort_upcall(struct iwch_ep *ep)
710{
711 struct iw_cm_event event;
712
Harvey Harrison33718362008-04-16 21:01:10 -0700713 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800714 memset(&event, 0, sizeof(event));
715 event.event = IW_CM_EVENT_CLOSE;
716 event.status = -ECONNRESET;
717 if (ep->com.cm_id) {
718 PDBG("abort delivered ep %p cm_id %p tid %d\n", ep,
719 ep->com.cm_id, ep->hwtid);
720 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
721 ep->com.cm_id->rem_ref(ep->com.cm_id);
722 ep->com.cm_id = NULL;
723 ep->com.qp = NULL;
724 }
725}
726
727static void connect_reply_upcall(struct iwch_ep *ep, int status)
728{
729 struct iw_cm_event event;
730
Harvey Harrison33718362008-04-16 21:01:10 -0700731 PDBG("%s ep %p status %d\n", __func__, ep, status);
Steve Wiseb038ced2007-02-12 16:16:18 -0800732 memset(&event, 0, sizeof(event));
733 event.event = IW_CM_EVENT_CONNECT_REPLY;
734 event.status = status;
735 event.local_addr = ep->com.local_addr;
736 event.remote_addr = ep->com.remote_addr;
737
738 if ((status == 0) || (status == -ECONNREFUSED)) {
739 event.private_data_len = ep->plen;
740 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
741 }
742 if (ep->com.cm_id) {
Harvey Harrison33718362008-04-16 21:01:10 -0700743 PDBG("%s ep %p tid %d status %d\n", __func__, ep,
Steve Wiseb038ced2007-02-12 16:16:18 -0800744 ep->hwtid, status);
745 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
746 }
747 if (status < 0) {
748 ep->com.cm_id->rem_ref(ep->com.cm_id);
749 ep->com.cm_id = NULL;
750 ep->com.qp = NULL;
751 }
752}
753
754static void connect_request_upcall(struct iwch_ep *ep)
755{
756 struct iw_cm_event event;
757
Harvey Harrison33718362008-04-16 21:01:10 -0700758 PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
Steve Wiseb038ced2007-02-12 16:16:18 -0800759 memset(&event, 0, sizeof(event));
760 event.event = IW_CM_EVENT_CONNECT_REQUEST;
761 event.local_addr = ep->com.local_addr;
762 event.remote_addr = ep->com.remote_addr;
763 event.private_data_len = ep->plen;
764 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
765 event.provider_data = ep;
Steve Wise6e47fe42009-09-05 20:22:38 -0700766 if (state_read(&ep->parent_ep->com) != DEAD) {
767 get_ep(&ep->com);
Steve Wiseb038ced2007-02-12 16:16:18 -0800768 ep->parent_ep->com.cm_id->event_handler(
769 ep->parent_ep->com.cm_id,
770 &event);
Steve Wise6e47fe42009-09-05 20:22:38 -0700771 }
Steve Wiseb038ced2007-02-12 16:16:18 -0800772 put_ep(&ep->parent_ep->com);
773 ep->parent_ep = NULL;
774}
775
776static void established_upcall(struct iwch_ep *ep)
777{
778 struct iw_cm_event event;
779
Harvey Harrison33718362008-04-16 21:01:10 -0700780 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800781 memset(&event, 0, sizeof(event));
782 event.event = IW_CM_EVENT_ESTABLISHED;
783 if (ep->com.cm_id) {
Harvey Harrison33718362008-04-16 21:01:10 -0700784 PDBG("%s ep %p tid %d\n", __func__, ep, ep->hwtid);
Steve Wiseb038ced2007-02-12 16:16:18 -0800785 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
786 }
787}
788
789static int update_rx_credits(struct iwch_ep *ep, u32 credits)
790{
791 struct cpl_rx_data_ack *req;
792 struct sk_buff *skb;
793
Harvey Harrison33718362008-04-16 21:01:10 -0700794 PDBG("%s ep %p credits %u\n", __func__, ep, credits);
Steve Wiseb038ced2007-02-12 16:16:18 -0800795 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
796 if (!skb) {
797 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
798 return 0;
799 }
800
801 req = (struct cpl_rx_data_ack *) skb_put(skb, sizeof(*req));
802 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
803 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_RX_DATA_ACK, ep->hwtid));
804 req->credit_dack = htonl(V_RX_CREDITS(credits) | V_RX_FORCE_ACK(1));
805 skb->priority = CPL_PRIORITY_ACK;
Steve Wise04b5d022009-03-30 08:37:56 -0700806 iwch_cxgb3_ofld_send(ep->com.tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -0800807 return credits;
808}
809
810static void process_mpa_reply(struct iwch_ep *ep, struct sk_buff *skb)
811{
812 struct mpa_message *mpa;
813 u16 plen;
814 struct iwch_qp_attributes attrs;
815 enum iwch_qp_attr_mask mask;
816 int err;
817
Harvey Harrison33718362008-04-16 21:01:10 -0700818 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800819
820 /*
821 * Stop mpa timer. If it expired, then the state has
822 * changed and we bail since ep_timeout already aborted
823 * the connection.
824 */
825 stop_ep_timer(ep);
826 if (state_read(&ep->com) != MPA_REQ_SENT)
827 return;
828
829 /*
830 * If we get more than the supported amount of private data
831 * then we must fail this connection.
832 */
833 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
834 err = -EINVAL;
835 goto err;
836 }
837
838 /*
839 * copy the new data into our accumulation buffer.
840 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300841 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
842 skb->len);
Steve Wiseb038ced2007-02-12 16:16:18 -0800843 ep->mpa_pkt_len += skb->len;
844
845 /*
846 * if we don't even have the mpa message, then bail.
847 */
848 if (ep->mpa_pkt_len < sizeof(*mpa))
849 return;
850 mpa = (struct mpa_message *) ep->mpa_pkt;
851
852 /* Validate MPA header. */
853 if (mpa->revision != mpa_rev) {
854 err = -EPROTO;
855 goto err;
856 }
857 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
858 err = -EPROTO;
859 goto err;
860 }
861
862 plen = ntohs(mpa->private_data_size);
863
864 /*
865 * Fail if there's too much private data.
866 */
867 if (plen > MPA_MAX_PRIVATE_DATA) {
868 err = -EPROTO;
869 goto err;
870 }
871
872 /*
873 * If plen does not account for pkt size
874 */
875 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
876 err = -EPROTO;
877 goto err;
878 }
879
880 ep->plen = (u8) plen;
881
882 /*
883 * If we don't have all the pdata yet, then bail.
884 * We'll continue process when more data arrives.
885 */
886 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
887 return;
888
889 if (mpa->flags & MPA_REJECT) {
890 err = -ECONNREFUSED;
891 goto err;
892 }
893
894 /*
895 * If we get here we have accumulated the entire mpa
896 * start reply message including private data. And
897 * the MPA header is valid.
898 */
899 state_set(&ep->com, FPDU_MODE);
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700900 ep->mpa_attr.initiator = 1;
Steve Wiseb038ced2007-02-12 16:16:18 -0800901 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
902 ep->mpa_attr.recv_marker_enabled = markers_enabled;
903 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
904 ep->mpa_attr.version = mpa_rev;
905 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Harvey Harrison33718362008-04-16 21:01:10 -0700906 "xmit_marker_enabled=%d, version=%d\n", __func__,
Steve Wiseb038ced2007-02-12 16:16:18 -0800907 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
908 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
909
910 attrs.mpa_attr = ep->mpa_attr;
911 attrs.max_ird = ep->ird;
912 attrs.max_ord = ep->ord;
913 attrs.llp_stream_handle = ep;
914 attrs.next_state = IWCH_QP_STATE_RTS;
915
916 mask = IWCH_QP_ATTR_NEXT_STATE |
917 IWCH_QP_ATTR_LLP_STREAM_HANDLE | IWCH_QP_ATTR_MPA_ATTR |
918 IWCH_QP_ATTR_MAX_IRD | IWCH_QP_ATTR_MAX_ORD;
919
920 /* bind QP and TID with INIT_WR */
921 err = iwch_modify_qp(ep->com.qp->rhp,
922 ep->com.qp, mask, &attrs, 1);
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700923 if (err)
924 goto err;
925
926 if (peer2peer && iwch_rqes_posted(ep->com.qp) == 0) {
927 iwch_post_zb_read(ep->com.qp);
928 }
929
930 goto out;
Steve Wiseb038ced2007-02-12 16:16:18 -0800931err:
932 abort_connection(ep, skb, GFP_KERNEL);
933out:
934 connect_reply_upcall(ep, err);
935 return;
936}
937
938static void process_mpa_request(struct iwch_ep *ep, struct sk_buff *skb)
939{
940 struct mpa_message *mpa;
941 u16 plen;
942
Harvey Harrison33718362008-04-16 21:01:10 -0700943 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -0800944
945 /*
946 * Stop mpa timer. If it expired, then the state has
947 * changed and we bail since ep_timeout already aborted
948 * the connection.
949 */
950 stop_ep_timer(ep);
951 if (state_read(&ep->com) != MPA_REQ_WAIT)
952 return;
953
954 /*
955 * If we get more than the supported amount of private data
956 * then we must fail this connection.
957 */
958 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
959 abort_connection(ep, skb, GFP_KERNEL);
960 return;
961 }
962
Harvey Harrison33718362008-04-16 21:01:10 -0700963 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800964
965 /*
966 * Copy the new data into our accumulation buffer.
967 */
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -0300968 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
969 skb->len);
Steve Wiseb038ced2007-02-12 16:16:18 -0800970 ep->mpa_pkt_len += skb->len;
971
972 /*
973 * If we don't even have the mpa message, then bail.
974 * We'll continue process when more data arrives.
975 */
976 if (ep->mpa_pkt_len < sizeof(*mpa))
977 return;
Harvey Harrison33718362008-04-16 21:01:10 -0700978 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wiseb038ced2007-02-12 16:16:18 -0800979 mpa = (struct mpa_message *) ep->mpa_pkt;
980
981 /*
982 * Validate MPA Header.
983 */
984 if (mpa->revision != mpa_rev) {
985 abort_connection(ep, skb, GFP_KERNEL);
986 return;
987 }
988
989 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
990 abort_connection(ep, skb, GFP_KERNEL);
991 return;
992 }
993
994 plen = ntohs(mpa->private_data_size);
995
996 /*
997 * Fail if there's too much private data.
998 */
999 if (plen > MPA_MAX_PRIVATE_DATA) {
1000 abort_connection(ep, skb, GFP_KERNEL);
1001 return;
1002 }
1003
1004 /*
1005 * If plen does not account for pkt size
1006 */
1007 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1008 abort_connection(ep, skb, GFP_KERNEL);
1009 return;
1010 }
1011 ep->plen = (u8) plen;
1012
1013 /*
1014 * If we don't have all the pdata yet, then bail.
1015 */
1016 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1017 return;
1018
1019 /*
1020 * If we get here we have accumulated the entire mpa
1021 * start reply message including private data.
1022 */
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001023 ep->mpa_attr.initiator = 0;
Steve Wiseb038ced2007-02-12 16:16:18 -08001024 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1025 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1026 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
1027 ep->mpa_attr.version = mpa_rev;
1028 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Harvey Harrison33718362008-04-16 21:01:10 -07001029 "xmit_marker_enabled=%d, version=%d\n", __func__,
Steve Wiseb038ced2007-02-12 16:16:18 -08001030 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1031 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version);
1032
1033 state_set(&ep->com, MPA_REQ_RCVD);
1034
1035 /* drive upcall */
1036 connect_request_upcall(ep);
1037 return;
1038}
1039
1040static int rx_data(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1041{
1042 struct iwch_ep *ep = ctx;
1043 struct cpl_rx_data *hdr = cplhdr(skb);
1044 unsigned int dlen = ntohs(hdr->len);
1045
Harvey Harrison33718362008-04-16 21:01:10 -07001046 PDBG("%s ep %p dlen %u\n", __func__, ep, dlen);
Steve Wiseb038ced2007-02-12 16:16:18 -08001047
1048 skb_pull(skb, sizeof(*hdr));
1049 skb_trim(skb, dlen);
1050
Steve Wisede3d3532007-05-14 13:27:27 -05001051 ep->rcv_seq += dlen;
1052 BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
1053
Steve Wiseb038ced2007-02-12 16:16:18 -08001054 switch (state_read(&ep->com)) {
1055 case MPA_REQ_SENT:
1056 process_mpa_reply(ep, skb);
1057 break;
1058 case MPA_REQ_WAIT:
1059 process_mpa_request(ep, skb);
1060 break;
1061 case MPA_REP_SENT:
1062 break;
1063 default:
1064 printk(KERN_ERR MOD "%s Unexpected streaming data."
1065 " ep %p state %d tid %d\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001066 __func__, ep, state_read(&ep->com), ep->hwtid);
Steve Wiseb038ced2007-02-12 16:16:18 -08001067
1068 /*
1069 * The ep will timeout and inform the ULP of the failure.
1070 * See ep_timeout().
1071 */
1072 break;
1073 }
1074
1075 /* update RX credits */
1076 update_rx_credits(ep, dlen);
1077
1078 return CPL_RET_BUF_DONE;
1079}
1080
1081/*
1082 * Upcall from the adapter indicating data has been transmitted.
1083 * For us its just the single MPA request or reply. We can now free
1084 * the skb holding the mpa message.
1085 */
1086static int tx_ack(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1087{
1088 struct iwch_ep *ep = ctx;
1089 struct cpl_wr_ack *hdr = cplhdr(skb);
1090 unsigned int credits = ntohs(hdr->credits);
Steve Wiseb038ced2007-02-12 16:16:18 -08001091
Harvey Harrison33718362008-04-16 21:01:10 -07001092 PDBG("%s ep %p credits %u\n", __func__, ep, credits);
Steve Wiseb038ced2007-02-12 16:16:18 -08001093
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001094 if (credits == 0) {
1095 PDBG(KERN_ERR "%s 0 credit ack ep %p state %u\n",
1096 __func__, ep, state_read(&ep->com));
Steve Wiseb038ced2007-02-12 16:16:18 -08001097 return CPL_RET_BUF_DONE;
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001098 }
1099
Steve Wiseb038ced2007-02-12 16:16:18 -08001100 BUG_ON(credits != 1);
Steve Wiseb038ced2007-02-12 16:16:18 -08001101 dst_confirm(ep->dst);
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001102 if (!ep->mpa_skb) {
1103 PDBG("%s rdma_init wr_ack ep %p state %u\n",
1104 __func__, ep, state_read(&ep->com));
1105 if (ep->mpa_attr.initiator) {
1106 PDBG("%s initiator ep %p state %u\n",
1107 __func__, ep, state_read(&ep->com));
1108 if (peer2peer)
1109 iwch_post_zb_read(ep->com.qp);
1110 } else {
1111 PDBG("%s responder ep %p state %u\n",
1112 __func__, ep, state_read(&ep->com));
1113 ep->com.rpl_done = 1;
1114 wake_up(&ep->com.waitq);
1115 }
1116 } else {
1117 PDBG("%s lsm ack ep %p state %u freeing skb\n",
1118 __func__, ep, state_read(&ep->com));
1119 kfree_skb(ep->mpa_skb);
1120 ep->mpa_skb = NULL;
Steve Wiseb038ced2007-02-12 16:16:18 -08001121 }
1122 return CPL_RET_BUF_DONE;
1123}
1124
1125static int abort_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1126{
1127 struct iwch_ep *ep = ctx;
Steve Wise989a1782008-04-29 13:46:51 -07001128 unsigned long flags;
1129 int release = 0;
Steve Wiseb038ced2007-02-12 16:16:18 -08001130
Harvey Harrison33718362008-04-16 21:01:10 -07001131 PDBG("%s ep %p\n", __func__, ep);
Steve Wise989a1782008-04-29 13:46:51 -07001132 BUG_ON(!ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001133
Steve Wiseaff9e392007-04-26 15:21:20 -05001134 /*
1135 * We get 2 abort replies from the HW. The first one must
1136 * be ignored except for scribbling that we need one more.
1137 */
Steve Wise6e47fe42009-09-05 20:22:38 -07001138 if (!test_and_set_bit(ABORT_REQ_IN_PROGRESS, &ep->com.flags)) {
Steve Wiseaff9e392007-04-26 15:21:20 -05001139 return CPL_RET_BUF_DONE;
1140 }
1141
Steve Wise989a1782008-04-29 13:46:51 -07001142 spin_lock_irqsave(&ep->com.lock, flags);
1143 switch (ep->com.state) {
1144 case ABORTING:
1145 close_complete_upcall(ep);
1146 __state_set(&ep->com, DEAD);
1147 release = 1;
1148 break;
1149 default:
1150 printk(KERN_ERR "%s ep %p state %d\n",
1151 __func__, ep, ep->com.state);
1152 break;
1153 }
1154 spin_unlock_irqrestore(&ep->com.lock, flags);
1155
1156 if (release)
1157 release_ep_resources(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001158 return CPL_RET_BUF_DONE;
1159}
1160
Steve Wise96d0e492007-06-21 18:17:57 -05001161/*
1162 * Return whether a failed active open has allocated a TID
1163 */
1164static inline int act_open_has_tid(int status)
1165{
1166 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1167 status != CPL_ERR_ARP_MISS;
1168}
1169
Steve Wiseb038ced2007-02-12 16:16:18 -08001170static int act_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1171{
1172 struct iwch_ep *ep = ctx;
1173 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1174
Harvey Harrison33718362008-04-16 21:01:10 -07001175 PDBG("%s ep %p status %u errno %d\n", __func__, ep, rpl->status,
Steve Wiseb038ced2007-02-12 16:16:18 -08001176 status2errno(rpl->status));
1177 connect_reply_upcall(ep, status2errno(rpl->status));
1178 state_set(&ep->com, DEAD);
Steve Wise8176d292008-01-24 16:30:16 -06001179 if (ep->com.tdev->type != T3A && act_open_has_tid(rpl->status))
Steve Wiseb038ced2007-02-12 16:16:18 -08001180 release_tid(ep->com.tdev, GET_TID(rpl), NULL);
1181 cxgb3_free_atid(ep->com.tdev, ep->atid);
1182 dst_release(ep->dst);
1183 l2t_release(L2DATA(ep->com.tdev), ep->l2t);
1184 put_ep(&ep->com);
1185 return CPL_RET_BUF_DONE;
1186}
1187
1188static int listen_start(struct iwch_listen_ep *ep)
1189{
1190 struct sk_buff *skb;
1191 struct cpl_pass_open_req *req;
1192
Harvey Harrison33718362008-04-16 21:01:10 -07001193 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001194 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1195 if (!skb) {
1196 printk(KERN_ERR MOD "t3c_listen_start failed to alloc skb!\n");
1197 return -ENOMEM;
1198 }
1199
1200 req = (struct cpl_pass_open_req *) skb_put(skb, sizeof(*req));
1201 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
1202 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_OPEN_REQ, ep->stid));
1203 req->local_port = ep->com.local_addr.sin_port;
1204 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
1205 req->peer_port = 0;
1206 req->peer_ip = 0;
1207 req->peer_netmask = 0;
1208 req->opt0h = htonl(F_DELACK | F_TCAM_BYPASS);
1209 req->opt0l = htonl(V_RCV_BUFSIZ(rcv_win>>10));
1210 req->opt1 = htonl(V_CONN_POLICY(CPL_CONN_POLICY_ASK));
1211
1212 skb->priority = 1;
Steve Wise04b5d022009-03-30 08:37:56 -07001213 return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -08001214}
1215
1216static int pass_open_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1217{
1218 struct iwch_listen_ep *ep = ctx;
1219 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1220
Harvey Harrison33718362008-04-16 21:01:10 -07001221 PDBG("%s ep %p status %d error %d\n", __func__, ep,
Steve Wiseb038ced2007-02-12 16:16:18 -08001222 rpl->status, status2errno(rpl->status));
1223 ep->com.rpl_err = status2errno(rpl->status);
1224 ep->com.rpl_done = 1;
1225 wake_up(&ep->com.waitq);
1226
1227 return CPL_RET_BUF_DONE;
1228}
1229
1230static int listen_stop(struct iwch_listen_ep *ep)
1231{
1232 struct sk_buff *skb;
1233 struct cpl_close_listserv_req *req;
1234
Harvey Harrison33718362008-04-16 21:01:10 -07001235 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001236 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1237 if (!skb) {
Harvey Harrison33718362008-04-16 21:01:10 -07001238 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001239 return -ENOMEM;
1240 }
1241 req = (struct cpl_close_listserv_req *) skb_put(skb, sizeof(*req));
1242 req->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
Steve Wise60be4b52007-04-26 15:21:15 -05001243 req->cpu_idx = 0;
Steve Wiseb038ced2007-02-12 16:16:18 -08001244 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ, ep->stid));
1245 skb->priority = 1;
Steve Wise04b5d022009-03-30 08:37:56 -07001246 return iwch_cxgb3_ofld_send(ep->com.tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -08001247}
1248
1249static int close_listsrv_rpl(struct t3cdev *tdev, struct sk_buff *skb,
1250 void *ctx)
1251{
1252 struct iwch_listen_ep *ep = ctx;
1253 struct cpl_close_listserv_rpl *rpl = cplhdr(skb);
1254
Harvey Harrison33718362008-04-16 21:01:10 -07001255 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001256 ep->com.rpl_err = status2errno(rpl->status);
1257 ep->com.rpl_done = 1;
1258 wake_up(&ep->com.waitq);
1259 return CPL_RET_BUF_DONE;
1260}
1261
1262static void accept_cr(struct iwch_ep *ep, __be32 peer_ip, struct sk_buff *skb)
1263{
1264 struct cpl_pass_accept_rpl *rpl;
1265 unsigned int mtu_idx;
1266 u32 opt0h, opt0l, opt2;
1267 int wscale;
1268
Harvey Harrison33718362008-04-16 21:01:10 -07001269 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001270 BUG_ON(skb_cloned(skb));
1271 skb_trim(skb, sizeof(*rpl));
1272 skb_get(skb);
1273 mtu_idx = find_best_mtu(T3C_DATA(ep->com.tdev), dst_mtu(ep->dst));
1274 wscale = compute_wscale(rcv_win);
1275 opt0h = V_NAGLE(0) |
1276 V_NO_CONG(nocong) |
1277 V_KEEP_ALIVE(1) |
1278 F_TCAM_BYPASS |
1279 V_WND_SCALE(wscale) |
1280 V_MSS_IDX(mtu_idx) |
1281 V_L2T_IDX(ep->l2t->idx) | V_TX_CHANNEL(ep->l2t->smt_idx);
1282 opt0l = V_TOS((ep->tos >> 2) & M_TOS) | V_RCV_BUFSIZ(rcv_win>>10);
1283 opt2 = V_FLAVORS_VALID(1) | V_CONG_CONTROL_FLAVOR(cong_flavor);
1284
1285 rpl = cplhdr(skb);
1286 rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
1287 OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL, ep->hwtid));
1288 rpl->peer_ip = peer_ip;
1289 rpl->opt0h = htonl(opt0h);
1290 rpl->opt0l_status = htonl(opt0l | CPL_PASS_OPEN_ACCEPT);
1291 rpl->opt2 = htonl(opt2);
1292 rpl->rsvd = rpl->opt2; /* workaround for HW bug */
1293 skb->priority = CPL_PRIORITY_SETUP;
Steve Wise04b5d022009-03-30 08:37:56 -07001294 iwch_l2t_send(ep->com.tdev, skb, ep->l2t);
Steve Wiseb038ced2007-02-12 16:16:18 -08001295
1296 return;
1297}
1298
1299static void reject_cr(struct t3cdev *tdev, u32 hwtid, __be32 peer_ip,
1300 struct sk_buff *skb)
1301{
Harvey Harrison33718362008-04-16 21:01:10 -07001302 PDBG("%s t3cdev %p tid %u peer_ip %x\n", __func__, tdev, hwtid,
Steve Wiseb038ced2007-02-12 16:16:18 -08001303 peer_ip);
1304 BUG_ON(skb_cloned(skb));
1305 skb_trim(skb, sizeof(struct cpl_tid_release));
1306 skb_get(skb);
1307
Steve Wise8176d292008-01-24 16:30:16 -06001308 if (tdev->type != T3A)
Steve Wiseb038ced2007-02-12 16:16:18 -08001309 release_tid(tdev, hwtid, skb);
1310 else {
1311 struct cpl_pass_accept_rpl *rpl;
1312
1313 rpl = cplhdr(skb);
1314 skb->priority = CPL_PRIORITY_SETUP;
1315 rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_FORWARD));
1316 OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1317 hwtid));
1318 rpl->peer_ip = peer_ip;
1319 rpl->opt0h = htonl(F_TCAM_BYPASS);
1320 rpl->opt0l_status = htonl(CPL_PASS_OPEN_REJECT);
1321 rpl->opt2 = 0;
1322 rpl->rsvd = rpl->opt2;
Steve Wise04b5d022009-03-30 08:37:56 -07001323 iwch_cxgb3_ofld_send(tdev, skb);
Steve Wiseb038ced2007-02-12 16:16:18 -08001324 }
1325}
1326
1327static int pass_accept_req(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1328{
1329 struct iwch_ep *child_ep, *parent_ep = ctx;
1330 struct cpl_pass_accept_req *req = cplhdr(skb);
1331 unsigned int hwtid = GET_TID(req);
1332 struct dst_entry *dst;
1333 struct l2t_entry *l2t;
1334 struct rtable *rt;
1335 struct iff_mac tim;
1336
Harvey Harrison33718362008-04-16 21:01:10 -07001337 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
Steve Wiseb038ced2007-02-12 16:16:18 -08001338
1339 if (state_read(&parent_ep->com) != LISTEN) {
1340 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001341 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001342 goto reject;
1343 }
1344
1345 /*
1346 * Find the netdev for this connection request.
1347 */
1348 tim.mac_addr = req->dst_mac;
1349 tim.vlan_tag = ntohs(req->vlan_tag);
1350 if (tdev->ctl(tdev, GET_IFF_FROM_MAC, &tim) < 0 || !tim.dev) {
H Hartley Sweeteneacc4d62010-01-07 01:17:27 -08001351 printk(KERN_ERR "%s bad dst mac %pM\n",
1352 __func__, req->dst_mac);
Steve Wiseb038ced2007-02-12 16:16:18 -08001353 goto reject;
1354 }
1355
1356 /* Find output route */
1357 rt = find_route(tdev,
1358 req->local_ip,
1359 req->peer_ip,
1360 req->local_port,
1361 req->peer_port, G_PASS_OPEN_TOS(ntohl(req->tos_tid)));
1362 if (!rt) {
1363 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001364 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001365 goto reject;
1366 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001367 dst = &rt->dst;
Steve Wiseb038ced2007-02-12 16:16:18 -08001368 l2t = t3_l2t_get(tdev, dst->neighbour, dst->neighbour->dev);
1369 if (!l2t) {
1370 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001371 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001372 dst_release(dst);
1373 goto reject;
1374 }
1375 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1376 if (!child_ep) {
1377 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001378 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001379 l2t_release(L2DATA(tdev), l2t);
1380 dst_release(dst);
1381 goto reject;
1382 }
1383 state_set(&child_ep->com, CONNECTING);
1384 child_ep->com.tdev = tdev;
1385 child_ep->com.cm_id = NULL;
1386 child_ep->com.local_addr.sin_family = PF_INET;
1387 child_ep->com.local_addr.sin_port = req->local_port;
1388 child_ep->com.local_addr.sin_addr.s_addr = req->local_ip;
1389 child_ep->com.remote_addr.sin_family = PF_INET;
1390 child_ep->com.remote_addr.sin_port = req->peer_port;
1391 child_ep->com.remote_addr.sin_addr.s_addr = req->peer_ip;
1392 get_ep(&parent_ep->com);
1393 child_ep->parent_ep = parent_ep;
1394 child_ep->tos = G_PASS_OPEN_TOS(ntohl(req->tos_tid));
1395 child_ep->l2t = l2t;
1396 child_ep->dst = dst;
1397 child_ep->hwtid = hwtid;
1398 init_timer(&child_ep->timer);
1399 cxgb3_insert_tid(tdev, &t3c_client, child_ep, hwtid);
1400 accept_cr(child_ep, req->peer_ip, skb);
1401 goto out;
1402reject:
1403 reject_cr(tdev, hwtid, req->peer_ip, skb);
1404out:
1405 return CPL_RET_BUF_DONE;
1406}
1407
1408static int pass_establish(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1409{
1410 struct iwch_ep *ep = ctx;
1411 struct cpl_pass_establish *req = cplhdr(skb);
1412
Harvey Harrison33718362008-04-16 21:01:10 -07001413 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001414 ep->snd_seq = ntohl(req->snd_isn);
Steve Wisede3d3532007-05-14 13:27:27 -05001415 ep->rcv_seq = ntohl(req->rcv_isn);
Steve Wiseb038ced2007-02-12 16:16:18 -08001416
1417 set_emss(ep, ntohs(req->tcp_opt));
1418
1419 dst_confirm(ep->dst);
1420 state_set(&ep->com, MPA_REQ_WAIT);
1421 start_ep_timer(ep);
1422
1423 return CPL_RET_BUF_DONE;
1424}
1425
1426static int peer_close(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1427{
1428 struct iwch_ep *ep = ctx;
1429 struct iwch_qp_attributes attrs;
1430 unsigned long flags;
1431 int disconnect = 1;
1432 int release = 0;
1433
Harvey Harrison33718362008-04-16 21:01:10 -07001434 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001435 dst_confirm(ep->dst);
1436
1437 spin_lock_irqsave(&ep->com.lock, flags);
1438 switch (ep->com.state) {
1439 case MPA_REQ_WAIT:
1440 __state_set(&ep->com, CLOSING);
1441 break;
1442 case MPA_REQ_SENT:
1443 __state_set(&ep->com, CLOSING);
1444 connect_reply_upcall(ep, -ECONNRESET);
1445 break;
1446 case MPA_REQ_RCVD:
1447
1448 /*
1449 * We're gonna mark this puppy DEAD, but keep
1450 * the reference on it until the ULP accepts or
Steve Wisea52bf982009-09-05 20:22:38 -07001451 * rejects the CR. Also wake up anyone waiting
1452 * in rdma connection migration (see iwch_accept_cr()).
Steve Wiseb038ced2007-02-12 16:16:18 -08001453 */
1454 __state_set(&ep->com, CLOSING);
Steve Wisea52bf982009-09-05 20:22:38 -07001455 ep->com.rpl_done = 1;
1456 ep->com.rpl_err = -ECONNRESET;
1457 PDBG("waking up ep %p\n", ep);
1458 wake_up(&ep->com.waitq);
Steve Wiseb038ced2007-02-12 16:16:18 -08001459 break;
1460 case MPA_REP_SENT:
1461 __state_set(&ep->com, CLOSING);
1462 ep->com.rpl_done = 1;
1463 ep->com.rpl_err = -ECONNRESET;
1464 PDBG("waking up ep %p\n", ep);
1465 wake_up(&ep->com.waitq);
1466 break;
1467 case FPDU_MODE:
Steve Wise42e31752007-03-06 14:43:56 -06001468 start_ep_timer(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001469 __state_set(&ep->com, CLOSING);
1470 attrs.next_state = IWCH_QP_STATE_CLOSING;
1471 iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
1472 IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
1473 peer_close_upcall(ep);
1474 break;
1475 case ABORTING:
1476 disconnect = 0;
1477 break;
1478 case CLOSING:
Steve Wiseb038ced2007-02-12 16:16:18 -08001479 __state_set(&ep->com, MORIBUND);
1480 disconnect = 0;
1481 break;
1482 case MORIBUND:
1483 stop_ep_timer(ep);
1484 if (ep->com.cm_id && ep->com.qp) {
1485 attrs.next_state = IWCH_QP_STATE_IDLE;
1486 iwch_modify_qp(ep->com.qp->rhp, ep->com.qp,
1487 IWCH_QP_ATTR_NEXT_STATE, &attrs, 1);
1488 }
1489 close_complete_upcall(ep);
1490 __state_set(&ep->com, DEAD);
1491 release = 1;
1492 disconnect = 0;
1493 break;
1494 case DEAD:
1495 disconnect = 0;
1496 break;
1497 default:
1498 BUG_ON(1);
1499 }
1500 spin_unlock_irqrestore(&ep->com.lock, flags);
1501 if (disconnect)
1502 iwch_ep_disconnect(ep, 0, GFP_KERNEL);
1503 if (release)
1504 release_ep_resources(ep);
1505 return CPL_RET_BUF_DONE;
1506}
1507
1508/*
1509 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1510 */
Adrian Bunk2b540352007-02-21 11:52:49 +01001511static int is_neg_adv_abort(unsigned int status)
Steve Wiseb038ced2007-02-12 16:16:18 -08001512{
1513 return status == CPL_ERR_RTX_NEG_ADVICE ||
1514 status == CPL_ERR_PERSIST_NEG_ADVICE;
1515}
1516
1517static int peer_abort(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1518{
1519 struct cpl_abort_req_rss *req = cplhdr(skb);
1520 struct iwch_ep *ep = ctx;
1521 struct cpl_abort_rpl *rpl;
1522 struct sk_buff *rpl_skb;
1523 struct iwch_qp_attributes attrs;
1524 int ret;
Steve Wise989a1782008-04-29 13:46:51 -07001525 int release = 0;
1526 unsigned long flags;
Steve Wiseb038ced2007-02-12 16:16:18 -08001527
Steve Wise15803672007-06-19 09:27:48 -05001528 if (is_neg_adv_abort(req->status)) {
Harvey Harrison33718362008-04-16 21:01:10 -07001529 PDBG("%s neg_adv_abort ep %p tid %d\n", __func__, ep,
Steve Wise15803672007-06-19 09:27:48 -05001530 ep->hwtid);
1531 t3_l2t_send_event(ep->com.tdev, ep->l2t);
1532 return CPL_RET_BUF_DONE;
1533 }
1534
Steve Wiseaff9e392007-04-26 15:21:20 -05001535 /*
1536 * We get 2 peer aborts from the HW. The first one must
1537 * be ignored except for scribbling that we need one more.
1538 */
Steve Wise6e47fe42009-09-05 20:22:38 -07001539 if (!test_and_set_bit(PEER_ABORT_IN_PROGRESS, &ep->com.flags)) {
Steve Wiseaff9e392007-04-26 15:21:20 -05001540 return CPL_RET_BUF_DONE;
1541 }
1542
Steve Wise989a1782008-04-29 13:46:51 -07001543 spin_lock_irqsave(&ep->com.lock, flags);
1544 PDBG("%s ep %p state %u\n", __func__, ep, ep->com.state);
1545 switch (ep->com.state) {
Steve Wiseb038ced2007-02-12 16:16:18 -08001546 case CONNECTING:
1547 break;
1548 case MPA_REQ_WAIT:
Steve Wiseadf376b2007-03-06 14:44:01 -06001549 stop_ep_timer(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001550 break;
1551 case MPA_REQ_SENT:
Steve Wiseadf376b2007-03-06 14:44:01 -06001552 stop_ep_timer(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001553 connect_reply_upcall(ep, -ECONNRESET);
1554 break;
1555 case MPA_REP_SENT:
1556 ep->com.rpl_done = 1;
1557 ep->com.rpl_err = -ECONNRESET;
1558 PDBG("waking up ep %p\n", ep);
1559 wake_up(&ep->com.waitq);
1560 break;
1561 case MPA_REQ_RCVD:
1562
1563 /*
1564 * We're gonna mark this puppy DEAD, but keep
1565 * the reference on it until the ULP accepts or
Steve Wisea52bf982009-09-05 20:22:38 -07001566 * rejects the CR. Also wake up anyone waiting
1567 * in rdma connection migration (see iwch_accept_cr()).
Steve Wiseb038ced2007-02-12 16:16:18 -08001568 */
Steve Wisea52bf982009-09-05 20:22:38 -07001569 ep->com.rpl_done = 1;
1570 ep->com.rpl_err = -ECONNRESET;
1571 PDBG("waking up ep %p\n", ep);
1572 wake_up(&ep->com.waitq);
Steve Wiseb038ced2007-02-12 16:16:18 -08001573 break;
1574 case MORIBUND:
Steve Wiseb038ced2007-02-12 16:16:18 -08001575 case CLOSING:
Steve Wise42e31752007-03-06 14:43:56 -06001576 stop_ep_timer(ep);
1577 /*FALLTHROUGH*/
1578 case FPDU_MODE:
Steve Wiseb038ced2007-02-12 16:16:18 -08001579 if (ep->com.cm_id && ep->com.qp) {
1580 attrs.next_state = IWCH_QP_STATE_ERROR;
1581 ret = iwch_modify_qp(ep->com.qp->rhp,
1582 ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
1583 &attrs, 1);
1584 if (ret)
1585 printk(KERN_ERR MOD
1586 "%s - qp <- error failed!\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001587 __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001588 }
1589 peer_abort_upcall(ep);
1590 break;
1591 case ABORTING:
1592 break;
1593 case DEAD:
Harvey Harrison33718362008-04-16 21:01:10 -07001594 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise989a1782008-04-29 13:46:51 -07001595 spin_unlock_irqrestore(&ep->com.lock, flags);
Steve Wiseb038ced2007-02-12 16:16:18 -08001596 return CPL_RET_BUF_DONE;
1597 default:
1598 BUG_ON(1);
1599 break;
1600 }
1601 dst_confirm(ep->dst);
Steve Wise989a1782008-04-29 13:46:51 -07001602 if (ep->com.state != ABORTING) {
1603 __state_set(&ep->com, DEAD);
1604 release = 1;
1605 }
1606 spin_unlock_irqrestore(&ep->com.lock, flags);
Steve Wiseb038ced2007-02-12 16:16:18 -08001607
1608 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
1609 if (!rpl_skb) {
1610 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001611 __func__);
Steve Wise989a1782008-04-29 13:46:51 -07001612 release = 1;
1613 goto out;
Steve Wiseb038ced2007-02-12 16:16:18 -08001614 }
1615 rpl_skb->priority = CPL_PRIORITY_DATA;
1616 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
1617 rpl->wr.wr_hi = htonl(V_WR_OP(FW_WROPCODE_OFLD_HOST_ABORT_CON_RPL));
1618 rpl->wr.wr_lo = htonl(V_WR_TID(ep->hwtid));
1619 OPCODE_TID(rpl) = htonl(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
1620 rpl->cmd = CPL_ABORT_NO_RST;
Steve Wise04b5d022009-03-30 08:37:56 -07001621 iwch_cxgb3_ofld_send(ep->com.tdev, rpl_skb);
Steve Wise989a1782008-04-29 13:46:51 -07001622out:
1623 if (release)
Steve Wiseb038ced2007-02-12 16:16:18 -08001624 release_ep_resources(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001625 return CPL_RET_BUF_DONE;
1626}
1627
1628static int close_con_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1629{
1630 struct iwch_ep *ep = ctx;
1631 struct iwch_qp_attributes attrs;
1632 unsigned long flags;
1633 int release = 0;
1634
Harvey Harrison33718362008-04-16 21:01:10 -07001635 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001636 BUG_ON(!ep);
1637
1638 /* The cm_id may be null if we failed to connect */
1639 spin_lock_irqsave(&ep->com.lock, flags);
1640 switch (ep->com.state) {
1641 case CLOSING:
Steve Wiseb038ced2007-02-12 16:16:18 -08001642 __state_set(&ep->com, MORIBUND);
1643 break;
1644 case MORIBUND:
1645 stop_ep_timer(ep);
1646 if ((ep->com.cm_id) && (ep->com.qp)) {
1647 attrs.next_state = IWCH_QP_STATE_IDLE;
1648 iwch_modify_qp(ep->com.qp->rhp,
1649 ep->com.qp,
1650 IWCH_QP_ATTR_NEXT_STATE,
1651 &attrs, 1);
1652 }
1653 close_complete_upcall(ep);
1654 __state_set(&ep->com, DEAD);
1655 release = 1;
1656 break;
Steve Wise42e31752007-03-06 14:43:56 -06001657 case ABORTING:
Steve Wiseb038ced2007-02-12 16:16:18 -08001658 case DEAD:
Steve Wisec4d49772008-05-02 10:57:09 -07001659 break;
Steve Wiseb038ced2007-02-12 16:16:18 -08001660 default:
1661 BUG_ON(1);
1662 break;
1663 }
1664 spin_unlock_irqrestore(&ep->com.lock, flags);
1665 if (release)
1666 release_ep_resources(ep);
1667 return CPL_RET_BUF_DONE;
1668}
1669
1670/*
1671 * T3A does 3 things when a TERM is received:
1672 * 1) send up a CPL_RDMA_TERMINATE message with the TERM packet
1673 * 2) generate an async event on the QP with the TERMINATE opcode
1674 * 3) post a TERMINATE opcde cqe into the associated CQ.
1675 *
1676 * For (1), we save the message in the qp for later consumer consumption.
1677 * For (2), we move the QP into TERMINATE, post a QP event and disconnect.
1678 * For (3), we toss the CQE in cxio_poll_cq().
1679 *
1680 * terminate() handles case (1)...
1681 */
1682static int terminate(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1683{
1684 struct iwch_ep *ep = ctx;
1685
Steve Wise42fb61f2009-02-10 16:38:57 -08001686 if (state_read(&ep->com) != FPDU_MODE)
1687 return CPL_RET_BUF_DONE;
1688
Harvey Harrison33718362008-04-16 21:01:10 -07001689 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001690 skb_pull(skb, sizeof(struct cpl_rdma_terminate));
Harvey Harrison33718362008-04-16 21:01:10 -07001691 PDBG("%s saving %d bytes of term msg\n", __func__, skb->len);
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001692 skb_copy_from_linear_data(skb, ep->com.qp->attr.terminate_buffer,
1693 skb->len);
Steve Wiseb038ced2007-02-12 16:16:18 -08001694 ep->com.qp->attr.terminate_msg_len = skb->len;
1695 ep->com.qp->attr.is_terminate_local = 0;
1696 return CPL_RET_BUF_DONE;
1697}
1698
1699static int ec_status(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
1700{
1701 struct cpl_rdma_ec_status *rep = cplhdr(skb);
1702 struct iwch_ep *ep = ctx;
1703
Harvey Harrison33718362008-04-16 21:01:10 -07001704 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid,
Steve Wiseb038ced2007-02-12 16:16:18 -08001705 rep->status);
1706 if (rep->status) {
1707 struct iwch_qp_attributes attrs;
1708
1709 printk(KERN_ERR MOD "%s BAD CLOSE - Aborting tid %u\n",
Harvey Harrison33718362008-04-16 21:01:10 -07001710 __func__, ep->hwtid);
Steve Wise2f236732007-02-21 14:45:39 -06001711 stop_ep_timer(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001712 attrs.next_state = IWCH_QP_STATE_ERROR;
1713 iwch_modify_qp(ep->com.qp->rhp,
1714 ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
1715 &attrs, 1);
1716 abort_connection(ep, NULL, GFP_KERNEL);
1717 }
1718 return CPL_RET_BUF_DONE;
1719}
1720
1721static void ep_timeout(unsigned long arg)
1722{
1723 struct iwch_ep *ep = (struct iwch_ep *)arg;
1724 struct iwch_qp_attributes attrs;
1725 unsigned long flags;
Steve Wise989a1782008-04-29 13:46:51 -07001726 int abort = 1;
Steve Wiseb038ced2007-02-12 16:16:18 -08001727
1728 spin_lock_irqsave(&ep->com.lock, flags);
Harvey Harrison33718362008-04-16 21:01:10 -07001729 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
Steve Wiseb038ced2007-02-12 16:16:18 -08001730 ep->com.state);
1731 switch (ep->com.state) {
1732 case MPA_REQ_SENT:
Steve Wise989a1782008-04-29 13:46:51 -07001733 __state_set(&ep->com, ABORTING);
Steve Wiseb038ced2007-02-12 16:16:18 -08001734 connect_reply_upcall(ep, -ETIMEDOUT);
1735 break;
1736 case MPA_REQ_WAIT:
Steve Wise989a1782008-04-29 13:46:51 -07001737 __state_set(&ep->com, ABORTING);
Steve Wiseb038ced2007-02-12 16:16:18 -08001738 break;
Steve Wise42e31752007-03-06 14:43:56 -06001739 case CLOSING:
Steve Wiseb038ced2007-02-12 16:16:18 -08001740 case MORIBUND:
1741 if (ep->com.cm_id && ep->com.qp) {
1742 attrs.next_state = IWCH_QP_STATE_ERROR;
1743 iwch_modify_qp(ep->com.qp->rhp,
1744 ep->com.qp, IWCH_QP_ATTR_NEXT_STATE,
1745 &attrs, 1);
1746 }
Steve Wise989a1782008-04-29 13:46:51 -07001747 __state_set(&ep->com, ABORTING);
Steve Wiseb038ced2007-02-12 16:16:18 -08001748 break;
1749 default:
Steve Wise989a1782008-04-29 13:46:51 -07001750 printk(KERN_ERR "%s unexpected state ep %p state %u\n",
1751 __func__, ep, ep->com.state);
1752 WARN_ON(1);
1753 abort = 0;
Steve Wiseb038ced2007-02-12 16:16:18 -08001754 }
Steve Wiseb038ced2007-02-12 16:16:18 -08001755 spin_unlock_irqrestore(&ep->com.lock, flags);
Steve Wise989a1782008-04-29 13:46:51 -07001756 if (abort)
1757 abort_connection(ep, NULL, GFP_ATOMIC);
Steve Wiseb038ced2007-02-12 16:16:18 -08001758 put_ep(&ep->com);
1759}
1760
1761int iwch_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
1762{
1763 int err;
1764 struct iwch_ep *ep = to_ep(cm_id);
Harvey Harrison33718362008-04-16 21:01:10 -07001765 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wiseb038ced2007-02-12 16:16:18 -08001766
1767 if (state_read(&ep->com) == DEAD) {
1768 put_ep(&ep->com);
1769 return -ECONNRESET;
1770 }
1771 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
Steve Wiseb038ced2007-02-12 16:16:18 -08001772 if (mpa_rev == 0)
1773 abort_connection(ep, NULL, GFP_KERNEL);
1774 else {
1775 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wise7d526e62007-03-05 17:32:46 -06001776 err = iwch_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wiseb038ced2007-02-12 16:16:18 -08001777 }
Steve Wise6e47fe42009-09-05 20:22:38 -07001778 put_ep(&ep->com);
Steve Wiseb038ced2007-02-12 16:16:18 -08001779 return 0;
1780}
1781
1782int iwch_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
1783{
1784 int err;
1785 struct iwch_qp_attributes attrs;
1786 enum iwch_qp_attr_mask mask;
1787 struct iwch_ep *ep = to_ep(cm_id);
1788 struct iwch_dev *h = to_iwch_dev(cm_id->device);
1789 struct iwch_qp *qp = get_qhp(h, conn_param->qpn);
1790
Harvey Harrison33718362008-04-16 21:01:10 -07001791 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise6e47fe42009-09-05 20:22:38 -07001792 if (state_read(&ep->com) == DEAD) {
1793 err = -ECONNRESET;
1794 goto err;
1795 }
Steve Wiseb038ced2007-02-12 16:16:18 -08001796
1797 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
1798 BUG_ON(!qp);
1799
1800 if ((conn_param->ord > qp->rhp->attr.max_rdma_read_qp_depth) ||
1801 (conn_param->ird > qp->rhp->attr.max_rdma_reads_per_qp)) {
1802 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wise6e47fe42009-09-05 20:22:38 -07001803 err = -EINVAL;
1804 goto err;
Steve Wiseb038ced2007-02-12 16:16:18 -08001805 }
1806
1807 cm_id->add_ref(cm_id);
1808 ep->com.cm_id = cm_id;
1809 ep->com.qp = qp;
1810
Steve Wiseb038ced2007-02-12 16:16:18 -08001811 ep->ird = conn_param->ird;
1812 ep->ord = conn_param->ord;
Steve Wise96ac7e82009-04-20 13:53:15 -07001813
1814 if (peer2peer && ep->ird == 0)
1815 ep->ird = 1;
1816
Harvey Harrison33718362008-04-16 21:01:10 -07001817 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
Steve Wisede3d3532007-05-14 13:27:27 -05001818
Steve Wiseb038ced2007-02-12 16:16:18 -08001819 /* bind QP to EP and move to RTS */
1820 attrs.mpa_attr = ep->mpa_attr;
Roland Dreier1f71f502008-03-28 10:28:17 -07001821 attrs.max_ird = ep->ird;
Steve Wiseb038ced2007-02-12 16:16:18 -08001822 attrs.max_ord = ep->ord;
1823 attrs.llp_stream_handle = ep;
1824 attrs.next_state = IWCH_QP_STATE_RTS;
1825
1826 /* bind QP and TID with INIT_WR */
1827 mask = IWCH_QP_ATTR_NEXT_STATE |
1828 IWCH_QP_ATTR_LLP_STREAM_HANDLE |
1829 IWCH_QP_ATTR_MPA_ATTR |
1830 IWCH_QP_ATTR_MAX_IRD |
1831 IWCH_QP_ATTR_MAX_ORD;
1832
1833 err = iwch_modify_qp(ep->com.qp->rhp,
1834 ep->com.qp, mask, &attrs, 1);
Steve Wisede3d3532007-05-14 13:27:27 -05001835 if (err)
Steve Wise6e47fe42009-09-05 20:22:38 -07001836 goto err1;
Steve Wiseb038ced2007-02-12 16:16:18 -08001837
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001838 /* if needed, wait for wr_ack */
1839 if (iwch_rqes_posted(qp)) {
1840 wait_event(ep->com.waitq, ep->com.rpl_done);
1841 err = ep->com.rpl_err;
1842 if (err)
Steve Wise6e47fe42009-09-05 20:22:38 -07001843 goto err1;
Steve Wisef8b0dfd2008-04-29 13:46:52 -07001844 }
1845
Steve Wisede3d3532007-05-14 13:27:27 -05001846 err = send_mpa_reply(ep, conn_param->private_data,
1847 conn_param->private_data_len);
1848 if (err)
Steve Wise6e47fe42009-09-05 20:22:38 -07001849 goto err1;
Steve Wisede3d3532007-05-14 13:27:27 -05001850
Steve Wisede3d3532007-05-14 13:27:27 -05001851
1852 state_set(&ep->com, FPDU_MODE);
1853 established_upcall(ep);
1854 put_ep(&ep->com);
1855 return 0;
Steve Wise6e47fe42009-09-05 20:22:38 -07001856err1:
Steve Wisede3d3532007-05-14 13:27:27 -05001857 ep->com.cm_id = NULL;
1858 ep->com.qp = NULL;
1859 cm_id->rem_ref(cm_id);
Steve Wise6e47fe42009-09-05 20:22:38 -07001860err:
Steve Wiseb038ced2007-02-12 16:16:18 -08001861 put_ep(&ep->com);
1862 return err;
1863}
1864
Steve Wise8704e9a2008-02-12 16:09:29 -06001865static int is_loopback_dst(struct iw_cm_id *cm_id)
1866{
1867 struct net_device *dev;
1868
1869 dev = ip_dev_find(&init_net, cm_id->remote_addr.sin_addr.s_addr);
1870 if (!dev)
1871 return 0;
1872 dev_put(dev);
1873 return 1;
1874}
1875
Steve Wiseb038ced2007-02-12 16:16:18 -08001876int iwch_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
1877{
1878 int err = 0;
1879 struct iwch_dev *h = to_iwch_dev(cm_id->device);
1880 struct iwch_ep *ep;
1881 struct rtable *rt;
1882
Steve Wise8704e9a2008-02-12 16:09:29 -06001883 if (is_loopback_dst(cm_id)) {
1884 err = -ENOSYS;
1885 goto out;
1886 }
1887
Steve Wiseb038ced2007-02-12 16:16:18 -08001888 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
1889 if (!ep) {
Harvey Harrison33718362008-04-16 21:01:10 -07001890 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001891 err = -ENOMEM;
1892 goto out;
1893 }
1894 init_timer(&ep->timer);
1895 ep->plen = conn_param->private_data_len;
1896 if (ep->plen)
1897 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
1898 conn_param->private_data, ep->plen);
1899 ep->ird = conn_param->ird;
1900 ep->ord = conn_param->ord;
Steve Wise96ac7e82009-04-20 13:53:15 -07001901
1902 if (peer2peer && ep->ord == 0)
1903 ep->ord = 1;
1904
Steve Wiseb038ced2007-02-12 16:16:18 -08001905 ep->com.tdev = h->rdev.t3cdev_p;
1906
1907 cm_id->add_ref(cm_id);
1908 ep->com.cm_id = cm_id;
1909 ep->com.qp = get_qhp(h, conn_param->qpn);
1910 BUG_ON(!ep->com.qp);
Harvey Harrison33718362008-04-16 21:01:10 -07001911 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
Steve Wiseb038ced2007-02-12 16:16:18 -08001912 ep->com.qp, cm_id);
1913
1914 /*
1915 * Allocate an active TID to initiate a TCP connection.
1916 */
1917 ep->atid = cxgb3_alloc_atid(h->rdev.t3cdev_p, &t3c_client, ep);
1918 if (ep->atid == -1) {
Harvey Harrison33718362008-04-16 21:01:10 -07001919 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001920 err = -ENOMEM;
1921 goto fail2;
1922 }
1923
1924 /* find a route */
1925 rt = find_route(h->rdev.t3cdev_p,
1926 cm_id->local_addr.sin_addr.s_addr,
1927 cm_id->remote_addr.sin_addr.s_addr,
1928 cm_id->local_addr.sin_port,
1929 cm_id->remote_addr.sin_port, IPTOS_LOWDELAY);
1930 if (!rt) {
Harvey Harrison33718362008-04-16 21:01:10 -07001931 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001932 err = -EHOSTUNREACH;
1933 goto fail3;
1934 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001935 ep->dst = &rt->dst;
Steve Wiseb038ced2007-02-12 16:16:18 -08001936
1937 /* get a l2t entry */
1938 ep->l2t = t3_l2t_get(ep->com.tdev, ep->dst->neighbour,
1939 ep->dst->neighbour->dev);
1940 if (!ep->l2t) {
Harvey Harrison33718362008-04-16 21:01:10 -07001941 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001942 err = -ENOMEM;
1943 goto fail4;
1944 }
1945
1946 state_set(&ep->com, CONNECTING);
1947 ep->tos = IPTOS_LOWDELAY;
1948 ep->com.local_addr = cm_id->local_addr;
1949 ep->com.remote_addr = cm_id->remote_addr;
1950
1951 /* send connect request to rnic */
1952 err = send_connect(ep);
1953 if (!err)
1954 goto out;
1955
1956 l2t_release(L2DATA(h->rdev.t3cdev_p), ep->l2t);
1957fail4:
1958 dst_release(ep->dst);
1959fail3:
1960 cxgb3_free_atid(ep->com.tdev, ep->atid);
1961fail2:
Steve Wisedc35fac2008-10-15 10:50:34 -07001962 cm_id->rem_ref(cm_id);
Steve Wiseb038ced2007-02-12 16:16:18 -08001963 put_ep(&ep->com);
1964out:
1965 return err;
1966}
1967
1968int iwch_create_listen(struct iw_cm_id *cm_id, int backlog)
1969{
1970 int err = 0;
1971 struct iwch_dev *h = to_iwch_dev(cm_id->device);
1972 struct iwch_listen_ep *ep;
1973
1974
1975 might_sleep();
1976
1977 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
1978 if (!ep) {
Harvey Harrison33718362008-04-16 21:01:10 -07001979 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001980 err = -ENOMEM;
1981 goto fail1;
1982 }
Harvey Harrison33718362008-04-16 21:01:10 -07001983 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08001984 ep->com.tdev = h->rdev.t3cdev_p;
1985 cm_id->add_ref(cm_id);
1986 ep->com.cm_id = cm_id;
1987 ep->backlog = backlog;
1988 ep->com.local_addr = cm_id->local_addr;
1989
1990 /*
1991 * Allocate a server TID.
1992 */
1993 ep->stid = cxgb3_alloc_stid(h->rdev.t3cdev_p, &t3c_client, ep);
1994 if (ep->stid == -1) {
Harvey Harrison33718362008-04-16 21:01:10 -07001995 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
Steve Wiseb038ced2007-02-12 16:16:18 -08001996 err = -ENOMEM;
1997 goto fail2;
1998 }
1999
2000 state_set(&ep->com, LISTEN);
2001 err = listen_start(ep);
2002 if (err)
2003 goto fail3;
2004
2005 /* wait for pass_open_rpl */
2006 wait_event(ep->com.waitq, ep->com.rpl_done);
2007 err = ep->com.rpl_err;
2008 if (!err) {
2009 cm_id->provider_data = ep;
2010 goto out;
2011 }
2012fail3:
2013 cxgb3_free_stid(ep->com.tdev, ep->stid);
2014fail2:
Steve Wise1b07db72007-07-11 13:04:35 -05002015 cm_id->rem_ref(cm_id);
Steve Wiseb038ced2007-02-12 16:16:18 -08002016 put_ep(&ep->com);
2017fail1:
2018out:
2019 return err;
2020}
2021
2022int iwch_destroy_listen(struct iw_cm_id *cm_id)
2023{
2024 int err;
2025 struct iwch_listen_ep *ep = to_listen_ep(cm_id);
2026
Harvey Harrison33718362008-04-16 21:01:10 -07002027 PDBG("%s ep %p\n", __func__, ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08002028
2029 might_sleep();
2030 state_set(&ep->com, DEAD);
2031 ep->com.rpl_done = 0;
2032 ep->com.rpl_err = 0;
2033 err = listen_stop(ep);
Steve Wise04b5d022009-03-30 08:37:56 -07002034 if (err)
2035 goto done;
Steve Wiseb038ced2007-02-12 16:16:18 -08002036 wait_event(ep->com.waitq, ep->com.rpl_done);
2037 cxgb3_free_stid(ep->com.tdev, ep->stid);
Steve Wise04b5d022009-03-30 08:37:56 -07002038done:
Steve Wiseb038ced2007-02-12 16:16:18 -08002039 err = ep->com.rpl_err;
2040 cm_id->rem_ref(cm_id);
2041 put_ep(&ep->com);
2042 return err;
2043}
2044
2045int iwch_ep_disconnect(struct iwch_ep *ep, int abrupt, gfp_t gfp)
2046{
2047 int ret=0;
2048 unsigned long flags;
2049 int close = 0;
Steve Wise04b5d022009-03-30 08:37:56 -07002050 int fatal = 0;
2051 struct t3cdev *tdev;
2052 struct cxio_rdev *rdev;
Steve Wiseb038ced2007-02-12 16:16:18 -08002053
2054 spin_lock_irqsave(&ep->com.lock, flags);
2055
Harvey Harrison33718362008-04-16 21:01:10 -07002056 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
Steve Wiseb038ced2007-02-12 16:16:18 -08002057 states[ep->com.state], abrupt);
2058
Steve Wise04b5d022009-03-30 08:37:56 -07002059 tdev = (struct t3cdev *)ep->com.tdev;
2060 rdev = (struct cxio_rdev *)tdev->ulp;
2061 if (cxio_fatal_error(rdev)) {
2062 fatal = 1;
2063 close_complete_upcall(ep);
2064 ep->com.state = DEAD;
2065 }
Steve Wiseb038ced2007-02-12 16:16:18 -08002066 switch (ep->com.state) {
2067 case MPA_REQ_WAIT:
2068 case MPA_REQ_SENT:
2069 case MPA_REQ_RCVD:
2070 case MPA_REP_SENT:
2071 case FPDU_MODE:
Steve Wiseb038ced2007-02-12 16:16:18 -08002072 close = 1;
Steve Wise989a1782008-04-29 13:46:51 -07002073 if (abrupt)
2074 ep->com.state = ABORTING;
2075 else {
2076 ep->com.state = CLOSING;
2077 start_ep_timer(ep);
2078 }
Steve Wise6e47fe42009-09-05 20:22:38 -07002079 set_bit(CLOSE_SENT, &ep->com.flags);
Steve Wiseb038ced2007-02-12 16:16:18 -08002080 break;
2081 case CLOSING:
Steve Wise6e47fe42009-09-05 20:22:38 -07002082 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2083 close = 1;
2084 if (abrupt) {
2085 stop_ep_timer(ep);
2086 ep->com.state = ABORTING;
2087 } else
2088 ep->com.state = MORIBUND;
2089 }
Steve Wiseb038ced2007-02-12 16:16:18 -08002090 break;
2091 case MORIBUND:
Steve Wise989a1782008-04-29 13:46:51 -07002092 case ABORTING:
2093 case DEAD:
2094 PDBG("%s ignoring disconnect ep %p state %u\n",
2095 __func__, ep, ep->com.state);
Steve Wiseb038ced2007-02-12 16:16:18 -08002096 break;
2097 default:
2098 BUG();
2099 break;
2100 }
Steve Wise989a1782008-04-29 13:46:51 -07002101
Steve Wiseb038ced2007-02-12 16:16:18 -08002102 spin_unlock_irqrestore(&ep->com.lock, flags);
2103 if (close) {
2104 if (abrupt)
2105 ret = send_abort(ep, NULL, gfp);
2106 else
2107 ret = send_halfclose(ep, gfp);
Steve Wise04b5d022009-03-30 08:37:56 -07002108 if (ret)
2109 fatal = 1;
Steve Wiseb038ced2007-02-12 16:16:18 -08002110 }
Steve Wise04b5d022009-03-30 08:37:56 -07002111 if (fatal)
2112 release_ep_resources(ep);
Steve Wiseb038ced2007-02-12 16:16:18 -08002113 return ret;
2114}
2115
2116int iwch_ep_redirect(void *ctx, struct dst_entry *old, struct dst_entry *new,
2117 struct l2t_entry *l2t)
2118{
2119 struct iwch_ep *ep = ctx;
2120
2121 if (ep->dst != old)
2122 return 0;
2123
Harvey Harrison33718362008-04-16 21:01:10 -07002124 PDBG("%s ep %p redirect to dst %p l2t %p\n", __func__, ep, new,
Steve Wiseb038ced2007-02-12 16:16:18 -08002125 l2t);
2126 dst_hold(new);
2127 l2t_release(L2DATA(ep->com.tdev), ep->l2t);
2128 ep->l2t = l2t;
2129 dst_release(old);
2130 ep->dst = new;
2131 return 1;
2132}
2133
2134/*
2135 * All the CM events are handled on a work queue to have a safe context.
Roland Dreier617c9a72010-04-28 14:57:40 -07002136 * These are the real handlers that are called from the work queue.
Steve Wiseb038ced2007-02-12 16:16:18 -08002137 */
Roland Dreier617c9a72010-04-28 14:57:40 -07002138static const cxgb3_cpl_handler_func work_handlers[NUM_CPL_CMDS] = {
2139 [CPL_ACT_ESTABLISH] = act_establish,
2140 [CPL_ACT_OPEN_RPL] = act_open_rpl,
2141 [CPL_RX_DATA] = rx_data,
2142 [CPL_TX_DMA_ACK] = tx_ack,
2143 [CPL_ABORT_RPL_RSS] = abort_rpl,
2144 [CPL_ABORT_RPL] = abort_rpl,
2145 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
2146 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
2147 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
2148 [CPL_PASS_ESTABLISH] = pass_establish,
2149 [CPL_PEER_CLOSE] = peer_close,
2150 [CPL_ABORT_REQ_RSS] = peer_abort,
2151 [CPL_CLOSE_CON_RPL] = close_con_rpl,
2152 [CPL_RDMA_TERMINATE] = terminate,
2153 [CPL_RDMA_EC_STATUS] = ec_status,
2154};
2155
2156static void process_work(struct work_struct *work)
2157{
2158 struct sk_buff *skb = NULL;
2159 void *ep;
2160 struct t3cdev *tdev;
2161 int ret;
2162
2163 while ((skb = skb_dequeue(&rxq))) {
2164 ep = *((void **) (skb->cb));
2165 tdev = *((struct t3cdev **) (skb->cb + sizeof(void *)));
2166 ret = work_handlers[G_OPCODE(ntohl((__force __be32)skb->csum))](tdev, skb, ep);
2167 if (ret & CPL_RET_BUF_DONE)
2168 kfree_skb(skb);
2169
2170 /*
2171 * ep was referenced in sched(), and is freed here.
2172 */
2173 put_ep((struct iwch_ep_common *)ep);
2174 }
2175}
2176
2177static DECLARE_WORK(skb_work, process_work);
2178
Steve Wiseb038ced2007-02-12 16:16:18 -08002179static int sched(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
2180{
2181 struct iwch_ep_common *epc = ctx;
2182
2183 get_ep(epc);
2184
2185 /*
2186 * Save ctx and tdev in the skb->cb area.
2187 */
2188 *((void **) skb->cb) = ctx;
2189 *((struct t3cdev **) (skb->cb + sizeof(void *))) = tdev;
2190
2191 /*
2192 * Queue the skb and schedule the worker thread.
2193 */
2194 skb_queue_tail(&rxq, skb);
2195 queue_work(workq, &skb_work);
2196 return 0;
2197}
2198
Steve Wise1ca19772007-04-12 07:56:34 -05002199static int set_tcb_rpl(struct t3cdev *tdev, struct sk_buff *skb, void *ctx)
2200{
2201 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
2202
2203 if (rpl->status != CPL_ERR_NONE) {
2204 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
2205 "for tid %u\n", rpl->status, GET_TID(rpl));
2206 }
2207 return CPL_RET_BUF_DONE;
2208}
2209
Roland Dreier617c9a72010-04-28 14:57:40 -07002210/*
2211 * All upcalls from the T3 Core go to sched() to schedule the
2212 * processing on a work queue.
2213 */
2214cxgb3_cpl_handler_func t3c_handlers[NUM_CPL_CMDS] = {
2215 [CPL_ACT_ESTABLISH] = sched,
2216 [CPL_ACT_OPEN_RPL] = sched,
2217 [CPL_RX_DATA] = sched,
2218 [CPL_TX_DMA_ACK] = sched,
2219 [CPL_ABORT_RPL_RSS] = sched,
2220 [CPL_ABORT_RPL] = sched,
2221 [CPL_PASS_OPEN_RPL] = sched,
2222 [CPL_CLOSE_LISTSRV_RPL] = sched,
2223 [CPL_PASS_ACCEPT_REQ] = sched,
2224 [CPL_PASS_ESTABLISH] = sched,
2225 [CPL_PEER_CLOSE] = sched,
2226 [CPL_CLOSE_CON_RPL] = sched,
2227 [CPL_ABORT_REQ_RSS] = sched,
2228 [CPL_RDMA_TERMINATE] = sched,
2229 [CPL_RDMA_EC_STATUS] = sched,
2230 [CPL_SET_TCB_RPL] = set_tcb_rpl,
2231};
2232
Steve Wiseb038ced2007-02-12 16:16:18 -08002233int __init iwch_cm_init(void)
2234{
2235 skb_queue_head_init(&rxq);
2236
2237 workq = create_singlethread_workqueue("iw_cxgb3");
2238 if (!workq)
2239 return -ENOMEM;
2240
Steve Wiseb038ced2007-02-12 16:16:18 -08002241 return 0;
2242}
2243
2244void __exit iwch_cm_term(void)
2245{
2246 flush_workqueue(workq);
2247 destroy_workqueue(workq);
2248}