blob: 3dce47a637094270bf025f0bff5e3cf6b2a4ac70 [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>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070047
48#include "iw_cxgb4.h"
49
50static char *states[] = {
51 "idle",
52 "listen",
53 "connecting",
54 "mpa_wait_req",
55 "mpa_req_sent",
56 "mpa_req_rcvd",
57 "mpa_rep_sent",
58 "fpdu_mode",
59 "aborting",
60 "closing",
61 "moribund",
62 "dead",
63 NULL,
64};
65
Vipul Pandya5be78ee2012-12-10 09:30:54 +000066static int nocong;
67module_param(nocong, int, 0644);
68MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
69
70static int enable_ecn;
71module_param(enable_ecn, int, 0644);
72MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
73
Steve Wiseb52fe092011-03-11 22:30:01 +000074static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000075module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000076MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000077
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070078int c4iw_max_read_depth = 8;
79module_param(c4iw_max_read_depth, int, 0644);
80MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
81
Steve Wisecfdda9d2010-04-21 15:30:06 -070082static int enable_tcp_timestamps;
83module_param(enable_tcp_timestamps, int, 0644);
84MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
85
86static int enable_tcp_sack;
87module_param(enable_tcp_sack, int, 0644);
88MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
89
90static int enable_tcp_window_scaling = 1;
91module_param(enable_tcp_window_scaling, int, 0644);
92MODULE_PARM_DESC(enable_tcp_window_scaling,
93 "Enable tcp window scaling (default=1)");
94
95int c4iw_debug;
96module_param(c4iw_debug, int, 0644);
97MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
98
99static int peer2peer;
100module_param(peer2peer, int, 0644);
101MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
102
103static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
104module_param(p2p_type, int, 0644);
105MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
106 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
107
108static int ep_timeout_secs = 60;
109module_param(ep_timeout_secs, int, 0644);
110MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
111 "in seconds (default=60)");
112
113static int mpa_rev = 1;
114module_param(mpa_rev, int, 0644);
115MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530116 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
117 " compliant (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700118
119static int markers_enabled;
120module_param(markers_enabled, int, 0644);
121MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
122
123static int crc_enabled = 1;
124module_param(crc_enabled, int, 0644);
125MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
126
127static int rcv_win = 256 * 1024;
128module_param(rcv_win, int, 0644);
129MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
130
Steve Wise98ae68b2010-09-10 11:15:41 -0500131static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700132module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500133MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700134
Steve Wisecfdda9d2010-04-21 15:30:06 -0700135static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700136
137static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138
139static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
140static void ep_timeout(unsigned long arg);
141static void connect_reply_upcall(struct c4iw_ep *ep, int status);
142
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700143static LIST_HEAD(timeout_list);
144static spinlock_t timeout_lock;
145
Steve Wisecfdda9d2010-04-21 15:30:06 -0700146static void start_ep_timer(struct c4iw_ep *ep)
147{
148 PDBG("%s ep %p\n", __func__, ep);
149 if (timer_pending(&ep->timer)) {
150 PDBG("%s stopped / restarted timer ep %p\n", __func__, ep);
151 del_timer_sync(&ep->timer);
152 } else
153 c4iw_get_ep(&ep->com);
154 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
155 ep->timer.data = (unsigned long)ep;
156 ep->timer.function = ep_timeout;
157 add_timer(&ep->timer);
158}
159
160static void stop_ep_timer(struct c4iw_ep *ep)
161{
162 PDBG("%s ep %p\n", __func__, ep);
163 if (!timer_pending(&ep->timer)) {
Julia Lawall76f267b2012-11-03 10:58:27 +0000164 WARN(1, "%s timer stopped when its not running! "
Steve Wisecfdda9d2010-04-21 15:30:06 -0700165 "ep %p state %u\n", __func__, ep, ep->com.state);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700166 return;
167 }
168 del_timer_sync(&ep->timer);
169 c4iw_put_ep(&ep->com);
170}
171
172static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
173 struct l2t_entry *l2e)
174{
175 int error = 0;
176
177 if (c4iw_fatal_error(rdev)) {
178 kfree_skb(skb);
179 PDBG("%s - device in error state - dropping\n", __func__);
180 return -EIO;
181 }
182 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
183 if (error < 0)
184 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500185 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700186}
187
188int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
189{
190 int error = 0;
191
192 if (c4iw_fatal_error(rdev)) {
193 kfree_skb(skb);
194 PDBG("%s - device in error state - dropping\n", __func__);
195 return -EIO;
196 }
197 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
198 if (error < 0)
199 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500200 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700201}
202
203static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
204{
205 struct cpl_tid_release *req;
206
207 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
208 if (!skb)
209 return;
210 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
211 INIT_TP_WR(req, hwtid);
212 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
213 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
214 c4iw_ofld_send(rdev, skb);
215 return;
216}
217
218static void set_emss(struct c4iw_ep *ep, u16 opt)
219{
220 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
221 ep->mss = ep->emss;
222 if (GET_TCPOPT_TSTAMP(opt))
223 ep->emss -= 12;
224 if (ep->emss < 128)
225 ep->emss = 128;
226 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
227 ep->mss, ep->emss);
228}
229
230static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
231{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700232 enum c4iw_ep_state state;
233
Steve Wise2f5b48c2010-09-10 11:15:36 -0500234 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700235 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500236 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700237 return state;
238}
239
240static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
241{
242 epc->state = new;
243}
244
245static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
246{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500247 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700248 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
249 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500250 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700251 return;
252}
253
254static void *alloc_ep(int size, gfp_t gfp)
255{
256 struct c4iw_ep_common *epc;
257
258 epc = kzalloc(size, gfp);
259 if (epc) {
260 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500261 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500262 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 }
264 PDBG("%s alloc ep %p\n", __func__, epc);
265 return epc;
266}
267
268void _c4iw_free_ep(struct kref *kref)
269{
270 struct c4iw_ep *ep;
271
272 ep = container_of(kref, struct c4iw_ep, com.kref);
273 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
274 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
275 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
276 dst_release(ep->dst);
277 cxgb4_l2t_release(ep->l2t);
Vipul Pandya793dad92012-12-10 09:30:56 +0000278 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279 }
280 kfree(ep);
281}
282
283static void release_ep_resources(struct c4iw_ep *ep)
284{
285 set_bit(RELEASE_RESOURCES, &ep->com.flags);
286 c4iw_put_ep(&ep->com);
287}
288
Steve Wisecfdda9d2010-04-21 15:30:06 -0700289static int status2errno(int status)
290{
291 switch (status) {
292 case CPL_ERR_NONE:
293 return 0;
294 case CPL_ERR_CONN_RESET:
295 return -ECONNRESET;
296 case CPL_ERR_ARP_MISS:
297 return -EHOSTUNREACH;
298 case CPL_ERR_CONN_TIMEDOUT:
299 return -ETIMEDOUT;
300 case CPL_ERR_TCAM_FULL:
301 return -ENOMEM;
302 case CPL_ERR_CONN_EXIST:
303 return -EADDRINUSE;
304 default:
305 return -EIO;
306 }
307}
308
309/*
310 * Try and reuse skbs already allocated...
311 */
312static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
313{
314 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
315 skb_trim(skb, 0);
316 skb_get(skb);
317 skb_reset_transport_header(skb);
318 } else {
319 skb = alloc_skb(len, gfp);
320 }
321 return skb;
322}
323
324static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
325 __be32 peer_ip, __be16 local_port,
326 __be16 peer_port, u8 tos)
327{
328 struct rtable *rt;
David S. Miller31e45432011-05-03 20:25:42 -0700329 struct flowi4 fl4;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700330
David S. Miller31e45432011-05-03 20:25:42 -0700331 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500332 peer_port, local_port, IPPROTO_TCP,
333 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800334 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700335 return NULL;
336 return rt;
337}
338
339static void arp_failure_discard(void *handle, struct sk_buff *skb)
340{
341 PDBG("%s c4iw_dev %p\n", __func__, handle);
342 kfree_skb(skb);
343}
344
345/*
346 * Handle an ARP failure for an active open.
347 */
348static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
349{
350 printk(KERN_ERR MOD "ARP failure duing connect\n");
351 kfree_skb(skb);
352}
353
354/*
355 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
356 * and send it along.
357 */
358static void abort_arp_failure(void *handle, struct sk_buff *skb)
359{
360 struct c4iw_rdev *rdev = handle;
361 struct cpl_abort_req *req = cplhdr(skb);
362
363 PDBG("%s rdev %p\n", __func__, rdev);
364 req->cmd = CPL_ABORT_NO_RST;
365 c4iw_ofld_send(rdev, skb);
366}
367
368static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
369{
370 unsigned int flowclen = 80;
371 struct fw_flowc_wr *flowc;
372 int i;
373
374 skb = get_skb(skb, flowclen, GFP_KERNEL);
375 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
376
377 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
378 FW_FLOWC_WR_NPARAMS(8));
379 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
380 16)) | FW_WR_FLOWID(ep->hwtid));
381
382 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise947886572011-01-21 17:00:34 +0000383 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700384 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
385 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
386 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
387 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
388 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
389 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
390 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
391 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
392 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
393 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
394 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
395 flowc->mnemval[6].val = cpu_to_be32(snd_win);
396 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
397 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
398 /* Pad WR to 16 byte boundary */
399 flowc->mnemval[8].mnemonic = 0;
400 flowc->mnemval[8].val = 0;
401 for (i = 0; i < 9; i++) {
402 flowc->mnemval[i].r4[0] = 0;
403 flowc->mnemval[i].r4[1] = 0;
404 flowc->mnemval[i].r4[2] = 0;
405 }
406
407 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
408 c4iw_ofld_send(&ep->com.dev->rdev, skb);
409}
410
411static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
412{
413 struct cpl_close_con_req *req;
414 struct sk_buff *skb;
415 int wrlen = roundup(sizeof *req, 16);
416
417 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
418 skb = get_skb(NULL, wrlen, gfp);
419 if (!skb) {
420 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
421 return -ENOMEM;
422 }
423 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
424 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
425 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
426 memset(req, 0, wrlen);
427 INIT_TP_WR(req, ep->hwtid);
428 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
429 ep->hwtid));
430 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
431}
432
433static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
434{
435 struct cpl_abort_req *req;
436 int wrlen = roundup(sizeof *req, 16);
437
438 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
439 skb = get_skb(skb, wrlen, gfp);
440 if (!skb) {
441 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
442 __func__);
443 return -ENOMEM;
444 }
445 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
446 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
447 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
448 memset(req, 0, wrlen);
449 INIT_TP_WR(req, ep->hwtid);
450 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
451 req->cmd = CPL_ABORT_SEND_RST;
452 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
453}
454
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000455#define VLAN_NONE 0xfff
456#define FILTER_SEL_VLAN_NONE 0xffff
457#define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
458#define FILTER_SEL_WIDTH_VIN_P_FC \
459 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
460#define FILTER_SEL_WIDTH_TAG_P_FC \
461 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
462#define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
463
464static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
465 struct l2t_entry *l2t)
466{
467 unsigned int ntuple = 0;
468 u32 viid;
469
470 switch (dev->rdev.lldi.filt_mode) {
471
472 /* default filter mode */
473 case HW_TPL_FR_MT_PR_IV_P_FC:
474 if (l2t->vlan == VLAN_NONE)
475 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
476 else {
477 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
478 ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
479 }
480 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
481 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
482 break;
483 case HW_TPL_FR_MT_PR_OV_P_FC: {
484 viid = cxgb4_port_viid(l2t->neigh->dev);
485
486 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
487 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
488 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
489 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
490 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
491 break;
492 }
493 default:
494 break;
495 }
496 return ntuple;
497}
498
Steve Wisecfdda9d2010-04-21 15:30:06 -0700499static int send_connect(struct c4iw_ep *ep)
500{
501 struct cpl_act_open_req *req;
502 struct sk_buff *skb;
503 u64 opt0;
504 u32 opt2;
505 unsigned int mtu_idx;
506 int wscale;
507 int wrlen = roundup(sizeof *req, 16);
508
509 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
510
511 skb = get_skb(NULL, wrlen, GFP_KERNEL);
512 if (!skb) {
513 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
514 __func__);
515 return -ENOMEM;
516 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000517 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700518
519 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
520 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000521 opt0 = (nocong ? NO_CONG(1) : 0) |
522 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000523 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700524 WND_SCALE(wscale) |
525 MSS_IDX(mtu_idx) |
526 L2T_IDX(ep->l2t->idx) |
527 TX_CHAN(ep->tx_chan) |
528 SMAC_SEL(ep->smac_idx) |
529 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000530 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700531 RCV_BUFSIZ(rcv_win>>10);
532 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000533 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700534 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
535 if (enable_tcp_timestamps)
536 opt2 |= TSTAMPS_EN(1);
537 if (enable_tcp_sack)
538 opt2 |= SACK_EN(1);
539 if (wscale && enable_tcp_window_scaling)
540 opt2 |= WND_SCALE_EN(1);
541 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
542
543 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
544 INIT_TP_WR(req, 0);
545 OPCODE_TID(req) = cpu_to_be32(
546 MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
547 req->local_port = ep->com.local_addr.sin_port;
548 req->peer_port = ep->com.remote_addr.sin_port;
549 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
550 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
551 req->opt0 = cpu_to_be64(opt0);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000552 req->params = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst, ep->l2t));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700553 req->opt2 = cpu_to_be32(opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +0000554 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700555 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
556}
557
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530558static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
559 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700560{
561 int mpalen, wrlen;
562 struct fw_ofld_tx_data_wr *req;
563 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530564 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700565
566 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
567
568 BUG_ON(skb_cloned(skb));
569
570 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530571 if (mpa_rev_to_use == 2)
572 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700573 wrlen = roundup(mpalen + sizeof *req, 16);
574 skb = get_skb(skb, wrlen, GFP_KERNEL);
575 if (!skb) {
576 connect_reply_upcall(ep, -ENOMEM);
577 return;
578 }
579 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
580
581 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
582 memset(req, 0, wrlen);
583 req->op_to_immdlen = cpu_to_be32(
584 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
585 FW_WR_COMPL(1) |
586 FW_WR_IMMDLEN(mpalen));
587 req->flowid_len16 = cpu_to_be32(
588 FW_WR_FLOWID(ep->hwtid) |
589 FW_WR_LEN16(wrlen >> 4));
590 req->plen = cpu_to_be32(mpalen);
591 req->tunnel_to_proxy = cpu_to_be32(
592 FW_OFLD_TX_DATA_WR_FLUSH(1) |
593 FW_OFLD_TX_DATA_WR_SHOVE(1));
594
595 mpa = (struct mpa_message *)(req + 1);
596 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
597 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530598 (markers_enabled ? MPA_MARKERS : 0) |
599 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530601 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530602 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530603 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530604 ep->retry_with_mpa_v1 = 0;
605 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530607 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700608 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
609 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530610 mpa_v2_params.ird = htons((u16)ep->ird);
611 mpa_v2_params.ord = htons((u16)ep->ord);
612
613 if (peer2peer) {
614 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
615 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
616 mpa_v2_params.ord |=
617 htons(MPA_V2_RDMA_WRITE_RTR);
618 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
619 mpa_v2_params.ord |=
620 htons(MPA_V2_RDMA_READ_RTR);
621 }
622 memcpy(mpa->private_data, &mpa_v2_params,
623 sizeof(struct mpa_v2_conn_params));
624
625 if (ep->plen)
626 memcpy(mpa->private_data +
627 sizeof(struct mpa_v2_conn_params),
628 ep->mpa_pkt + sizeof(*mpa), ep->plen);
629 } else
630 if (ep->plen)
631 memcpy(mpa->private_data,
632 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700633
634 /*
635 * Reference the mpa skb. This ensures the data area
636 * will remain in memory until the hw acks the tx.
637 * Function fw4_ack() will deref it.
638 */
639 skb_get(skb);
640 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
641 BUG_ON(ep->mpa_skb);
642 ep->mpa_skb = skb;
643 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
644 start_ep_timer(ep);
645 state_set(&ep->com, MPA_REQ_SENT);
646 ep->mpa_attr.initiator = 1;
647 return;
648}
649
650static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
651{
652 int mpalen, wrlen;
653 struct fw_ofld_tx_data_wr *req;
654 struct mpa_message *mpa;
655 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530656 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700657
658 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
659
660 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530661 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
662 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700663 wrlen = roundup(mpalen + sizeof *req, 16);
664
665 skb = get_skb(NULL, wrlen, GFP_KERNEL);
666 if (!skb) {
667 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
668 return -ENOMEM;
669 }
670 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
671
672 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
673 memset(req, 0, wrlen);
674 req->op_to_immdlen = cpu_to_be32(
675 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
676 FW_WR_COMPL(1) |
677 FW_WR_IMMDLEN(mpalen));
678 req->flowid_len16 = cpu_to_be32(
679 FW_WR_FLOWID(ep->hwtid) |
680 FW_WR_LEN16(wrlen >> 4));
681 req->plen = cpu_to_be32(mpalen);
682 req->tunnel_to_proxy = cpu_to_be32(
683 FW_OFLD_TX_DATA_WR_FLUSH(1) |
684 FW_OFLD_TX_DATA_WR_SHOVE(1));
685
686 mpa = (struct mpa_message *)(req + 1);
687 memset(mpa, 0, sizeof(*mpa));
688 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
689 mpa->flags = MPA_REJECT;
690 mpa->revision = mpa_rev;
691 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530692
693 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
694 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700695 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
696 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530697 mpa_v2_params.ird = htons(((u16)ep->ird) |
698 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
699 0));
700 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
701 (p2p_type ==
702 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
703 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
704 FW_RI_INIT_P2PTYPE_READ_REQ ?
705 MPA_V2_RDMA_READ_RTR : 0) : 0));
706 memcpy(mpa->private_data, &mpa_v2_params,
707 sizeof(struct mpa_v2_conn_params));
708
709 if (ep->plen)
710 memcpy(mpa->private_data +
711 sizeof(struct mpa_v2_conn_params), pdata, plen);
712 } else
713 if (plen)
714 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700715
716 /*
717 * Reference the mpa skb again. This ensures the data area
718 * will remain in memory until the hw acks the tx.
719 * Function fw4_ack() will deref it.
720 */
721 skb_get(skb);
722 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
723 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
724 BUG_ON(ep->mpa_skb);
725 ep->mpa_skb = skb;
726 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
727}
728
729static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
730{
731 int mpalen, wrlen;
732 struct fw_ofld_tx_data_wr *req;
733 struct mpa_message *mpa;
734 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530735 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700736
737 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
738
739 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530740 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
741 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700742 wrlen = roundup(mpalen + sizeof *req, 16);
743
744 skb = get_skb(NULL, wrlen, GFP_KERNEL);
745 if (!skb) {
746 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
747 return -ENOMEM;
748 }
749 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
750
751 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
752 memset(req, 0, wrlen);
753 req->op_to_immdlen = cpu_to_be32(
754 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
755 FW_WR_COMPL(1) |
756 FW_WR_IMMDLEN(mpalen));
757 req->flowid_len16 = cpu_to_be32(
758 FW_WR_FLOWID(ep->hwtid) |
759 FW_WR_LEN16(wrlen >> 4));
760 req->plen = cpu_to_be32(mpalen);
761 req->tunnel_to_proxy = cpu_to_be32(
762 FW_OFLD_TX_DATA_WR_FLUSH(1) |
763 FW_OFLD_TX_DATA_WR_SHOVE(1));
764
765 mpa = (struct mpa_message *)(req + 1);
766 memset(mpa, 0, sizeof(*mpa));
767 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
768 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
769 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530770 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700771 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530772
773 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
774 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700775 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
776 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530777 mpa_v2_params.ird = htons((u16)ep->ird);
778 mpa_v2_params.ord = htons((u16)ep->ord);
779 if (peer2peer && (ep->mpa_attr.p2p_type !=
780 FW_RI_INIT_P2PTYPE_DISABLED)) {
781 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
782
783 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
784 mpa_v2_params.ord |=
785 htons(MPA_V2_RDMA_WRITE_RTR);
786 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
787 mpa_v2_params.ord |=
788 htons(MPA_V2_RDMA_READ_RTR);
789 }
790
791 memcpy(mpa->private_data, &mpa_v2_params,
792 sizeof(struct mpa_v2_conn_params));
793
794 if (ep->plen)
795 memcpy(mpa->private_data +
796 sizeof(struct mpa_v2_conn_params), pdata, plen);
797 } else
798 if (plen)
799 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700800
801 /*
802 * Reference the mpa skb. This ensures the data area
803 * will remain in memory until the hw acks the tx.
804 * Function fw4_ack() will deref it.
805 */
806 skb_get(skb);
807 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
808 ep->mpa_skb = skb;
809 state_set(&ep->com, MPA_REP_SENT);
810 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
811}
812
813static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
814{
815 struct c4iw_ep *ep;
816 struct cpl_act_establish *req = cplhdr(skb);
817 unsigned int tid = GET_TID(req);
818 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
819 struct tid_info *t = dev->rdev.lldi.tids;
820
821 ep = lookup_atid(t, atid);
822
823 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
824 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
825
826 dst_confirm(ep->dst);
827
828 /* setup the hwtid for this connection */
829 ep->hwtid = tid;
830 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000831 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700832
833 ep->snd_seq = be32_to_cpu(req->snd_isn);
834 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
835
836 set_emss(ep, ntohs(req->tcp_opt));
837
838 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000839 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700840 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000841 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700842
843 /* start MPA negotiation */
844 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530845 if (ep->retry_with_mpa_v1)
846 send_mpa_req(ep, skb, 1);
847 else
848 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700849
850 return 0;
851}
852
853static void close_complete_upcall(struct c4iw_ep *ep)
854{
855 struct iw_cm_event event;
856
857 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
858 memset(&event, 0, sizeof(event));
859 event.event = IW_CM_EVENT_CLOSE;
860 if (ep->com.cm_id) {
861 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
862 ep, ep->com.cm_id, ep->hwtid);
863 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
864 ep->com.cm_id->rem_ref(ep->com.cm_id);
865 ep->com.cm_id = NULL;
866 ep->com.qp = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000867 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700868 }
869}
870
871static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
872{
873 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
874 close_complete_upcall(ep);
875 state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +0000876 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700877 return send_abort(ep, skb, gfp);
878}
879
880static void peer_close_upcall(struct c4iw_ep *ep)
881{
882 struct iw_cm_event event;
883
884 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
885 memset(&event, 0, sizeof(event));
886 event.event = IW_CM_EVENT_DISCONNECT;
887 if (ep->com.cm_id) {
888 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
889 ep, ep->com.cm_id, ep->hwtid);
890 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +0000891 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700892 }
893}
894
895static void peer_abort_upcall(struct c4iw_ep *ep)
896{
897 struct iw_cm_event event;
898
899 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
900 memset(&event, 0, sizeof(event));
901 event.event = IW_CM_EVENT_CLOSE;
902 event.status = -ECONNRESET;
903 if (ep->com.cm_id) {
904 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
905 ep->com.cm_id, ep->hwtid);
906 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
907 ep->com.cm_id->rem_ref(ep->com.cm_id);
908 ep->com.cm_id = NULL;
909 ep->com.qp = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000910 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700911 }
912}
913
914static void connect_reply_upcall(struct c4iw_ep *ep, int status)
915{
916 struct iw_cm_event event;
917
918 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
919 memset(&event, 0, sizeof(event));
920 event.event = IW_CM_EVENT_CONNECT_REPLY;
921 event.status = status;
922 event.local_addr = ep->com.local_addr;
923 event.remote_addr = ep->com.remote_addr;
924
925 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530926 if (!ep->tried_with_mpa_v1) {
927 /* this means MPA_v2 is used */
928 event.private_data_len = ep->plen -
929 sizeof(struct mpa_v2_conn_params);
930 event.private_data = ep->mpa_pkt +
931 sizeof(struct mpa_message) +
932 sizeof(struct mpa_v2_conn_params);
933 } else {
934 /* this means MPA_v1 is used */
935 event.private_data_len = ep->plen;
936 event.private_data = ep->mpa_pkt +
937 sizeof(struct mpa_message);
938 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700939 }
Roland Dreier85963e42010-07-19 13:13:09 -0700940
941 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
942 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +0000943 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -0700944 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
945
Steve Wisecfdda9d2010-04-21 15:30:06 -0700946 if (status < 0) {
947 ep->com.cm_id->rem_ref(ep->com.cm_id);
948 ep->com.cm_id = NULL;
949 ep->com.qp = NULL;
950 }
951}
952
953static void connect_request_upcall(struct c4iw_ep *ep)
954{
955 struct iw_cm_event event;
956
957 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
958 memset(&event, 0, sizeof(event));
959 event.event = IW_CM_EVENT_CONNECT_REQUEST;
960 event.local_addr = ep->com.local_addr;
961 event.remote_addr = ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700962 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530963 if (!ep->tried_with_mpa_v1) {
964 /* this means MPA_v2 is used */
965 event.ord = ep->ord;
966 event.ird = ep->ird;
967 event.private_data_len = ep->plen -
968 sizeof(struct mpa_v2_conn_params);
969 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
970 sizeof(struct mpa_v2_conn_params);
971 } else {
972 /* this means MPA_v1 is used. Send max supported */
973 event.ord = c4iw_max_read_depth;
974 event.ird = c4iw_max_read_depth;
975 event.private_data_len = ep->plen;
976 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
977 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 if (state_read(&ep->parent_ep->com) != DEAD) {
979 c4iw_get_ep(&ep->com);
980 ep->parent_ep->com.cm_id->event_handler(
981 ep->parent_ep->com.cm_id,
982 &event);
983 }
Vipul Pandya793dad92012-12-10 09:30:56 +0000984 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700985 c4iw_put_ep(&ep->parent_ep->com);
986 ep->parent_ep = NULL;
987}
988
989static void established_upcall(struct c4iw_ep *ep)
990{
991 struct iw_cm_event event;
992
993 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
994 memset(&event, 0, sizeof(event));
995 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530996 event.ird = ep->ird;
997 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700998 if (ep->com.cm_id) {
999 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1000 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001001 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001002 }
1003}
1004
1005static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1006{
1007 struct cpl_rx_data_ack *req;
1008 struct sk_buff *skb;
1009 int wrlen = roundup(sizeof *req, 16);
1010
1011 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1012 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1013 if (!skb) {
1014 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1015 return 0;
1016 }
1017
1018 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1019 memset(req, 0, wrlen);
1020 INIT_TP_WR(req, ep->hwtid);
1021 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1022 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001023 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1024 F_RX_DACK_CHANGE |
1025 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001026 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1028 return credits;
1029}
1030
1031static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1032{
1033 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301034 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001035 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301036 u16 resp_ird, resp_ord;
1037 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001038 struct c4iw_qp_attributes attrs;
1039 enum c4iw_qp_attr_mask mask;
1040 int err;
1041
1042 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1043
1044 /*
1045 * Stop mpa timer. If it expired, then the state has
1046 * changed and we bail since ep_timeout already aborted
1047 * the connection.
1048 */
1049 stop_ep_timer(ep);
1050 if (state_read(&ep->com) != MPA_REQ_SENT)
1051 return;
1052
1053 /*
1054 * If we get more than the supported amount of private data
1055 * then we must fail this connection.
1056 */
1057 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1058 err = -EINVAL;
1059 goto err;
1060 }
1061
1062 /*
1063 * copy the new data into our accumulation buffer.
1064 */
1065 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1066 skb->len);
1067 ep->mpa_pkt_len += skb->len;
1068
1069 /*
1070 * if we don't even have the mpa message, then bail.
1071 */
1072 if (ep->mpa_pkt_len < sizeof(*mpa))
1073 return;
1074 mpa = (struct mpa_message *) ep->mpa_pkt;
1075
1076 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301077 if (mpa->revision > mpa_rev) {
1078 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1079 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080 err = -EPROTO;
1081 goto err;
1082 }
1083 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1084 err = -EPROTO;
1085 goto err;
1086 }
1087
1088 plen = ntohs(mpa->private_data_size);
1089
1090 /*
1091 * Fail if there's too much private data.
1092 */
1093 if (plen > MPA_MAX_PRIVATE_DATA) {
1094 err = -EPROTO;
1095 goto err;
1096 }
1097
1098 /*
1099 * If plen does not account for pkt size
1100 */
1101 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1102 err = -EPROTO;
1103 goto err;
1104 }
1105
1106 ep->plen = (u8) plen;
1107
1108 /*
1109 * If we don't have all the pdata yet, then bail.
1110 * We'll continue process when more data arrives.
1111 */
1112 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1113 return;
1114
1115 if (mpa->flags & MPA_REJECT) {
1116 err = -ECONNREFUSED;
1117 goto err;
1118 }
1119
1120 /*
1121 * If we get here we have accumulated the entire mpa
1122 * start reply message including private data. And
1123 * the MPA header is valid.
1124 */
1125 state_set(&ep->com, FPDU_MODE);
1126 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1127 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1128 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301129 ep->mpa_attr.version = mpa->revision;
1130 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1131
1132 if (mpa->revision == 2) {
1133 ep->mpa_attr.enhanced_rdma_conn =
1134 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1135 if (ep->mpa_attr.enhanced_rdma_conn) {
1136 mpa_v2_params = (struct mpa_v2_conn_params *)
1137 (ep->mpa_pkt + sizeof(*mpa));
1138 resp_ird = ntohs(mpa_v2_params->ird) &
1139 MPA_V2_IRD_ORD_MASK;
1140 resp_ord = ntohs(mpa_v2_params->ord) &
1141 MPA_V2_IRD_ORD_MASK;
1142
1143 /*
1144 * This is a double-check. Ideally, below checks are
1145 * not required since ird/ord stuff has been taken
1146 * care of in c4iw_accept_cr
1147 */
1148 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1149 err = -ENOMEM;
1150 ep->ird = resp_ord;
1151 ep->ord = resp_ird;
1152 insuff_ird = 1;
1153 }
1154
1155 if (ntohs(mpa_v2_params->ird) &
1156 MPA_V2_PEER2PEER_MODEL) {
1157 if (ntohs(mpa_v2_params->ord) &
1158 MPA_V2_RDMA_WRITE_RTR)
1159 ep->mpa_attr.p2p_type =
1160 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1161 else if (ntohs(mpa_v2_params->ord) &
1162 MPA_V2_RDMA_READ_RTR)
1163 ep->mpa_attr.p2p_type =
1164 FW_RI_INIT_P2PTYPE_READ_REQ;
1165 }
1166 }
1167 } else if (mpa->revision == 1)
1168 if (peer2peer)
1169 ep->mpa_attr.p2p_type = p2p_type;
1170
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301172 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1173 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1174 ep->mpa_attr.recv_marker_enabled,
1175 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1176 ep->mpa_attr.p2p_type, p2p_type);
1177
1178 /*
1179 * If responder's RTR does not match with that of initiator, assign
1180 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1181 * generated when moving QP to RTS state.
1182 * A TERM message will be sent after QP has moved to RTS state
1183 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001184 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301185 (ep->mpa_attr.p2p_type != p2p_type)) {
1186 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1187 rtr_mismatch = 1;
1188 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001189
1190 attrs.mpa_attr = ep->mpa_attr;
1191 attrs.max_ird = ep->ird;
1192 attrs.max_ord = ep->ord;
1193 attrs.llp_stream_handle = ep;
1194 attrs.next_state = C4IW_QP_STATE_RTS;
1195
1196 mask = C4IW_QP_ATTR_NEXT_STATE |
1197 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1198 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1199
1200 /* bind QP and TID with INIT_WR */
1201 err = c4iw_modify_qp(ep->com.qp->rhp,
1202 ep->com.qp, mask, &attrs, 1);
1203 if (err)
1204 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301205
1206 /*
1207 * If responder's RTR requirement did not match with what initiator
1208 * supports, generate TERM message
1209 */
1210 if (rtr_mismatch) {
1211 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1212 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1213 attrs.ecode = MPA_NOMATCH_RTR;
1214 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1215 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1216 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1217 err = -ENOMEM;
1218 goto out;
1219 }
1220
1221 /*
1222 * Generate TERM if initiator IRD is not sufficient for responder
1223 * provided ORD. Currently, we do the same behaviour even when
1224 * responder provided IRD is also not sufficient as regards to
1225 * initiator ORD.
1226 */
1227 if (insuff_ird) {
1228 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1229 __func__);
1230 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1231 attrs.ecode = MPA_INSUFF_IRD;
1232 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1233 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1234 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1235 err = -ENOMEM;
1236 goto out;
1237 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001238 goto out;
1239err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001240 state_set(&ep->com, ABORTING);
1241 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001242out:
1243 connect_reply_upcall(ep, err);
1244 return;
1245}
1246
1247static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1248{
1249 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301250 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251 u16 plen;
1252
1253 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1254
1255 if (state_read(&ep->com) != MPA_REQ_WAIT)
1256 return;
1257
1258 /*
1259 * If we get more than the supported amount of private data
1260 * then we must fail this connection.
1261 */
1262 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1263 stop_ep_timer(ep);
1264 abort_connection(ep, skb, GFP_KERNEL);
1265 return;
1266 }
1267
1268 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1269
1270 /*
1271 * Copy the new data into our accumulation buffer.
1272 */
1273 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1274 skb->len);
1275 ep->mpa_pkt_len += skb->len;
1276
1277 /*
1278 * If we don't even have the mpa message, then bail.
1279 * We'll continue process when more data arrives.
1280 */
1281 if (ep->mpa_pkt_len < sizeof(*mpa))
1282 return;
1283
1284 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1285 stop_ep_timer(ep);
1286 mpa = (struct mpa_message *) ep->mpa_pkt;
1287
1288 /*
1289 * Validate MPA Header.
1290 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301291 if (mpa->revision > mpa_rev) {
1292 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1293 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001294 abort_connection(ep, skb, GFP_KERNEL);
1295 return;
1296 }
1297
1298 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1299 abort_connection(ep, skb, GFP_KERNEL);
1300 return;
1301 }
1302
1303 plen = ntohs(mpa->private_data_size);
1304
1305 /*
1306 * Fail if there's too much private data.
1307 */
1308 if (plen > MPA_MAX_PRIVATE_DATA) {
1309 abort_connection(ep, skb, GFP_KERNEL);
1310 return;
1311 }
1312
1313 /*
1314 * If plen does not account for pkt size
1315 */
1316 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1317 abort_connection(ep, skb, GFP_KERNEL);
1318 return;
1319 }
1320 ep->plen = (u8) plen;
1321
1322 /*
1323 * If we don't have all the pdata yet, then bail.
1324 */
1325 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1326 return;
1327
1328 /*
1329 * If we get here we have accumulated the entire mpa
1330 * start reply message including private data.
1331 */
1332 ep->mpa_attr.initiator = 0;
1333 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1334 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1335 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301336 ep->mpa_attr.version = mpa->revision;
1337 if (mpa->revision == 1)
1338 ep->tried_with_mpa_v1 = 1;
1339 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1340
1341 if (mpa->revision == 2) {
1342 ep->mpa_attr.enhanced_rdma_conn =
1343 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1344 if (ep->mpa_attr.enhanced_rdma_conn) {
1345 mpa_v2_params = (struct mpa_v2_conn_params *)
1346 (ep->mpa_pkt + sizeof(*mpa));
1347 ep->ird = ntohs(mpa_v2_params->ird) &
1348 MPA_V2_IRD_ORD_MASK;
1349 ep->ord = ntohs(mpa_v2_params->ord) &
1350 MPA_V2_IRD_ORD_MASK;
1351 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1352 if (peer2peer) {
1353 if (ntohs(mpa_v2_params->ord) &
1354 MPA_V2_RDMA_WRITE_RTR)
1355 ep->mpa_attr.p2p_type =
1356 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1357 else if (ntohs(mpa_v2_params->ord) &
1358 MPA_V2_RDMA_READ_RTR)
1359 ep->mpa_attr.p2p_type =
1360 FW_RI_INIT_P2PTYPE_READ_REQ;
1361 }
1362 }
1363 } else if (mpa->revision == 1)
1364 if (peer2peer)
1365 ep->mpa_attr.p2p_type = p2p_type;
1366
Steve Wisecfdda9d2010-04-21 15:30:06 -07001367 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1368 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1369 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1370 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1371 ep->mpa_attr.p2p_type);
1372
1373 state_set(&ep->com, MPA_REQ_RCVD);
1374
1375 /* drive upcall */
1376 connect_request_upcall(ep);
1377 return;
1378}
1379
1380static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1381{
1382 struct c4iw_ep *ep;
1383 struct cpl_rx_data *hdr = cplhdr(skb);
1384 unsigned int dlen = ntohs(hdr->len);
1385 unsigned int tid = GET_TID(hdr);
1386 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001387 __u8 status = hdr->status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001388
1389 ep = lookup_tid(t, tid);
1390 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1391 skb_pull(skb, sizeof(*hdr));
1392 skb_trim(skb, dlen);
1393
Steve Wisecfdda9d2010-04-21 15:30:06 -07001394 /* update RX credits */
1395 update_rx_credits(ep, dlen);
1396
1397 switch (state_read(&ep->com)) {
1398 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001399 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001400 process_mpa_reply(ep, skb);
1401 break;
1402 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001403 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 process_mpa_request(ep, skb);
1405 break;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001406 default:
Vipul Pandya793dad92012-12-10 09:30:56 +00001407 pr_err("%s Unexpected streaming data." \
1408 " ep %p state %d tid %u status %d\n",
1409 __func__, ep, state_read(&ep->com), ep->hwtid, status);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001410
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001411 if (ep->com.qp) {
1412 struct c4iw_qp_attributes attrs;
1413
1414 attrs.next_state = C4IW_QP_STATE_ERROR;
1415 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1416 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1417 }
1418 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001419 break;
1420 }
1421 return 0;
1422}
1423
1424static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1425{
1426 struct c4iw_ep *ep;
1427 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001428 int release = 0;
1429 unsigned int tid = GET_TID(rpl);
1430 struct tid_info *t = dev->rdev.lldi.tids;
1431
1432 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301433 if (!ep) {
1434 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1435 return 0;
1436 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001437 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001438 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439 switch (ep->com.state) {
1440 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001441 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001442 __state_set(&ep->com, DEAD);
1443 release = 1;
1444 break;
1445 default:
1446 printk(KERN_ERR "%s ep %p state %d\n",
1447 __func__, ep, ep->com.state);
1448 break;
1449 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001450 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001451
1452 if (release)
1453 release_ep_resources(ep);
1454 return 0;
1455}
1456
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001457static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1458{
1459 struct sk_buff *skb;
1460 struct fw_ofld_connection_wr *req;
1461 unsigned int mtu_idx;
1462 int wscale;
1463
1464 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1465 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1466 memset(req, 0, sizeof(*req));
1467 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1468 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1469 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1470 ep->l2t));
1471 req->le.lport = ep->com.local_addr.sin_port;
1472 req->le.pport = ep->com.remote_addr.sin_port;
1473 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1474 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1475 req->tcb.t_state_to_astid =
1476 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1477 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1478 req->tcb.cplrxdataack_cplpassacceptrpl =
1479 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1480 req->tcb.tx_max = jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001481 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001482 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1483 wscale = compute_wscale(rcv_win);
1484 req->tcb.opt0 = TCAM_BYPASS(1) |
1485 (nocong ? NO_CONG(1) : 0) |
1486 KEEP_ALIVE(1) |
1487 DELACK(1) |
1488 WND_SCALE(wscale) |
1489 MSS_IDX(mtu_idx) |
1490 L2T_IDX(ep->l2t->idx) |
1491 TX_CHAN(ep->tx_chan) |
1492 SMAC_SEL(ep->smac_idx) |
1493 DSCP(ep->tos) |
1494 ULP_MODE(ULP_MODE_TCPDDP) |
1495 RCV_BUFSIZ(rcv_win >> 10);
1496 req->tcb.opt2 = PACE(1) |
1497 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1498 RX_CHANNEL(0) |
1499 CCTRL_ECN(enable_ecn) |
1500 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1501 if (enable_tcp_timestamps)
1502 req->tcb.opt2 |= TSTAMPS_EN(1);
1503 if (enable_tcp_sack)
1504 req->tcb.opt2 |= SACK_EN(1);
1505 if (wscale && enable_tcp_window_scaling)
1506 req->tcb.opt2 |= WND_SCALE_EN(1);
1507 req->tcb.opt0 = cpu_to_be64(req->tcb.opt0);
1508 req->tcb.opt2 = cpu_to_be32(req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001509 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1510 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001511 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1512}
1513
Steve Wisecfdda9d2010-04-21 15:30:06 -07001514/*
1515 * Return whether a failed active open has allocated a TID
1516 */
1517static inline int act_open_has_tid(int status)
1518{
1519 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1520 status != CPL_ERR_ARP_MISS;
1521}
1522
Vipul Pandya793dad92012-12-10 09:30:56 +00001523#define ACT_OPEN_RETRY_COUNT 2
1524
1525static int c4iw_reconnect(struct c4iw_ep *ep)
1526{
1527 int err = 0;
1528 struct rtable *rt;
1529 struct port_info *pi;
1530 struct net_device *pdev;
1531 int step;
1532 struct neighbour *neigh;
1533
1534 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1535 init_timer(&ep->timer);
1536
1537 /*
1538 * Allocate an active TID to initiate a TCP connection.
1539 */
1540 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1541 if (ep->atid == -1) {
1542 pr_err("%s - cannot alloc atid.\n", __func__);
1543 err = -ENOMEM;
1544 goto fail2;
1545 }
1546 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1547
1548 /* find a route */
1549 rt = find_route(ep->com.dev,
1550 ep->com.cm_id->local_addr.sin_addr.s_addr,
1551 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1552 ep->com.cm_id->local_addr.sin_port,
1553 ep->com.cm_id->remote_addr.sin_port, 0);
1554 if (!rt) {
1555 pr_err("%s - cannot find route.\n", __func__);
1556 err = -EHOSTUNREACH;
1557 goto fail3;
1558 }
1559 ep->dst = &rt->dst;
1560
1561 neigh = dst_neigh_lookup(ep->dst,
1562 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1563 /* get a l2t entry */
1564 if (neigh->dev->flags & IFF_LOOPBACK) {
1565 PDBG("%s LOOPBACK\n", __func__);
1566 pdev = ip_dev_find(&init_net,
1567 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1568 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1569 neigh, pdev, 0);
1570 pi = (struct port_info *)netdev_priv(pdev);
1571 ep->mtu = pdev->mtu;
1572 ep->tx_chan = cxgb4_port_chan(pdev);
1573 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1574 dev_put(pdev);
1575 } else {
1576 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1577 neigh, neigh->dev, 0);
1578 pi = (struct port_info *)netdev_priv(neigh->dev);
1579 ep->mtu = dst_mtu(ep->dst);
1580 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1581 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1582 0x7F) << 1;
1583 }
1584
1585 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1586 ep->txq_idx = pi->port_id * step;
1587 ep->ctrlq_idx = pi->port_id;
1588 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1589 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1590
1591 if (!ep->l2t) {
1592 pr_err("%s - cannot alloc l2e.\n", __func__);
1593 err = -ENOMEM;
1594 goto fail4;
1595 }
1596
1597 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1598 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1599 ep->l2t->idx);
1600
1601 state_set(&ep->com, CONNECTING);
1602 ep->tos = 0;
1603
1604 /* send connect request to rnic */
1605 err = send_connect(ep);
1606 if (!err)
1607 goto out;
1608
1609 cxgb4_l2t_release(ep->l2t);
1610fail4:
1611 dst_release(ep->dst);
1612fail3:
1613 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1614 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1615fail2:
1616 /*
1617 * remember to send notification to upper layer.
1618 * We are in here so the upper layer is not aware that this is
1619 * re-connect attempt and so, upper layer is still waiting for
1620 * response of 1st connect request.
1621 */
1622 connect_reply_upcall(ep, -ECONNRESET);
1623 c4iw_put_ep(&ep->com);
1624out:
1625 return err;
1626}
1627
Steve Wisecfdda9d2010-04-21 15:30:06 -07001628static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1629{
1630 struct c4iw_ep *ep;
1631 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1632 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1633 ntohl(rpl->atid_status)));
1634 struct tid_info *t = dev->rdev.lldi.tids;
1635 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1636
1637 ep = lookup_atid(t, atid);
1638
1639 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1640 status, status2errno(status));
1641
1642 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1643 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1644 atid);
1645 return 0;
1646 }
1647
Vipul Pandya793dad92012-12-10 09:30:56 +00001648 set_bit(ACT_OPEN_RPL, &ep->com.history);
1649
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301650 /*
1651 * Log interesting failures.
1652 */
1653 switch (status) {
1654 case CPL_ERR_CONN_RESET:
1655 case CPL_ERR_CONN_TIMEDOUT:
1656 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001657 case CPL_ERR_TCAM_FULL:
Vipul Pandya793dad92012-12-10 09:30:56 +00001658 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1659 mutex_lock(&dev->rdev.stats.lock);
1660 dev->rdev.stats.tcam_full++;
1661 mutex_unlock(&dev->rdev.stats.lock);
1662 send_fw_act_open_req(ep,
1663 GET_TID_TID(GET_AOPEN_ATID(
1664 ntohl(rpl->atid_status))));
1665 return 0;
1666 }
1667 break;
1668 case CPL_ERR_CONN_EXIST:
1669 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1670 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1671 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1672 atid);
1673 cxgb4_free_atid(t, atid);
1674 dst_release(ep->dst);
1675 cxgb4_l2t_release(ep->l2t);
1676 c4iw_reconnect(ep);
1677 return 0;
1678 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001679 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301680 default:
1681 printk(KERN_INFO MOD "Active open failure - "
1682 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1683 atid, status, status2errno(status),
1684 &ep->com.local_addr.sin_addr.s_addr,
1685 ntohs(ep->com.local_addr.sin_port),
1686 &ep->com.remote_addr.sin_addr.s_addr,
1687 ntohs(ep->com.remote_addr.sin_port));
1688 break;
1689 }
1690
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691 connect_reply_upcall(ep, status2errno(status));
1692 state_set(&ep->com, DEAD);
1693
1694 if (status && act_open_has_tid(status))
1695 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1696
Vipul Pandya793dad92012-12-10 09:30:56 +00001697 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001698 cxgb4_free_atid(t, atid);
1699 dst_release(ep->dst);
1700 cxgb4_l2t_release(ep->l2t);
1701 c4iw_put_ep(&ep->com);
1702
1703 return 0;
1704}
1705
1706static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1707{
1708 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1709 struct tid_info *t = dev->rdev.lldi.tids;
1710 unsigned int stid = GET_TID(rpl);
1711 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1712
1713 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001714 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1715 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716 }
1717 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1718 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001719 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001720
Vipul Pandya1cab7752012-12-10 09:30:55 +00001721out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001722 return 0;
1723}
1724
1725static int listen_stop(struct c4iw_listen_ep *ep)
1726{
1727 struct sk_buff *skb;
1728 struct cpl_close_listsvr_req *req;
1729
1730 PDBG("%s ep %p\n", __func__, ep);
1731 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1732 if (!skb) {
1733 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1734 return -ENOMEM;
1735 }
1736 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1737 INIT_TP_WR(req, 0);
1738 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1739 ep->stid));
1740 req->reply_ctrl = cpu_to_be16(
1741 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1742 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1743 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1744}
1745
1746static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1747{
1748 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1749 struct tid_info *t = dev->rdev.lldi.tids;
1750 unsigned int stid = GET_TID(rpl);
1751 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1752
1753 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001754 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001755 return 0;
1756}
1757
1758static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1759 struct cpl_pass_accept_req *req)
1760{
1761 struct cpl_pass_accept_rpl *rpl;
1762 unsigned int mtu_idx;
1763 u64 opt0;
1764 u32 opt2;
1765 int wscale;
1766
1767 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1768 BUG_ON(skb_cloned(skb));
1769 skb_trim(skb, sizeof(*rpl));
1770 skb_get(skb);
1771 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1772 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001773 opt0 = (nocong ? NO_CONG(1) : 0) |
1774 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001775 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776 WND_SCALE(wscale) |
1777 MSS_IDX(mtu_idx) |
1778 L2T_IDX(ep->l2t->idx) |
1779 TX_CHAN(ep->tx_chan) |
1780 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001781 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001782 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001783 RCV_BUFSIZ(rcv_win>>10);
1784 opt2 = RX_CHANNEL(0) |
1785 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1786
1787 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1788 opt2 |= TSTAMPS_EN(1);
1789 if (enable_tcp_sack && req->tcpopt.sack)
1790 opt2 |= SACK_EN(1);
1791 if (wscale && enable_tcp_window_scaling)
1792 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001793 if (enable_ecn) {
1794 const struct tcphdr *tcph;
1795 u32 hlen = ntohl(req->hdr_len);
1796
1797 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1798 G_IP_HDR_LEN(hlen);
1799 if (tcph->ece && tcph->cwr)
1800 opt2 |= CCTRL_ECN(1);
1801 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802
1803 rpl = cplhdr(skb);
1804 INIT_TP_WR(rpl, ep->hwtid);
1805 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1806 ep->hwtid));
1807 rpl->opt0 = cpu_to_be64(opt0);
1808 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001809 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001810 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1811
1812 return;
1813}
1814
1815static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1816 struct sk_buff *skb)
1817{
1818 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1819 peer_ip);
1820 BUG_ON(skb_cloned(skb));
1821 skb_trim(skb, sizeof(struct cpl_tid_release));
1822 skb_get(skb);
1823 release_tid(&dev->rdev, hwtid, skb);
1824 return;
1825}
1826
1827static void get_4tuple(struct cpl_pass_accept_req *req,
1828 __be32 *local_ip, __be32 *peer_ip,
1829 __be16 *local_port, __be16 *peer_port)
1830{
1831 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1832 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1833 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1834 struct tcphdr *tcp = (struct tcphdr *)
1835 ((u8 *)(req + 1) + eth_len + ip_len);
1836
1837 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1838 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1839 ntohs(tcp->dest));
1840
1841 *peer_ip = ip->saddr;
1842 *local_ip = ip->daddr;
1843 *peer_port = tcp->source;
1844 *local_port = tcp->dest;
1845
1846 return;
1847}
1848
David Miller3786cf12011-12-02 16:52:31 +00001849static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1850 struct c4iw_dev *cdev, bool clear_mpa_v1)
1851{
1852 struct neighbour *n;
1853 int err, step;
1854
David Miller64b70072012-01-24 13:15:57 +00001855 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001856 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001857 return -ENODEV;
1858
1859 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001860 err = -ENOMEM;
1861 if (n->dev->flags & IFF_LOOPBACK) {
1862 struct net_device *pdev;
1863
1864 pdev = ip_dev_find(&init_net, peer_ip);
Thadeu Lima de Souza Cascardo71b43fd2012-05-17 17:51:53 -03001865 if (!pdev) {
1866 err = -ENODEV;
1867 goto out;
1868 }
David Miller3786cf12011-12-02 16:52:31 +00001869 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1870 n, pdev, 0);
1871 if (!ep->l2t)
1872 goto out;
1873 ep->mtu = pdev->mtu;
1874 ep->tx_chan = cxgb4_port_chan(pdev);
1875 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1876 step = cdev->rdev.lldi.ntxq /
1877 cdev->rdev.lldi.nchan;
1878 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1879 step = cdev->rdev.lldi.nrxq /
1880 cdev->rdev.lldi.nchan;
1881 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1882 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1883 cxgb4_port_idx(pdev) * step];
1884 dev_put(pdev);
1885 } else {
1886 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1887 n, n->dev, 0);
1888 if (!ep->l2t)
1889 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001890 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001891 ep->tx_chan = cxgb4_port_chan(n->dev);
1892 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1893 step = cdev->rdev.lldi.ntxq /
1894 cdev->rdev.lldi.nchan;
1895 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1896 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1897 step = cdev->rdev.lldi.nrxq /
1898 cdev->rdev.lldi.nchan;
1899 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1900 cxgb4_port_idx(n->dev) * step];
1901
1902 if (clear_mpa_v1) {
1903 ep->retry_with_mpa_v1 = 0;
1904 ep->tried_with_mpa_v1 = 0;
1905 }
1906 }
1907 err = 0;
1908out:
1909 rcu_read_unlock();
1910
David Miller64b70072012-01-24 13:15:57 +00001911 neigh_release(n);
1912
David Miller3786cf12011-12-02 16:52:31 +00001913 return err;
1914}
1915
Steve Wisecfdda9d2010-04-21 15:30:06 -07001916static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1917{
Vipul Pandya793dad92012-12-10 09:30:56 +00001918 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001919 struct cpl_pass_accept_req *req = cplhdr(skb);
1920 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1921 struct tid_info *t = dev->rdev.lldi.tids;
1922 unsigned int hwtid = GET_TID(req);
1923 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001924 struct rtable *rt;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001925 __be32 local_ip, peer_ip = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001926 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001927 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001928 u16 peer_mss = ntohs(req->tcpopt.mss);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001929
1930 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00001931 if (!parent_ep) {
1932 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1933 goto reject;
1934 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001935 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1936
Vipul Pandya1cab7752012-12-10 09:30:55 +00001937 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1938 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1939 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1940 ntohs(peer_port), peer_mss);
1941
Steve Wisecfdda9d2010-04-21 15:30:06 -07001942 if (state_read(&parent_ep->com) != LISTEN) {
1943 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1944 __func__);
1945 goto reject;
1946 }
1947
1948 /* Find output route */
1949 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1950 GET_POPEN_TOS(ntohl(req->tos_stid)));
1951 if (!rt) {
1952 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1953 __func__);
1954 goto reject;
1955 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001956 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001957
1958 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1959 if (!child_ep) {
1960 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1961 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962 dst_release(dst);
1963 goto reject;
1964 }
David Miller3786cf12011-12-02 16:52:31 +00001965
1966 err = import_ep(child_ep, peer_ip, dst, dev, false);
1967 if (err) {
1968 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1969 __func__);
1970 dst_release(dst);
1971 kfree(child_ep);
1972 goto reject;
1973 }
1974
Vipul Pandya1cab7752012-12-10 09:30:55 +00001975 if (peer_mss && child_ep->mtu > (peer_mss + 40))
1976 child_ep->mtu = peer_mss + 40;
1977
Steve Wisecfdda9d2010-04-21 15:30:06 -07001978 state_set(&child_ep->com, CONNECTING);
1979 child_ep->com.dev = dev;
1980 child_ep->com.cm_id = NULL;
1981 child_ep->com.local_addr.sin_family = PF_INET;
1982 child_ep->com.local_addr.sin_port = local_port;
1983 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1984 child_ep->com.remote_addr.sin_family = PF_INET;
1985 child_ep->com.remote_addr.sin_port = peer_port;
1986 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1987 c4iw_get_ep(&parent_ep->com);
1988 child_ep->parent_ep = parent_ep;
1989 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001990 child_ep->dst = dst;
1991 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001992
1993 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00001994 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001995
1996 init_timer(&child_ep->timer);
1997 cxgb4_insert_tid(t, child_ep, hwtid);
1998 accept_cr(child_ep, peer_ip, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00001999 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002000 goto out;
2001reject:
2002 reject_cr(dev, hwtid, peer_ip, skb);
2003out:
2004 return 0;
2005}
2006
2007static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2008{
2009 struct c4iw_ep *ep;
2010 struct cpl_pass_establish *req = cplhdr(skb);
2011 struct tid_info *t = dev->rdev.lldi.tids;
2012 unsigned int tid = GET_TID(req);
2013
2014 ep = lookup_tid(t, tid);
2015 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2016 ep->snd_seq = be32_to_cpu(req->snd_isn);
2017 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2018
Vipul Pandya1cab7752012-12-10 09:30:55 +00002019 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2020 ntohs(req->tcp_opt));
2021
Steve Wisecfdda9d2010-04-21 15:30:06 -07002022 set_emss(ep, ntohs(req->tcp_opt));
Vipul Pandya793dad92012-12-10 09:30:56 +00002023 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002024
2025 dst_confirm(ep->dst);
2026 state_set(&ep->com, MPA_REQ_WAIT);
2027 start_ep_timer(ep);
2028 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002029 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002030
2031 return 0;
2032}
2033
2034static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2035{
2036 struct cpl_peer_close *hdr = cplhdr(skb);
2037 struct c4iw_ep *ep;
2038 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002039 int disconnect = 1;
2040 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002041 struct tid_info *t = dev->rdev.lldi.tids;
2042 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002043 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002044
2045 ep = lookup_tid(t, tid);
2046 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2047 dst_confirm(ep->dst);
2048
Vipul Pandya793dad92012-12-10 09:30:56 +00002049 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002050 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002051 switch (ep->com.state) {
2052 case MPA_REQ_WAIT:
2053 __state_set(&ep->com, CLOSING);
2054 break;
2055 case MPA_REQ_SENT:
2056 __state_set(&ep->com, CLOSING);
2057 connect_reply_upcall(ep, -ECONNRESET);
2058 break;
2059 case MPA_REQ_RCVD:
2060
2061 /*
2062 * We're gonna mark this puppy DEAD, but keep
2063 * the reference on it until the ULP accepts or
2064 * rejects the CR. Also wake up anyone waiting
2065 * in rdma connection migration (see c4iw_accept_cr()).
2066 */
2067 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002068 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002069 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002070 break;
2071 case MPA_REP_SENT:
2072 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002073 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002074 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002075 break;
2076 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002077 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002078 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002079 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002080 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002081 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002082 if (ret != -ECONNRESET) {
2083 peer_close_upcall(ep);
2084 disconnect = 1;
2085 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086 break;
2087 case ABORTING:
2088 disconnect = 0;
2089 break;
2090 case CLOSING:
2091 __state_set(&ep->com, MORIBUND);
2092 disconnect = 0;
2093 break;
2094 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002095 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002096 if (ep->com.cm_id && ep->com.qp) {
2097 attrs.next_state = C4IW_QP_STATE_IDLE;
2098 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2099 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2100 }
2101 close_complete_upcall(ep);
2102 __state_set(&ep->com, DEAD);
2103 release = 1;
2104 disconnect = 0;
2105 break;
2106 case DEAD:
2107 disconnect = 0;
2108 break;
2109 default:
2110 BUG_ON(1);
2111 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002112 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002113 if (disconnect)
2114 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2115 if (release)
2116 release_ep_resources(ep);
2117 return 0;
2118}
2119
2120/*
2121 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2122 */
2123static int is_neg_adv_abort(unsigned int status)
2124{
2125 return status == CPL_ERR_RTX_NEG_ADVICE ||
2126 status == CPL_ERR_PERSIST_NEG_ADVICE;
2127}
2128
2129static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2130{
2131 struct cpl_abort_req_rss *req = cplhdr(skb);
2132 struct c4iw_ep *ep;
2133 struct cpl_abort_rpl *rpl;
2134 struct sk_buff *rpl_skb;
2135 struct c4iw_qp_attributes attrs;
2136 int ret;
2137 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002138 struct tid_info *t = dev->rdev.lldi.tids;
2139 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002140
2141 ep = lookup_tid(t, tid);
2142 if (is_neg_adv_abort(req->status)) {
2143 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2144 ep->hwtid);
2145 return 0;
2146 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002147 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2148 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002149 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002150
2151 /*
2152 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302153 * However, this is not needed if com state is just
2154 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002155 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302156 if (ep->com.state != MPA_REQ_SENT)
2157 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002158
2159 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002160 switch (ep->com.state) {
2161 case CONNECTING:
2162 break;
2163 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002164 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002165 break;
2166 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002167 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302168 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
2169 connect_reply_upcall(ep, -ECONNRESET);
2170 else {
2171 /*
2172 * we just don't send notification upwards because we
2173 * want to retry with mpa_v1 without upper layers even
2174 * knowing it.
2175 *
2176 * do some housekeeping so as to re-initiate the
2177 * connection
2178 */
2179 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2180 mpa_rev);
2181 ep->retry_with_mpa_v1 = 1;
2182 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002183 break;
2184 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002185 break;
2186 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002187 break;
2188 case MORIBUND:
2189 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002190 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191 /*FALLTHROUGH*/
2192 case FPDU_MODE:
2193 if (ep->com.cm_id && ep->com.qp) {
2194 attrs.next_state = C4IW_QP_STATE_ERROR;
2195 ret = c4iw_modify_qp(ep->com.qp->rhp,
2196 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2197 &attrs, 1);
2198 if (ret)
2199 printk(KERN_ERR MOD
2200 "%s - qp <- error failed!\n",
2201 __func__);
2202 }
2203 peer_abort_upcall(ep);
2204 break;
2205 case ABORTING:
2206 break;
2207 case DEAD:
2208 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002209 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002210 return 0;
2211 default:
2212 BUG_ON(1);
2213 break;
2214 }
2215 dst_confirm(ep->dst);
2216 if (ep->com.state != ABORTING) {
2217 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302218 /* we don't release if we want to retry with mpa_v1 */
2219 if (!ep->retry_with_mpa_v1)
2220 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002221 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002222 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002223
2224 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2225 if (!rpl_skb) {
2226 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2227 __func__);
2228 release = 1;
2229 goto out;
2230 }
2231 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2232 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2233 INIT_TP_WR(rpl, ep->hwtid);
2234 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2235 rpl->cmd = CPL_ABORT_NO_RST;
2236 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2237out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238 if (release)
2239 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302240
2241 /* retry with mpa-v1 */
2242 if (ep && ep->retry_with_mpa_v1) {
2243 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2244 dst_release(ep->dst);
2245 cxgb4_l2t_release(ep->l2t);
2246 c4iw_reconnect(ep);
2247 }
2248
Steve Wisecfdda9d2010-04-21 15:30:06 -07002249 return 0;
2250}
2251
2252static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2253{
2254 struct c4iw_ep *ep;
2255 struct c4iw_qp_attributes attrs;
2256 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257 int release = 0;
2258 struct tid_info *t = dev->rdev.lldi.tids;
2259 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002260
2261 ep = lookup_tid(t, tid);
2262
2263 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2264 BUG_ON(!ep);
2265
2266 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002267 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002268 switch (ep->com.state) {
2269 case CLOSING:
2270 __state_set(&ep->com, MORIBUND);
2271 break;
2272 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002273 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002274 if ((ep->com.cm_id) && (ep->com.qp)) {
2275 attrs.next_state = C4IW_QP_STATE_IDLE;
2276 c4iw_modify_qp(ep->com.qp->rhp,
2277 ep->com.qp,
2278 C4IW_QP_ATTR_NEXT_STATE,
2279 &attrs, 1);
2280 }
2281 close_complete_upcall(ep);
2282 __state_set(&ep->com, DEAD);
2283 release = 1;
2284 break;
2285 case ABORTING:
2286 case DEAD:
2287 break;
2288 default:
2289 BUG_ON(1);
2290 break;
2291 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002292 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293 if (release)
2294 release_ep_resources(ep);
2295 return 0;
2296}
2297
2298static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2299{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002300 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002301 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002302 unsigned int tid = GET_TID(rpl);
2303 struct c4iw_ep *ep;
2304 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002305
2306 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002307 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308
Steve Wise30c95c22011-05-09 22:06:22 -07002309 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002310 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2311 ep->com.qp->wq.sq.qid);
2312 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2313 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2314 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2315 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002316 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318 return 0;
2319}
2320
2321/*
2322 * Upcall from the adapter indicating data has been transmitted.
2323 * For us its just the single MPA request or reply. We can now free
2324 * the skb holding the mpa message.
2325 */
2326static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2327{
2328 struct c4iw_ep *ep;
2329 struct cpl_fw4_ack *hdr = cplhdr(skb);
2330 u8 credits = hdr->credits;
2331 unsigned int tid = GET_TID(hdr);
2332 struct tid_info *t = dev->rdev.lldi.tids;
2333
2334
2335 ep = lookup_tid(t, tid);
2336 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2337 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002338 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2339 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340 return 0;
2341 }
2342
2343 dst_confirm(ep->dst);
2344 if (ep->mpa_skb) {
2345 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2346 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2347 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2348 kfree_skb(ep->mpa_skb);
2349 ep->mpa_skb = NULL;
2350 }
2351 return 0;
2352}
2353
Steve Wisecfdda9d2010-04-21 15:30:06 -07002354int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2355{
2356 int err;
2357 struct c4iw_ep *ep = to_ep(cm_id);
2358 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2359
2360 if (state_read(&ep->com) == DEAD) {
2361 c4iw_put_ep(&ep->com);
2362 return -ECONNRESET;
2363 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002364 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002365 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2366 if (mpa_rev == 0)
2367 abort_connection(ep, NULL, GFP_KERNEL);
2368 else {
2369 err = send_mpa_reject(ep, pdata, pdata_len);
2370 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2371 }
2372 c4iw_put_ep(&ep->com);
2373 return 0;
2374}
2375
2376int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2377{
2378 int err;
2379 struct c4iw_qp_attributes attrs;
2380 enum c4iw_qp_attr_mask mask;
2381 struct c4iw_ep *ep = to_ep(cm_id);
2382 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2383 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2384
2385 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2386 if (state_read(&ep->com) == DEAD) {
2387 err = -ECONNRESET;
2388 goto err;
2389 }
2390
2391 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2392 BUG_ON(!qp);
2393
Vipul Pandya793dad92012-12-10 09:30:56 +00002394 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002395 if ((conn_param->ord > c4iw_max_read_depth) ||
2396 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002397 abort_connection(ep, NULL, GFP_KERNEL);
2398 err = -EINVAL;
2399 goto err;
2400 }
2401
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302402 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2403 if (conn_param->ord > ep->ird) {
2404 ep->ird = conn_param->ird;
2405 ep->ord = conn_param->ord;
2406 send_mpa_reject(ep, conn_param->private_data,
2407 conn_param->private_data_len);
2408 abort_connection(ep, NULL, GFP_KERNEL);
2409 err = -ENOMEM;
2410 goto err;
2411 }
2412 if (conn_param->ird > ep->ord) {
2413 if (!ep->ord)
2414 conn_param->ird = 1;
2415 else {
2416 abort_connection(ep, NULL, GFP_KERNEL);
2417 err = -ENOMEM;
2418 goto err;
2419 }
2420 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302422 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423 ep->ird = conn_param->ird;
2424 ep->ord = conn_param->ord;
2425
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302426 if (ep->mpa_attr.version != 2)
2427 if (peer2peer && ep->ird == 0)
2428 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429
2430 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2431
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302432 cm_id->add_ref(cm_id);
2433 ep->com.cm_id = cm_id;
2434 ep->com.qp = qp;
2435
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 /* bind QP to EP and move to RTS */
2437 attrs.mpa_attr = ep->mpa_attr;
2438 attrs.max_ird = ep->ird;
2439 attrs.max_ord = ep->ord;
2440 attrs.llp_stream_handle = ep;
2441 attrs.next_state = C4IW_QP_STATE_RTS;
2442
2443 /* bind QP and TID with INIT_WR */
2444 mask = C4IW_QP_ATTR_NEXT_STATE |
2445 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2446 C4IW_QP_ATTR_MPA_ATTR |
2447 C4IW_QP_ATTR_MAX_IRD |
2448 C4IW_QP_ATTR_MAX_ORD;
2449
2450 err = c4iw_modify_qp(ep->com.qp->rhp,
2451 ep->com.qp, mask, &attrs, 1);
2452 if (err)
2453 goto err1;
2454 err = send_mpa_reply(ep, conn_param->private_data,
2455 conn_param->private_data_len);
2456 if (err)
2457 goto err1;
2458
2459 state_set(&ep->com, FPDU_MODE);
2460 established_upcall(ep);
2461 c4iw_put_ep(&ep->com);
2462 return 0;
2463err1:
2464 ep->com.cm_id = NULL;
2465 ep->com.qp = NULL;
2466 cm_id->rem_ref(cm_id);
2467err:
2468 c4iw_put_ep(&ep->com);
2469 return err;
2470}
2471
2472int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2473{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002474 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2475 struct c4iw_ep *ep;
2476 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002477 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002479 if ((conn_param->ord > c4iw_max_read_depth) ||
2480 (conn_param->ird > c4iw_max_read_depth)) {
2481 err = -EINVAL;
2482 goto out;
2483 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2485 if (!ep) {
2486 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2487 err = -ENOMEM;
2488 goto out;
2489 }
2490 init_timer(&ep->timer);
2491 ep->plen = conn_param->private_data_len;
2492 if (ep->plen)
2493 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2494 conn_param->private_data, ep->plen);
2495 ep->ird = conn_param->ird;
2496 ep->ord = conn_param->ord;
2497
2498 if (peer2peer && ep->ord == 0)
2499 ep->ord = 1;
2500
2501 cm_id->add_ref(cm_id);
2502 ep->com.dev = dev;
2503 ep->com.cm_id = cm_id;
2504 ep->com.qp = get_qhp(dev, conn_param->qpn);
2505 BUG_ON(!ep->com.qp);
2506 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2507 ep->com.qp, cm_id);
2508
2509 /*
2510 * Allocate an active TID to initiate a TCP connection.
2511 */
2512 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2513 if (ep->atid == -1) {
2514 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2515 err = -ENOMEM;
2516 goto fail2;
2517 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002518 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002519
2520 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2521 ntohl(cm_id->local_addr.sin_addr.s_addr),
2522 ntohs(cm_id->local_addr.sin_port),
2523 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2524 ntohs(cm_id->remote_addr.sin_port));
2525
2526 /* find a route */
2527 rt = find_route(dev,
2528 cm_id->local_addr.sin_addr.s_addr,
2529 cm_id->remote_addr.sin_addr.s_addr,
2530 cm_id->local_addr.sin_port,
2531 cm_id->remote_addr.sin_port, 0);
2532 if (!rt) {
2533 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2534 err = -EHOSTUNREACH;
2535 goto fail3;
2536 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002537 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002538
David Miller3786cf12011-12-02 16:52:31 +00002539 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2540 ep->dst, ep->com.dev, true);
2541 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002542 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002543 goto fail4;
2544 }
2545
2546 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2547 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2548 ep->l2t->idx);
2549
2550 state_set(&ep->com, CONNECTING);
2551 ep->tos = 0;
2552 ep->com.local_addr = cm_id->local_addr;
2553 ep->com.remote_addr = cm_id->remote_addr;
2554
2555 /* send connect request to rnic */
2556 err = send_connect(ep);
2557 if (!err)
2558 goto out;
2559
2560 cxgb4_l2t_release(ep->l2t);
2561fail4:
2562 dst_release(ep->dst);
2563fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002564 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2566fail2:
2567 cm_id->rem_ref(cm_id);
2568 c4iw_put_ep(&ep->com);
2569out:
2570 return err;
2571}
2572
2573int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2574{
2575 int err = 0;
2576 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2577 struct c4iw_listen_ep *ep;
2578
Steve Wisecfdda9d2010-04-21 15:30:06 -07002579 might_sleep();
2580
2581 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2582 if (!ep) {
2583 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2584 err = -ENOMEM;
2585 goto fail1;
2586 }
2587 PDBG("%s ep %p\n", __func__, ep);
2588 cm_id->add_ref(cm_id);
2589 ep->com.cm_id = cm_id;
2590 ep->com.dev = dev;
2591 ep->backlog = backlog;
2592 ep->com.local_addr = cm_id->local_addr;
2593
2594 /*
2595 * Allocate a server TID.
2596 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002597 if (dev->rdev.lldi.enable_fw_ofld_conn)
2598 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2599 else
2600 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2601
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002603 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 err = -ENOMEM;
2605 goto fail2;
2606 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002607 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608 state_set(&ep->com, LISTEN);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002609 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2610 do {
2611 err = cxgb4_create_server_filter(
2612 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2613 ep->com.local_addr.sin_addr.s_addr,
2614 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002615 0,
2616 ep->com.dev->rdev.lldi.rxq_ids[0],
2617 0,
2618 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002619 if (err == -EBUSY) {
2620 set_current_state(TASK_UNINTERRUPTIBLE);
2621 schedule_timeout(usecs_to_jiffies(100));
2622 }
2623 } while (err == -EBUSY);
2624 } else {
2625 c4iw_init_wr_wait(&ep->com.wr_wait);
2626 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2627 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2628 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002629 0,
Vipul Pandya1cab7752012-12-10 09:30:55 +00002630 ep->com.dev->rdev.lldi.rxq_ids[0]);
2631 if (!err)
2632 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2633 &ep->com.wr_wait,
2634 0, 0, __func__);
2635 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636 if (!err) {
2637 cm_id->provider_data = ep;
2638 goto out;
2639 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002640 pr_err("%s cxgb4_create_server/filter failed err %d " \
2641 "stid %d laddr %08x lport %d\n", \
2642 __func__, err, ep->stid,
2643 ntohl(ep->com.local_addr.sin_addr.s_addr),
2644 ntohs(ep->com.local_addr.sin_port));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2646fail2:
2647 cm_id->rem_ref(cm_id);
2648 c4iw_put_ep(&ep->com);
2649fail1:
2650out:
2651 return err;
2652}
2653
2654int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2655{
2656 int err;
2657 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2658
2659 PDBG("%s ep %p\n", __func__, ep);
2660
2661 might_sleep();
2662 state_set(&ep->com, DEAD);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002663 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2664 err = cxgb4_remove_server_filter(
2665 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2666 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2667 } else {
2668 c4iw_init_wr_wait(&ep->com.wr_wait);
2669 err = listen_stop(ep);
2670 if (err)
2671 goto done;
2672 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2673 0, 0, __func__);
2674 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002675 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002676 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2677done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002678 cm_id->rem_ref(cm_id);
2679 c4iw_put_ep(&ep->com);
2680 return err;
2681}
2682
2683int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2684{
2685 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002686 int close = 0;
2687 int fatal = 0;
2688 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689
Steve Wise2f5b48c2010-09-10 11:15:36 -05002690 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691
2692 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2693 states[ep->com.state], abrupt);
2694
2695 rdev = &ep->com.dev->rdev;
2696 if (c4iw_fatal_error(rdev)) {
2697 fatal = 1;
2698 close_complete_upcall(ep);
2699 ep->com.state = DEAD;
2700 }
2701 switch (ep->com.state) {
2702 case MPA_REQ_WAIT:
2703 case MPA_REQ_SENT:
2704 case MPA_REQ_RCVD:
2705 case MPA_REP_SENT:
2706 case FPDU_MODE:
2707 close = 1;
2708 if (abrupt)
2709 ep->com.state = ABORTING;
2710 else {
2711 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002712 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002713 }
2714 set_bit(CLOSE_SENT, &ep->com.flags);
2715 break;
2716 case CLOSING:
2717 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2718 close = 1;
2719 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002720 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002721 ep->com.state = ABORTING;
2722 } else
2723 ep->com.state = MORIBUND;
2724 }
2725 break;
2726 case MORIBUND:
2727 case ABORTING:
2728 case DEAD:
2729 PDBG("%s ignoring disconnect ep %p state %u\n",
2730 __func__, ep, ep->com.state);
2731 break;
2732 default:
2733 BUG();
2734 break;
2735 }
2736
Steve Wisecfdda9d2010-04-21 15:30:06 -07002737 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002738 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002739 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002740 close_complete_upcall(ep);
2741 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002742 } else {
2743 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002745 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002746 if (ret)
2747 fatal = 1;
2748 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002749 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 if (fatal)
2751 release_ep_resources(ep);
2752 return ret;
2753}
2754
Vipul Pandya1cab7752012-12-10 09:30:55 +00002755static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2756 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2757{
2758 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00002759 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002760
2761 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, req->tid);
2762 if (!ep)
2763 return;
2764
2765 switch (req->retval) {
2766 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00002767 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2768 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2769 send_fw_act_open_req(ep, atid);
2770 return;
2771 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002772 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00002773 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2774 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2775 send_fw_act_open_req(ep, atid);
2776 return;
2777 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002778 break;
2779 default:
2780 pr_info("%s unexpected ofld conn wr retval %d\n",
2781 __func__, req->retval);
2782 break;
2783 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002784 pr_err("active ofld_connect_wr failure %d atid %d\n",
2785 req->retval, atid);
2786 mutex_lock(&dev->rdev.stats.lock);
2787 dev->rdev.stats.act_ofld_conn_fails++;
2788 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002789 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00002790 state_set(&ep->com, DEAD);
2791 remove_handle(dev, &dev->atid_idr, atid);
2792 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2793 dst_release(ep->dst);
2794 cxgb4_l2t_release(ep->l2t);
2795 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002796}
2797
2798static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2799 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2800{
2801 struct sk_buff *rpl_skb;
2802 struct cpl_pass_accept_req *cpl;
2803 int ret;
2804
2805 rpl_skb = (struct sk_buff *)cpu_to_be64(req->cookie);
2806 BUG_ON(!rpl_skb);
2807 if (req->retval) {
2808 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00002809 mutex_lock(&dev->rdev.stats.lock);
2810 dev->rdev.stats.pas_ofld_conn_fails++;
2811 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002812 kfree_skb(rpl_skb);
2813 } else {
2814 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2815 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2816 htonl(req->tid)));
2817 ret = pass_accept_req(dev, rpl_skb);
2818 if (!ret)
2819 kfree_skb(rpl_skb);
2820 }
2821 return;
2822}
2823
2824static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05002825{
2826 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002827 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2828
2829 switch (rpl->type) {
2830 case FW6_TYPE_CQE:
2831 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2832 break;
2833 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2834 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2835 switch (req->t_state) {
2836 case TCP_SYN_SENT:
2837 active_ofld_conn_reply(dev, skb, req);
2838 break;
2839 case TCP_SYN_RECV:
2840 passive_ofld_conn_reply(dev, skb, req);
2841 break;
2842 default:
2843 pr_err("%s unexpected ofld conn wr state %d\n",
2844 __func__, req->t_state);
2845 break;
2846 }
2847 break;
2848 }
2849 return 0;
2850}
2851
2852static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2853{
2854 u32 l2info;
2855 u16 vlantag, len, hdr_len;
2856 u8 intf;
2857 struct cpl_rx_pkt *cpl = cplhdr(skb);
2858 struct cpl_pass_accept_req *req;
2859 struct tcp_options_received tmp_opt;
2860
2861 /* Store values from cpl_rx_pkt in temporary location. */
2862 vlantag = cpl->vlan;
2863 len = cpl->len;
2864 l2info = cpl->l2info;
2865 hdr_len = cpl->hdr_len;
2866 intf = cpl->iff;
2867
2868 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2869
2870 /*
2871 * We need to parse the TCP options from SYN packet.
2872 * to generate cpl_pass_accept_req.
2873 */
2874 memset(&tmp_opt, 0, sizeof(tmp_opt));
2875 tcp_clear_options(&tmp_opt);
2876 tcp_parse_options(skb, &tmp_opt, 0, 0, NULL);
2877
2878 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2879 memset(req, 0, sizeof(*req));
2880 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2881 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info))) |
2882 F_SYN_XACT_MATCH);
2883 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info))) |
2884 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len))) |
2885 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len))) |
2886 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info))));
2887 req->vlan = vlantag;
2888 req->len = len;
2889 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2890 PASS_OPEN_TOS(tos));
2891 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2892 if (tmp_opt.wscale_ok)
2893 req->tcpopt.wsf = tmp_opt.snd_wscale;
2894 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2895 if (tmp_opt.sack_ok)
2896 req->tcpopt.sack = 1;
2897 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2898 return;
2899}
2900
2901static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2902 __be32 laddr, __be16 lport,
2903 __be32 raddr, __be16 rport,
2904 u32 rcv_isn, u32 filter, u16 window,
2905 u32 rss_qid, u8 port_id)
2906{
2907 struct sk_buff *req_skb;
2908 struct fw_ofld_connection_wr *req;
2909 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2910
2911 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2912 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2913 memset(req, 0, sizeof(*req));
2914 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2915 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2916 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2917 req->le.filter = filter;
2918 req->le.lport = lport;
2919 req->le.pport = rport;
2920 req->le.u.ipv4.lip = laddr;
2921 req->le.u.ipv4.pip = raddr;
2922 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2923 req->tcb.rcv_adv = htons(window);
2924 req->tcb.t_state_to_astid =
2925 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2926 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2927 V_FW_OFLD_CONNECTION_WR_ASTID(
2928 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2929
2930 /*
2931 * We store the qid in opt2 which will be used by the firmware
2932 * to send us the wr response.
2933 */
2934 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2935
2936 /*
2937 * We initialize the MSS index in TCB to 0xF.
2938 * So that when driver sends cpl_pass_accept_rpl
2939 * TCB picks up the correct value. If this was 0
2940 * TP will ignore any value > 0 for MSS index.
2941 */
2942 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2943 req->cookie = cpu_to_be64((u64)skb);
2944
2945 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2946 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2947}
2948
2949/*
2950 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2951 * messages when a filter is being used instead of server to
2952 * redirect a syn packet. When packets hit filter they are redirected
2953 * to the offload queue and driver tries to establish the connection
2954 * using firmware work request.
2955 */
2956static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
2957{
2958 int stid;
2959 unsigned int filter;
2960 struct ethhdr *eh = NULL;
2961 struct vlan_ethhdr *vlan_eh = NULL;
2962 struct iphdr *iph;
2963 struct tcphdr *tcph;
2964 struct rss_header *rss = (void *)skb->data;
2965 struct cpl_rx_pkt *cpl = (void *)skb->data;
2966 struct cpl_pass_accept_req *req = (void *)(rss + 1);
2967 struct l2t_entry *e;
2968 struct dst_entry *dst;
2969 struct rtable *rt;
2970 struct c4iw_ep *lep;
2971 u16 window;
2972 struct port_info *pi;
2973 struct net_device *pdev;
2974 u16 rss_qid;
2975 int step;
2976 u32 tx_chan;
2977 struct neighbour *neigh;
2978
2979 /* Drop all non-SYN packets */
2980 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
2981 goto reject;
2982
2983 /*
2984 * Drop all packets which did not hit the filter.
2985 * Unlikely to happen.
2986 */
2987 if (!(rss->filter_hit && rss->filter_tid))
2988 goto reject;
2989
2990 /*
2991 * Calculate the server tid from filter hit index from cpl_rx_pkt.
2992 */
2993 stid = cpu_to_be32(rss->hash_val) - dev->rdev.lldi.tids->sftid_base
2994 + dev->rdev.lldi.tids->nstids;
2995
2996 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
2997 if (!lep) {
2998 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2999 goto reject;
3000 }
3001
3002 if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
3003 eh = (struct ethhdr *)(req + 1);
3004 iph = (struct iphdr *)(eh + 1);
3005 } else {
3006 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3007 iph = (struct iphdr *)(vlan_eh + 1);
3008 skb->vlan_tci = ntohs(cpl->vlan);
3009 }
3010
3011 if (iph->version != 0x4)
3012 goto reject;
3013
3014 tcph = (struct tcphdr *)(iph + 1);
3015 skb_set_network_header(skb, (void *)iph - (void *)rss);
3016 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3017 skb_get(skb);
3018
3019 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3020 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3021 ntohs(tcph->source), iph->tos);
3022
3023 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3024 iph->tos);
3025 if (!rt) {
3026 pr_err("%s - failed to find dst entry!\n",
3027 __func__);
3028 goto reject;
3029 }
3030 dst = &rt->dst;
3031 neigh = dst_neigh_lookup_skb(dst, skb);
3032
3033 if (neigh->dev->flags & IFF_LOOPBACK) {
3034 pdev = ip_dev_find(&init_net, iph->daddr);
3035 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3036 pdev, 0);
3037 pi = (struct port_info *)netdev_priv(pdev);
3038 tx_chan = cxgb4_port_chan(pdev);
3039 dev_put(pdev);
3040 } else {
3041 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3042 neigh->dev, 0);
3043 pi = (struct port_info *)netdev_priv(neigh->dev);
3044 tx_chan = cxgb4_port_chan(neigh->dev);
3045 }
3046 if (!e) {
3047 pr_err("%s - failed to allocate l2t entry!\n",
3048 __func__);
3049 goto free_dst;
3050 }
3051
3052 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3053 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3054 window = htons(tcph->window);
3055
3056 /* Calcuate filter portion for LE region. */
3057 filter = cpu_to_be32(select_ntuple(dev, dst, e));
3058
3059 /*
3060 * Synthesize the cpl_pass_accept_req. We have everything except the
3061 * TID. Once firmware sends a reply with TID we update the TID field
3062 * in cpl and pass it through the regular cpl_pass_accept_req path.
3063 */
3064 build_cpl_pass_accept_req(skb, stid, iph->tos);
3065 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3066 tcph->source, ntohl(tcph->seq), filter, window,
3067 rss_qid, pi->port_id);
3068 cxgb4_l2t_release(e);
3069free_dst:
3070 dst_release(dst);
3071reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003072 return 0;
3073}
3074
Steve Wisecfdda9d2010-04-21 15:30:06 -07003075/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003076 * These are the real handlers that are called from a
3077 * work queue.
3078 */
3079static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3080 [CPL_ACT_ESTABLISH] = act_establish,
3081 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3082 [CPL_RX_DATA] = rx_data,
3083 [CPL_ABORT_RPL_RSS] = abort_rpl,
3084 [CPL_ABORT_RPL] = abort_rpl,
3085 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3086 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3087 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3088 [CPL_PASS_ESTABLISH] = pass_establish,
3089 [CPL_PEER_CLOSE] = peer_close,
3090 [CPL_ABORT_REQ_RSS] = peer_abort,
3091 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3092 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003093 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003094 [CPL_FW6_MSG] = deferred_fw6_msg,
3095 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003096};
3097
3098static void process_timeout(struct c4iw_ep *ep)
3099{
3100 struct c4iw_qp_attributes attrs;
3101 int abort = 1;
3102
Steve Wise2f5b48c2010-09-10 11:15:36 -05003103 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003104 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3105 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003106 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003107 switch (ep->com.state) {
3108 case MPA_REQ_SENT:
3109 __state_set(&ep->com, ABORTING);
3110 connect_reply_upcall(ep, -ETIMEDOUT);
3111 break;
3112 case MPA_REQ_WAIT:
3113 __state_set(&ep->com, ABORTING);
3114 break;
3115 case CLOSING:
3116 case MORIBUND:
3117 if (ep->com.cm_id && ep->com.qp) {
3118 attrs.next_state = C4IW_QP_STATE_ERROR;
3119 c4iw_modify_qp(ep->com.qp->rhp,
3120 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3121 &attrs, 1);
3122 }
3123 __state_set(&ep->com, ABORTING);
3124 break;
3125 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003126 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003127 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003128 abort = 0;
3129 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003130 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003131 if (abort)
3132 abort_connection(ep, NULL, GFP_KERNEL);
3133 c4iw_put_ep(&ep->com);
3134}
3135
3136static void process_timedout_eps(void)
3137{
3138 struct c4iw_ep *ep;
3139
3140 spin_lock_irq(&timeout_lock);
3141 while (!list_empty(&timeout_list)) {
3142 struct list_head *tmp;
3143
3144 tmp = timeout_list.next;
3145 list_del(tmp);
3146 spin_unlock_irq(&timeout_lock);
3147 ep = list_entry(tmp, struct c4iw_ep, entry);
3148 process_timeout(ep);
3149 spin_lock_irq(&timeout_lock);
3150 }
3151 spin_unlock_irq(&timeout_lock);
3152}
3153
3154static void process_work(struct work_struct *work)
3155{
3156 struct sk_buff *skb = NULL;
3157 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003158 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003159 unsigned int opcode;
3160 int ret;
3161
3162 while ((skb = skb_dequeue(&rxq))) {
3163 rpl = cplhdr(skb);
3164 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3165 opcode = rpl->ot.opcode;
3166
3167 BUG_ON(!work_handlers[opcode]);
3168 ret = work_handlers[opcode](dev, skb);
3169 if (!ret)
3170 kfree_skb(skb);
3171 }
3172 process_timedout_eps();
3173}
3174
3175static DECLARE_WORK(skb_work, process_work);
3176
3177static void ep_timeout(unsigned long arg)
3178{
3179 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3180
3181 spin_lock(&timeout_lock);
3182 list_add_tail(&ep->entry, &timeout_list);
3183 spin_unlock(&timeout_lock);
3184 queue_work(workq, &skb_work);
3185}
3186
3187/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003188 * All the CM events are handled on a work queue to have a safe context.
3189 */
3190static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3191{
3192
3193 /*
3194 * Save dev in the skb->cb area.
3195 */
3196 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3197
3198 /*
3199 * Queue the skb and schedule the worker thread.
3200 */
3201 skb_queue_tail(&rxq, skb);
3202 queue_work(workq, &skb_work);
3203 return 0;
3204}
3205
3206static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3207{
3208 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3209
3210 if (rpl->status != CPL_ERR_NONE) {
3211 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3212 "for tid %u\n", rpl->status, GET_TID(rpl));
3213 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003214 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003215 return 0;
3216}
3217
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003218static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3219{
3220 struct cpl_fw6_msg *rpl = cplhdr(skb);
3221 struct c4iw_wr_wait *wr_waitp;
3222 int ret;
3223
3224 PDBG("%s type %u\n", __func__, rpl->type);
3225
3226 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003227 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003228 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003229 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003230 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003231 if (wr_waitp)
3232 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003233 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003234 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003235 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003236 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003237 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003238 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003239 default:
3240 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3241 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003242 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003243 break;
3244 }
3245 return 0;
3246}
3247
Steve Wise8da7e7a2011-06-14 20:59:27 +00003248static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3249{
3250 struct cpl_abort_req_rss *req = cplhdr(skb);
3251 struct c4iw_ep *ep;
3252 struct tid_info *t = dev->rdev.lldi.tids;
3253 unsigned int tid = GET_TID(req);
3254
3255 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003256 if (!ep) {
3257 printk(KERN_WARNING MOD
3258 "Abort on non-existent endpoint, tid %d\n", tid);
3259 kfree_skb(skb);
3260 return 0;
3261 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003262 if (is_neg_adv_abort(req->status)) {
3263 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3264 ep->hwtid);
3265 kfree_skb(skb);
3266 return 0;
3267 }
3268 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3269 ep->com.state);
3270
3271 /*
3272 * Wake up any threads in rdma_init() or rdma_fini().
3273 */
Steve Wise0f1dcfa2012-04-27 09:59:16 -05003274 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003275 sched(dev, skb);
3276 return 0;
3277}
3278
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003279/*
3280 * Most upcalls from the T4 Core go to sched() to
3281 * schedule the processing on a work queue.
3282 */
3283c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3284 [CPL_ACT_ESTABLISH] = sched,
3285 [CPL_ACT_OPEN_RPL] = sched,
3286 [CPL_RX_DATA] = sched,
3287 [CPL_ABORT_RPL_RSS] = sched,
3288 [CPL_ABORT_RPL] = sched,
3289 [CPL_PASS_OPEN_RPL] = sched,
3290 [CPL_CLOSE_LISTSRV_RPL] = sched,
3291 [CPL_PASS_ACCEPT_REQ] = sched,
3292 [CPL_PASS_ESTABLISH] = sched,
3293 [CPL_PEER_CLOSE] = sched,
3294 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003295 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003296 [CPL_RDMA_TERMINATE] = sched,
3297 [CPL_FW4_ACK] = sched,
3298 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003299 [CPL_FW6_MSG] = fw6_msg,
3300 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003301};
3302
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303int __init c4iw_cm_init(void)
3304{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003305 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003306 skb_queue_head_init(&rxq);
3307
3308 workq = create_singlethread_workqueue("iw_cxgb4");
3309 if (!workq)
3310 return -ENOMEM;
3311
Steve Wisecfdda9d2010-04-21 15:30:06 -07003312 return 0;
3313}
3314
3315void __exit c4iw_cm_term(void)
3316{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003317 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318 flush_workqueue(workq);
3319 destroy_workqueue(workq);
3320}