blob: 9cab6a6eb96adc196681e1bb816a7522a1484d74 [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. Miller31e4543d2011-05-03 20:25:42 -0700329 struct flowi4 fl4;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700330
David S. Miller31e4543d2011-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 Wise94788652011-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:
1441 __state_set(&ep->com, DEAD);
1442 release = 1;
1443 break;
1444 default:
1445 printk(KERN_ERR "%s ep %p state %d\n",
1446 __func__, ep, ep->com.state);
1447 break;
1448 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001449 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001450
1451 if (release)
1452 release_ep_resources(ep);
1453 return 0;
1454}
1455
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001456static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1457{
1458 struct sk_buff *skb;
1459 struct fw_ofld_connection_wr *req;
1460 unsigned int mtu_idx;
1461 int wscale;
1462
1463 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1464 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1465 memset(req, 0, sizeof(*req));
1466 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1467 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1468 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1469 ep->l2t));
1470 req->le.lport = ep->com.local_addr.sin_port;
1471 req->le.pport = ep->com.remote_addr.sin_port;
1472 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1473 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1474 req->tcb.t_state_to_astid =
1475 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1476 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1477 req->tcb.cplrxdataack_cplpassacceptrpl =
1478 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1479 req->tcb.tx_max = jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001480 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001481 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1482 wscale = compute_wscale(rcv_win);
1483 req->tcb.opt0 = TCAM_BYPASS(1) |
1484 (nocong ? NO_CONG(1) : 0) |
1485 KEEP_ALIVE(1) |
1486 DELACK(1) |
1487 WND_SCALE(wscale) |
1488 MSS_IDX(mtu_idx) |
1489 L2T_IDX(ep->l2t->idx) |
1490 TX_CHAN(ep->tx_chan) |
1491 SMAC_SEL(ep->smac_idx) |
1492 DSCP(ep->tos) |
1493 ULP_MODE(ULP_MODE_TCPDDP) |
1494 RCV_BUFSIZ(rcv_win >> 10);
1495 req->tcb.opt2 = PACE(1) |
1496 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1497 RX_CHANNEL(0) |
1498 CCTRL_ECN(enable_ecn) |
1499 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1500 if (enable_tcp_timestamps)
1501 req->tcb.opt2 |= TSTAMPS_EN(1);
1502 if (enable_tcp_sack)
1503 req->tcb.opt2 |= SACK_EN(1);
1504 if (wscale && enable_tcp_window_scaling)
1505 req->tcb.opt2 |= WND_SCALE_EN(1);
1506 req->tcb.opt0 = cpu_to_be64(req->tcb.opt0);
1507 req->tcb.opt2 = cpu_to_be32(req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001508 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1509 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001510 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1511}
1512
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513/*
1514 * Return whether a failed active open has allocated a TID
1515 */
1516static inline int act_open_has_tid(int status)
1517{
1518 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1519 status != CPL_ERR_ARP_MISS;
1520}
1521
Vipul Pandya793dad92012-12-10 09:30:56 +00001522#define ACT_OPEN_RETRY_COUNT 2
1523
1524static int c4iw_reconnect(struct c4iw_ep *ep)
1525{
1526 int err = 0;
1527 struct rtable *rt;
1528 struct port_info *pi;
1529 struct net_device *pdev;
1530 int step;
1531 struct neighbour *neigh;
1532
1533 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1534 init_timer(&ep->timer);
1535
1536 /*
1537 * Allocate an active TID to initiate a TCP connection.
1538 */
1539 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1540 if (ep->atid == -1) {
1541 pr_err("%s - cannot alloc atid.\n", __func__);
1542 err = -ENOMEM;
1543 goto fail2;
1544 }
1545 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1546
1547 /* find a route */
1548 rt = find_route(ep->com.dev,
1549 ep->com.cm_id->local_addr.sin_addr.s_addr,
1550 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1551 ep->com.cm_id->local_addr.sin_port,
1552 ep->com.cm_id->remote_addr.sin_port, 0);
1553 if (!rt) {
1554 pr_err("%s - cannot find route.\n", __func__);
1555 err = -EHOSTUNREACH;
1556 goto fail3;
1557 }
1558 ep->dst = &rt->dst;
1559
1560 neigh = dst_neigh_lookup(ep->dst,
1561 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1562 /* get a l2t entry */
1563 if (neigh->dev->flags & IFF_LOOPBACK) {
1564 PDBG("%s LOOPBACK\n", __func__);
1565 pdev = ip_dev_find(&init_net,
1566 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1567 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1568 neigh, pdev, 0);
1569 pi = (struct port_info *)netdev_priv(pdev);
1570 ep->mtu = pdev->mtu;
1571 ep->tx_chan = cxgb4_port_chan(pdev);
1572 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1573 dev_put(pdev);
1574 } else {
1575 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1576 neigh, neigh->dev, 0);
1577 pi = (struct port_info *)netdev_priv(neigh->dev);
1578 ep->mtu = dst_mtu(ep->dst);
1579 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1580 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1581 0x7F) << 1;
1582 }
1583
1584 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1585 ep->txq_idx = pi->port_id * step;
1586 ep->ctrlq_idx = pi->port_id;
1587 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1588 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1589
1590 if (!ep->l2t) {
1591 pr_err("%s - cannot alloc l2e.\n", __func__);
1592 err = -ENOMEM;
1593 goto fail4;
1594 }
1595
1596 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1597 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1598 ep->l2t->idx);
1599
1600 state_set(&ep->com, CONNECTING);
1601 ep->tos = 0;
1602
1603 /* send connect request to rnic */
1604 err = send_connect(ep);
1605 if (!err)
1606 goto out;
1607
1608 cxgb4_l2t_release(ep->l2t);
1609fail4:
1610 dst_release(ep->dst);
1611fail3:
1612 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1613 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1614fail2:
1615 /*
1616 * remember to send notification to upper layer.
1617 * We are in here so the upper layer is not aware that this is
1618 * re-connect attempt and so, upper layer is still waiting for
1619 * response of 1st connect request.
1620 */
1621 connect_reply_upcall(ep, -ECONNRESET);
1622 c4iw_put_ep(&ep->com);
1623out:
1624 return err;
1625}
1626
Steve Wisecfdda9d2010-04-21 15:30:06 -07001627static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1628{
1629 struct c4iw_ep *ep;
1630 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1631 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1632 ntohl(rpl->atid_status)));
1633 struct tid_info *t = dev->rdev.lldi.tids;
1634 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1635
1636 ep = lookup_atid(t, atid);
1637
1638 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1639 status, status2errno(status));
1640
1641 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1642 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1643 atid);
1644 return 0;
1645 }
1646
Vipul Pandya793dad92012-12-10 09:30:56 +00001647 set_bit(ACT_OPEN_RPL, &ep->com.history);
1648
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301649 /*
1650 * Log interesting failures.
1651 */
1652 switch (status) {
1653 case CPL_ERR_CONN_RESET:
1654 case CPL_ERR_CONN_TIMEDOUT:
1655 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001656 case CPL_ERR_TCAM_FULL:
Vipul Pandya793dad92012-12-10 09:30:56 +00001657 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1658 mutex_lock(&dev->rdev.stats.lock);
1659 dev->rdev.stats.tcam_full++;
1660 mutex_unlock(&dev->rdev.stats.lock);
1661 send_fw_act_open_req(ep,
1662 GET_TID_TID(GET_AOPEN_ATID(
1663 ntohl(rpl->atid_status))));
1664 return 0;
1665 }
1666 break;
1667 case CPL_ERR_CONN_EXIST:
1668 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1669 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1670 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1671 atid);
1672 cxgb4_free_atid(t, atid);
1673 dst_release(ep->dst);
1674 cxgb4_l2t_release(ep->l2t);
1675 c4iw_reconnect(ep);
1676 return 0;
1677 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001678 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301679 default:
1680 printk(KERN_INFO MOD "Active open failure - "
1681 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1682 atid, status, status2errno(status),
1683 &ep->com.local_addr.sin_addr.s_addr,
1684 ntohs(ep->com.local_addr.sin_port),
1685 &ep->com.remote_addr.sin_addr.s_addr,
1686 ntohs(ep->com.remote_addr.sin_port));
1687 break;
1688 }
1689
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690 connect_reply_upcall(ep, status2errno(status));
1691 state_set(&ep->com, DEAD);
1692
1693 if (status && act_open_has_tid(status))
1694 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1695
Vipul Pandya793dad92012-12-10 09:30:56 +00001696 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697 cxgb4_free_atid(t, atid);
1698 dst_release(ep->dst);
1699 cxgb4_l2t_release(ep->l2t);
1700 c4iw_put_ep(&ep->com);
1701
1702 return 0;
1703}
1704
1705static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1706{
1707 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1708 struct tid_info *t = dev->rdev.lldi.tids;
1709 unsigned int stid = GET_TID(rpl);
1710 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1711
1712 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001713 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1714 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001715 }
1716 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1717 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001718 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001719
Vipul Pandya1cab7752012-12-10 09:30:55 +00001720out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001721 return 0;
1722}
1723
1724static int listen_stop(struct c4iw_listen_ep *ep)
1725{
1726 struct sk_buff *skb;
1727 struct cpl_close_listsvr_req *req;
1728
1729 PDBG("%s ep %p\n", __func__, ep);
1730 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1731 if (!skb) {
1732 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1733 return -ENOMEM;
1734 }
1735 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1736 INIT_TP_WR(req, 0);
1737 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1738 ep->stid));
1739 req->reply_ctrl = cpu_to_be16(
1740 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1741 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1742 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1743}
1744
1745static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1746{
1747 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1748 struct tid_info *t = dev->rdev.lldi.tids;
1749 unsigned int stid = GET_TID(rpl);
1750 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1751
1752 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001753 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001754 return 0;
1755}
1756
1757static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1758 struct cpl_pass_accept_req *req)
1759{
1760 struct cpl_pass_accept_rpl *rpl;
1761 unsigned int mtu_idx;
1762 u64 opt0;
1763 u32 opt2;
1764 int wscale;
1765
1766 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1767 BUG_ON(skb_cloned(skb));
1768 skb_trim(skb, sizeof(*rpl));
1769 skb_get(skb);
1770 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1771 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001772 opt0 = (nocong ? NO_CONG(1) : 0) |
1773 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001774 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775 WND_SCALE(wscale) |
1776 MSS_IDX(mtu_idx) |
1777 L2T_IDX(ep->l2t->idx) |
1778 TX_CHAN(ep->tx_chan) |
1779 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001780 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001781 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001782 RCV_BUFSIZ(rcv_win>>10);
1783 opt2 = RX_CHANNEL(0) |
1784 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1785
1786 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1787 opt2 |= TSTAMPS_EN(1);
1788 if (enable_tcp_sack && req->tcpopt.sack)
1789 opt2 |= SACK_EN(1);
1790 if (wscale && enable_tcp_window_scaling)
1791 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001792 if (enable_ecn) {
1793 const struct tcphdr *tcph;
1794 u32 hlen = ntohl(req->hdr_len);
1795
1796 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1797 G_IP_HDR_LEN(hlen);
1798 if (tcph->ece && tcph->cwr)
1799 opt2 |= CCTRL_ECN(1);
1800 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801
1802 rpl = cplhdr(skb);
1803 INIT_TP_WR(rpl, ep->hwtid);
1804 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1805 ep->hwtid));
1806 rpl->opt0 = cpu_to_be64(opt0);
1807 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001808 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1810
1811 return;
1812}
1813
1814static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1815 struct sk_buff *skb)
1816{
1817 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1818 peer_ip);
1819 BUG_ON(skb_cloned(skb));
1820 skb_trim(skb, sizeof(struct cpl_tid_release));
1821 skb_get(skb);
1822 release_tid(&dev->rdev, hwtid, skb);
1823 return;
1824}
1825
1826static void get_4tuple(struct cpl_pass_accept_req *req,
1827 __be32 *local_ip, __be32 *peer_ip,
1828 __be16 *local_port, __be16 *peer_port)
1829{
1830 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1831 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1832 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1833 struct tcphdr *tcp = (struct tcphdr *)
1834 ((u8 *)(req + 1) + eth_len + ip_len);
1835
1836 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1837 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1838 ntohs(tcp->dest));
1839
1840 *peer_ip = ip->saddr;
1841 *local_ip = ip->daddr;
1842 *peer_port = tcp->source;
1843 *local_port = tcp->dest;
1844
1845 return;
1846}
1847
David Miller3786cf12011-12-02 16:52:31 +00001848static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1849 struct c4iw_dev *cdev, bool clear_mpa_v1)
1850{
1851 struct neighbour *n;
1852 int err, step;
1853
David Miller64b70072012-01-24 13:15:57 +00001854 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001855 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001856 return -ENODEV;
1857
1858 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001859 err = -ENOMEM;
1860 if (n->dev->flags & IFF_LOOPBACK) {
1861 struct net_device *pdev;
1862
1863 pdev = ip_dev_find(&init_net, peer_ip);
Thadeu Lima de Souza Cascardo71b43fd2012-05-17 17:51:53 -03001864 if (!pdev) {
1865 err = -ENODEV;
1866 goto out;
1867 }
David Miller3786cf12011-12-02 16:52:31 +00001868 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1869 n, pdev, 0);
1870 if (!ep->l2t)
1871 goto out;
1872 ep->mtu = pdev->mtu;
1873 ep->tx_chan = cxgb4_port_chan(pdev);
1874 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1875 step = cdev->rdev.lldi.ntxq /
1876 cdev->rdev.lldi.nchan;
1877 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1878 step = cdev->rdev.lldi.nrxq /
1879 cdev->rdev.lldi.nchan;
1880 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1881 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1882 cxgb4_port_idx(pdev) * step];
1883 dev_put(pdev);
1884 } else {
1885 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1886 n, n->dev, 0);
1887 if (!ep->l2t)
1888 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001889 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001890 ep->tx_chan = cxgb4_port_chan(n->dev);
1891 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1892 step = cdev->rdev.lldi.ntxq /
1893 cdev->rdev.lldi.nchan;
1894 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1895 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1896 step = cdev->rdev.lldi.nrxq /
1897 cdev->rdev.lldi.nchan;
1898 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1899 cxgb4_port_idx(n->dev) * step];
1900
1901 if (clear_mpa_v1) {
1902 ep->retry_with_mpa_v1 = 0;
1903 ep->tried_with_mpa_v1 = 0;
1904 }
1905 }
1906 err = 0;
1907out:
1908 rcu_read_unlock();
1909
David Miller64b70072012-01-24 13:15:57 +00001910 neigh_release(n);
1911
David Miller3786cf12011-12-02 16:52:31 +00001912 return err;
1913}
1914
Steve Wisecfdda9d2010-04-21 15:30:06 -07001915static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1916{
Vipul Pandya793dad92012-12-10 09:30:56 +00001917 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001918 struct cpl_pass_accept_req *req = cplhdr(skb);
1919 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1920 struct tid_info *t = dev->rdev.lldi.tids;
1921 unsigned int hwtid = GET_TID(req);
1922 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001923 struct rtable *rt;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001924 __be32 local_ip, peer_ip = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001925 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001926 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001927 u16 peer_mss = ntohs(req->tcpopt.mss);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001928
1929 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00001930 if (!parent_ep) {
1931 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1932 goto reject;
1933 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001934 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1935
Vipul Pandya1cab7752012-12-10 09:30:55 +00001936 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1937 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1938 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1939 ntohs(peer_port), peer_mss);
1940
Steve Wisecfdda9d2010-04-21 15:30:06 -07001941 if (state_read(&parent_ep->com) != LISTEN) {
1942 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1943 __func__);
1944 goto reject;
1945 }
1946
1947 /* Find output route */
1948 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1949 GET_POPEN_TOS(ntohl(req->tos_stid)));
1950 if (!rt) {
1951 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1952 __func__);
1953 goto reject;
1954 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001955 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001956
1957 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1958 if (!child_ep) {
1959 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1960 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001961 dst_release(dst);
1962 goto reject;
1963 }
David Miller3786cf12011-12-02 16:52:31 +00001964
1965 err = import_ep(child_ep, peer_ip, dst, dev, false);
1966 if (err) {
1967 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1968 __func__);
1969 dst_release(dst);
1970 kfree(child_ep);
1971 goto reject;
1972 }
1973
Vipul Pandya1cab7752012-12-10 09:30:55 +00001974 if (peer_mss && child_ep->mtu > (peer_mss + 40))
1975 child_ep->mtu = peer_mss + 40;
1976
Steve Wisecfdda9d2010-04-21 15:30:06 -07001977 state_set(&child_ep->com, CONNECTING);
1978 child_ep->com.dev = dev;
1979 child_ep->com.cm_id = NULL;
1980 child_ep->com.local_addr.sin_family = PF_INET;
1981 child_ep->com.local_addr.sin_port = local_port;
1982 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1983 child_ep->com.remote_addr.sin_family = PF_INET;
1984 child_ep->com.remote_addr.sin_port = peer_port;
1985 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1986 c4iw_get_ep(&parent_ep->com);
1987 child_ep->parent_ep = parent_ep;
1988 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001989 child_ep->dst = dst;
1990 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001991
1992 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00001993 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001994
1995 init_timer(&child_ep->timer);
1996 cxgb4_insert_tid(t, child_ep, hwtid);
1997 accept_cr(child_ep, peer_ip, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00001998 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001999 goto out;
2000reject:
2001 reject_cr(dev, hwtid, peer_ip, skb);
2002out:
2003 return 0;
2004}
2005
2006static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2007{
2008 struct c4iw_ep *ep;
2009 struct cpl_pass_establish *req = cplhdr(skb);
2010 struct tid_info *t = dev->rdev.lldi.tids;
2011 unsigned int tid = GET_TID(req);
2012
2013 ep = lookup_tid(t, tid);
2014 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2015 ep->snd_seq = be32_to_cpu(req->snd_isn);
2016 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2017
Vipul Pandya1cab7752012-12-10 09:30:55 +00002018 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2019 ntohs(req->tcp_opt));
2020
Steve Wisecfdda9d2010-04-21 15:30:06 -07002021 set_emss(ep, ntohs(req->tcp_opt));
Vipul Pandya793dad92012-12-10 09:30:56 +00002022 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002023
2024 dst_confirm(ep->dst);
2025 state_set(&ep->com, MPA_REQ_WAIT);
2026 start_ep_timer(ep);
2027 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002028 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002029
2030 return 0;
2031}
2032
2033static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2034{
2035 struct cpl_peer_close *hdr = cplhdr(skb);
2036 struct c4iw_ep *ep;
2037 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002038 int disconnect = 1;
2039 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002040 struct tid_info *t = dev->rdev.lldi.tids;
2041 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002042 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043
2044 ep = lookup_tid(t, tid);
2045 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2046 dst_confirm(ep->dst);
2047
Vipul Pandya793dad92012-12-10 09:30:56 +00002048 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002049 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002050 switch (ep->com.state) {
2051 case MPA_REQ_WAIT:
2052 __state_set(&ep->com, CLOSING);
2053 break;
2054 case MPA_REQ_SENT:
2055 __state_set(&ep->com, CLOSING);
2056 connect_reply_upcall(ep, -ECONNRESET);
2057 break;
2058 case MPA_REQ_RCVD:
2059
2060 /*
2061 * We're gonna mark this puppy DEAD, but keep
2062 * the reference on it until the ULP accepts or
2063 * rejects the CR. Also wake up anyone waiting
2064 * in rdma connection migration (see c4iw_accept_cr()).
2065 */
2066 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002067 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002068 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002069 break;
2070 case MPA_REP_SENT:
2071 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002072 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002073 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002074 break;
2075 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002076 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002078 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002079 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002080 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002081 if (ret != -ECONNRESET) {
2082 peer_close_upcall(ep);
2083 disconnect = 1;
2084 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002085 break;
2086 case ABORTING:
2087 disconnect = 0;
2088 break;
2089 case CLOSING:
2090 __state_set(&ep->com, MORIBUND);
2091 disconnect = 0;
2092 break;
2093 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002094 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002095 if (ep->com.cm_id && ep->com.qp) {
2096 attrs.next_state = C4IW_QP_STATE_IDLE;
2097 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2098 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2099 }
2100 close_complete_upcall(ep);
2101 __state_set(&ep->com, DEAD);
2102 release = 1;
2103 disconnect = 0;
2104 break;
2105 case DEAD:
2106 disconnect = 0;
2107 break;
2108 default:
2109 BUG_ON(1);
2110 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002111 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002112 if (disconnect)
2113 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2114 if (release)
2115 release_ep_resources(ep);
2116 return 0;
2117}
2118
2119/*
2120 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2121 */
2122static int is_neg_adv_abort(unsigned int status)
2123{
2124 return status == CPL_ERR_RTX_NEG_ADVICE ||
2125 status == CPL_ERR_PERSIST_NEG_ADVICE;
2126}
2127
2128static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2129{
2130 struct cpl_abort_req_rss *req = cplhdr(skb);
2131 struct c4iw_ep *ep;
2132 struct cpl_abort_rpl *rpl;
2133 struct sk_buff *rpl_skb;
2134 struct c4iw_qp_attributes attrs;
2135 int ret;
2136 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002137 struct tid_info *t = dev->rdev.lldi.tids;
2138 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002139
2140 ep = lookup_tid(t, tid);
2141 if (is_neg_adv_abort(req->status)) {
2142 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2143 ep->hwtid);
2144 return 0;
2145 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002146 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2147 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002148 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002149
2150 /*
2151 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302152 * However, this is not needed if com state is just
2153 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002154 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302155 if (ep->com.state != MPA_REQ_SENT)
2156 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002157
2158 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002159 switch (ep->com.state) {
2160 case CONNECTING:
2161 break;
2162 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002163 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002164 break;
2165 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002166 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302167 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
2168 connect_reply_upcall(ep, -ECONNRESET);
2169 else {
2170 /*
2171 * we just don't send notification upwards because we
2172 * want to retry with mpa_v1 without upper layers even
2173 * knowing it.
2174 *
2175 * do some housekeeping so as to re-initiate the
2176 * connection
2177 */
2178 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2179 mpa_rev);
2180 ep->retry_with_mpa_v1 = 1;
2181 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182 break;
2183 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002184 break;
2185 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002186 break;
2187 case MORIBUND:
2188 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002189 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190 /*FALLTHROUGH*/
2191 case FPDU_MODE:
2192 if (ep->com.cm_id && ep->com.qp) {
2193 attrs.next_state = C4IW_QP_STATE_ERROR;
2194 ret = c4iw_modify_qp(ep->com.qp->rhp,
2195 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2196 &attrs, 1);
2197 if (ret)
2198 printk(KERN_ERR MOD
2199 "%s - qp <- error failed!\n",
2200 __func__);
2201 }
2202 peer_abort_upcall(ep);
2203 break;
2204 case ABORTING:
2205 break;
2206 case DEAD:
2207 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002208 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002209 return 0;
2210 default:
2211 BUG_ON(1);
2212 break;
2213 }
2214 dst_confirm(ep->dst);
2215 if (ep->com.state != ABORTING) {
2216 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302217 /* we don't release if we want to retry with mpa_v1 */
2218 if (!ep->retry_with_mpa_v1)
2219 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002221 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222
2223 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2224 if (!rpl_skb) {
2225 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2226 __func__);
2227 release = 1;
2228 goto out;
2229 }
2230 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2231 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2232 INIT_TP_WR(rpl, ep->hwtid);
2233 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2234 rpl->cmd = CPL_ABORT_NO_RST;
2235 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2236out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002237 if (release)
2238 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302239
2240 /* retry with mpa-v1 */
2241 if (ep && ep->retry_with_mpa_v1) {
2242 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2243 dst_release(ep->dst);
2244 cxgb4_l2t_release(ep->l2t);
2245 c4iw_reconnect(ep);
2246 }
2247
Steve Wisecfdda9d2010-04-21 15:30:06 -07002248 return 0;
2249}
2250
2251static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2252{
2253 struct c4iw_ep *ep;
2254 struct c4iw_qp_attributes attrs;
2255 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002256 int release = 0;
2257 struct tid_info *t = dev->rdev.lldi.tids;
2258 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259
2260 ep = lookup_tid(t, tid);
2261
2262 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2263 BUG_ON(!ep);
2264
2265 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002266 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002267 switch (ep->com.state) {
2268 case CLOSING:
2269 __state_set(&ep->com, MORIBUND);
2270 break;
2271 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002272 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273 if ((ep->com.cm_id) && (ep->com.qp)) {
2274 attrs.next_state = C4IW_QP_STATE_IDLE;
2275 c4iw_modify_qp(ep->com.qp->rhp,
2276 ep->com.qp,
2277 C4IW_QP_ATTR_NEXT_STATE,
2278 &attrs, 1);
2279 }
2280 close_complete_upcall(ep);
2281 __state_set(&ep->com, DEAD);
2282 release = 1;
2283 break;
2284 case ABORTING:
2285 case DEAD:
2286 break;
2287 default:
2288 BUG_ON(1);
2289 break;
2290 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002291 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002292 if (release)
2293 release_ep_resources(ep);
2294 return 0;
2295}
2296
2297static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2298{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002299 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002300 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002301 unsigned int tid = GET_TID(rpl);
2302 struct c4iw_ep *ep;
2303 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304
2305 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002306 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307
Steve Wise30c95c22011-05-09 22:06:22 -07002308 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002309 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2310 ep->com.qp->wq.sq.qid);
2311 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2312 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2313 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2314 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002315 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317 return 0;
2318}
2319
2320/*
2321 * Upcall from the adapter indicating data has been transmitted.
2322 * For us its just the single MPA request or reply. We can now free
2323 * the skb holding the mpa message.
2324 */
2325static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2326{
2327 struct c4iw_ep *ep;
2328 struct cpl_fw4_ack *hdr = cplhdr(skb);
2329 u8 credits = hdr->credits;
2330 unsigned int tid = GET_TID(hdr);
2331 struct tid_info *t = dev->rdev.lldi.tids;
2332
2333
2334 ep = lookup_tid(t, tid);
2335 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2336 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002337 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2338 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339 return 0;
2340 }
2341
2342 dst_confirm(ep->dst);
2343 if (ep->mpa_skb) {
2344 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2345 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2346 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2347 kfree_skb(ep->mpa_skb);
2348 ep->mpa_skb = NULL;
2349 }
2350 return 0;
2351}
2352
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2354{
2355 int err;
2356 struct c4iw_ep *ep = to_ep(cm_id);
2357 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2358
2359 if (state_read(&ep->com) == DEAD) {
2360 c4iw_put_ep(&ep->com);
2361 return -ECONNRESET;
2362 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002363 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2365 if (mpa_rev == 0)
2366 abort_connection(ep, NULL, GFP_KERNEL);
2367 else {
2368 err = send_mpa_reject(ep, pdata, pdata_len);
2369 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2370 }
2371 c4iw_put_ep(&ep->com);
2372 return 0;
2373}
2374
2375int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2376{
2377 int err;
2378 struct c4iw_qp_attributes attrs;
2379 enum c4iw_qp_attr_mask mask;
2380 struct c4iw_ep *ep = to_ep(cm_id);
2381 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2382 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2383
2384 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2385 if (state_read(&ep->com) == DEAD) {
2386 err = -ECONNRESET;
2387 goto err;
2388 }
2389
2390 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2391 BUG_ON(!qp);
2392
Vipul Pandya793dad92012-12-10 09:30:56 +00002393 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002394 if ((conn_param->ord > c4iw_max_read_depth) ||
2395 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 abort_connection(ep, NULL, GFP_KERNEL);
2397 err = -EINVAL;
2398 goto err;
2399 }
2400
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302401 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2402 if (conn_param->ord > ep->ird) {
2403 ep->ird = conn_param->ird;
2404 ep->ord = conn_param->ord;
2405 send_mpa_reject(ep, conn_param->private_data,
2406 conn_param->private_data_len);
2407 abort_connection(ep, NULL, GFP_KERNEL);
2408 err = -ENOMEM;
2409 goto err;
2410 }
2411 if (conn_param->ird > ep->ord) {
2412 if (!ep->ord)
2413 conn_param->ird = 1;
2414 else {
2415 abort_connection(ep, NULL, GFP_KERNEL);
2416 err = -ENOMEM;
2417 goto err;
2418 }
2419 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302421 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002422 ep->ird = conn_param->ird;
2423 ep->ord = conn_param->ord;
2424
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302425 if (ep->mpa_attr.version != 2)
2426 if (peer2peer && ep->ird == 0)
2427 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428
2429 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2430
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302431 cm_id->add_ref(cm_id);
2432 ep->com.cm_id = cm_id;
2433 ep->com.qp = qp;
2434
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 /* bind QP to EP and move to RTS */
2436 attrs.mpa_attr = ep->mpa_attr;
2437 attrs.max_ird = ep->ird;
2438 attrs.max_ord = ep->ord;
2439 attrs.llp_stream_handle = ep;
2440 attrs.next_state = C4IW_QP_STATE_RTS;
2441
2442 /* bind QP and TID with INIT_WR */
2443 mask = C4IW_QP_ATTR_NEXT_STATE |
2444 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2445 C4IW_QP_ATTR_MPA_ATTR |
2446 C4IW_QP_ATTR_MAX_IRD |
2447 C4IW_QP_ATTR_MAX_ORD;
2448
2449 err = c4iw_modify_qp(ep->com.qp->rhp,
2450 ep->com.qp, mask, &attrs, 1);
2451 if (err)
2452 goto err1;
2453 err = send_mpa_reply(ep, conn_param->private_data,
2454 conn_param->private_data_len);
2455 if (err)
2456 goto err1;
2457
2458 state_set(&ep->com, FPDU_MODE);
2459 established_upcall(ep);
2460 c4iw_put_ep(&ep->com);
2461 return 0;
2462err1:
2463 ep->com.cm_id = NULL;
2464 ep->com.qp = NULL;
2465 cm_id->rem_ref(cm_id);
2466err:
2467 c4iw_put_ep(&ep->com);
2468 return err;
2469}
2470
2471int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2472{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002473 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2474 struct c4iw_ep *ep;
2475 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002476 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002478 if ((conn_param->ord > c4iw_max_read_depth) ||
2479 (conn_param->ird > c4iw_max_read_depth)) {
2480 err = -EINVAL;
2481 goto out;
2482 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2484 if (!ep) {
2485 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2486 err = -ENOMEM;
2487 goto out;
2488 }
2489 init_timer(&ep->timer);
2490 ep->plen = conn_param->private_data_len;
2491 if (ep->plen)
2492 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2493 conn_param->private_data, ep->plen);
2494 ep->ird = conn_param->ird;
2495 ep->ord = conn_param->ord;
2496
2497 if (peer2peer && ep->ord == 0)
2498 ep->ord = 1;
2499
2500 cm_id->add_ref(cm_id);
2501 ep->com.dev = dev;
2502 ep->com.cm_id = cm_id;
2503 ep->com.qp = get_qhp(dev, conn_param->qpn);
2504 BUG_ON(!ep->com.qp);
2505 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2506 ep->com.qp, cm_id);
2507
2508 /*
2509 * Allocate an active TID to initiate a TCP connection.
2510 */
2511 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2512 if (ep->atid == -1) {
2513 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2514 err = -ENOMEM;
2515 goto fail2;
2516 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002517 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518
2519 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2520 ntohl(cm_id->local_addr.sin_addr.s_addr),
2521 ntohs(cm_id->local_addr.sin_port),
2522 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2523 ntohs(cm_id->remote_addr.sin_port));
2524
2525 /* find a route */
2526 rt = find_route(dev,
2527 cm_id->local_addr.sin_addr.s_addr,
2528 cm_id->remote_addr.sin_addr.s_addr,
2529 cm_id->local_addr.sin_port,
2530 cm_id->remote_addr.sin_port, 0);
2531 if (!rt) {
2532 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2533 err = -EHOSTUNREACH;
2534 goto fail3;
2535 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002536 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002537
David Miller3786cf12011-12-02 16:52:31 +00002538 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2539 ep->dst, ep->com.dev, true);
2540 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002541 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002542 goto fail4;
2543 }
2544
2545 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2546 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2547 ep->l2t->idx);
2548
2549 state_set(&ep->com, CONNECTING);
2550 ep->tos = 0;
2551 ep->com.local_addr = cm_id->local_addr;
2552 ep->com.remote_addr = cm_id->remote_addr;
2553
2554 /* send connect request to rnic */
2555 err = send_connect(ep);
2556 if (!err)
2557 goto out;
2558
2559 cxgb4_l2t_release(ep->l2t);
2560fail4:
2561 dst_release(ep->dst);
2562fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002563 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002564 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2565fail2:
2566 cm_id->rem_ref(cm_id);
2567 c4iw_put_ep(&ep->com);
2568out:
2569 return err;
2570}
2571
2572int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2573{
2574 int err = 0;
2575 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2576 struct c4iw_listen_ep *ep;
2577
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578 might_sleep();
2579
2580 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2581 if (!ep) {
2582 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2583 err = -ENOMEM;
2584 goto fail1;
2585 }
2586 PDBG("%s ep %p\n", __func__, ep);
2587 cm_id->add_ref(cm_id);
2588 ep->com.cm_id = cm_id;
2589 ep->com.dev = dev;
2590 ep->backlog = backlog;
2591 ep->com.local_addr = cm_id->local_addr;
2592
2593 /*
2594 * Allocate a server TID.
2595 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002596 if (dev->rdev.lldi.enable_fw_ofld_conn)
2597 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2598 else
2599 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2600
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002602 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002603 err = -ENOMEM;
2604 goto fail2;
2605 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002606 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002607 state_set(&ep->com, LISTEN);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002608 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2609 do {
2610 err = cxgb4_create_server_filter(
2611 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2612 ep->com.local_addr.sin_addr.s_addr,
2613 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002614 0,
2615 ep->com.dev->rdev.lldi.rxq_ids[0],
2616 0,
2617 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002618 if (err == -EBUSY) {
2619 set_current_state(TASK_UNINTERRUPTIBLE);
2620 schedule_timeout(usecs_to_jiffies(100));
2621 }
2622 } while (err == -EBUSY);
2623 } else {
2624 c4iw_init_wr_wait(&ep->com.wr_wait);
2625 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2626 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2627 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002628 0,
Vipul Pandya1cab7752012-12-10 09:30:55 +00002629 ep->com.dev->rdev.lldi.rxq_ids[0]);
2630 if (!err)
2631 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2632 &ep->com.wr_wait,
2633 0, 0, __func__);
2634 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002635 if (!err) {
2636 cm_id->provider_data = ep;
2637 goto out;
2638 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002639 pr_err("%s cxgb4_create_server/filter failed err %d " \
2640 "stid %d laddr %08x lport %d\n", \
2641 __func__, err, ep->stid,
2642 ntohl(ep->com.local_addr.sin_addr.s_addr),
2643 ntohs(ep->com.local_addr.sin_port));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2645fail2:
2646 cm_id->rem_ref(cm_id);
2647 c4iw_put_ep(&ep->com);
2648fail1:
2649out:
2650 return err;
2651}
2652
2653int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2654{
2655 int err;
2656 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2657
2658 PDBG("%s ep %p\n", __func__, ep);
2659
2660 might_sleep();
2661 state_set(&ep->com, DEAD);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002662 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2663 err = cxgb4_remove_server_filter(
2664 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2665 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2666 } else {
2667 c4iw_init_wr_wait(&ep->com.wr_wait);
2668 err = listen_stop(ep);
2669 if (err)
2670 goto done;
2671 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2672 0, 0, __func__);
2673 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002674 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2676done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002677 cm_id->rem_ref(cm_id);
2678 c4iw_put_ep(&ep->com);
2679 return err;
2680}
2681
2682int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2683{
2684 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 int close = 0;
2686 int fatal = 0;
2687 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688
Steve Wise2f5b48c2010-09-10 11:15:36 -05002689 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690
2691 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2692 states[ep->com.state], abrupt);
2693
2694 rdev = &ep->com.dev->rdev;
2695 if (c4iw_fatal_error(rdev)) {
2696 fatal = 1;
2697 close_complete_upcall(ep);
2698 ep->com.state = DEAD;
2699 }
2700 switch (ep->com.state) {
2701 case MPA_REQ_WAIT:
2702 case MPA_REQ_SENT:
2703 case MPA_REQ_RCVD:
2704 case MPA_REP_SENT:
2705 case FPDU_MODE:
2706 close = 1;
2707 if (abrupt)
2708 ep->com.state = ABORTING;
2709 else {
2710 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002711 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002712 }
2713 set_bit(CLOSE_SENT, &ep->com.flags);
2714 break;
2715 case CLOSING:
2716 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2717 close = 1;
2718 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002719 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 ep->com.state = ABORTING;
2721 } else
2722 ep->com.state = MORIBUND;
2723 }
2724 break;
2725 case MORIBUND:
2726 case ABORTING:
2727 case DEAD:
2728 PDBG("%s ignoring disconnect ep %p state %u\n",
2729 __func__, ep, ep->com.state);
2730 break;
2731 default:
2732 BUG();
2733 break;
2734 }
2735
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002737 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002738 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002739 close_complete_upcall(ep);
2740 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002741 } else {
2742 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002743 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002744 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745 if (ret)
2746 fatal = 1;
2747 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002748 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002749 if (fatal)
2750 release_ep_resources(ep);
2751 return ret;
2752}
2753
Vipul Pandya1cab7752012-12-10 09:30:55 +00002754static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2755 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2756{
2757 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00002758 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002759
2760 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, req->tid);
2761 if (!ep)
2762 return;
2763
2764 switch (req->retval) {
2765 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00002766 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2767 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2768 send_fw_act_open_req(ep, atid);
2769 return;
2770 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002771 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00002772 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2773 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2774 send_fw_act_open_req(ep, atid);
2775 return;
2776 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002777 break;
2778 default:
2779 pr_info("%s unexpected ofld conn wr retval %d\n",
2780 __func__, req->retval);
2781 break;
2782 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002783 pr_err("active ofld_connect_wr failure %d atid %d\n",
2784 req->retval, atid);
2785 mutex_lock(&dev->rdev.stats.lock);
2786 dev->rdev.stats.act_ofld_conn_fails++;
2787 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002788 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00002789 state_set(&ep->com, DEAD);
2790 remove_handle(dev, &dev->atid_idr, atid);
2791 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2792 dst_release(ep->dst);
2793 cxgb4_l2t_release(ep->l2t);
2794 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002795}
2796
2797static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2798 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2799{
2800 struct sk_buff *rpl_skb;
2801 struct cpl_pass_accept_req *cpl;
2802 int ret;
2803
2804 rpl_skb = (struct sk_buff *)cpu_to_be64(req->cookie);
2805 BUG_ON(!rpl_skb);
2806 if (req->retval) {
2807 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00002808 mutex_lock(&dev->rdev.stats.lock);
2809 dev->rdev.stats.pas_ofld_conn_fails++;
2810 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002811 kfree_skb(rpl_skb);
2812 } else {
2813 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2814 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2815 htonl(req->tid)));
2816 ret = pass_accept_req(dev, rpl_skb);
2817 if (!ret)
2818 kfree_skb(rpl_skb);
2819 }
2820 return;
2821}
2822
2823static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05002824{
2825 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002826 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2827
2828 switch (rpl->type) {
2829 case FW6_TYPE_CQE:
2830 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2831 break;
2832 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2833 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2834 switch (req->t_state) {
2835 case TCP_SYN_SENT:
2836 active_ofld_conn_reply(dev, skb, req);
2837 break;
2838 case TCP_SYN_RECV:
2839 passive_ofld_conn_reply(dev, skb, req);
2840 break;
2841 default:
2842 pr_err("%s unexpected ofld conn wr state %d\n",
2843 __func__, req->t_state);
2844 break;
2845 }
2846 break;
2847 }
2848 return 0;
2849}
2850
2851static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2852{
2853 u32 l2info;
2854 u16 vlantag, len, hdr_len;
2855 u8 intf;
2856 struct cpl_rx_pkt *cpl = cplhdr(skb);
2857 struct cpl_pass_accept_req *req;
2858 struct tcp_options_received tmp_opt;
2859
2860 /* Store values from cpl_rx_pkt in temporary location. */
2861 vlantag = cpl->vlan;
2862 len = cpl->len;
2863 l2info = cpl->l2info;
2864 hdr_len = cpl->hdr_len;
2865 intf = cpl->iff;
2866
2867 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2868
2869 /*
2870 * We need to parse the TCP options from SYN packet.
2871 * to generate cpl_pass_accept_req.
2872 */
2873 memset(&tmp_opt, 0, sizeof(tmp_opt));
2874 tcp_clear_options(&tmp_opt);
2875 tcp_parse_options(skb, &tmp_opt, 0, 0, NULL);
2876
2877 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2878 memset(req, 0, sizeof(*req));
2879 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2880 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info))) |
2881 F_SYN_XACT_MATCH);
2882 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info))) |
2883 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len))) |
2884 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len))) |
2885 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info))));
2886 req->vlan = vlantag;
2887 req->len = len;
2888 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2889 PASS_OPEN_TOS(tos));
2890 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2891 if (tmp_opt.wscale_ok)
2892 req->tcpopt.wsf = tmp_opt.snd_wscale;
2893 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2894 if (tmp_opt.sack_ok)
2895 req->tcpopt.sack = 1;
2896 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2897 return;
2898}
2899
2900static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2901 __be32 laddr, __be16 lport,
2902 __be32 raddr, __be16 rport,
2903 u32 rcv_isn, u32 filter, u16 window,
2904 u32 rss_qid, u8 port_id)
2905{
2906 struct sk_buff *req_skb;
2907 struct fw_ofld_connection_wr *req;
2908 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2909
2910 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2911 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2912 memset(req, 0, sizeof(*req));
2913 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2914 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2915 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2916 req->le.filter = filter;
2917 req->le.lport = lport;
2918 req->le.pport = rport;
2919 req->le.u.ipv4.lip = laddr;
2920 req->le.u.ipv4.pip = raddr;
2921 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2922 req->tcb.rcv_adv = htons(window);
2923 req->tcb.t_state_to_astid =
2924 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2925 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2926 V_FW_OFLD_CONNECTION_WR_ASTID(
2927 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2928
2929 /*
2930 * We store the qid in opt2 which will be used by the firmware
2931 * to send us the wr response.
2932 */
2933 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2934
2935 /*
2936 * We initialize the MSS index in TCB to 0xF.
2937 * So that when driver sends cpl_pass_accept_rpl
2938 * TCB picks up the correct value. If this was 0
2939 * TP will ignore any value > 0 for MSS index.
2940 */
2941 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2942 req->cookie = cpu_to_be64((u64)skb);
2943
2944 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2945 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2946}
2947
2948/*
2949 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2950 * messages when a filter is being used instead of server to
2951 * redirect a syn packet. When packets hit filter they are redirected
2952 * to the offload queue and driver tries to establish the connection
2953 * using firmware work request.
2954 */
2955static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
2956{
2957 int stid;
2958 unsigned int filter;
2959 struct ethhdr *eh = NULL;
2960 struct vlan_ethhdr *vlan_eh = NULL;
2961 struct iphdr *iph;
2962 struct tcphdr *tcph;
2963 struct rss_header *rss = (void *)skb->data;
2964 struct cpl_rx_pkt *cpl = (void *)skb->data;
2965 struct cpl_pass_accept_req *req = (void *)(rss + 1);
2966 struct l2t_entry *e;
2967 struct dst_entry *dst;
2968 struct rtable *rt;
2969 struct c4iw_ep *lep;
2970 u16 window;
2971 struct port_info *pi;
2972 struct net_device *pdev;
2973 u16 rss_qid;
2974 int step;
2975 u32 tx_chan;
2976 struct neighbour *neigh;
2977
2978 /* Drop all non-SYN packets */
2979 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
2980 goto reject;
2981
2982 /*
2983 * Drop all packets which did not hit the filter.
2984 * Unlikely to happen.
2985 */
2986 if (!(rss->filter_hit && rss->filter_tid))
2987 goto reject;
2988
2989 /*
2990 * Calculate the server tid from filter hit index from cpl_rx_pkt.
2991 */
2992 stid = cpu_to_be32(rss->hash_val) - dev->rdev.lldi.tids->sftid_base
2993 + dev->rdev.lldi.tids->nstids;
2994
2995 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
2996 if (!lep) {
2997 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2998 goto reject;
2999 }
3000
3001 if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
3002 eh = (struct ethhdr *)(req + 1);
3003 iph = (struct iphdr *)(eh + 1);
3004 } else {
3005 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3006 iph = (struct iphdr *)(vlan_eh + 1);
3007 skb->vlan_tci = ntohs(cpl->vlan);
3008 }
3009
3010 if (iph->version != 0x4)
3011 goto reject;
3012
3013 tcph = (struct tcphdr *)(iph + 1);
3014 skb_set_network_header(skb, (void *)iph - (void *)rss);
3015 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3016 skb_get(skb);
3017
3018 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3019 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3020 ntohs(tcph->source), iph->tos);
3021
3022 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3023 iph->tos);
3024 if (!rt) {
3025 pr_err("%s - failed to find dst entry!\n",
3026 __func__);
3027 goto reject;
3028 }
3029 dst = &rt->dst;
3030 neigh = dst_neigh_lookup_skb(dst, skb);
3031
3032 if (neigh->dev->flags & IFF_LOOPBACK) {
3033 pdev = ip_dev_find(&init_net, iph->daddr);
3034 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3035 pdev, 0);
3036 pi = (struct port_info *)netdev_priv(pdev);
3037 tx_chan = cxgb4_port_chan(pdev);
3038 dev_put(pdev);
3039 } else {
3040 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3041 neigh->dev, 0);
3042 pi = (struct port_info *)netdev_priv(neigh->dev);
3043 tx_chan = cxgb4_port_chan(neigh->dev);
3044 }
3045 if (!e) {
3046 pr_err("%s - failed to allocate l2t entry!\n",
3047 __func__);
3048 goto free_dst;
3049 }
3050
3051 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3052 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3053 window = htons(tcph->window);
3054
3055 /* Calcuate filter portion for LE region. */
3056 filter = cpu_to_be32(select_ntuple(dev, dst, e));
3057
3058 /*
3059 * Synthesize the cpl_pass_accept_req. We have everything except the
3060 * TID. Once firmware sends a reply with TID we update the TID field
3061 * in cpl and pass it through the regular cpl_pass_accept_req path.
3062 */
3063 build_cpl_pass_accept_req(skb, stid, iph->tos);
3064 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3065 tcph->source, ntohl(tcph->seq), filter, window,
3066 rss_qid, pi->port_id);
3067 cxgb4_l2t_release(e);
3068free_dst:
3069 dst_release(dst);
3070reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003071 return 0;
3072}
3073
Steve Wisecfdda9d2010-04-21 15:30:06 -07003074/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003075 * These are the real handlers that are called from a
3076 * work queue.
3077 */
3078static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3079 [CPL_ACT_ESTABLISH] = act_establish,
3080 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3081 [CPL_RX_DATA] = rx_data,
3082 [CPL_ABORT_RPL_RSS] = abort_rpl,
3083 [CPL_ABORT_RPL] = abort_rpl,
3084 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3085 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3086 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3087 [CPL_PASS_ESTABLISH] = pass_establish,
3088 [CPL_PEER_CLOSE] = peer_close,
3089 [CPL_ABORT_REQ_RSS] = peer_abort,
3090 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3091 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003092 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003093 [CPL_FW6_MSG] = deferred_fw6_msg,
3094 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003095};
3096
3097static void process_timeout(struct c4iw_ep *ep)
3098{
3099 struct c4iw_qp_attributes attrs;
3100 int abort = 1;
3101
Steve Wise2f5b48c2010-09-10 11:15:36 -05003102 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003103 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3104 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003105 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003106 switch (ep->com.state) {
3107 case MPA_REQ_SENT:
3108 __state_set(&ep->com, ABORTING);
3109 connect_reply_upcall(ep, -ETIMEDOUT);
3110 break;
3111 case MPA_REQ_WAIT:
3112 __state_set(&ep->com, ABORTING);
3113 break;
3114 case CLOSING:
3115 case MORIBUND:
3116 if (ep->com.cm_id && ep->com.qp) {
3117 attrs.next_state = C4IW_QP_STATE_ERROR;
3118 c4iw_modify_qp(ep->com.qp->rhp,
3119 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3120 &attrs, 1);
3121 }
3122 __state_set(&ep->com, ABORTING);
3123 break;
3124 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003125 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003126 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003127 abort = 0;
3128 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003129 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003130 if (abort)
3131 abort_connection(ep, NULL, GFP_KERNEL);
3132 c4iw_put_ep(&ep->com);
3133}
3134
3135static void process_timedout_eps(void)
3136{
3137 struct c4iw_ep *ep;
3138
3139 spin_lock_irq(&timeout_lock);
3140 while (!list_empty(&timeout_list)) {
3141 struct list_head *tmp;
3142
3143 tmp = timeout_list.next;
3144 list_del(tmp);
3145 spin_unlock_irq(&timeout_lock);
3146 ep = list_entry(tmp, struct c4iw_ep, entry);
3147 process_timeout(ep);
3148 spin_lock_irq(&timeout_lock);
3149 }
3150 spin_unlock_irq(&timeout_lock);
3151}
3152
3153static void process_work(struct work_struct *work)
3154{
3155 struct sk_buff *skb = NULL;
3156 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003157 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003158 unsigned int opcode;
3159 int ret;
3160
3161 while ((skb = skb_dequeue(&rxq))) {
3162 rpl = cplhdr(skb);
3163 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3164 opcode = rpl->ot.opcode;
3165
3166 BUG_ON(!work_handlers[opcode]);
3167 ret = work_handlers[opcode](dev, skb);
3168 if (!ret)
3169 kfree_skb(skb);
3170 }
3171 process_timedout_eps();
3172}
3173
3174static DECLARE_WORK(skb_work, process_work);
3175
3176static void ep_timeout(unsigned long arg)
3177{
3178 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3179
3180 spin_lock(&timeout_lock);
3181 list_add_tail(&ep->entry, &timeout_list);
3182 spin_unlock(&timeout_lock);
3183 queue_work(workq, &skb_work);
3184}
3185
3186/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003187 * All the CM events are handled on a work queue to have a safe context.
3188 */
3189static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3190{
3191
3192 /*
3193 * Save dev in the skb->cb area.
3194 */
3195 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3196
3197 /*
3198 * Queue the skb and schedule the worker thread.
3199 */
3200 skb_queue_tail(&rxq, skb);
3201 queue_work(workq, &skb_work);
3202 return 0;
3203}
3204
3205static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3206{
3207 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3208
3209 if (rpl->status != CPL_ERR_NONE) {
3210 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3211 "for tid %u\n", rpl->status, GET_TID(rpl));
3212 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003213 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003214 return 0;
3215}
3216
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003217static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3218{
3219 struct cpl_fw6_msg *rpl = cplhdr(skb);
3220 struct c4iw_wr_wait *wr_waitp;
3221 int ret;
3222
3223 PDBG("%s type %u\n", __func__, rpl->type);
3224
3225 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003226 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003227 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003228 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003229 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003230 if (wr_waitp)
3231 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003232 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003233 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003234 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003235 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003236 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003237 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003238 default:
3239 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3240 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003241 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003242 break;
3243 }
3244 return 0;
3245}
3246
Steve Wise8da7e7a2011-06-14 20:59:27 +00003247static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3248{
3249 struct cpl_abort_req_rss *req = cplhdr(skb);
3250 struct c4iw_ep *ep;
3251 struct tid_info *t = dev->rdev.lldi.tids;
3252 unsigned int tid = GET_TID(req);
3253
3254 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003255 if (!ep) {
3256 printk(KERN_WARNING MOD
3257 "Abort on non-existent endpoint, tid %d\n", tid);
3258 kfree_skb(skb);
3259 return 0;
3260 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003261 if (is_neg_adv_abort(req->status)) {
3262 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3263 ep->hwtid);
3264 kfree_skb(skb);
3265 return 0;
3266 }
3267 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3268 ep->com.state);
3269
3270 /*
3271 * Wake up any threads in rdma_init() or rdma_fini().
3272 */
Steve Wise0f1dcfa2012-04-27 09:59:16 -05003273 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003274 sched(dev, skb);
3275 return 0;
3276}
3277
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003278/*
3279 * Most upcalls from the T4 Core go to sched() to
3280 * schedule the processing on a work queue.
3281 */
3282c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3283 [CPL_ACT_ESTABLISH] = sched,
3284 [CPL_ACT_OPEN_RPL] = sched,
3285 [CPL_RX_DATA] = sched,
3286 [CPL_ABORT_RPL_RSS] = sched,
3287 [CPL_ABORT_RPL] = sched,
3288 [CPL_PASS_OPEN_RPL] = sched,
3289 [CPL_CLOSE_LISTSRV_RPL] = sched,
3290 [CPL_PASS_ACCEPT_REQ] = sched,
3291 [CPL_PASS_ESTABLISH] = sched,
3292 [CPL_PEER_CLOSE] = sched,
3293 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003294 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003295 [CPL_RDMA_TERMINATE] = sched,
3296 [CPL_FW4_ACK] = sched,
3297 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003298 [CPL_FW6_MSG] = fw6_msg,
3299 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003300};
3301
Steve Wisecfdda9d2010-04-21 15:30:06 -07003302int __init c4iw_cm_init(void)
3303{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003304 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305 skb_queue_head_init(&rxq);
3306
3307 workq = create_singlethread_workqueue("iw_cxgb4");
3308 if (!workq)
3309 return -ENOMEM;
3310
Steve Wisecfdda9d2010-04-21 15:30:06 -07003311 return 0;
3312}
3313
3314void __exit c4iw_cm_term(void)
3315{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003316 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003317 flush_workqueue(workq);
3318 destroy_workqueue(workq);
3319}