blob: 6ce401abdbd004d39b89368e7b5c6b7f6cd4ec06 [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. Miller31e4543d2011-05-03 20:25:42 -0700319 struct flowi4 fl4;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700320
David S. Miller31e4543d2011-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;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530545 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530546 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530547 ep->retry_with_mpa_v1 = 0;
548 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700549
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530550 if (mpa_rev_to_use == 2) {
551 mpa->private_data_size +=
552 htons(sizeof(struct mpa_v2_conn_params));
553 mpa_v2_params.ird = htons((u16)ep->ird);
554 mpa_v2_params.ord = htons((u16)ep->ord);
555
556 if (peer2peer) {
557 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
558 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
559 mpa_v2_params.ord |=
560 htons(MPA_V2_RDMA_WRITE_RTR);
561 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
562 mpa_v2_params.ord |=
563 htons(MPA_V2_RDMA_READ_RTR);
564 }
565 memcpy(mpa->private_data, &mpa_v2_params,
566 sizeof(struct mpa_v2_conn_params));
567
568 if (ep->plen)
569 memcpy(mpa->private_data +
570 sizeof(struct mpa_v2_conn_params),
571 ep->mpa_pkt + sizeof(*mpa), ep->plen);
572 } else
573 if (ep->plen)
574 memcpy(mpa->private_data,
575 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700576
577 /*
578 * Reference the mpa skb. This ensures the data area
579 * will remain in memory until the hw acks the tx.
580 * Function fw4_ack() will deref it.
581 */
582 skb_get(skb);
583 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
584 BUG_ON(ep->mpa_skb);
585 ep->mpa_skb = skb;
586 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
587 start_ep_timer(ep);
588 state_set(&ep->com, MPA_REQ_SENT);
589 ep->mpa_attr.initiator = 1;
590 return;
591}
592
593static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
594{
595 int mpalen, wrlen;
596 struct fw_ofld_tx_data_wr *req;
597 struct mpa_message *mpa;
598 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530599 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600
601 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
602
603 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530604 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
605 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606 wrlen = roundup(mpalen + sizeof *req, 16);
607
608 skb = get_skb(NULL, wrlen, GFP_KERNEL);
609 if (!skb) {
610 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
611 return -ENOMEM;
612 }
613 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
614
615 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
616 memset(req, 0, wrlen);
617 req->op_to_immdlen = cpu_to_be32(
618 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
619 FW_WR_COMPL(1) |
620 FW_WR_IMMDLEN(mpalen));
621 req->flowid_len16 = cpu_to_be32(
622 FW_WR_FLOWID(ep->hwtid) |
623 FW_WR_LEN16(wrlen >> 4));
624 req->plen = cpu_to_be32(mpalen);
625 req->tunnel_to_proxy = cpu_to_be32(
626 FW_OFLD_TX_DATA_WR_FLUSH(1) |
627 FW_OFLD_TX_DATA_WR_SHOVE(1));
628
629 mpa = (struct mpa_message *)(req + 1);
630 memset(mpa, 0, sizeof(*mpa));
631 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
632 mpa->flags = MPA_REJECT;
633 mpa->revision = mpa_rev;
634 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530635
636 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
637 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
638 mpa->private_data_size +=
639 htons(sizeof(struct mpa_v2_conn_params));
640 mpa_v2_params.ird = htons(((u16)ep->ird) |
641 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
642 0));
643 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
644 (p2p_type ==
645 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
646 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
647 FW_RI_INIT_P2PTYPE_READ_REQ ?
648 MPA_V2_RDMA_READ_RTR : 0) : 0));
649 memcpy(mpa->private_data, &mpa_v2_params,
650 sizeof(struct mpa_v2_conn_params));
651
652 if (ep->plen)
653 memcpy(mpa->private_data +
654 sizeof(struct mpa_v2_conn_params), pdata, plen);
655 } else
656 if (plen)
657 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700658
659 /*
660 * Reference the mpa skb again. This ensures the data area
661 * will remain in memory until the hw acks the tx.
662 * Function fw4_ack() will deref it.
663 */
664 skb_get(skb);
665 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
666 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
667 BUG_ON(ep->mpa_skb);
668 ep->mpa_skb = skb;
669 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
670}
671
672static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
673{
674 int mpalen, wrlen;
675 struct fw_ofld_tx_data_wr *req;
676 struct mpa_message *mpa;
677 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530678 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700679
680 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
681
682 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530683 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
684 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700685 wrlen = roundup(mpalen + sizeof *req, 16);
686
687 skb = get_skb(NULL, wrlen, GFP_KERNEL);
688 if (!skb) {
689 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
690 return -ENOMEM;
691 }
692 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
693
694 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
695 memset(req, 0, wrlen);
696 req->op_to_immdlen = cpu_to_be32(
697 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
698 FW_WR_COMPL(1) |
699 FW_WR_IMMDLEN(mpalen));
700 req->flowid_len16 = cpu_to_be32(
701 FW_WR_FLOWID(ep->hwtid) |
702 FW_WR_LEN16(wrlen >> 4));
703 req->plen = cpu_to_be32(mpalen);
704 req->tunnel_to_proxy = cpu_to_be32(
705 FW_OFLD_TX_DATA_WR_FLUSH(1) |
706 FW_OFLD_TX_DATA_WR_SHOVE(1));
707
708 mpa = (struct mpa_message *)(req + 1);
709 memset(mpa, 0, sizeof(*mpa));
710 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
711 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
712 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530713 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700714 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530715
716 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
717 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
718 mpa->private_data_size +=
719 htons(sizeof(struct mpa_v2_conn_params));
720 mpa_v2_params.ird = htons((u16)ep->ird);
721 mpa_v2_params.ord = htons((u16)ep->ord);
722 if (peer2peer && (ep->mpa_attr.p2p_type !=
723 FW_RI_INIT_P2PTYPE_DISABLED)) {
724 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
725
726 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
727 mpa_v2_params.ord |=
728 htons(MPA_V2_RDMA_WRITE_RTR);
729 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
730 mpa_v2_params.ord |=
731 htons(MPA_V2_RDMA_READ_RTR);
732 }
733
734 memcpy(mpa->private_data, &mpa_v2_params,
735 sizeof(struct mpa_v2_conn_params));
736
737 if (ep->plen)
738 memcpy(mpa->private_data +
739 sizeof(struct mpa_v2_conn_params), pdata, plen);
740 } else
741 if (plen)
742 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700743
744 /*
745 * Reference the mpa skb. This ensures the data area
746 * will remain in memory until the hw acks the tx.
747 * Function fw4_ack() will deref it.
748 */
749 skb_get(skb);
750 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
751 ep->mpa_skb = skb;
752 state_set(&ep->com, MPA_REP_SENT);
753 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
754}
755
756static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
757{
758 struct c4iw_ep *ep;
759 struct cpl_act_establish *req = cplhdr(skb);
760 unsigned int tid = GET_TID(req);
761 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
762 struct tid_info *t = dev->rdev.lldi.tids;
763
764 ep = lookup_atid(t, atid);
765
766 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
767 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
768
769 dst_confirm(ep->dst);
770
771 /* setup the hwtid for this connection */
772 ep->hwtid = tid;
773 cxgb4_insert_tid(t, ep, tid);
774
775 ep->snd_seq = be32_to_cpu(req->snd_isn);
776 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
777
778 set_emss(ep, ntohs(req->tcp_opt));
779
780 /* dealloc the atid */
781 cxgb4_free_atid(t, atid);
782
783 /* start MPA negotiation */
784 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530785 if (ep->retry_with_mpa_v1)
786 send_mpa_req(ep, skb, 1);
787 else
788 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700789
790 return 0;
791}
792
793static void close_complete_upcall(struct c4iw_ep *ep)
794{
795 struct iw_cm_event event;
796
797 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
798 memset(&event, 0, sizeof(event));
799 event.event = IW_CM_EVENT_CLOSE;
800 if (ep->com.cm_id) {
801 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
802 ep, ep->com.cm_id, ep->hwtid);
803 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
804 ep->com.cm_id->rem_ref(ep->com.cm_id);
805 ep->com.cm_id = NULL;
806 ep->com.qp = NULL;
807 }
808}
809
810static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
811{
812 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
813 close_complete_upcall(ep);
814 state_set(&ep->com, ABORTING);
815 return send_abort(ep, skb, gfp);
816}
817
818static void peer_close_upcall(struct c4iw_ep *ep)
819{
820 struct iw_cm_event event;
821
822 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
823 memset(&event, 0, sizeof(event));
824 event.event = IW_CM_EVENT_DISCONNECT;
825 if (ep->com.cm_id) {
826 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
827 ep, ep->com.cm_id, ep->hwtid);
828 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
829 }
830}
831
832static void peer_abort_upcall(struct c4iw_ep *ep)
833{
834 struct iw_cm_event event;
835
836 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
837 memset(&event, 0, sizeof(event));
838 event.event = IW_CM_EVENT_CLOSE;
839 event.status = -ECONNRESET;
840 if (ep->com.cm_id) {
841 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
842 ep->com.cm_id, ep->hwtid);
843 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
844 ep->com.cm_id->rem_ref(ep->com.cm_id);
845 ep->com.cm_id = NULL;
846 ep->com.qp = NULL;
847 }
848}
849
850static void connect_reply_upcall(struct c4iw_ep *ep, int status)
851{
852 struct iw_cm_event event;
853
854 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
855 memset(&event, 0, sizeof(event));
856 event.event = IW_CM_EVENT_CONNECT_REPLY;
857 event.status = status;
858 event.local_addr = ep->com.local_addr;
859 event.remote_addr = ep->com.remote_addr;
860
861 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530862 if (!ep->tried_with_mpa_v1) {
863 /* this means MPA_v2 is used */
864 event.private_data_len = ep->plen -
865 sizeof(struct mpa_v2_conn_params);
866 event.private_data = ep->mpa_pkt +
867 sizeof(struct mpa_message) +
868 sizeof(struct mpa_v2_conn_params);
869 } else {
870 /* this means MPA_v1 is used */
871 event.private_data_len = ep->plen;
872 event.private_data = ep->mpa_pkt +
873 sizeof(struct mpa_message);
874 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700875 }
Roland Dreier85963e42010-07-19 13:13:09 -0700876
877 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
878 ep->hwtid, status);
879 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
880
Steve Wisecfdda9d2010-04-21 15:30:06 -0700881 if (status < 0) {
882 ep->com.cm_id->rem_ref(ep->com.cm_id);
883 ep->com.cm_id = NULL;
884 ep->com.qp = NULL;
885 }
886}
887
888static void connect_request_upcall(struct c4iw_ep *ep)
889{
890 struct iw_cm_event event;
891
892 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
893 memset(&event, 0, sizeof(event));
894 event.event = IW_CM_EVENT_CONNECT_REQUEST;
895 event.local_addr = ep->com.local_addr;
896 event.remote_addr = ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530898 if (!ep->tried_with_mpa_v1) {
899 /* this means MPA_v2 is used */
900 event.ord = ep->ord;
901 event.ird = ep->ird;
902 event.private_data_len = ep->plen -
903 sizeof(struct mpa_v2_conn_params);
904 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
905 sizeof(struct mpa_v2_conn_params);
906 } else {
907 /* this means MPA_v1 is used. Send max supported */
908 event.ord = c4iw_max_read_depth;
909 event.ird = c4iw_max_read_depth;
910 event.private_data_len = ep->plen;
911 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
912 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700913 if (state_read(&ep->parent_ep->com) != DEAD) {
914 c4iw_get_ep(&ep->com);
915 ep->parent_ep->com.cm_id->event_handler(
916 ep->parent_ep->com.cm_id,
917 &event);
918 }
919 c4iw_put_ep(&ep->parent_ep->com);
920 ep->parent_ep = NULL;
921}
922
923static void established_upcall(struct c4iw_ep *ep)
924{
925 struct iw_cm_event event;
926
927 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
928 memset(&event, 0, sizeof(event));
929 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530930 event.ird = ep->ird;
931 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932 if (ep->com.cm_id) {
933 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
934 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
935 }
936}
937
938static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
939{
940 struct cpl_rx_data_ack *req;
941 struct sk_buff *skb;
942 int wrlen = roundup(sizeof *req, 16);
943
944 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
945 skb = get_skb(NULL, wrlen, GFP_KERNEL);
946 if (!skb) {
947 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
948 return 0;
949 }
950
951 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
952 memset(req, 0, wrlen);
953 INIT_TP_WR(req, ep->hwtid);
954 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
955 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +0000956 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
957 F_RX_DACK_CHANGE |
958 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +0000959 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700960 c4iw_ofld_send(&ep->com.dev->rdev, skb);
961 return credits;
962}
963
964static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
965{
966 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530967 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700968 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530969 u16 resp_ird, resp_ord;
970 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700971 struct c4iw_qp_attributes attrs;
972 enum c4iw_qp_attr_mask mask;
973 int err;
974
975 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
976
977 /*
978 * Stop mpa timer. If it expired, then the state has
979 * changed and we bail since ep_timeout already aborted
980 * the connection.
981 */
982 stop_ep_timer(ep);
983 if (state_read(&ep->com) != MPA_REQ_SENT)
984 return;
985
986 /*
987 * If we get more than the supported amount of private data
988 * then we must fail this connection.
989 */
990 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
991 err = -EINVAL;
992 goto err;
993 }
994
995 /*
996 * copy the new data into our accumulation buffer.
997 */
998 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
999 skb->len);
1000 ep->mpa_pkt_len += skb->len;
1001
1002 /*
1003 * if we don't even have the mpa message, then bail.
1004 */
1005 if (ep->mpa_pkt_len < sizeof(*mpa))
1006 return;
1007 mpa = (struct mpa_message *) ep->mpa_pkt;
1008
1009 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301010 if (mpa->revision > mpa_rev) {
1011 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1012 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001013 err = -EPROTO;
1014 goto err;
1015 }
1016 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1017 err = -EPROTO;
1018 goto err;
1019 }
1020
1021 plen = ntohs(mpa->private_data_size);
1022
1023 /*
1024 * Fail if there's too much private data.
1025 */
1026 if (plen > MPA_MAX_PRIVATE_DATA) {
1027 err = -EPROTO;
1028 goto err;
1029 }
1030
1031 /*
1032 * If plen does not account for pkt size
1033 */
1034 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1035 err = -EPROTO;
1036 goto err;
1037 }
1038
1039 ep->plen = (u8) plen;
1040
1041 /*
1042 * If we don't have all the pdata yet, then bail.
1043 * We'll continue process when more data arrives.
1044 */
1045 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1046 return;
1047
1048 if (mpa->flags & MPA_REJECT) {
1049 err = -ECONNREFUSED;
1050 goto err;
1051 }
1052
1053 /*
1054 * If we get here we have accumulated the entire mpa
1055 * start reply message including private data. And
1056 * the MPA header is valid.
1057 */
1058 state_set(&ep->com, FPDU_MODE);
1059 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1060 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1061 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301062 ep->mpa_attr.version = mpa->revision;
1063 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1064
1065 if (mpa->revision == 2) {
1066 ep->mpa_attr.enhanced_rdma_conn =
1067 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1068 if (ep->mpa_attr.enhanced_rdma_conn) {
1069 mpa_v2_params = (struct mpa_v2_conn_params *)
1070 (ep->mpa_pkt + sizeof(*mpa));
1071 resp_ird = ntohs(mpa_v2_params->ird) &
1072 MPA_V2_IRD_ORD_MASK;
1073 resp_ord = ntohs(mpa_v2_params->ord) &
1074 MPA_V2_IRD_ORD_MASK;
1075
1076 /*
1077 * This is a double-check. Ideally, below checks are
1078 * not required since ird/ord stuff has been taken
1079 * care of in c4iw_accept_cr
1080 */
1081 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1082 err = -ENOMEM;
1083 ep->ird = resp_ord;
1084 ep->ord = resp_ird;
1085 insuff_ird = 1;
1086 }
1087
1088 if (ntohs(mpa_v2_params->ird) &
1089 MPA_V2_PEER2PEER_MODEL) {
1090 if (ntohs(mpa_v2_params->ord) &
1091 MPA_V2_RDMA_WRITE_RTR)
1092 ep->mpa_attr.p2p_type =
1093 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1094 else if (ntohs(mpa_v2_params->ord) &
1095 MPA_V2_RDMA_READ_RTR)
1096 ep->mpa_attr.p2p_type =
1097 FW_RI_INIT_P2PTYPE_READ_REQ;
1098 }
1099 }
1100 } else if (mpa->revision == 1)
1101 if (peer2peer)
1102 ep->mpa_attr.p2p_type = p2p_type;
1103
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301105 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1106 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1107 ep->mpa_attr.recv_marker_enabled,
1108 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1109 ep->mpa_attr.p2p_type, p2p_type);
1110
1111 /*
1112 * If responder's RTR does not match with that of initiator, assign
1113 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1114 * generated when moving QP to RTS state.
1115 * A TERM message will be sent after QP has moved to RTS state
1116 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001117 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301118 (ep->mpa_attr.p2p_type != p2p_type)) {
1119 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1120 rtr_mismatch = 1;
1121 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001122
1123 attrs.mpa_attr = ep->mpa_attr;
1124 attrs.max_ird = ep->ird;
1125 attrs.max_ord = ep->ord;
1126 attrs.llp_stream_handle = ep;
1127 attrs.next_state = C4IW_QP_STATE_RTS;
1128
1129 mask = C4IW_QP_ATTR_NEXT_STATE |
1130 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1131 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1132
1133 /* bind QP and TID with INIT_WR */
1134 err = c4iw_modify_qp(ep->com.qp->rhp,
1135 ep->com.qp, mask, &attrs, 1);
1136 if (err)
1137 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301138
1139 /*
1140 * If responder's RTR requirement did not match with what initiator
1141 * supports, generate TERM message
1142 */
1143 if (rtr_mismatch) {
1144 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1145 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1146 attrs.ecode = MPA_NOMATCH_RTR;
1147 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1148 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1149 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1150 err = -ENOMEM;
1151 goto out;
1152 }
1153
1154 /*
1155 * Generate TERM if initiator IRD is not sufficient for responder
1156 * provided ORD. Currently, we do the same behaviour even when
1157 * responder provided IRD is also not sufficient as regards to
1158 * initiator ORD.
1159 */
1160 if (insuff_ird) {
1161 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1162 __func__);
1163 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1164 attrs.ecode = MPA_INSUFF_IRD;
1165 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1166 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1167 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1168 err = -ENOMEM;
1169 goto out;
1170 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171 goto out;
1172err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001173 state_set(&ep->com, ABORTING);
1174 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175out:
1176 connect_reply_upcall(ep, err);
1177 return;
1178}
1179
1180static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1181{
1182 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301183 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001184 u16 plen;
1185
1186 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1187
1188 if (state_read(&ep->com) != MPA_REQ_WAIT)
1189 return;
1190
1191 /*
1192 * If we get more than the supported amount of private data
1193 * then we must fail this connection.
1194 */
1195 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1196 stop_ep_timer(ep);
1197 abort_connection(ep, skb, GFP_KERNEL);
1198 return;
1199 }
1200
1201 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1202
1203 /*
1204 * Copy the new data into our accumulation buffer.
1205 */
1206 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1207 skb->len);
1208 ep->mpa_pkt_len += skb->len;
1209
1210 /*
1211 * If we don't even have the mpa message, then bail.
1212 * We'll continue process when more data arrives.
1213 */
1214 if (ep->mpa_pkt_len < sizeof(*mpa))
1215 return;
1216
1217 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1218 stop_ep_timer(ep);
1219 mpa = (struct mpa_message *) ep->mpa_pkt;
1220
1221 /*
1222 * Validate MPA Header.
1223 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301224 if (mpa->revision > mpa_rev) {
1225 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1226 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227 abort_connection(ep, skb, GFP_KERNEL);
1228 return;
1229 }
1230
1231 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1232 abort_connection(ep, skb, GFP_KERNEL);
1233 return;
1234 }
1235
1236 plen = ntohs(mpa->private_data_size);
1237
1238 /*
1239 * Fail if there's too much private data.
1240 */
1241 if (plen > MPA_MAX_PRIVATE_DATA) {
1242 abort_connection(ep, skb, GFP_KERNEL);
1243 return;
1244 }
1245
1246 /*
1247 * If plen does not account for pkt size
1248 */
1249 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1250 abort_connection(ep, skb, GFP_KERNEL);
1251 return;
1252 }
1253 ep->plen = (u8) plen;
1254
1255 /*
1256 * If we don't have all the pdata yet, then bail.
1257 */
1258 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1259 return;
1260
1261 /*
1262 * If we get here we have accumulated the entire mpa
1263 * start reply message including private data.
1264 */
1265 ep->mpa_attr.initiator = 0;
1266 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1267 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1268 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301269 ep->mpa_attr.version = mpa->revision;
1270 if (mpa->revision == 1)
1271 ep->tried_with_mpa_v1 = 1;
1272 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1273
1274 if (mpa->revision == 2) {
1275 ep->mpa_attr.enhanced_rdma_conn =
1276 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1277 if (ep->mpa_attr.enhanced_rdma_conn) {
1278 mpa_v2_params = (struct mpa_v2_conn_params *)
1279 (ep->mpa_pkt + sizeof(*mpa));
1280 ep->ird = ntohs(mpa_v2_params->ird) &
1281 MPA_V2_IRD_ORD_MASK;
1282 ep->ord = ntohs(mpa_v2_params->ord) &
1283 MPA_V2_IRD_ORD_MASK;
1284 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1285 if (peer2peer) {
1286 if (ntohs(mpa_v2_params->ord) &
1287 MPA_V2_RDMA_WRITE_RTR)
1288 ep->mpa_attr.p2p_type =
1289 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1290 else if (ntohs(mpa_v2_params->ord) &
1291 MPA_V2_RDMA_READ_RTR)
1292 ep->mpa_attr.p2p_type =
1293 FW_RI_INIT_P2PTYPE_READ_REQ;
1294 }
1295 }
1296 } else if (mpa->revision == 1)
1297 if (peer2peer)
1298 ep->mpa_attr.p2p_type = p2p_type;
1299
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1301 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1302 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1303 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1304 ep->mpa_attr.p2p_type);
1305
1306 state_set(&ep->com, MPA_REQ_RCVD);
1307
1308 /* drive upcall */
1309 connect_request_upcall(ep);
1310 return;
1311}
1312
1313static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1314{
1315 struct c4iw_ep *ep;
1316 struct cpl_rx_data *hdr = cplhdr(skb);
1317 unsigned int dlen = ntohs(hdr->len);
1318 unsigned int tid = GET_TID(hdr);
1319 struct tid_info *t = dev->rdev.lldi.tids;
1320
1321 ep = lookup_tid(t, tid);
1322 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1323 skb_pull(skb, sizeof(*hdr));
1324 skb_trim(skb, dlen);
1325
1326 ep->rcv_seq += dlen;
1327 BUG_ON(ep->rcv_seq != (ntohl(hdr->seq) + dlen));
1328
1329 /* update RX credits */
1330 update_rx_credits(ep, dlen);
1331
1332 switch (state_read(&ep->com)) {
1333 case MPA_REQ_SENT:
1334 process_mpa_reply(ep, skb);
1335 break;
1336 case MPA_REQ_WAIT:
1337 process_mpa_request(ep, skb);
1338 break;
1339 case MPA_REP_SENT:
1340 break;
1341 default:
1342 printk(KERN_ERR MOD "%s Unexpected streaming data."
1343 " ep %p state %d tid %u\n",
1344 __func__, ep, state_read(&ep->com), ep->hwtid);
1345
1346 /*
1347 * The ep will timeout and inform the ULP of the failure.
1348 * See ep_timeout().
1349 */
1350 break;
1351 }
1352 return 0;
1353}
1354
1355static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1356{
1357 struct c4iw_ep *ep;
1358 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001359 int release = 0;
1360 unsigned int tid = GET_TID(rpl);
1361 struct tid_info *t = dev->rdev.lldi.tids;
1362
1363 ep = lookup_tid(t, tid);
1364 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Vipul Pandya49840372012-05-18 15:29:29 +05301365 if (!ep) {
1366 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1367 return 0;
1368 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001369 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370 switch (ep->com.state) {
1371 case ABORTING:
1372 __state_set(&ep->com, DEAD);
1373 release = 1;
1374 break;
1375 default:
1376 printk(KERN_ERR "%s ep %p state %d\n",
1377 __func__, ep, ep->com.state);
1378 break;
1379 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001380 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001381
1382 if (release)
1383 release_ep_resources(ep);
1384 return 0;
1385}
1386
1387/*
1388 * Return whether a failed active open has allocated a TID
1389 */
1390static inline int act_open_has_tid(int status)
1391{
1392 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1393 status != CPL_ERR_ARP_MISS;
1394}
1395
1396static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1397{
1398 struct c4iw_ep *ep;
1399 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1400 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1401 ntohl(rpl->atid_status)));
1402 struct tid_info *t = dev->rdev.lldi.tids;
1403 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1404
1405 ep = lookup_atid(t, atid);
1406
1407 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1408 status, status2errno(status));
1409
1410 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1411 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1412 atid);
1413 return 0;
1414 }
1415
1416 connect_reply_upcall(ep, status2errno(status));
1417 state_set(&ep->com, DEAD);
1418
1419 if (status && act_open_has_tid(status))
1420 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1421
1422 cxgb4_free_atid(t, atid);
1423 dst_release(ep->dst);
1424 cxgb4_l2t_release(ep->l2t);
1425 c4iw_put_ep(&ep->com);
1426
1427 return 0;
1428}
1429
1430static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1431{
1432 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1433 struct tid_info *t = dev->rdev.lldi.tids;
1434 unsigned int stid = GET_TID(rpl);
1435 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1436
1437 if (!ep) {
1438 printk(KERN_ERR MOD "stid %d lookup failure!\n", stid);
1439 return 0;
1440 }
1441 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1442 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001443 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444
1445 return 0;
1446}
1447
1448static int listen_stop(struct c4iw_listen_ep *ep)
1449{
1450 struct sk_buff *skb;
1451 struct cpl_close_listsvr_req *req;
1452
1453 PDBG("%s ep %p\n", __func__, ep);
1454 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1455 if (!skb) {
1456 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1457 return -ENOMEM;
1458 }
1459 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1460 INIT_TP_WR(req, 0);
1461 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1462 ep->stid));
1463 req->reply_ctrl = cpu_to_be16(
1464 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1465 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1466 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1467}
1468
1469static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1470{
1471 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1472 struct tid_info *t = dev->rdev.lldi.tids;
1473 unsigned int stid = GET_TID(rpl);
1474 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1475
1476 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001477 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001478 return 0;
1479}
1480
1481static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1482 struct cpl_pass_accept_req *req)
1483{
1484 struct cpl_pass_accept_rpl *rpl;
1485 unsigned int mtu_idx;
1486 u64 opt0;
1487 u32 opt2;
1488 int wscale;
1489
1490 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1491 BUG_ON(skb_cloned(skb));
1492 skb_trim(skb, sizeof(*rpl));
1493 skb_get(skb);
1494 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1495 wscale = compute_wscale(rcv_win);
1496 opt0 = KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001497 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001498 WND_SCALE(wscale) |
1499 MSS_IDX(mtu_idx) |
1500 L2T_IDX(ep->l2t->idx) |
1501 TX_CHAN(ep->tx_chan) |
1502 SMAC_SEL(ep->smac_idx) |
1503 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001504 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 RCV_BUFSIZ(rcv_win>>10);
1506 opt2 = RX_CHANNEL(0) |
1507 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1508
1509 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1510 opt2 |= TSTAMPS_EN(1);
1511 if (enable_tcp_sack && req->tcpopt.sack)
1512 opt2 |= SACK_EN(1);
1513 if (wscale && enable_tcp_window_scaling)
1514 opt2 |= WND_SCALE_EN(1);
1515
1516 rpl = cplhdr(skb);
1517 INIT_TP_WR(rpl, ep->hwtid);
1518 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1519 ep->hwtid));
1520 rpl->opt0 = cpu_to_be64(opt0);
1521 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001522 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001523 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1524
1525 return;
1526}
1527
1528static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1529 struct sk_buff *skb)
1530{
1531 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1532 peer_ip);
1533 BUG_ON(skb_cloned(skb));
1534 skb_trim(skb, sizeof(struct cpl_tid_release));
1535 skb_get(skb);
1536 release_tid(&dev->rdev, hwtid, skb);
1537 return;
1538}
1539
1540static void get_4tuple(struct cpl_pass_accept_req *req,
1541 __be32 *local_ip, __be32 *peer_ip,
1542 __be16 *local_port, __be16 *peer_port)
1543{
1544 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1545 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1546 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1547 struct tcphdr *tcp = (struct tcphdr *)
1548 ((u8 *)(req + 1) + eth_len + ip_len);
1549
1550 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1551 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1552 ntohs(tcp->dest));
1553
1554 *peer_ip = ip->saddr;
1555 *local_ip = ip->daddr;
1556 *peer_port = tcp->source;
1557 *local_port = tcp->dest;
1558
1559 return;
1560}
1561
David Miller3786cf12011-12-02 16:52:31 +00001562static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1563 struct c4iw_dev *cdev, bool clear_mpa_v1)
1564{
1565 struct neighbour *n;
1566 int err, step;
1567
David Miller64b70072012-01-24 13:15:57 +00001568 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001569 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001570 return -ENODEV;
1571
1572 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001573 err = -ENOMEM;
1574 if (n->dev->flags & IFF_LOOPBACK) {
1575 struct net_device *pdev;
1576
1577 pdev = ip_dev_find(&init_net, peer_ip);
1578 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1579 n, pdev, 0);
1580 if (!ep->l2t)
1581 goto out;
1582 ep->mtu = pdev->mtu;
1583 ep->tx_chan = cxgb4_port_chan(pdev);
1584 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1585 step = cdev->rdev.lldi.ntxq /
1586 cdev->rdev.lldi.nchan;
1587 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1588 step = cdev->rdev.lldi.nrxq /
1589 cdev->rdev.lldi.nchan;
1590 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1591 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1592 cxgb4_port_idx(pdev) * step];
1593 dev_put(pdev);
1594 } else {
1595 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1596 n, n->dev, 0);
1597 if (!ep->l2t)
1598 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001599 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001600 ep->tx_chan = cxgb4_port_chan(n->dev);
1601 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1602 step = cdev->rdev.lldi.ntxq /
1603 cdev->rdev.lldi.nchan;
1604 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1605 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1606 step = cdev->rdev.lldi.nrxq /
1607 cdev->rdev.lldi.nchan;
1608 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1609 cxgb4_port_idx(n->dev) * step];
1610
1611 if (clear_mpa_v1) {
1612 ep->retry_with_mpa_v1 = 0;
1613 ep->tried_with_mpa_v1 = 0;
1614 }
1615 }
1616 err = 0;
1617out:
1618 rcu_read_unlock();
1619
David Miller64b70072012-01-24 13:15:57 +00001620 neigh_release(n);
1621
David Miller3786cf12011-12-02 16:52:31 +00001622 return err;
1623}
1624
Steve Wisecfdda9d2010-04-21 15:30:06 -07001625static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1626{
1627 struct c4iw_ep *child_ep, *parent_ep;
1628 struct cpl_pass_accept_req *req = cplhdr(skb);
1629 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1630 struct tid_info *t = dev->rdev.lldi.tids;
1631 unsigned int hwtid = GET_TID(req);
1632 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001633 struct rtable *rt;
1634 __be32 local_ip, peer_ip;
1635 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001636 int err;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001637
1638 parent_ep = lookup_stid(t, stid);
1639 PDBG("%s parent ep %p tid %u\n", __func__, parent_ep, hwtid);
1640
1641 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1642
1643 if (state_read(&parent_ep->com) != LISTEN) {
1644 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1645 __func__);
1646 goto reject;
1647 }
1648
1649 /* Find output route */
1650 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1651 GET_POPEN_TOS(ntohl(req->tos_stid)));
1652 if (!rt) {
1653 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1654 __func__);
1655 goto reject;
1656 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001657 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001658
1659 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1660 if (!child_ep) {
1661 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1662 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001663 dst_release(dst);
1664 goto reject;
1665 }
David Miller3786cf12011-12-02 16:52:31 +00001666
1667 err = import_ep(child_ep, peer_ip, dst, dev, false);
1668 if (err) {
1669 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1670 __func__);
1671 dst_release(dst);
1672 kfree(child_ep);
1673 goto reject;
1674 }
1675
Steve Wisecfdda9d2010-04-21 15:30:06 -07001676 state_set(&child_ep->com, CONNECTING);
1677 child_ep->com.dev = dev;
1678 child_ep->com.cm_id = NULL;
1679 child_ep->com.local_addr.sin_family = PF_INET;
1680 child_ep->com.local_addr.sin_port = local_port;
1681 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1682 child_ep->com.remote_addr.sin_family = PF_INET;
1683 child_ep->com.remote_addr.sin_port = peer_port;
1684 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1685 c4iw_get_ep(&parent_ep->com);
1686 child_ep->parent_ep = parent_ep;
1687 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001688 child_ep->dst = dst;
1689 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690
1691 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00001692 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693
1694 init_timer(&child_ep->timer);
1695 cxgb4_insert_tid(t, child_ep, hwtid);
1696 accept_cr(child_ep, peer_ip, skb, req);
1697 goto out;
1698reject:
1699 reject_cr(dev, hwtid, peer_ip, skb);
1700out:
1701 return 0;
1702}
1703
1704static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1705{
1706 struct c4iw_ep *ep;
1707 struct cpl_pass_establish *req = cplhdr(skb);
1708 struct tid_info *t = dev->rdev.lldi.tids;
1709 unsigned int tid = GET_TID(req);
1710
1711 ep = lookup_tid(t, tid);
1712 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1713 ep->snd_seq = be32_to_cpu(req->snd_isn);
1714 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1715
1716 set_emss(ep, ntohs(req->tcp_opt));
1717
1718 dst_confirm(ep->dst);
1719 state_set(&ep->com, MPA_REQ_WAIT);
1720 start_ep_timer(ep);
1721 send_flowc(ep, skb);
1722
1723 return 0;
1724}
1725
1726static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
1727{
1728 struct cpl_peer_close *hdr = cplhdr(skb);
1729 struct c4iw_ep *ep;
1730 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001731 int disconnect = 1;
1732 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001733 struct tid_info *t = dev->rdev.lldi.tids;
1734 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00001735 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001736
1737 ep = lookup_tid(t, tid);
1738 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1739 dst_confirm(ep->dst);
1740
Steve Wise2f5b48c2010-09-10 11:15:36 -05001741 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001742 switch (ep->com.state) {
1743 case MPA_REQ_WAIT:
1744 __state_set(&ep->com, CLOSING);
1745 break;
1746 case MPA_REQ_SENT:
1747 __state_set(&ep->com, CLOSING);
1748 connect_reply_upcall(ep, -ECONNRESET);
1749 break;
1750 case MPA_REQ_RCVD:
1751
1752 /*
1753 * We're gonna mark this puppy DEAD, but keep
1754 * the reference on it until the ULP accepts or
1755 * rejects the CR. Also wake up anyone waiting
1756 * in rdma connection migration (see c4iw_accept_cr()).
1757 */
1758 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001759 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07001760 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001761 break;
1762 case MPA_REP_SENT:
1763 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001764 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07001765 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001766 break;
1767 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00001768 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001769 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07001770 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00001771 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07001772 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00001773 if (ret != -ECONNRESET) {
1774 peer_close_upcall(ep);
1775 disconnect = 1;
1776 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777 break;
1778 case ABORTING:
1779 disconnect = 0;
1780 break;
1781 case CLOSING:
1782 __state_set(&ep->com, MORIBUND);
1783 disconnect = 0;
1784 break;
1785 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00001786 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001787 if (ep->com.cm_id && ep->com.qp) {
1788 attrs.next_state = C4IW_QP_STATE_IDLE;
1789 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1790 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1791 }
1792 close_complete_upcall(ep);
1793 __state_set(&ep->com, DEAD);
1794 release = 1;
1795 disconnect = 0;
1796 break;
1797 case DEAD:
1798 disconnect = 0;
1799 break;
1800 default:
1801 BUG_ON(1);
1802 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001803 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804 if (disconnect)
1805 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1806 if (release)
1807 release_ep_resources(ep);
1808 return 0;
1809}
1810
1811/*
1812 * Returns whether an ABORT_REQ_RSS message is a negative advice.
1813 */
1814static int is_neg_adv_abort(unsigned int status)
1815{
1816 return status == CPL_ERR_RTX_NEG_ADVICE ||
1817 status == CPL_ERR_PERSIST_NEG_ADVICE;
1818}
1819
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301820static int c4iw_reconnect(struct c4iw_ep *ep)
1821{
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301822 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00001823 int err = 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301824
1825 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1826 init_timer(&ep->timer);
1827
1828 /*
1829 * Allocate an active TID to initiate a TCP connection.
1830 */
1831 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1832 if (ep->atid == -1) {
1833 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
1834 err = -ENOMEM;
1835 goto fail2;
1836 }
1837
1838 /* find a route */
1839 rt = find_route(ep->com.dev,
1840 ep->com.cm_id->local_addr.sin_addr.s_addr,
1841 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1842 ep->com.cm_id->local_addr.sin_port,
1843 ep->com.cm_id->remote_addr.sin_port, 0);
1844 if (!rt) {
1845 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
1846 err = -EHOSTUNREACH;
1847 goto fail3;
1848 }
1849 ep->dst = &rt->dst;
1850
David Miller3786cf12011-12-02 16:52:31 +00001851 err = import_ep(ep, ep->com.cm_id->remote_addr.sin_addr.s_addr,
1852 ep->dst, ep->com.dev, false);
1853 if (err) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301854 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301855 goto fail4;
1856 }
1857
1858 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1859 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1860 ep->l2t->idx);
1861
1862 state_set(&ep->com, CONNECTING);
1863 ep->tos = 0;
1864
1865 /* send connect request to rnic */
1866 err = send_connect(ep);
1867 if (!err)
1868 goto out;
1869
1870 cxgb4_l2t_release(ep->l2t);
1871fail4:
1872 dst_release(ep->dst);
1873fail3:
1874 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1875fail2:
1876 /*
1877 * remember to send notification to upper layer.
1878 * We are in here so the upper layer is not aware that this is
1879 * re-connect attempt and so, upper layer is still waiting for
1880 * response of 1st connect request.
1881 */
1882 connect_reply_upcall(ep, -ECONNRESET);
1883 c4iw_put_ep(&ep->com);
1884out:
1885 return err;
1886}
1887
Steve Wisecfdda9d2010-04-21 15:30:06 -07001888static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
1889{
1890 struct cpl_abort_req_rss *req = cplhdr(skb);
1891 struct c4iw_ep *ep;
1892 struct cpl_abort_rpl *rpl;
1893 struct sk_buff *rpl_skb;
1894 struct c4iw_qp_attributes attrs;
1895 int ret;
1896 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001897 struct tid_info *t = dev->rdev.lldi.tids;
1898 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899
1900 ep = lookup_tid(t, tid);
1901 if (is_neg_adv_abort(req->status)) {
1902 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
1903 ep->hwtid);
1904 return 0;
1905 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001906 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
1907 ep->com.state);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001908
1909 /*
1910 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301911 * However, this is not needed if com state is just
1912 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05001913 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301914 if (ep->com.state != MPA_REQ_SENT)
1915 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001916
1917 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001918 switch (ep->com.state) {
1919 case CONNECTING:
1920 break;
1921 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00001922 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001923 break;
1924 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00001925 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301926 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
1927 connect_reply_upcall(ep, -ECONNRESET);
1928 else {
1929 /*
1930 * we just don't send notification upwards because we
1931 * want to retry with mpa_v1 without upper layers even
1932 * knowing it.
1933 *
1934 * do some housekeeping so as to re-initiate the
1935 * connection
1936 */
1937 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
1938 mpa_rev);
1939 ep->retry_with_mpa_v1 = 1;
1940 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001941 break;
1942 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001943 break;
1944 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001945 break;
1946 case MORIBUND:
1947 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00001948 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001949 /*FALLTHROUGH*/
1950 case FPDU_MODE:
1951 if (ep->com.cm_id && ep->com.qp) {
1952 attrs.next_state = C4IW_QP_STATE_ERROR;
1953 ret = c4iw_modify_qp(ep->com.qp->rhp,
1954 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
1955 &attrs, 1);
1956 if (ret)
1957 printk(KERN_ERR MOD
1958 "%s - qp <- error failed!\n",
1959 __func__);
1960 }
1961 peer_abort_upcall(ep);
1962 break;
1963 case ABORTING:
1964 break;
1965 case DEAD:
1966 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001967 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001968 return 0;
1969 default:
1970 BUG_ON(1);
1971 break;
1972 }
1973 dst_confirm(ep->dst);
1974 if (ep->com.state != ABORTING) {
1975 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301976 /* we don't release if we want to retry with mpa_v1 */
1977 if (!ep->retry_with_mpa_v1)
1978 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001979 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001980 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001981
1982 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
1983 if (!rpl_skb) {
1984 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
1985 __func__);
1986 release = 1;
1987 goto out;
1988 }
1989 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1990 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
1991 INIT_TP_WR(rpl, ep->hwtid);
1992 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
1993 rpl->cmd = CPL_ABORT_NO_RST;
1994 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
1995out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001996 if (release)
1997 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301998
1999 /* retry with mpa-v1 */
2000 if (ep && ep->retry_with_mpa_v1) {
2001 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2002 dst_release(ep->dst);
2003 cxgb4_l2t_release(ep->l2t);
2004 c4iw_reconnect(ep);
2005 }
2006
Steve Wisecfdda9d2010-04-21 15:30:06 -07002007 return 0;
2008}
2009
2010static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2011{
2012 struct c4iw_ep *ep;
2013 struct c4iw_qp_attributes attrs;
2014 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002015 int release = 0;
2016 struct tid_info *t = dev->rdev.lldi.tids;
2017 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002018
2019 ep = lookup_tid(t, tid);
2020
2021 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2022 BUG_ON(!ep);
2023
2024 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002025 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002026 switch (ep->com.state) {
2027 case CLOSING:
2028 __state_set(&ep->com, MORIBUND);
2029 break;
2030 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002031 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002032 if ((ep->com.cm_id) && (ep->com.qp)) {
2033 attrs.next_state = C4IW_QP_STATE_IDLE;
2034 c4iw_modify_qp(ep->com.qp->rhp,
2035 ep->com.qp,
2036 C4IW_QP_ATTR_NEXT_STATE,
2037 &attrs, 1);
2038 }
2039 close_complete_upcall(ep);
2040 __state_set(&ep->com, DEAD);
2041 release = 1;
2042 break;
2043 case ABORTING:
2044 case DEAD:
2045 break;
2046 default:
2047 BUG_ON(1);
2048 break;
2049 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002050 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002051 if (release)
2052 release_ep_resources(ep);
2053 return 0;
2054}
2055
2056static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2057{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002058 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002059 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002060 unsigned int tid = GET_TID(rpl);
2061 struct c4iw_ep *ep;
2062 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002063
2064 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002065 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002066
Steve Wise30c95c22011-05-09 22:06:22 -07002067 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002068 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2069 ep->com.qp->wq.sq.qid);
2070 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2071 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2072 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2073 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002074 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002075
Steve Wisecfdda9d2010-04-21 15:30:06 -07002076 return 0;
2077}
2078
2079/*
2080 * Upcall from the adapter indicating data has been transmitted.
2081 * For us its just the single MPA request or reply. We can now free
2082 * the skb holding the mpa message.
2083 */
2084static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2085{
2086 struct c4iw_ep *ep;
2087 struct cpl_fw4_ack *hdr = cplhdr(skb);
2088 u8 credits = hdr->credits;
2089 unsigned int tid = GET_TID(hdr);
2090 struct tid_info *t = dev->rdev.lldi.tids;
2091
2092
2093 ep = lookup_tid(t, tid);
2094 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2095 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002096 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2097 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002098 return 0;
2099 }
2100
2101 dst_confirm(ep->dst);
2102 if (ep->mpa_skb) {
2103 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2104 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2105 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2106 kfree_skb(ep->mpa_skb);
2107 ep->mpa_skb = NULL;
2108 }
2109 return 0;
2110}
2111
Steve Wisecfdda9d2010-04-21 15:30:06 -07002112int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2113{
2114 int err;
2115 struct c4iw_ep *ep = to_ep(cm_id);
2116 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2117
2118 if (state_read(&ep->com) == DEAD) {
2119 c4iw_put_ep(&ep->com);
2120 return -ECONNRESET;
2121 }
2122 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2123 if (mpa_rev == 0)
2124 abort_connection(ep, NULL, GFP_KERNEL);
2125 else {
2126 err = send_mpa_reject(ep, pdata, pdata_len);
2127 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2128 }
2129 c4iw_put_ep(&ep->com);
2130 return 0;
2131}
2132
2133int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2134{
2135 int err;
2136 struct c4iw_qp_attributes attrs;
2137 enum c4iw_qp_attr_mask mask;
2138 struct c4iw_ep *ep = to_ep(cm_id);
2139 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2140 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2141
2142 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2143 if (state_read(&ep->com) == DEAD) {
2144 err = -ECONNRESET;
2145 goto err;
2146 }
2147
2148 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2149 BUG_ON(!qp);
2150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002151 if ((conn_param->ord > c4iw_max_read_depth) ||
2152 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002153 abort_connection(ep, NULL, GFP_KERNEL);
2154 err = -EINVAL;
2155 goto err;
2156 }
2157
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302158 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2159 if (conn_param->ord > ep->ird) {
2160 ep->ird = conn_param->ird;
2161 ep->ord = conn_param->ord;
2162 send_mpa_reject(ep, conn_param->private_data,
2163 conn_param->private_data_len);
2164 abort_connection(ep, NULL, GFP_KERNEL);
2165 err = -ENOMEM;
2166 goto err;
2167 }
2168 if (conn_param->ird > ep->ord) {
2169 if (!ep->ord)
2170 conn_param->ird = 1;
2171 else {
2172 abort_connection(ep, NULL, GFP_KERNEL);
2173 err = -ENOMEM;
2174 goto err;
2175 }
2176 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002177
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302178 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002179 ep->ird = conn_param->ird;
2180 ep->ord = conn_param->ord;
2181
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302182 if (ep->mpa_attr.version != 2)
2183 if (peer2peer && ep->ird == 0)
2184 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002185
2186 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2187
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302188 cm_id->add_ref(cm_id);
2189 ep->com.cm_id = cm_id;
2190 ep->com.qp = qp;
2191
Steve Wisecfdda9d2010-04-21 15:30:06 -07002192 /* bind QP to EP and move to RTS */
2193 attrs.mpa_attr = ep->mpa_attr;
2194 attrs.max_ird = ep->ird;
2195 attrs.max_ord = ep->ord;
2196 attrs.llp_stream_handle = ep;
2197 attrs.next_state = C4IW_QP_STATE_RTS;
2198
2199 /* bind QP and TID with INIT_WR */
2200 mask = C4IW_QP_ATTR_NEXT_STATE |
2201 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2202 C4IW_QP_ATTR_MPA_ATTR |
2203 C4IW_QP_ATTR_MAX_IRD |
2204 C4IW_QP_ATTR_MAX_ORD;
2205
2206 err = c4iw_modify_qp(ep->com.qp->rhp,
2207 ep->com.qp, mask, &attrs, 1);
2208 if (err)
2209 goto err1;
2210 err = send_mpa_reply(ep, conn_param->private_data,
2211 conn_param->private_data_len);
2212 if (err)
2213 goto err1;
2214
2215 state_set(&ep->com, FPDU_MODE);
2216 established_upcall(ep);
2217 c4iw_put_ep(&ep->com);
2218 return 0;
2219err1:
2220 ep->com.cm_id = NULL;
2221 ep->com.qp = NULL;
2222 cm_id->rem_ref(cm_id);
2223err:
2224 c4iw_put_ep(&ep->com);
2225 return err;
2226}
2227
2228int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2229{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002230 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2231 struct c4iw_ep *ep;
2232 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002233 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002235 if ((conn_param->ord > c4iw_max_read_depth) ||
2236 (conn_param->ird > c4iw_max_read_depth)) {
2237 err = -EINVAL;
2238 goto out;
2239 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2241 if (!ep) {
2242 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2243 err = -ENOMEM;
2244 goto out;
2245 }
2246 init_timer(&ep->timer);
2247 ep->plen = conn_param->private_data_len;
2248 if (ep->plen)
2249 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2250 conn_param->private_data, ep->plen);
2251 ep->ird = conn_param->ird;
2252 ep->ord = conn_param->ord;
2253
2254 if (peer2peer && ep->ord == 0)
2255 ep->ord = 1;
2256
2257 cm_id->add_ref(cm_id);
2258 ep->com.dev = dev;
2259 ep->com.cm_id = cm_id;
2260 ep->com.qp = get_qhp(dev, conn_param->qpn);
2261 BUG_ON(!ep->com.qp);
2262 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2263 ep->com.qp, cm_id);
2264
2265 /*
2266 * Allocate an active TID to initiate a TCP connection.
2267 */
2268 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2269 if (ep->atid == -1) {
2270 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2271 err = -ENOMEM;
2272 goto fail2;
2273 }
2274
2275 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2276 ntohl(cm_id->local_addr.sin_addr.s_addr),
2277 ntohs(cm_id->local_addr.sin_port),
2278 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2279 ntohs(cm_id->remote_addr.sin_port));
2280
2281 /* find a route */
2282 rt = find_route(dev,
2283 cm_id->local_addr.sin_addr.s_addr,
2284 cm_id->remote_addr.sin_addr.s_addr,
2285 cm_id->local_addr.sin_port,
2286 cm_id->remote_addr.sin_port, 0);
2287 if (!rt) {
2288 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2289 err = -EHOSTUNREACH;
2290 goto fail3;
2291 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002292 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293
David Miller3786cf12011-12-02 16:52:31 +00002294 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2295 ep->dst, ep->com.dev, true);
2296 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002298 goto fail4;
2299 }
2300
2301 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2302 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2303 ep->l2t->idx);
2304
2305 state_set(&ep->com, CONNECTING);
2306 ep->tos = 0;
2307 ep->com.local_addr = cm_id->local_addr;
2308 ep->com.remote_addr = cm_id->remote_addr;
2309
2310 /* send connect request to rnic */
2311 err = send_connect(ep);
2312 if (!err)
2313 goto out;
2314
2315 cxgb4_l2t_release(ep->l2t);
2316fail4:
2317 dst_release(ep->dst);
2318fail3:
2319 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2320fail2:
2321 cm_id->rem_ref(cm_id);
2322 c4iw_put_ep(&ep->com);
2323out:
2324 return err;
2325}
2326
2327int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2328{
2329 int err = 0;
2330 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2331 struct c4iw_listen_ep *ep;
2332
2333
2334 might_sleep();
2335
2336 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2337 if (!ep) {
2338 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2339 err = -ENOMEM;
2340 goto fail1;
2341 }
2342 PDBG("%s ep %p\n", __func__, ep);
2343 cm_id->add_ref(cm_id);
2344 ep->com.cm_id = cm_id;
2345 ep->com.dev = dev;
2346 ep->backlog = backlog;
2347 ep->com.local_addr = cm_id->local_addr;
2348
2349 /*
2350 * Allocate a server TID.
2351 */
2352 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2353 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002354 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355 err = -ENOMEM;
2356 goto fail2;
2357 }
2358
2359 state_set(&ep->com, LISTEN);
Steve Wiseaadc4df2010-09-10 11:15:25 -05002360 c4iw_init_wr_wait(&ep->com.wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0], ep->stid,
2362 ep->com.local_addr.sin_addr.s_addr,
2363 ep->com.local_addr.sin_port,
2364 ep->com.dev->rdev.lldi.rxq_ids[0]);
2365 if (err)
2366 goto fail3;
2367
2368 /* wait for pass_open_rpl */
Steve Wiseaadc4df2010-09-10 11:15:25 -05002369 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2370 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371 if (!err) {
2372 cm_id->provider_data = ep;
2373 goto out;
2374 }
2375fail3:
2376 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2377fail2:
2378 cm_id->rem_ref(cm_id);
2379 c4iw_put_ep(&ep->com);
2380fail1:
2381out:
2382 return err;
2383}
2384
2385int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2386{
2387 int err;
2388 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2389
2390 PDBG("%s ep %p\n", __func__, ep);
2391
2392 might_sleep();
2393 state_set(&ep->com, DEAD);
Steve Wiseaadc4df2010-09-10 11:15:25 -05002394 c4iw_init_wr_wait(&ep->com.wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002395 err = listen_stop(ep);
2396 if (err)
2397 goto done;
Steve Wiseaadc4df2010-09-10 11:15:25 -05002398 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait, 0, 0,
2399 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002400 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2401done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002402 cm_id->rem_ref(cm_id);
2403 c4iw_put_ep(&ep->com);
2404 return err;
2405}
2406
2407int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2408{
2409 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410 int close = 0;
2411 int fatal = 0;
2412 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002413
Steve Wise2f5b48c2010-09-10 11:15:36 -05002414 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415
2416 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2417 states[ep->com.state], abrupt);
2418
2419 rdev = &ep->com.dev->rdev;
2420 if (c4iw_fatal_error(rdev)) {
2421 fatal = 1;
2422 close_complete_upcall(ep);
2423 ep->com.state = DEAD;
2424 }
2425 switch (ep->com.state) {
2426 case MPA_REQ_WAIT:
2427 case MPA_REQ_SENT:
2428 case MPA_REQ_RCVD:
2429 case MPA_REP_SENT:
2430 case FPDU_MODE:
2431 close = 1;
2432 if (abrupt)
2433 ep->com.state = ABORTING;
2434 else {
2435 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002436 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437 }
2438 set_bit(CLOSE_SENT, &ep->com.flags);
2439 break;
2440 case CLOSING:
2441 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2442 close = 1;
2443 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002444 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445 ep->com.state = ABORTING;
2446 } else
2447 ep->com.state = MORIBUND;
2448 }
2449 break;
2450 case MORIBUND:
2451 case ABORTING:
2452 case DEAD:
2453 PDBG("%s ignoring disconnect ep %p state %u\n",
2454 __func__, ep, ep->com.state);
2455 break;
2456 default:
2457 BUG();
2458 break;
2459 }
2460
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002462 if (abrupt) {
2463 close_complete_upcall(ep);
2464 ret = send_abort(ep, NULL, gfp);
2465 } else
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 ret = send_halfclose(ep, gfp);
2467 if (ret)
2468 fatal = 1;
2469 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002470 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002471 if (fatal)
2472 release_ep_resources(ep);
2473 return ret;
2474}
2475
Steve Wise2f5b48c2010-09-10 11:15:36 -05002476static int async_event(struct c4iw_dev *dev, struct sk_buff *skb)
2477{
2478 struct cpl_fw6_msg *rpl = cplhdr(skb);
2479 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2480 return 0;
2481}
2482
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002484 * These are the real handlers that are called from a
2485 * work queue.
2486 */
2487static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
2488 [CPL_ACT_ESTABLISH] = act_establish,
2489 [CPL_ACT_OPEN_RPL] = act_open_rpl,
2490 [CPL_RX_DATA] = rx_data,
2491 [CPL_ABORT_RPL_RSS] = abort_rpl,
2492 [CPL_ABORT_RPL] = abort_rpl,
2493 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
2494 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
2495 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
2496 [CPL_PASS_ESTABLISH] = pass_establish,
2497 [CPL_PEER_CLOSE] = peer_close,
2498 [CPL_ABORT_REQ_RSS] = peer_abort,
2499 [CPL_CLOSE_CON_RPL] = close_con_rpl,
2500 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05002501 [CPL_FW4_ACK] = fw4_ack,
2502 [CPL_FW6_MSG] = async_event
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002503};
2504
2505static void process_timeout(struct c4iw_ep *ep)
2506{
2507 struct c4iw_qp_attributes attrs;
2508 int abort = 1;
2509
Steve Wise2f5b48c2010-09-10 11:15:36 -05002510 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002511 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
2512 ep->com.state);
2513 switch (ep->com.state) {
2514 case MPA_REQ_SENT:
2515 __state_set(&ep->com, ABORTING);
2516 connect_reply_upcall(ep, -ETIMEDOUT);
2517 break;
2518 case MPA_REQ_WAIT:
2519 __state_set(&ep->com, ABORTING);
2520 break;
2521 case CLOSING:
2522 case MORIBUND:
2523 if (ep->com.cm_id && ep->com.qp) {
2524 attrs.next_state = C4IW_QP_STATE_ERROR;
2525 c4iw_modify_qp(ep->com.qp->rhp,
2526 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2527 &attrs, 1);
2528 }
2529 __state_set(&ep->com, ABORTING);
2530 break;
2531 default:
2532 printk(KERN_ERR "%s unexpected state ep %p tid %u state %u\n",
2533 __func__, ep, ep->hwtid, ep->com.state);
2534 WARN_ON(1);
2535 abort = 0;
2536 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002537 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002538 if (abort)
2539 abort_connection(ep, NULL, GFP_KERNEL);
2540 c4iw_put_ep(&ep->com);
2541}
2542
2543static void process_timedout_eps(void)
2544{
2545 struct c4iw_ep *ep;
2546
2547 spin_lock_irq(&timeout_lock);
2548 while (!list_empty(&timeout_list)) {
2549 struct list_head *tmp;
2550
2551 tmp = timeout_list.next;
2552 list_del(tmp);
2553 spin_unlock_irq(&timeout_lock);
2554 ep = list_entry(tmp, struct c4iw_ep, entry);
2555 process_timeout(ep);
2556 spin_lock_irq(&timeout_lock);
2557 }
2558 spin_unlock_irq(&timeout_lock);
2559}
2560
2561static void process_work(struct work_struct *work)
2562{
2563 struct sk_buff *skb = NULL;
2564 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00002565 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002566 unsigned int opcode;
2567 int ret;
2568
2569 while ((skb = skb_dequeue(&rxq))) {
2570 rpl = cplhdr(skb);
2571 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
2572 opcode = rpl->ot.opcode;
2573
2574 BUG_ON(!work_handlers[opcode]);
2575 ret = work_handlers[opcode](dev, skb);
2576 if (!ret)
2577 kfree_skb(skb);
2578 }
2579 process_timedout_eps();
2580}
2581
2582static DECLARE_WORK(skb_work, process_work);
2583
2584static void ep_timeout(unsigned long arg)
2585{
2586 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
2587
2588 spin_lock(&timeout_lock);
2589 list_add_tail(&ep->entry, &timeout_list);
2590 spin_unlock(&timeout_lock);
2591 queue_work(workq, &skb_work);
2592}
2593
2594/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 * All the CM events are handled on a work queue to have a safe context.
2596 */
2597static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
2598{
2599
2600 /*
2601 * Save dev in the skb->cb area.
2602 */
2603 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
2604
2605 /*
2606 * Queue the skb and schedule the worker thread.
2607 */
2608 skb_queue_tail(&rxq, skb);
2609 queue_work(workq, &skb_work);
2610 return 0;
2611}
2612
2613static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2614{
2615 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
2616
2617 if (rpl->status != CPL_ERR_NONE) {
2618 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
2619 "for tid %u\n", rpl->status, GET_TID(rpl));
2620 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002621 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 return 0;
2623}
2624
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002625static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
2626{
2627 struct cpl_fw6_msg *rpl = cplhdr(skb);
2628 struct c4iw_wr_wait *wr_waitp;
2629 int ret;
2630
2631 PDBG("%s type %u\n", __func__, rpl->type);
2632
2633 switch (rpl->type) {
2634 case 1:
2635 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07002636 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002637 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07002638 if (wr_waitp)
2639 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002640 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002641 break;
2642 case 2:
Steve Wise2f5b48c2010-09-10 11:15:36 -05002643 sched(dev, skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002644 break;
2645 default:
2646 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
2647 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002648 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002649 break;
2650 }
2651 return 0;
2652}
2653
Steve Wise8da7e7a2011-06-14 20:59:27 +00002654static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
2655{
2656 struct cpl_abort_req_rss *req = cplhdr(skb);
2657 struct c4iw_ep *ep;
2658 struct tid_info *t = dev->rdev.lldi.tids;
2659 unsigned int tid = GET_TID(req);
2660
2661 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05002662 if (!ep) {
2663 printk(KERN_WARNING MOD
2664 "Abort on non-existent endpoint, tid %d\n", tid);
2665 kfree_skb(skb);
2666 return 0;
2667 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002668 if (is_neg_adv_abort(req->status)) {
2669 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2670 ep->hwtid);
2671 kfree_skb(skb);
2672 return 0;
2673 }
2674 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2675 ep->com.state);
2676
2677 /*
2678 * Wake up any threads in rdma_init() or rdma_fini().
2679 */
Steve Wise0f1dcfa2012-04-27 09:59:16 -05002680 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002681 sched(dev, skb);
2682 return 0;
2683}
2684
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002685/*
2686 * Most upcalls from the T4 Core go to sched() to
2687 * schedule the processing on a work queue.
2688 */
2689c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
2690 [CPL_ACT_ESTABLISH] = sched,
2691 [CPL_ACT_OPEN_RPL] = sched,
2692 [CPL_RX_DATA] = sched,
2693 [CPL_ABORT_RPL_RSS] = sched,
2694 [CPL_ABORT_RPL] = sched,
2695 [CPL_PASS_OPEN_RPL] = sched,
2696 [CPL_CLOSE_LISTSRV_RPL] = sched,
2697 [CPL_PASS_ACCEPT_REQ] = sched,
2698 [CPL_PASS_ESTABLISH] = sched,
2699 [CPL_PEER_CLOSE] = sched,
2700 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00002701 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002702 [CPL_RDMA_TERMINATE] = sched,
2703 [CPL_FW4_ACK] = sched,
2704 [CPL_SET_TCB_RPL] = set_tcb_rpl,
2705 [CPL_FW6_MSG] = fw6_msg
2706};
2707
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708int __init c4iw_cm_init(void)
2709{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002710 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002711 skb_queue_head_init(&rxq);
2712
2713 workq = create_singlethread_workqueue("iw_cxgb4");
2714 if (!workq)
2715 return -ENOMEM;
2716
Steve Wisecfdda9d2010-04-21 15:30:06 -07002717 return 0;
2718}
2719
2720void __exit c4iw_cm_term(void)
2721{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002722 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002723 flush_workqueue(workq);
2724 destroy_workqueue(workq);
2725}