blob: 75b57bee6622d6d4fa34088e429a8588a3a9cb2a [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
41
42#include <net/neighbour.h>
43#include <net/netevent.h>
44#include <net/route.h>
45
46#include "iw_cxgb4.h"
47
48static char *states[] = {
49 "idle",
50 "listen",
51 "connecting",
52 "mpa_wait_req",
53 "mpa_req_sent",
54 "mpa_req_rcvd",
55 "mpa_rep_sent",
56 "fpdu_mode",
57 "aborting",
58 "closing",
59 "moribund",
60 "dead",
61 NULL,
62};
63
Steve Wiseb52fe092011-03-11 22:30:01 +000064static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000065module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000066MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000067
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070068int c4iw_max_read_depth = 8;
69module_param(c4iw_max_read_depth, int, 0644);
70MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
71
Steve Wisecfdda9d2010-04-21 15:30:06 -070072static int enable_tcp_timestamps;
73module_param(enable_tcp_timestamps, int, 0644);
74MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
75
76static int enable_tcp_sack;
77module_param(enable_tcp_sack, int, 0644);
78MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
79
80static int enable_tcp_window_scaling = 1;
81module_param(enable_tcp_window_scaling, int, 0644);
82MODULE_PARM_DESC(enable_tcp_window_scaling,
83 "Enable tcp window scaling (default=1)");
84
85int c4iw_debug;
86module_param(c4iw_debug, int, 0644);
87MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
88
89static int peer2peer;
90module_param(peer2peer, int, 0644);
91MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
92
93static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
94module_param(p2p_type, int, 0644);
95MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
96 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
97
98static int ep_timeout_secs = 60;
99module_param(ep_timeout_secs, int, 0644);
100MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
101 "in seconds (default=60)");
102
103static int mpa_rev = 1;
104module_param(mpa_rev, int, 0644);
105MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530106 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
107 " compliant (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int markers_enabled;
110module_param(markers_enabled, int, 0644);
111MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
112
113static int crc_enabled = 1;
114module_param(crc_enabled, int, 0644);
115MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
116
117static int rcv_win = 256 * 1024;
118module_param(rcv_win, int, 0644);
119MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
120
Steve Wise98ae68b2010-09-10 11:15:41 -0500121static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700122module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500123MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
Steve Wisecfdda9d2010-04-21 15:30:06 -0700125static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700126
127static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700128
129static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
130static void ep_timeout(unsigned long arg);
131static void connect_reply_upcall(struct c4iw_ep *ep, int status);
132
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700133static LIST_HEAD(timeout_list);
134static spinlock_t timeout_lock;
135
Steve Wisecfdda9d2010-04-21 15:30:06 -0700136static void start_ep_timer(struct c4iw_ep *ep)
137{
138 PDBG("%s ep %p\n", __func__, ep);
139 if (timer_pending(&ep->timer)) {
140 PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
141 del_timer_sync(&ep->timer);
142 } else
143 c4iw_get_ep(&ep->com);
144 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
145 ep->timer.data = (unsigned long)ep;
146 ep->timer.function = ep_timeout;
147 add_timer(&ep->timer);
148}
149
150static void stop_ep_timer(struct c4iw_ep *ep)
151{
152 PDBG("%s ep %p\n", __func__, ep);
153 if (!timer_pending(&ep->timer)) {
154 printk(KERN_ERR "%s timer stopped when its not running! "
155 "ep %p state %u\n", __func__, ep, ep->com.state);
156 WARN_ON(1);
157 return;
158 }
159 del_timer_sync(&ep->timer);
160 c4iw_put_ep(&ep->com);
161}
162
163static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
164 struct l2t_entry *l2e)
165{
166 int error = 0;
167
168 if (c4iw_fatal_error(rdev)) {
169 kfree_skb(skb);
170 PDBG("%s - device in error state - dropping\n", __func__);
171 return -EIO;
172 }
173 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
174 if (error < 0)
175 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500176 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700177}
178
179int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
180{
181 int error = 0;
182
183 if (c4iw_fatal_error(rdev)) {
184 kfree_skb(skb);
185 PDBG("%s - device in error state - dropping\n", __func__);
186 return -EIO;
187 }
188 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
189 if (error < 0)
190 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500191 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700192}
193
194static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
195{
196 struct cpl_tid_release *req;
197
198 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
199 if (!skb)
200 return;
201 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
202 INIT_TP_WR(req, hwtid);
203 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
204 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
205 c4iw_ofld_send(rdev, skb);
206 return;
207}
208
209static void set_emss(struct c4iw_ep *ep, u16 opt)
210{
211 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
212 ep->mss = ep->emss;
213 if (GET_TCPOPT_TSTAMP(opt))
214 ep->emss -= 12;
215 if (ep->emss < 128)
216 ep->emss = 128;
217 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
218 ep->mss, ep->emss);
219}
220
221static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
222{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700223 enum c4iw_ep_state state;
224
Steve Wise2f5b48c2010-09-10 11:15:36 -0500225 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700226 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500227 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700228 return state;
229}
230
231static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
232{
233 epc->state = new;
234}
235
236static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
237{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500238 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700239 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
240 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500241 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700242 return;
243}
244
245static void *alloc_ep(int size, gfp_t gfp)
246{
247 struct c4iw_ep_common *epc;
248
249 epc = kzalloc(size, gfp);
250 if (epc) {
251 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500252 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500253 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700254 }
255 PDBG("%s alloc ep %p\n", __func__, epc);
256 return epc;
257}
258
259void _c4iw_free_ep(struct kref *kref)
260{
261 struct c4iw_ep *ep;
262
263 ep = container_of(kref, struct c4iw_ep, com.kref);
264 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
265 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
266 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
267 dst_release(ep->dst);
268 cxgb4_l2t_release(ep->l2t);
269 }
270 kfree(ep);
271}
272
273static void release_ep_resources(struct c4iw_ep *ep)
274{
275 set_bit(RELEASE_RESOURCES, &ep->com.flags);
276 c4iw_put_ep(&ep->com);
277}
278
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279static int status2errno(int status)
280{
281 switch (status) {
282 case CPL_ERR_NONE:
283 return 0;
284 case CPL_ERR_CONN_RESET:
285 return -ECONNRESET;
286 case CPL_ERR_ARP_MISS:
287 return -EHOSTUNREACH;
288 case CPL_ERR_CONN_TIMEDOUT:
289 return -ETIMEDOUT;
290 case CPL_ERR_TCAM_FULL:
291 return -ENOMEM;
292 case CPL_ERR_CONN_EXIST:
293 return -EADDRINUSE;
294 default:
295 return -EIO;
296 }
297}
298
299/*
300 * Try and reuse skbs already allocated...
301 */
302static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
303{
304 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
305 skb_trim(skb, 0);
306 skb_get(skb);
307 skb_reset_transport_header(skb);
308 } else {
309 skb = alloc_skb(len, gfp);
310 }
311 return skb;
312}
313
314static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
315 __be32 peer_ip, __be16 local_port,
316 __be16 peer_port, u8 tos)
317{
318 struct rtable *rt;
David S. Miller31e45432011-05-03 20:25:42 -0700319 struct flowi4 fl4;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700320
David S. Miller31e45432011-05-03 20:25:42 -0700321 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500322 peer_port, local_port, IPPROTO_TCP,
323 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800324 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700325 return NULL;
326 return rt;
327}
328
329static void arp_failure_discard(void *handle, struct sk_buff *skb)
330{
331 PDBG("%s c4iw_dev %p\n", __func__, handle);
332 kfree_skb(skb);
333}
334
335/*
336 * Handle an ARP failure for an active open.
337 */
338static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
339{
340 printk(KERN_ERR MOD "ARP failure duing connect\n");
341 kfree_skb(skb);
342}
343
344/*
345 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
346 * and send it along.
347 */
348static void abort_arp_failure(void *handle, struct sk_buff *skb)
349{
350 struct c4iw_rdev *rdev = handle;
351 struct cpl_abort_req *req = cplhdr(skb);
352
353 PDBG("%s rdev %p\n", __func__, rdev);
354 req->cmd = CPL_ABORT_NO_RST;
355 c4iw_ofld_send(rdev, skb);
356}
357
358static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
359{
360 unsigned int flowclen = 80;
361 struct fw_flowc_wr *flowc;
362 int i;
363
364 skb = get_skb(skb, flowclen, GFP_KERNEL);
365 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
366
367 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
368 FW_FLOWC_WR_NPARAMS(8));
369 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
370 16)) | FW_WR_FLOWID(ep->hwtid));
371
372 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000373 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700374 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
375 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
376 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
377 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
378 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
379 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
380 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
381 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
382 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
383 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
384 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
385 flowc->mnemval[6].val = cpu_to_be32(snd_win);
386 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
387 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
388 /* Pad WR to 16 byte boundary */
389 flowc->mnemval[8].mnemonic = 0;
390 flowc->mnemval[8].val = 0;
391 for (i = 0; i < 9; i++) {
392 flowc->mnemval[i].r4[0] = 0;
393 flowc->mnemval[i].r4[1] = 0;
394 flowc->mnemval[i].r4[2] = 0;
395 }
396
397 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
398 c4iw_ofld_send(&ep->com.dev->rdev, skb);
399}
400
401static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
402{
403 struct cpl_close_con_req *req;
404 struct sk_buff *skb;
405 int wrlen = roundup(sizeof *req, 16);
406
407 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
408 skb = get_skb(NULL, wrlen, gfp);
409 if (!skb) {
410 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
411 return -ENOMEM;
412 }
413 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
414 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
415 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
416 memset(req, 0, wrlen);
417 INIT_TP_WR(req, ep->hwtid);
418 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
419 ep->hwtid));
420 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
421}
422
423static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
424{
425 struct cpl_abort_req *req;
426 int wrlen = roundup(sizeof *req, 16);
427
428 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
429 skb = get_skb(skb, wrlen, gfp);
430 if (!skb) {
431 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
432 __func__);
433 return -ENOMEM;
434 }
435 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
436 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
437 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
438 memset(req, 0, wrlen);
439 INIT_TP_WR(req, ep->hwtid);
440 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
441 req->cmd = CPL_ABORT_SEND_RST;
442 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
443}
444
445static int send_connect(struct c4iw_ep *ep)
446{
447 struct cpl_act_open_req *req;
448 struct sk_buff *skb;
449 u64 opt0;
450 u32 opt2;
451 unsigned int mtu_idx;
452 int wscale;
453 int wrlen = roundup(sizeof *req, 16);
454
455 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
456
457 skb = get_skb(NULL, wrlen, GFP_KERNEL);
458 if (!skb) {
459 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
460 __func__);
461 return -ENOMEM;
462 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000463 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700464
465 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
466 wscale = compute_wscale(rcv_win);
467 opt0 = KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000468 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700469 WND_SCALE(wscale) |
470 MSS_IDX(mtu_idx) |
471 L2T_IDX(ep->l2t->idx) |
472 TX_CHAN(ep->tx_chan) |
473 SMAC_SEL(ep->smac_idx) |
474 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000475 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700476 RCV_BUFSIZ(rcv_win>>10);
477 opt2 = RX_CHANNEL(0) |
478 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
479 if (enable_tcp_timestamps)
480 opt2 |= TSTAMPS_EN(1);
481 if (enable_tcp_sack)
482 opt2 |= SACK_EN(1);
483 if (wscale && enable_tcp_window_scaling)
484 opt2 |= WND_SCALE_EN(1);
485 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
486
487 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
488 INIT_TP_WR(req, 0);
489 OPCODE_TID(req) = cpu_to_be32(
490 MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
491 req->local_port = ep->com.local_addr.sin_port;
492 req->peer_port = ep->com.remote_addr.sin_port;
493 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
494 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
495 req->opt0 = cpu_to_be64(opt0);
496 req->params = 0;
497 req->opt2 = cpu_to_be32(opt2);
498 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
499}
500
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530501static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
502 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700503{
504 int mpalen, wrlen;
505 struct fw_ofld_tx_data_wr *req;
506 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530507 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700508
509 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
510
511 BUG_ON(skb_cloned(skb));
512
513 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530514 if (mpa_rev_to_use == 2)
515 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700516 wrlen = roundup(mpalen + sizeof *req, 16);
517 skb = get_skb(skb, wrlen, GFP_KERNEL);
518 if (!skb) {
519 connect_reply_upcall(ep, -ENOMEM);
520 return;
521 }
522 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
523
524 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
525 memset(req, 0, wrlen);
526 req->op_to_immdlen = cpu_to_be32(
527 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
528 FW_WR_COMPL(1) |
529 FW_WR_IMMDLEN(mpalen));
530 req->flowid_len16 = cpu_to_be32(
531 FW_WR_FLOWID(ep->hwtid) |
532 FW_WR_LEN16(wrlen >> 4));
533 req->plen = cpu_to_be32(mpalen);
534 req->tunnel_to_proxy = cpu_to_be32(
535 FW_OFLD_TX_DATA_WR_FLUSH(1) |
536 FW_OFLD_TX_DATA_WR_SHOVE(1));
537
538 mpa = (struct mpa_message *)(req + 1);
539 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
540 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530541 (markers_enabled ? MPA_MARKERS : 0) |
542 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700543 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530544 mpa->revision = mpa_rev_to_use;
545 if (mpa_rev_to_use == 1)
546 ep->tried_with_mpa_v1 = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700547
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530548 if (mpa_rev_to_use == 2) {
549 mpa->private_data_size +=
550 htons(sizeof(struct mpa_v2_conn_params));
551 mpa_v2_params.ird = htons((u16)ep->ird);
552 mpa_v2_params.ord = htons((u16)ep->ord);
553
554 if (peer2peer) {
555 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
556 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
557 mpa_v2_params.ord |=
558 htons(MPA_V2_RDMA_WRITE_RTR);
559 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
560 mpa_v2_params.ord |=
561 htons(MPA_V2_RDMA_READ_RTR);
562 }
563 memcpy(mpa->private_data, &mpa_v2_params,
564 sizeof(struct mpa_v2_conn_params));
565
566 if (ep->plen)
567 memcpy(mpa->private_data +
568 sizeof(struct mpa_v2_conn_params),
569 ep->mpa_pkt + sizeof(*mpa), ep->plen);
570 } else
571 if (ep->plen)
572 memcpy(mpa->private_data,
573 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700574
575 /*
576 * Reference the mpa skb. This ensures the data area
577 * will remain in memory until the hw acks the tx.
578 * Function fw4_ack() will deref it.
579 */
580 skb_get(skb);
581 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
582 BUG_ON(ep->mpa_skb);
583 ep->mpa_skb = skb;
584 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
585 start_ep_timer(ep);
586 state_set(&ep->com, MPA_REQ_SENT);
587 ep->mpa_attr.initiator = 1;
588 return;
589}
590
591static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
592{
593 int mpalen, wrlen;
594 struct fw_ofld_tx_data_wr *req;
595 struct mpa_message *mpa;
596 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530597 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700598
599 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
600
601 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530602 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
603 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700604 wrlen = roundup(mpalen + sizeof *req, 16);
605
606 skb = get_skb(NULL, wrlen, GFP_KERNEL);
607 if (!skb) {
608 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
609 return -ENOMEM;
610 }
611 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
612
613 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
614 memset(req, 0, wrlen);
615 req->op_to_immdlen = cpu_to_be32(
616 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
617 FW_WR_COMPL(1) |
618 FW_WR_IMMDLEN(mpalen));
619 req->flowid_len16 = cpu_to_be32(
620 FW_WR_FLOWID(ep->hwtid) |
621 FW_WR_LEN16(wrlen >> 4));
622 req->plen = cpu_to_be32(mpalen);
623 req->tunnel_to_proxy = cpu_to_be32(
624 FW_OFLD_TX_DATA_WR_FLUSH(1) |
625 FW_OFLD_TX_DATA_WR_SHOVE(1));
626
627 mpa = (struct mpa_message *)(req + 1);
628 memset(mpa, 0, sizeof(*mpa));
629 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
630 mpa->flags = MPA_REJECT;
631 mpa->revision = mpa_rev;
632 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530633
634 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
635 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
636 mpa->private_data_size +=
637 htons(sizeof(struct mpa_v2_conn_params));
638 mpa_v2_params.ird = htons(((u16)ep->ird) |
639 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
640 0));
641 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
642 (p2p_type ==
643 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
644 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
645 FW_RI_INIT_P2PTYPE_READ_REQ ?
646 MPA_V2_RDMA_READ_RTR : 0) : 0));
647 memcpy(mpa->private_data, &mpa_v2_params,
648 sizeof(struct mpa_v2_conn_params));
649
650 if (ep->plen)
651 memcpy(mpa->private_data +
652 sizeof(struct mpa_v2_conn_params), pdata, plen);
653 } else
654 if (plen)
655 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700656
657 /*
658 * Reference the mpa skb again. This ensures the data area
659 * will remain in memory until the hw acks the tx.
660 * Function fw4_ack() will deref it.
661 */
662 skb_get(skb);
663 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
664 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
665 BUG_ON(ep->mpa_skb);
666 ep->mpa_skb = skb;
667 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
668}
669
670static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
671{
672 int mpalen, wrlen;
673 struct fw_ofld_tx_data_wr *req;
674 struct mpa_message *mpa;
675 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530676 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700677
678 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
679
680 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530681 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
682 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700683 wrlen = roundup(mpalen + sizeof *req, 16);
684
685 skb = get_skb(NULL, wrlen, GFP_KERNEL);
686 if (!skb) {
687 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
688 return -ENOMEM;
689 }
690 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
691
692 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
693 memset(req, 0, wrlen);
694 req->op_to_immdlen = cpu_to_be32(
695 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
696 FW_WR_COMPL(1) |
697 FW_WR_IMMDLEN(mpalen));
698 req->flowid_len16 = cpu_to_be32(
699 FW_WR_FLOWID(ep->hwtid) |
700 FW_WR_LEN16(wrlen >> 4));
701 req->plen = cpu_to_be32(mpalen);
702 req->tunnel_to_proxy = cpu_to_be32(
703 FW_OFLD_TX_DATA_WR_FLUSH(1) |
704 FW_OFLD_TX_DATA_WR_SHOVE(1));
705
706 mpa = (struct mpa_message *)(req + 1);
707 memset(mpa, 0, sizeof(*mpa));
708 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
709 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
710 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530711 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700712 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530713
714 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
715 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
716 mpa->private_data_size +=
717 htons(sizeof(struct mpa_v2_conn_params));
718 mpa_v2_params.ird = htons((u16)ep->ird);
719 mpa_v2_params.ord = htons((u16)ep->ord);
720 if (peer2peer && (ep->mpa_attr.p2p_type !=
721 FW_RI_INIT_P2PTYPE_DISABLED)) {
722 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
723
724 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
725 mpa_v2_params.ord |=
726 htons(MPA_V2_RDMA_WRITE_RTR);
727 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
728 mpa_v2_params.ord |=
729 htons(MPA_V2_RDMA_READ_RTR);
730 }
731
732 memcpy(mpa->private_data, &mpa_v2_params,
733 sizeof(struct mpa_v2_conn_params));
734
735 if (ep->plen)
736 memcpy(mpa->private_data +
737 sizeof(struct mpa_v2_conn_params), pdata, plen);
738 } else
739 if (plen)
740 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700741
742 /*
743 * Reference the mpa skb. This ensures the data area
744 * will remain in memory until the hw acks the tx.
745 * Function fw4_ack() will deref it.
746 */
747 skb_get(skb);
748 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
749 ep->mpa_skb = skb;
750 state_set(&ep->com, MPA_REP_SENT);
751 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
752}
753
754static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
755{
756 struct c4iw_ep *ep;
757 struct cpl_act_establish *req = cplhdr(skb);
758 unsigned int tid = GET_TID(req);
759 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
760 struct tid_info *t = dev->rdev.lldi.tids;
761
762 ep = lookup_atid(t, atid);
763
764 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
765 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
766
767 dst_confirm(ep->dst);
768
769 /* setup the hwtid for this connection */
770 ep->hwtid = tid;
771 cxgb4_insert_tid(t, ep, tid);
772
773 ep->snd_seq = be32_to_cpu(req->snd_isn);
774 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
775
776 set_emss(ep, ntohs(req->tcp_opt));
777
778 /* dealloc the atid */
779 cxgb4_free_atid(t, atid);
780
781 /* start MPA negotiation */
782 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530783 if (ep->retry_with_mpa_v1)
784 send_mpa_req(ep, skb, 1);
785 else
786 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700787
788 return 0;
789}
790
791static void close_complete_upcall(struct c4iw_ep *ep)
792{
793 struct iw_cm_event event;
794
795 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
796 memset(&event, 0, sizeof(event));
797 event.event = IW_CM_EVENT_CLOSE;
798 if (ep->com.cm_id) {
799 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
800 ep, ep->com.cm_id, ep->hwtid);
801 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
802 ep->com.cm_id->rem_ref(ep->com.cm_id);
803 ep->com.cm_id = NULL;
804 ep->com.qp = NULL;
805 }
806}
807
808static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
809{
810 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
811 close_complete_upcall(ep);
812 state_set(&ep->com, ABORTING);
813 return send_abort(ep, skb, gfp);
814}
815
816static void peer_close_upcall(struct c4iw_ep *ep)
817{
818 struct iw_cm_event event;
819
820 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
821 memset(&event, 0, sizeof(event));
822 event.event = IW_CM_EVENT_DISCONNECT;
823 if (ep->com.cm_id) {
824 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
825 ep, ep->com.cm_id, ep->hwtid);
826 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
827 }
828}
829
830static void peer_abort_upcall(struct c4iw_ep *ep)
831{
832 struct iw_cm_event event;
833
834 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
835 memset(&event, 0, sizeof(event));
836 event.event = IW_CM_EVENT_CLOSE;
837 event.status = -ECONNRESET;
838 if (ep->com.cm_id) {
839 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
840 ep->com.cm_id, ep->hwtid);
841 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
842 ep->com.cm_id->rem_ref(ep->com.cm_id);
843 ep->com.cm_id = NULL;
844 ep->com.qp = NULL;
845 }
846}
847
848static void connect_reply_upcall(struct c4iw_ep *ep, int status)
849{
850 struct iw_cm_event event;
851
852 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
853 memset(&event, 0, sizeof(event));
854 event.event = IW_CM_EVENT_CONNECT_REPLY;
855 event.status = status;
856 event.local_addr = ep->com.local_addr;
857 event.remote_addr = ep->com.remote_addr;
858
859 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530860 if (!ep->tried_with_mpa_v1) {
861 /* this means MPA_v2 is used */
862 event.private_data_len = ep->plen -
863 sizeof(struct mpa_v2_conn_params);
864 event.private_data = ep->mpa_pkt +
865 sizeof(struct mpa_message) +
866 sizeof(struct mpa_v2_conn_params);
867 } else {
868 /* this means MPA_v1 is used */
869 event.private_data_len = ep->plen;
870 event.private_data = ep->mpa_pkt +
871 sizeof(struct mpa_message);
872 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700873 }
Roland Dreier85963e42010-07-19 13:13:09 -0700874
875 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
876 ep->hwtid, status);
877 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
878
Steve Wisecfdda9d2010-04-21 15:30:06 -0700879 if (status < 0) {
880 ep->com.cm_id->rem_ref(ep->com.cm_id);
881 ep->com.cm_id = NULL;
882 ep->com.qp = NULL;
883 }
884}
885
886static void connect_request_upcall(struct c4iw_ep *ep)
887{
888 struct iw_cm_event event;
889
890 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
891 memset(&event, 0, sizeof(event));
892 event.event = IW_CM_EVENT_CONNECT_REQUEST;
893 event.local_addr = ep->com.local_addr;
894 event.remote_addr = ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700895 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530896 if (!ep->tried_with_mpa_v1) {
897 /* this means MPA_v2 is used */
898 event.ord = ep->ord;
899 event.ird = ep->ird;
900 event.private_data_len = ep->plen -
901 sizeof(struct mpa_v2_conn_params);
902 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
903 sizeof(struct mpa_v2_conn_params);
904 } else {
905 /* this means MPA_v1 is used. Send max supported */
906 event.ord = c4iw_max_read_depth;
907 event.ird = c4iw_max_read_depth;
908 event.private_data_len = ep->plen;
909 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
910 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700911 if (state_read(&ep->parent_ep->com) != DEAD) {
912 c4iw_get_ep(&ep->com);
913 ep->parent_ep->com.cm_id->event_handler(
914 ep->parent_ep->com.cm_id,
915 &event);
916 }
917 c4iw_put_ep(&ep->parent_ep->com);
918 ep->parent_ep = NULL;
919}
920
921static void established_upcall(struct c4iw_ep *ep)
922{
923 struct iw_cm_event event;
924
925 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
926 memset(&event, 0, sizeof(event));
927 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530928 event.ird = ep->ird;
929 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930 if (ep->com.cm_id) {
931 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
932 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
933 }
934}
935
936static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
937{
938 struct cpl_rx_data_ack *req;
939 struct sk_buff *skb;
940 int wrlen = roundup(sizeof *req, 16);
941
942 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
943 skb = get_skb(NULL, wrlen, GFP_KERNEL);
944 if (!skb) {
945 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
946 return 0;
947 }
948
949 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
950 memset(req, 0, wrlen);
951 INIT_TP_WR(req, ep->hwtid);
952 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
953 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +0000954 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
955 F_RX_DACK_CHANGE |
956 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +0000957 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700958 c4iw_ofld_send(&ep->com.dev->rdev, skb);
959 return credits;
960}
961
962static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
963{
964 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700966 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530967 u16 resp_ird, resp_ord;
968 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700969 struct c4iw_qp_attributes attrs;
970 enum c4iw_qp_attr_mask mask;
971 int err;
972
973 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
974
975 /*
976 * Stop mpa timer. If it expired, then the state has
977 * changed and we bail since ep_timeout already aborted
978 * the connection.
979 */
980 stop_ep_timer(ep);
981 if (state_read(&ep->com) != MPA_REQ_SENT)
982 return;
983
984 /*
985 * If we get more than the supported amount of private data
986 * then we must fail this connection.
987 */
988 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
989 err = -EINVAL;
990 goto err;
991 }
992
993 /*
994 * copy the new data into our accumulation buffer.
995 */
996 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
997 skb->len);
998 ep->mpa_pkt_len += skb->len;
999
1000 /*
1001 * if we don't even have the mpa message, then bail.
1002 */
1003 if (ep->mpa_pkt_len < sizeof(*mpa))
1004 return;
1005 mpa = (struct mpa_message *) ep->mpa_pkt;
1006
1007 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301008 if (mpa->revision > mpa_rev) {
1009 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1010 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011 err = -EPROTO;
1012 goto err;
1013 }
1014 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1015 err = -EPROTO;
1016 goto err;
1017 }
1018
1019 plen = ntohs(mpa->private_data_size);
1020
1021 /*
1022 * Fail if there's too much private data.
1023 */
1024 if (plen > MPA_MAX_PRIVATE_DATA) {
1025 err = -EPROTO;
1026 goto err;
1027 }
1028
1029 /*
1030 * If plen does not account for pkt size
1031 */
1032 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1033 err = -EPROTO;
1034 goto err;
1035 }
1036
1037 ep->plen = (u8) plen;
1038
1039 /*
1040 * If we don't have all the pdata yet, then bail.
1041 * We'll continue process when more data arrives.
1042 */
1043 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1044 return;
1045
1046 if (mpa->flags & MPA_REJECT) {
1047 err = -ECONNREFUSED;
1048 goto err;
1049 }
1050
1051 /*
1052 * If we get here we have accumulated the entire mpa
1053 * start reply message including private data. And
1054 * the MPA header is valid.
1055 */
1056 state_set(&ep->com, FPDU_MODE);
1057 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1058 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1059 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301060 ep->mpa_attr.version = mpa->revision;
1061 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1062
1063 if (mpa->revision == 2) {
1064 ep->mpa_attr.enhanced_rdma_conn =
1065 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1066 if (ep->mpa_attr.enhanced_rdma_conn) {
1067 mpa_v2_params = (struct mpa_v2_conn_params *)
1068 (ep->mpa_pkt + sizeof(*mpa));
1069 resp_ird = ntohs(mpa_v2_params->ird) &
1070 MPA_V2_IRD_ORD_MASK;
1071 resp_ord = ntohs(mpa_v2_params->ord) &
1072 MPA_V2_IRD_ORD_MASK;
1073
1074 /*
1075 * This is a double-check. Ideally, below checks are
1076 * not required since ird/ord stuff has been taken
1077 * care of in c4iw_accept_cr
1078 */
1079 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1080 err = -ENOMEM;
1081 ep->ird = resp_ord;
1082 ep->ord = resp_ird;
1083 insuff_ird = 1;
1084 }
1085
1086 if (ntohs(mpa_v2_params->ird) &
1087 MPA_V2_PEER2PEER_MODEL) {
1088 if (ntohs(mpa_v2_params->ord) &
1089 MPA_V2_RDMA_WRITE_RTR)
1090 ep->mpa_attr.p2p_type =
1091 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1092 else if (ntohs(mpa_v2_params->ord) &
1093 MPA_V2_RDMA_READ_RTR)
1094 ep->mpa_attr.p2p_type =
1095 FW_RI_INIT_P2PTYPE_READ_REQ;
1096 }
1097 }
1098 } else if (mpa->revision == 1)
1099 if (peer2peer)
1100 ep->mpa_attr.p2p_type = p2p_type;
1101
Steve Wisecfdda9d2010-04-21 15:30:06 -07001102 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301103 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1104 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1105 ep->mpa_attr.recv_marker_enabled,
1106 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1107 ep->mpa_attr.p2p_type, p2p_type);
1108
1109 /*
1110 * If responder's RTR does not match with that of initiator, assign
1111 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1112 * generated when moving QP to RTS state.
1113 * A TERM message will be sent after QP has moved to RTS state
1114 */
1115 if ((ep->mpa_attr.version == 2) &&
1116 (ep->mpa_attr.p2p_type != p2p_type)) {
1117 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1118 rtr_mismatch = 1;
1119 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001120
1121 attrs.mpa_attr = ep->mpa_attr;
1122 attrs.max_ird = ep->ird;
1123 attrs.max_ord = ep->ord;
1124 attrs.llp_stream_handle = ep;
1125 attrs.next_state = C4IW_QP_STATE_RTS;
1126
1127 mask = C4IW_QP_ATTR_NEXT_STATE |
1128 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1129 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1130
1131 /* bind QP and TID with INIT_WR */
1132 err = c4iw_modify_qp(ep->com.qp->rhp,
1133 ep->com.qp, mask, &attrs, 1);
1134 if (err)
1135 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301136
1137 /*
1138 * If responder's RTR requirement did not match with what initiator
1139 * supports, generate TERM message
1140 */
1141 if (rtr_mismatch) {
1142 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1143 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1144 attrs.ecode = MPA_NOMATCH_RTR;
1145 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1146 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1147 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1148 err = -ENOMEM;
1149 goto out;
1150 }
1151
1152 /*
1153 * Generate TERM if initiator IRD is not sufficient for responder
1154 * provided ORD. Currently, we do the same behaviour even when
1155 * responder provided IRD is also not sufficient as regards to
1156 * initiator ORD.
1157 */
1158 if (insuff_ird) {
1159 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1160 __func__);
1161 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1162 attrs.ecode = MPA_INSUFF_IRD;
1163 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1164 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1165 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1166 err = -ENOMEM;
1167 goto out;
1168 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169 goto out;
1170err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001171 state_set(&ep->com, ABORTING);
1172 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173out:
1174 connect_reply_upcall(ep, err);
1175 return;
1176}
1177
1178static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1179{
1180 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301181 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182 u16 plen;
1183
1184 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1185
1186 if (state_read(&ep->com) != MPA_REQ_WAIT)
1187 return;
1188
1189 /*
1190 * If we get more than the supported amount of private data
1191 * then we must fail this connection.
1192 */
1193 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1194 stop_ep_timer(ep);
1195 abort_connection(ep, skb, GFP_KERNEL);
1196 return;
1197 }
1198
1199 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1200
1201 /*
1202 * Copy the new data into our accumulation buffer.
1203 */
1204 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1205 skb->len);
1206 ep->mpa_pkt_len += skb->len;
1207
1208 /*
1209 * If we don't even have the mpa message, then bail.
1210 * We'll continue process when more data arrives.
1211 */
1212 if (ep->mpa_pkt_len < sizeof(*mpa))
1213 return;
1214
1215 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1216 stop_ep_timer(ep);
1217 mpa = (struct mpa_message *) ep->mpa_pkt;
1218
1219 /*
1220 * Validate MPA Header.
1221 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301222 if (mpa->revision > mpa_rev) {
1223 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1224 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001225 abort_connection(ep, skb, GFP_KERNEL);
1226 return;
1227 }
1228
1229 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1230 abort_connection(ep, skb, GFP_KERNEL);
1231 return;
1232 }
1233
1234 plen = ntohs(mpa->private_data_size);
1235
1236 /*
1237 * Fail if there's too much private data.
1238 */
1239 if (plen > MPA_MAX_PRIVATE_DATA) {
1240 abort_connection(ep, skb, GFP_KERNEL);
1241 return;
1242 }
1243
1244 /*
1245 * If plen does not account for pkt size
1246 */
1247 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1248 abort_connection(ep, skb, GFP_KERNEL);
1249 return;
1250 }
1251 ep->plen = (u8) plen;
1252
1253 /*
1254 * If we don't have all the pdata yet, then bail.
1255 */
1256 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1257 return;
1258
1259 /*
1260 * If we get here we have accumulated the entire mpa
1261 * start reply message including private data.
1262 */
1263 ep->mpa_attr.initiator = 0;
1264 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1265 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1266 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301267 ep->mpa_attr.version = mpa->revision;
1268 if (mpa->revision == 1)
1269 ep->tried_with_mpa_v1 = 1;
1270 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1271
1272 if (mpa->revision == 2) {
1273 ep->mpa_attr.enhanced_rdma_conn =
1274 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1275 if (ep->mpa_attr.enhanced_rdma_conn) {
1276 mpa_v2_params = (struct mpa_v2_conn_params *)
1277 (ep->mpa_pkt + sizeof(*mpa));
1278 ep->ird = ntohs(mpa_v2_params->ird) &
1279 MPA_V2_IRD_ORD_MASK;
1280 ep->ord = ntohs(mpa_v2_params->ord) &
1281 MPA_V2_IRD_ORD_MASK;
1282 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1283 if (peer2peer) {
1284 if (ntohs(mpa_v2_params->ord) &
1285 MPA_V2_RDMA_WRITE_RTR)
1286 ep->mpa_attr.p2p_type =
1287 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1288 else if (ntohs(mpa_v2_params->ord) &
1289 MPA_V2_RDMA_READ_RTR)
1290 ep->mpa_attr.p2p_type =
1291 FW_RI_INIT_P2PTYPE_READ_REQ;
1292 }
1293 }
1294 } else if (mpa->revision == 1)
1295 if (peer2peer)
1296 ep->mpa_attr.p2p_type = p2p_type;
1297
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1299 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1300 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1301 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1302 ep->mpa_attr.p2p_type);
1303
1304 state_set(&ep->com, MPA_REQ_RCVD);
1305
1306 /* drive upcall */
1307 connect_request_upcall(ep);
1308 return;
1309}
1310
1311static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1312{
1313 struct c4iw_ep *ep;
1314 struct cpl_rx_data *hdr = cplhdr(skb);
1315 unsigned int dlen = ntohs(hdr->len);
1316 unsigned int tid = GET_TID(hdr);
1317 struct tid_info *t = dev->rdev.lldi.tids;
1318
1319 ep = lookup_tid(t, tid);
1320 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1321 skb_pull(skb, sizeof(*hdr));
1322 skb_trim(skb, dlen);
1323
1324 ep->rcv_seq += dlen;
1325 BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
1326
1327 /* update RX credits */
1328 update_rx_credits(ep, dlen);
1329
1330 switch (state_read(&ep->com)) {
1331 case MPA_REQ_SENT:
1332 process_mpa_reply(ep, skb);
1333 break;
1334 case MPA_REQ_WAIT:
1335 process_mpa_request(ep, skb);
1336 break;
1337 case MPA_REP_SENT:
1338 break;
1339 default:
1340 printk(KERN_ERR MOD "%s Unexpected streaming data."
1341 " ep %p state %d tid %u\n",
1342 __func__, ep, state_read(&ep->com), ep->hwtid);
1343
1344 /*
1345 * The ep will timeout and inform the ULP of the failure.
1346 * See ep_timeout().
1347 */
1348 break;
1349 }
1350 return 0;
1351}
1352
1353static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1354{
1355 struct c4iw_ep *ep;
1356 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001357 int release = 0;
1358 unsigned int tid = GET_TID(rpl);
1359 struct tid_info *t = dev->rdev.lldi.tids;
1360
1361 ep = lookup_tid(t, tid);
1362 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1363 BUG_ON(!ep);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001364 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 switch (ep->com.state) {
1366 case ABORTING:
1367 __state_set(&ep->com, DEAD);
1368 release = 1;
1369 break;
1370 default:
1371 printk(KERN_ERR "%s ep %p state %d\n",
1372 __func__, ep, ep->com.state);
1373 break;
1374 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001375 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376
1377 if (release)
1378 release_ep_resources(ep);
1379 return 0;
1380}
1381
1382/*
1383 * Return whether a failed active open has allocated a TID
1384 */
1385static inline int act_open_has_tid(int status)
1386{
1387 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1388 status != CPL_ERR_ARP_MISS;
1389}
1390
1391static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1392{
1393 struct c4iw_ep *ep;
1394 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1395 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1396 ntohl(rpl->atid_status)));
1397 struct tid_info *t = dev->rdev.lldi.tids;
1398 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1399
1400 ep = lookup_atid(t, atid);
1401
1402 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1403 status, status2errno(status));
1404
1405 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1406 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1407 atid);
1408 return 0;
1409 }
1410
1411 connect_reply_upcall(ep, status2errno(status));
1412 state_set(&ep->com, DEAD);
1413
1414 if (status && act_open_has_tid(status))
1415 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1416
1417 cxgb4_free_atid(t, atid);
1418 dst_release(ep->dst);
1419 cxgb4_l2t_release(ep->l2t);
1420 c4iw_put_ep(&ep->com);
1421
1422 return 0;
1423}
1424
1425static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1426{
1427 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1428 struct tid_info *t = dev->rdev.lldi.tids;
1429 unsigned int stid = GET_TID(rpl);
1430 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1431
1432 if (!ep) {
1433 printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
1434 return 0;
1435 }
1436 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1437 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001438 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439
1440 return 0;
1441}
1442
1443static int listen_stop(struct c4iw_listen_ep *ep)
1444{
1445 struct sk_buff *skb;
1446 struct cpl_close_listsvr_req *req;
1447
1448 PDBG("%s ep %p\n", __func__, ep);
1449 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1450 if (!skb) {
1451 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1452 return -ENOMEM;
1453 }
1454 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1455 INIT_TP_WR(req, 0);
1456 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1457 ep->stid));
1458 req->reply_ctrl = cpu_to_be16(
1459 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1460 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1461 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1462}
1463
1464static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1465{
1466 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1467 struct tid_info *t = dev->rdev.lldi.tids;
1468 unsigned int stid = GET_TID(rpl);
1469 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1470
1471 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001472 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 return 0;
1474}
1475
1476static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1477 struct cpl_pass_accept_req *req)
1478{
1479 struct cpl_pass_accept_rpl *rpl;
1480 unsigned int mtu_idx;
1481 u64 opt0;
1482 u32 opt2;
1483 int wscale;
1484
1485 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1486 BUG_ON(skb_cloned(skb));
1487 skb_trim(skb, sizeof(*rpl));
1488 skb_get(skb);
1489 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1490 wscale = compute_wscale(rcv_win);
1491 opt0 = KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001492 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001493 WND_SCALE(wscale) |
1494 MSS_IDX(mtu_idx) |
1495 L2T_IDX(ep->l2t->idx) |
1496 TX_CHAN(ep->tx_chan) |
1497 SMAC_SEL(ep->smac_idx) |
1498 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001499 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001500 RCV_BUFSIZ(rcv_win>>10);
1501 opt2 = RX_CHANNEL(0) |
1502 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1503
1504 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1505 opt2 |= TSTAMPS_EN(1);
1506 if (enable_tcp_sack && req->tcpopt.sack)
1507 opt2 |= SACK_EN(1);
1508 if (wscale && enable_tcp_window_scaling)
1509 opt2 |= WND_SCALE_EN(1);
1510
1511 rpl = cplhdr(skb);
1512 INIT_TP_WR(rpl, ep->hwtid);
1513 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1514 ep->hwtid));
1515 rpl->opt0 = cpu_to_be64(opt0);
1516 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001517 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001518 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1519
1520 return;
1521}
1522
1523static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1524 struct sk_buff *skb)
1525{
1526 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1527 peer_ip);
1528 BUG_ON(skb_cloned(skb));
1529 skb_trim(skb, sizeof(struct cpl_tid_release));
1530 skb_get(skb);
1531 release_tid(&dev->rdev, hwtid, skb);
1532 return;
1533}
1534
1535static void get_4tuple(struct cpl_pass_accept_req *req,
1536 __be32 *local_ip, __be32 *peer_ip,
1537 __be16 *local_port, __be16 *peer_port)
1538{
1539 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1540 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1541 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1542 struct tcphdr *tcp = (struct tcphdr *)
1543 ((u8 *)(req + 1) + eth_len + ip_len);
1544
1545 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1546 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1547 ntohs(tcp->dest));
1548
1549 *peer_ip = ip->saddr;
1550 *local_ip = ip->daddr;
1551 *peer_port = tcp->source;
1552 *local_port = tcp->dest;
1553
1554 return;
1555}
1556
1557static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1558{
1559 struct c4iw_ep *child_ep, *parent_ep;
1560 struct cpl_pass_accept_req *req = cplhdr(skb);
1561 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1562 struct tid_info *t = dev->rdev.lldi.tids;
1563 unsigned int hwtid = GET_TID(req);
David S. Miller69cce1d2011-07-17 23:09:49 -07001564 struct neighbour *neigh;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001565 struct dst_entry *dst;
1566 struct l2t_entry *l2t;
1567 struct rtable *rt;
1568 __be32 local_ip, peer_ip;
1569 __be16 local_port, peer_port;
1570 struct net_device *pdev;
1571 u32 tx_chan, smac_idx;
1572 u16 rss_qid;
1573 u32 mtu;
1574 int step;
Steve Wised4f1a5c2010-07-23 19:12:32 +00001575 int txq_idx, ctrlq_idx;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001576
1577 parent_ep = lookup_stid(t, stid);
1578 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
1579
1580 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1581
1582 if (state_read(&parent_ep->com) != LISTEN) {
1583 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1584 __func__);
1585 goto reject;
1586 }
1587
1588 /* Find output route */
1589 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1590 GET_POPEN_TOS(ntohl(req->tos_stid)));
1591 if (!rt) {
1592 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1593 __func__);
1594 goto reject;
1595 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001596 dst = &rt->dst;
Eric Dumazet580da352011-11-29 22:31:23 +01001597 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07001598 neigh = dst_get_neighbour(dst);
1599 if (neigh->dev->flags & IFF_LOOPBACK) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001600 pdev = ip_dev_find(&init_net, peer_ip);
1601 BUG_ON(!pdev);
David S. Miller69cce1d2011-07-17 23:09:49 -07001602 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, pdev, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001603 mtu = pdev->mtu;
1604 tx_chan = cxgb4_port_chan(pdev);
Steve Wise2c5934b2010-06-23 15:46:44 +00001605 smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001606 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
1607 txq_idx = cxgb4_port_idx(pdev) * step;
Steve Wised4f1a5c2010-07-23 19:12:32 +00001608 ctrlq_idx = cxgb4_port_idx(pdev);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001609 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1610 rss_qid = dev->rdev.lldi.rxq_ids[cxgb4_port_idx(pdev) * step];
1611 dev_put(pdev);
1612 } else {
David S. Miller69cce1d2011-07-17 23:09:49 -07001613 l2t = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh, neigh->dev, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001614 mtu = dst_mtu(dst);
David S. Miller69cce1d2011-07-17 23:09:49 -07001615 tx_chan = cxgb4_port_chan(neigh->dev);
1616 smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001617 step = dev->rdev.lldi.ntxq / dev->rdev.lldi.nchan;
David S. Miller69cce1d2011-07-17 23:09:49 -07001618 txq_idx = cxgb4_port_idx(neigh->dev) * step;
1619 ctrlq_idx = cxgb4_port_idx(neigh->dev);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
1621 rss_qid = dev->rdev.lldi.rxq_ids[
David S. Miller69cce1d2011-07-17 23:09:49 -07001622 cxgb4_port_idx(neigh->dev) * step];
Steve Wisecfdda9d2010-04-21 15:30:06 -07001623 }
Eric Dumazet580da352011-11-29 22:31:23 +01001624 rcu_read_unlock();
Steve Wisecfdda9d2010-04-21 15:30:06 -07001625 if (!l2t) {
1626 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1627 __func__);
1628 dst_release(dst);
1629 goto reject;
1630 }
1631
1632 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1633 if (!child_ep) {
1634 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1635 __func__);
1636 cxgb4_l2t_release(l2t);
1637 dst_release(dst);
1638 goto reject;
1639 }
1640 state_set(&child_ep->com, CONNECTING);
1641 child_ep->com.dev = dev;
1642 child_ep->com.cm_id = NULL;
1643 child_ep->com.local_addr.sin_family = PF_INET;
1644 child_ep->com.local_addr.sin_port = local_port;
1645 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1646 child_ep->com.remote_addr.sin_family = PF_INET;
1647 child_ep->com.remote_addr.sin_port = peer_port;
1648 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1649 c4iw_get_ep(&parent_ep->com);
1650 child_ep->parent_ep = parent_ep;
1651 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
1652 child_ep->l2t = l2t;
1653 child_ep->dst = dst;
1654 child_ep->hwtid = hwtid;
1655 child_ep->tx_chan = tx_chan;
1656 child_ep->smac_idx = smac_idx;
1657 child_ep->rss_qid = rss_qid;
1658 child_ep->mtu = mtu;
1659 child_ep->txq_idx = txq_idx;
Steve Wised4f1a5c2010-07-23 19:12:32 +00001660 child_ep->ctrlq_idx = ctrlq_idx;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001661
1662 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
1663 tx_chan, smac_idx, rss_qid);
1664
1665 init_timer(&child_ep->timer);
1666 cxgb4_insert_tid(t, child_ep, hwtid);
1667 accept_cr(child_ep, peer_ip, skb, req);
1668 goto out;
1669reject:
1670 reject_cr(dev, hwtid, peer_ip, skb);
1671out:
1672 return 0;
1673}
1674
1675static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1676{
1677 struct c4iw_ep *ep;
1678 struct cpl_pass_establish *req = cplhdr(skb);
1679 struct tid_info *t = dev->rdev.lldi.tids;
1680 unsigned int tid = GET_TID(req);
1681
1682 ep = lookup_tid(t, tid);
1683 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1684 ep->snd_seq = be32_to_cpu(req->snd_isn);
1685 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1686
1687 set_emss(ep, ntohs(req->tcp_opt));
1688
1689 dst_confirm(ep->dst);
1690 state_set(&ep->com, MPA_REQ_WAIT);
1691 start_ep_timer(ep);
1692 send_flowc(ep, skb);
1693
1694 return 0;
1695}
1696
1697static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
1698{
1699 struct cpl_peer_close *hdr = cplhdr(skb);
1700 struct c4iw_ep *ep;
1701 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001702 int disconnect = 1;
1703 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001704 struct tid_info *t = dev->rdev.lldi.tids;
1705 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00001706 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001707
1708 ep = lookup_tid(t, tid);
1709 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1710 dst_confirm(ep->dst);
1711
Steve Wise2f5b48c2010-09-10 11:15:36 -05001712 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001713 switch (ep->com.state) {
1714 case MPA_REQ_WAIT:
1715 __state_set(&ep->com, CLOSING);
1716 break;
1717 case MPA_REQ_SENT:
1718 __state_set(&ep->com, CLOSING);
1719 connect_reply_upcall(ep, -ECONNRESET);
1720 break;
1721 case MPA_REQ_RCVD:
1722
1723 /*
1724 * We're gonna mark this puppy DEAD, but keep
1725 * the reference on it until the ULP accepts or
1726 * rejects the CR. Also wake up anyone waiting
1727 * in rdma connection migration (see c4iw_accept_cr()).
1728 */
1729 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001730 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07001731 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001732 break;
1733 case MPA_REP_SENT:
1734 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001735 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07001736 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001737 break;
1738 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00001739 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001740 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07001741 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00001742 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07001743 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00001744 if (ret != -ECONNRESET) {
1745 peer_close_upcall(ep);
1746 disconnect = 1;
1747 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001748 break;
1749 case ABORTING:
1750 disconnect = 0;
1751 break;
1752 case CLOSING:
1753 __state_set(&ep->com, MORIBUND);
1754 disconnect = 0;
1755 break;
1756 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00001757 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001758 if (ep->com.cm_id && ep->com.qp) {
1759 attrs.next_state = C4IW_QP_STATE_IDLE;
1760 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1761 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1762 }
1763 close_complete_upcall(ep);
1764 __state_set(&ep->com, DEAD);
1765 release = 1;
1766 disconnect = 0;
1767 break;
1768 case DEAD:
1769 disconnect = 0;
1770 break;
1771 default:
1772 BUG_ON(1);
1773 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001774 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775 if (disconnect)
1776 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1777 if (release)
1778 release_ep_resources(ep);
1779 return 0;
1780}
1781
1782/*
1783 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1784 */
1785static int is_neg_adv_abort(unsigned int status)
1786{
1787 return status == CPL_ERR_RTX_NEG_ADVICE ||
1788 status == CPL_ERR_PERSIST_NEG_ADVICE;
1789}
1790
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301791static int c4iw_reconnect(struct c4iw_ep *ep)
1792{
1793 int err = 0;
1794 struct rtable *rt;
1795 struct net_device *pdev;
1796 struct neighbour *neigh;
1797 int step;
1798
1799 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1800 init_timer(&ep->timer);
1801
1802 /*
1803 * Allocate an active TID to initiate a TCP connection.
1804 */
1805 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1806 if (ep->atid == -1) {
1807 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
1808 err = -ENOMEM;
1809 goto fail2;
1810 }
1811
1812 /* find a route */
1813 rt = find_route(ep->com.dev,
1814 ep->com.cm_id->local_addr.sin_addr.s_addr,
1815 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1816 ep->com.cm_id->local_addr.sin_port,
1817 ep->com.cm_id->remote_addr.sin_port, 0);
1818 if (!rt) {
1819 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
1820 err = -EHOSTUNREACH;
1821 goto fail3;
1822 }
1823 ep->dst = &rt->dst;
1824
Eric Dumazet580da352011-11-29 22:31:23 +01001825 rcu_read_lock();
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301826 neigh = dst_get_neighbour(ep->dst);
1827
1828 /* get a l2t entry */
1829 if (neigh->dev->flags & IFF_LOOPBACK) {
1830 PDBG("%s LOOPBACK\n", __func__);
1831 pdev = ip_dev_find(&init_net,
1832 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1833 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1834 neigh, pdev, 0);
1835 ep->mtu = pdev->mtu;
1836 ep->tx_chan = cxgb4_port_chan(pdev);
1837 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1838 step = ep->com.dev->rdev.lldi.ntxq /
1839 ep->com.dev->rdev.lldi.nchan;
1840 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1841 step = ep->com.dev->rdev.lldi.nrxq /
1842 ep->com.dev->rdev.lldi.nchan;
1843 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1844 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1845 cxgb4_port_idx(pdev) * step];
1846 dev_put(pdev);
1847 } else {
1848 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1849 neigh, neigh->dev, 0);
1850 ep->mtu = dst_mtu(ep->dst);
1851 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1852 ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
1853 step = ep->com.dev->rdev.lldi.ntxq /
1854 ep->com.dev->rdev.lldi.nchan;
1855 ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
1856 ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
1857 step = ep->com.dev->rdev.lldi.nrxq /
1858 ep->com.dev->rdev.lldi.nchan;
1859 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
1860 cxgb4_port_idx(neigh->dev) * step];
1861 }
Eric Dumazet580da352011-11-29 22:31:23 +01001862 rcu_read_unlock();
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301863 if (!ep->l2t) {
1864 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
1865 err = -ENOMEM;
1866 goto fail4;
1867 }
1868
1869 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1870 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1871 ep->l2t->idx);
1872
1873 state_set(&ep->com, CONNECTING);
1874 ep->tos = 0;
1875
1876 /* send connect request to rnic */
1877 err = send_connect(ep);
1878 if (!err)
1879 goto out;
1880
1881 cxgb4_l2t_release(ep->l2t);
1882fail4:
1883 dst_release(ep->dst);
1884fail3:
1885 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1886fail2:
1887 /*
1888 * remember to send notification to upper layer.
1889 * We are in here so the upper layer is not aware that this is
1890 * re-connect attempt and so, upper layer is still waiting for
1891 * response of 1st connect request.
1892 */
1893 connect_reply_upcall(ep, -ECONNRESET);
1894 c4iw_put_ep(&ep->com);
1895out:
1896 return err;
1897}
1898
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
1900{
1901 struct cpl_abort_req_rss *req = cplhdr(skb);
1902 struct c4iw_ep *ep;
1903 struct cpl_abort_rpl *rpl;
1904 struct sk_buff *rpl_skb;
1905 struct c4iw_qp_attributes attrs;
1906 int ret;
1907 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001908 struct tid_info *t = dev->rdev.lldi.tids;
1909 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001910
1911 ep = lookup_tid(t, tid);
1912 if (is_neg_adv_abort(req->status)) {
1913 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
1914 ep->hwtid);
1915 return 0;
1916 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001917 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
1918 ep->com.state);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001919
1920 /*
1921 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301922 * However, this is not needed if com state is just
1923 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05001924 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301925 if (ep->com.state != MPA_REQ_SENT)
1926 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001927
1928 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001929 switch (ep->com.state) {
1930 case CONNECTING:
1931 break;
1932 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00001933 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001934 break;
1935 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00001936 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301937 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
1938 connect_reply_upcall(ep, -ECONNRESET);
1939 else {
1940 /*
1941 * we just don't send notification upwards because we
1942 * want to retry with mpa_v1 without upper layers even
1943 * knowing it.
1944 *
1945 * do some housekeeping so as to re-initiate the
1946 * connection
1947 */
1948 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
1949 mpa_rev);
1950 ep->retry_with_mpa_v1 = 1;
1951 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001952 break;
1953 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001954 break;
1955 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001956 break;
1957 case MORIBUND:
1958 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00001959 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001960 /*FALLTHROUGH*/
1961 case FPDU_MODE:
1962 if (ep->com.cm_id && ep->com.qp) {
1963 attrs.next_state = C4IW_QP_STATE_ERROR;
1964 ret = c4iw_modify_qp(ep->com.qp->rhp,
1965 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
1966 &attrs, 1);
1967 if (ret)
1968 printk(KERN_ERR MOD
1969 "%s - qp <- error failed!\n",
1970 __func__);
1971 }
1972 peer_abort_upcall(ep);
1973 break;
1974 case ABORTING:
1975 break;
1976 case DEAD:
1977 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001978 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001979 return 0;
1980 default:
1981 BUG_ON(1);
1982 break;
1983 }
1984 dst_confirm(ep->dst);
1985 if (ep->com.state != ABORTING) {
1986 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301987 /* we don't release if we want to retry with mpa_v1 */
1988 if (!ep->retry_with_mpa_v1)
1989 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001990 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001991 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001992
1993 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
1994 if (!rpl_skb) {
1995 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
1996 __func__);
1997 release = 1;
1998 goto out;
1999 }
2000 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2001 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2002 INIT_TP_WR(rpl, ep->hwtid);
2003 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2004 rpl->cmd = CPL_ABORT_NO_RST;
2005 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2006out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002007 if (release)
2008 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302009
2010 /* retry with mpa-v1 */
2011 if (ep && ep->retry_with_mpa_v1) {
2012 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2013 dst_release(ep->dst);
2014 cxgb4_l2t_release(ep->l2t);
2015 c4iw_reconnect(ep);
2016 }
2017
Steve Wisecfdda9d2010-04-21 15:30:06 -07002018 return 0;
2019}
2020
2021static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2022{
2023 struct c4iw_ep *ep;
2024 struct c4iw_qp_attributes attrs;
2025 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002026 int release = 0;
2027 struct tid_info *t = dev->rdev.lldi.tids;
2028 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002029
2030 ep = lookup_tid(t, tid);
2031
2032 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2033 BUG_ON(!ep);
2034
2035 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002036 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002037 switch (ep->com.state) {
2038 case CLOSING:
2039 __state_set(&ep->com, MORIBUND);
2040 break;
2041 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002042 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043 if ((ep->com.cm_id) && (ep->com.qp)) {
2044 attrs.next_state = C4IW_QP_STATE_IDLE;
2045 c4iw_modify_qp(ep->com.qp->rhp,
2046 ep->com.qp,
2047 C4IW_QP_ATTR_NEXT_STATE,
2048 &attrs, 1);
2049 }
2050 close_complete_upcall(ep);
2051 __state_set(&ep->com, DEAD);
2052 release = 1;
2053 break;
2054 case ABORTING:
2055 case DEAD:
2056 break;
2057 default:
2058 BUG_ON(1);
2059 break;
2060 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002061 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002062 if (release)
2063 release_ep_resources(ep);
2064 return 0;
2065}
2066
2067static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2068{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002069 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002070 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002071 unsigned int tid = GET_TID(rpl);
2072 struct c4iw_ep *ep;
2073 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002074
2075 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002076 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077
Steve Wise30c95c22011-05-09 22:06:22 -07002078 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002079 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2080 ep->com.qp->wq.sq.qid);
2081 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2082 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2083 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2084 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002085 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086
Steve Wisecfdda9d2010-04-21 15:30:06 -07002087 return 0;
2088}
2089
2090/*
2091 * Upcall from the adapter indicating data has been transmitted.
2092 * For us its just the single MPA request or reply. We can now free
2093 * the skb holding the mpa message.
2094 */
2095static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2096{
2097 struct c4iw_ep *ep;
2098 struct cpl_fw4_ack *hdr = cplhdr(skb);
2099 u8 credits = hdr->credits;
2100 unsigned int tid = GET_TID(hdr);
2101 struct tid_info *t = dev->rdev.lldi.tids;
2102
2103
2104 ep = lookup_tid(t, tid);
2105 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2106 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002107 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2108 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002109 return 0;
2110 }
2111
2112 dst_confirm(ep->dst);
2113 if (ep->mpa_skb) {
2114 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2115 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2116 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2117 kfree_skb(ep->mpa_skb);
2118 ep->mpa_skb = NULL;
2119 }
2120 return 0;
2121}
2122
Steve Wisecfdda9d2010-04-21 15:30:06 -07002123int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2124{
2125 int err;
2126 struct c4iw_ep *ep = to_ep(cm_id);
2127 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2128
2129 if (state_read(&ep->com) == DEAD) {
2130 c4iw_put_ep(&ep->com);
2131 return -ECONNRESET;
2132 }
2133 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2134 if (mpa_rev == 0)
2135 abort_connection(ep, NULL, GFP_KERNEL);
2136 else {
2137 err = send_mpa_reject(ep, pdata, pdata_len);
2138 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2139 }
2140 c4iw_put_ep(&ep->com);
2141 return 0;
2142}
2143
2144int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2145{
2146 int err;
2147 struct c4iw_qp_attributes attrs;
2148 enum c4iw_qp_attr_mask mask;
2149 struct c4iw_ep *ep = to_ep(cm_id);
2150 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2151 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2152
2153 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2154 if (state_read(&ep->com) == DEAD) {
2155 err = -ECONNRESET;
2156 goto err;
2157 }
2158
2159 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2160 BUG_ON(!qp);
2161
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002162 if ((conn_param->ord > c4iw_max_read_depth) ||
2163 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002164 abort_connection(ep, NULL, GFP_KERNEL);
2165 err = -EINVAL;
2166 goto err;
2167 }
2168
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302169 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2170 if (conn_param->ord > ep->ird) {
2171 ep->ird = conn_param->ird;
2172 ep->ord = conn_param->ord;
2173 send_mpa_reject(ep, conn_param->private_data,
2174 conn_param->private_data_len);
2175 abort_connection(ep, NULL, GFP_KERNEL);
2176 err = -ENOMEM;
2177 goto err;
2178 }
2179 if (conn_param->ird > ep->ord) {
2180 if (!ep->ord)
2181 conn_param->ird = 1;
2182 else {
2183 abort_connection(ep, NULL, GFP_KERNEL);
2184 err = -ENOMEM;
2185 goto err;
2186 }
2187 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002188
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302189 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190 ep->ird = conn_param->ird;
2191 ep->ord = conn_param->ord;
2192
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302193 if (ep->mpa_attr.version != 2)
2194 if (peer2peer && ep->ird == 0)
2195 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196
2197 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2198
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302199 cm_id->add_ref(cm_id);
2200 ep->com.cm_id = cm_id;
2201 ep->com.qp = qp;
2202
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203 /* bind QP to EP and move to RTS */
2204 attrs.mpa_attr = ep->mpa_attr;
2205 attrs.max_ird = ep->ird;
2206 attrs.max_ord = ep->ord;
2207 attrs.llp_stream_handle = ep;
2208 attrs.next_state = C4IW_QP_STATE_RTS;
2209
2210 /* bind QP and TID with INIT_WR */
2211 mask = C4IW_QP_ATTR_NEXT_STATE |
2212 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2213 C4IW_QP_ATTR_MPA_ATTR |
2214 C4IW_QP_ATTR_MAX_IRD |
2215 C4IW_QP_ATTR_MAX_ORD;
2216
2217 err = c4iw_modify_qp(ep->com.qp->rhp,
2218 ep->com.qp, mask, &attrs, 1);
2219 if (err)
2220 goto err1;
2221 err = send_mpa_reply(ep, conn_param->private_data,
2222 conn_param->private_data_len);
2223 if (err)
2224 goto err1;
2225
2226 state_set(&ep->com, FPDU_MODE);
2227 established_upcall(ep);
2228 c4iw_put_ep(&ep->com);
2229 return 0;
2230err1:
2231 ep->com.cm_id = NULL;
2232 ep->com.qp = NULL;
2233 cm_id->rem_ref(cm_id);
2234err:
2235 c4iw_put_ep(&ep->com);
2236 return err;
2237}
2238
2239int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2240{
2241 int err = 0;
2242 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2243 struct c4iw_ep *ep;
2244 struct rtable *rt;
2245 struct net_device *pdev;
David S. Miller69cce1d2011-07-17 23:09:49 -07002246 struct neighbour *neigh;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002247 int step;
2248
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002249 if ((conn_param->ord > c4iw_max_read_depth) ||
2250 (conn_param->ird > c4iw_max_read_depth)) {
2251 err = -EINVAL;
2252 goto out;
2253 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2255 if (!ep) {
2256 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2257 err = -ENOMEM;
2258 goto out;
2259 }
2260 init_timer(&ep->timer);
2261 ep->plen = conn_param->private_data_len;
2262 if (ep->plen)
2263 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2264 conn_param->private_data, ep->plen);
2265 ep->ird = conn_param->ird;
2266 ep->ord = conn_param->ord;
2267
2268 if (peer2peer && ep->ord == 0)
2269 ep->ord = 1;
2270
2271 cm_id->add_ref(cm_id);
2272 ep->com.dev = dev;
2273 ep->com.cm_id = cm_id;
2274 ep->com.qp = get_qhp(dev, conn_param->qpn);
2275 BUG_ON(!ep->com.qp);
2276 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2277 ep->com.qp, cm_id);
2278
2279 /*
2280 * Allocate an active TID to initiate a TCP connection.
2281 */
2282 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2283 if (ep->atid == -1) {
2284 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2285 err = -ENOMEM;
2286 goto fail2;
2287 }
2288
2289 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2290 ntohl(cm_id->local_addr.sin_addr.s_addr),
2291 ntohs(cm_id->local_addr.sin_port),
2292 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2293 ntohs(cm_id->remote_addr.sin_port));
2294
2295 /* find a route */
2296 rt = find_route(dev,
2297 cm_id->local_addr.sin_addr.s_addr,
2298 cm_id->remote_addr.sin_addr.s_addr,
2299 cm_id->local_addr.sin_port,
2300 cm_id->remote_addr.sin_port, 0);
2301 if (!rt) {
2302 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2303 err = -EHOSTUNREACH;
2304 goto fail3;
2305 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002306 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307
Eric Dumazet580da352011-11-29 22:31:23 +01002308 rcu_read_lock();
David S. Miller69cce1d2011-07-17 23:09:49 -07002309 neigh = dst_get_neighbour(ep->dst);
2310
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 /* get a l2t entry */
David S. Miller69cce1d2011-07-17 23:09:49 -07002312 if (neigh->dev->flags & IFF_LOOPBACK) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313 PDBG("%s LOOPBACK\n", __func__);
2314 pdev = ip_dev_find(&init_net,
2315 cm_id->remote_addr.sin_addr.s_addr);
2316 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
David S. Miller69cce1d2011-07-17 23:09:49 -07002317 neigh, pdev, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318 ep->mtu = pdev->mtu;
2319 ep->tx_chan = cxgb4_port_chan(pdev);
Steve Wise2c5934b2010-06-23 15:46:44 +00002320 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 step = ep->com.dev->rdev.lldi.ntxq /
2322 ep->com.dev->rdev.lldi.nchan;
2323 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2324 step = ep->com.dev->rdev.lldi.nrxq /
2325 ep->com.dev->rdev.lldi.nchan;
Steve Wised4f1a5c2010-07-23 19:12:32 +00002326 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
2328 cxgb4_port_idx(pdev) * step];
2329 dev_put(pdev);
2330 } else {
2331 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
David S. Miller69cce1d2011-07-17 23:09:49 -07002332 neigh, neigh->dev, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333 ep->mtu = dst_mtu(ep->dst);
David S. Miller69cce1d2011-07-17 23:09:49 -07002334 ep->tx_chan = cxgb4_port_chan(neigh->dev);
2335 ep->smac_idx = (cxgb4_port_viid(neigh->dev) & 0x7F) << 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336 step = ep->com.dev->rdev.lldi.ntxq /
2337 ep->com.dev->rdev.lldi.nchan;
David S. Miller69cce1d2011-07-17 23:09:49 -07002338 ep->txq_idx = cxgb4_port_idx(neigh->dev) * step;
2339 ep->ctrlq_idx = cxgb4_port_idx(neigh->dev);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340 step = ep->com.dev->rdev.lldi.nrxq /
2341 ep->com.dev->rdev.lldi.nchan;
2342 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[
David S. Miller69cce1d2011-07-17 23:09:49 -07002343 cxgb4_port_idx(neigh->dev) * step];
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302344 ep->retry_with_mpa_v1 = 0;
2345 ep->tried_with_mpa_v1 = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346 }
Eric Dumazet580da352011-11-29 22:31:23 +01002347 rcu_read_unlock();
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348 if (!ep->l2t) {
2349 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
2350 err = -ENOMEM;
2351 goto fail4;
2352 }
2353
2354 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2355 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2356 ep->l2t->idx);
2357
2358 state_set(&ep->com, CONNECTING);
2359 ep->tos = 0;
2360 ep->com.local_addr = cm_id->local_addr;
2361 ep->com.remote_addr = cm_id->remote_addr;
2362
2363 /* send connect request to rnic */
2364 err = send_connect(ep);
2365 if (!err)
2366 goto out;
2367
2368 cxgb4_l2t_release(ep->l2t);
2369fail4:
2370 dst_release(ep->dst);
2371fail3:
2372 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2373fail2:
2374 cm_id->rem_ref(cm_id);
2375 c4iw_put_ep(&ep->com);
2376out:
2377 return err;
2378}
2379
2380int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2381{
2382 int err = 0;
2383 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2384 struct c4iw_listen_ep *ep;
2385
2386
2387 might_sleep();
2388
2389 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2390 if (!ep) {
2391 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2392 err = -ENOMEM;
2393 goto fail1;
2394 }
2395 PDBG("%s ep %p\n", __func__, ep);
2396 cm_id->add_ref(cm_id);
2397 ep->com.cm_id = cm_id;
2398 ep->com.dev = dev;
2399 ep->backlog = backlog;
2400 ep->com.local_addr = cm_id->local_addr;
2401
2402 /*
2403 * Allocate a server TID.
2404 */
2405 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2406 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002407 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 err = -ENOMEM;
2409 goto fail2;
2410 }
2411
2412 state_set(&ep->com, LISTEN);
Steve Wiseaadc4df2010-09-10 11:15:25 -05002413 c4iw_init_wr_wait(&ep->com.wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002414 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
2415 ep->com.local_addr.sin_addr.s_addr,
2416 ep->com.local_addr.sin_port,
2417 ep->com.dev->rdev.lldi.rxq_ids[0]);
2418 if (err)
2419 goto fail3;
2420
2421 /* wait for pass_open_rpl */
Steve Wiseaadc4df2010-09-10 11:15:25 -05002422 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2423 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002424 if (!err) {
2425 cm_id->provider_data = ep;
2426 goto out;
2427 }
2428fail3:
2429 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2430fail2:
2431 cm_id->rem_ref(cm_id);
2432 c4iw_put_ep(&ep->com);
2433fail1:
2434out:
2435 return err;
2436}
2437
2438int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2439{
2440 int err;
2441 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2442
2443 PDBG("%s ep %p\n", __func__, ep);
2444
2445 might_sleep();
2446 state_set(&ep->com, DEAD);
Steve Wiseaadc4df2010-09-10 11:15:25 -05002447 c4iw_init_wr_wait(&ep->com.wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 err = listen_stop(ep);
2449 if (err)
2450 goto done;
Steve Wiseaadc4df2010-09-10 11:15:25 -05002451 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2452 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2454done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455 cm_id->rem_ref(cm_id);
2456 c4iw_put_ep(&ep->com);
2457 return err;
2458}
2459
2460int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2461{
2462 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002463 int close = 0;
2464 int fatal = 0;
2465 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466
Steve Wise2f5b48c2010-09-10 11:15:36 -05002467 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468
2469 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2470 states[ep->com.state], abrupt);
2471
2472 rdev = &ep->com.dev->rdev;
2473 if (c4iw_fatal_error(rdev)) {
2474 fatal = 1;
2475 close_complete_upcall(ep);
2476 ep->com.state = DEAD;
2477 }
2478 switch (ep->com.state) {
2479 case MPA_REQ_WAIT:
2480 case MPA_REQ_SENT:
2481 case MPA_REQ_RCVD:
2482 case MPA_REP_SENT:
2483 case FPDU_MODE:
2484 close = 1;
2485 if (abrupt)
2486 ep->com.state = ABORTING;
2487 else {
2488 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002489 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490 }
2491 set_bit(CLOSE_SENT, &ep->com.flags);
2492 break;
2493 case CLOSING:
2494 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2495 close = 1;
2496 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002497 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002498 ep->com.state = ABORTING;
2499 } else
2500 ep->com.state = MORIBUND;
2501 }
2502 break;
2503 case MORIBUND:
2504 case ABORTING:
2505 case DEAD:
2506 PDBG("%s ignoring disconnect ep %p state %u\n",
2507 __func__, ep, ep->com.state);
2508 break;
2509 default:
2510 BUG();
2511 break;
2512 }
2513
Steve Wisecfdda9d2010-04-21 15:30:06 -07002514 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002515 if (abrupt) {
2516 close_complete_upcall(ep);
2517 ret = send_abort(ep, NULL, gfp);
2518 } else
Steve Wisecfdda9d2010-04-21 15:30:06 -07002519 ret = send_halfclose(ep, gfp);
2520 if (ret)
2521 fatal = 1;
2522 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002523 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002524 if (fatal)
2525 release_ep_resources(ep);
2526 return ret;
2527}
2528
Steve Wise2f5b48c2010-09-10 11:15:36 -05002529static int async_event(struct c4iw_dev *dev, struct sk_buff *skb)
2530{
2531 struct cpl_fw6_msg *rpl = cplhdr(skb);
2532 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2533 return 0;
2534}
2535
Steve Wisecfdda9d2010-04-21 15:30:06 -07002536/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002537 * These are the real handlers that are called from a
2538 * work queue.
2539 */
2540static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
2541 [CPL_ACT_ESTABLISH] = act_establish,
2542 [CPL_ACT_OPEN_RPL] = act_open_rpl,
2543 [CPL_RX_DATA] = rx_data,
2544 [CPL_ABORT_RPL_RSS] = abort_rpl,
2545 [CPL_ABORT_RPL] = abort_rpl,
2546 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
2547 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
2548 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
2549 [CPL_PASS_ESTABLISH] = pass_establish,
2550 [CPL_PEER_CLOSE] = peer_close,
2551 [CPL_ABORT_REQ_RSS] = peer_abort,
2552 [CPL_CLOSE_CON_RPL] = close_con_rpl,
2553 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05002554 [CPL_FW4_ACK] = fw4_ack,
2555 [CPL_FW6_MSG] = async_event
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002556};
2557
2558static void process_timeout(struct c4iw_ep *ep)
2559{
2560 struct c4iw_qp_attributes attrs;
2561 int abort = 1;
2562
Steve Wise2f5b48c2010-09-10 11:15:36 -05002563 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002564 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
2565 ep->com.state);
2566 switch (ep->com.state) {
2567 case MPA_REQ_SENT:
2568 __state_set(&ep->com, ABORTING);
2569 connect_reply_upcall(ep, -ETIMEDOUT);
2570 break;
2571 case MPA_REQ_WAIT:
2572 __state_set(&ep->com, ABORTING);
2573 break;
2574 case CLOSING:
2575 case MORIBUND:
2576 if (ep->com.cm_id && ep->com.qp) {
2577 attrs.next_state = C4IW_QP_STATE_ERROR;
2578 c4iw_modify_qp(ep->com.qp->rhp,
2579 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2580 &attrs, 1);
2581 }
2582 __state_set(&ep->com, ABORTING);
2583 break;
2584 default:
2585 printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
2586 __func__, ep, ep->hwtid, ep->com.state);
2587 WARN_ON(1);
2588 abort = 0;
2589 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002590 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002591 if (abort)
2592 abort_connection(ep, NULL, GFP_KERNEL);
2593 c4iw_put_ep(&ep->com);
2594}
2595
2596static void process_timedout_eps(void)
2597{
2598 struct c4iw_ep *ep;
2599
2600 spin_lock_irq(&timeout_lock);
2601 while (!list_empty(&timeout_list)) {
2602 struct list_head *tmp;
2603
2604 tmp = timeout_list.next;
2605 list_del(tmp);
2606 spin_unlock_irq(&timeout_lock);
2607 ep = list_entry(tmp, struct c4iw_ep, entry);
2608 process_timeout(ep);
2609 spin_lock_irq(&timeout_lock);
2610 }
2611 spin_unlock_irq(&timeout_lock);
2612}
2613
2614static void process_work(struct work_struct *work)
2615{
2616 struct sk_buff *skb = NULL;
2617 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00002618 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002619 unsigned int opcode;
2620 int ret;
2621
2622 while ((skb = skb_dequeue(&rxq))) {
2623 rpl = cplhdr(skb);
2624 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
2625 opcode = rpl->ot.opcode;
2626
2627 BUG_ON(!work_handlers[opcode]);
2628 ret = work_handlers[opcode](dev, skb);
2629 if (!ret)
2630 kfree_skb(skb);
2631 }
2632 process_timedout_eps();
2633}
2634
2635static DECLARE_WORK(skb_work, process_work);
2636
2637static void ep_timeout(unsigned long arg)
2638{
2639 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
2640
2641 spin_lock(&timeout_lock);
2642 list_add_tail(&ep->entry, &timeout_list);
2643 spin_unlock(&timeout_lock);
2644 queue_work(workq, &skb_work);
2645}
2646
2647/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 * All the CM events are handled on a work queue to have a safe context.
2649 */
2650static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
2651{
2652
2653 /*
2654 * Save dev in the skb->cb area.
2655 */
2656 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
2657
2658 /*
2659 * Queue the skb and schedule the worker thread.
2660 */
2661 skb_queue_tail(&rxq, skb);
2662 queue_work(workq, &skb_work);
2663 return 0;
2664}
2665
2666static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2667{
2668 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
2669
2670 if (rpl->status != CPL_ERR_NONE) {
2671 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
2672 "for tid %u\n", rpl->status, GET_TID(rpl));
2673 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002674 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 return 0;
2676}
2677
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002678static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2679{
2680 struct cpl_fw6_msg *rpl = cplhdr(skb);
2681 struct c4iw_wr_wait *wr_waitp;
2682 int ret;
2683
2684 PDBG("%s type %u\n", __func__, rpl->type);
2685
2686 switch (rpl->type) {
2687 case 1:
2688 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07002689 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002690 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07002691 if (wr_waitp)
2692 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002693 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002694 break;
2695 case 2:
Steve Wise2f5b48c2010-09-10 11:15:36 -05002696 sched(dev, skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002697 break;
2698 default:
2699 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
2700 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002701 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002702 break;
2703 }
2704 return 0;
2705}
2706
Steve Wise8da7e7a2011-06-14 20:59:27 +00002707static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
2708{
2709 struct cpl_abort_req_rss *req = cplhdr(skb);
2710 struct c4iw_ep *ep;
2711 struct tid_info *t = dev->rdev.lldi.tids;
2712 unsigned int tid = GET_TID(req);
2713
2714 ep = lookup_tid(t, tid);
2715 if (is_neg_adv_abort(req->status)) {
2716 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2717 ep->hwtid);
2718 kfree_skb(skb);
2719 return 0;
2720 }
2721 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2722 ep->com.state);
2723
2724 /*
2725 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302726 * However, this is not needed if com state is just
2727 * MPA_REQ_SENT
Steve Wise8da7e7a2011-06-14 20:59:27 +00002728 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302729 if (ep->com.state != MPA_REQ_SENT)
2730 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002731 sched(dev, skb);
2732 return 0;
2733}
2734
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002735/*
2736 * Most upcalls from the T4 Core go to sched() to
2737 * schedule the processing on a work queue.
2738 */
2739c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
2740 [CPL_ACT_ESTABLISH] = sched,
2741 [CPL_ACT_OPEN_RPL] = sched,
2742 [CPL_RX_DATA] = sched,
2743 [CPL_ABORT_RPL_RSS] = sched,
2744 [CPL_ABORT_RPL] = sched,
2745 [CPL_PASS_OPEN_RPL] = sched,
2746 [CPL_CLOSE_LISTSRV_RPL] = sched,
2747 [CPL_PASS_ACCEPT_REQ] = sched,
2748 [CPL_PASS_ESTABLISH] = sched,
2749 [CPL_PEER_CLOSE] = sched,
2750 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00002751 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002752 [CPL_RDMA_TERMINATE] = sched,
2753 [CPL_FW4_ACK] = sched,
2754 [CPL_SET_TCB_RPL] = set_tcb_rpl,
2755 [CPL_FW6_MSG] = fw6_msg
2756};
2757
Steve Wisecfdda9d2010-04-21 15:30:06 -07002758int __init c4iw_cm_init(void)
2759{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002760 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002761 skb_queue_head_init(&rxq);
2762
2763 workq = create_singlethread_workqueue("iw_cxgb4");
2764 if (!workq)
2765 return -ENOMEM;
2766
Steve Wisecfdda9d2010-04-21 15:30:06 -07002767 return 0;
2768}
2769
2770void __exit c4iw_cm_term(void)
2771{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002772 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002773 flush_workqueue(workq);
2774 destroy_workqueue(workq);
2775}