blob: 31d1fac605d3047942e29d4d0fe23ff18dd9dd0c [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;
Vipul Pandya15579672013-01-07 13:11:52 +00001406 case FPDU_MODE: {
1407 struct c4iw_qp_attributes attrs;
1408 BUG_ON(!ep->com.qp);
1409 if (ep->com.qp->attr.state == C4IW_QP_STATE_RTS)
1410 pr_err("%s Unexpected streaming data." \
1411 " ep %p state %d tid %u status %d\n",
1412 __func__, ep, state_read(&ep->com),
1413 ep->hwtid, status);
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);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001417 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001418 break;
1419 }
Vipul Pandya15579672013-01-07 13:11:52 +00001420 default:
1421 break;
1422 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001423 return 0;
1424}
1425
1426static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1427{
1428 struct c4iw_ep *ep;
1429 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430 int release = 0;
1431 unsigned int tid = GET_TID(rpl);
1432 struct tid_info *t = dev->rdev.lldi.tids;
1433
1434 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301435 if (!ep) {
1436 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1437 return 0;
1438 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001439 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001440 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 switch (ep->com.state) {
1442 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001443 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444 __state_set(&ep->com, DEAD);
1445 release = 1;
1446 break;
1447 default:
1448 printk(KERN_ERR "%s ep %p state %d\n",
1449 __func__, ep, ep->com.state);
1450 break;
1451 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001452 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001453
1454 if (release)
1455 release_ep_resources(ep);
1456 return 0;
1457}
1458
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001459static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1460{
1461 struct sk_buff *skb;
1462 struct fw_ofld_connection_wr *req;
1463 unsigned int mtu_idx;
1464 int wscale;
1465
1466 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1467 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1468 memset(req, 0, sizeof(*req));
1469 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1470 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1471 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1472 ep->l2t));
1473 req->le.lport = ep->com.local_addr.sin_port;
1474 req->le.pport = ep->com.remote_addr.sin_port;
1475 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1476 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1477 req->tcb.t_state_to_astid =
1478 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1479 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1480 req->tcb.cplrxdataack_cplpassacceptrpl =
1481 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1482 req->tcb.tx_max = jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001483 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001484 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1485 wscale = compute_wscale(rcv_win);
1486 req->tcb.opt0 = TCAM_BYPASS(1) |
1487 (nocong ? NO_CONG(1) : 0) |
1488 KEEP_ALIVE(1) |
1489 DELACK(1) |
1490 WND_SCALE(wscale) |
1491 MSS_IDX(mtu_idx) |
1492 L2T_IDX(ep->l2t->idx) |
1493 TX_CHAN(ep->tx_chan) |
1494 SMAC_SEL(ep->smac_idx) |
1495 DSCP(ep->tos) |
1496 ULP_MODE(ULP_MODE_TCPDDP) |
1497 RCV_BUFSIZ(rcv_win >> 10);
1498 req->tcb.opt2 = PACE(1) |
1499 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1500 RX_CHANNEL(0) |
1501 CCTRL_ECN(enable_ecn) |
1502 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1503 if (enable_tcp_timestamps)
1504 req->tcb.opt2 |= TSTAMPS_EN(1);
1505 if (enable_tcp_sack)
1506 req->tcb.opt2 |= SACK_EN(1);
1507 if (wscale && enable_tcp_window_scaling)
1508 req->tcb.opt2 |= WND_SCALE_EN(1);
1509 req->tcb.opt0 = cpu_to_be64(req->tcb.opt0);
1510 req->tcb.opt2 = cpu_to_be32(req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001511 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1512 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001513 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1514}
1515
Steve Wisecfdda9d2010-04-21 15:30:06 -07001516/*
1517 * Return whether a failed active open has allocated a TID
1518 */
1519static inline int act_open_has_tid(int status)
1520{
1521 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1522 status != CPL_ERR_ARP_MISS;
1523}
1524
Vipul Pandya793dad92012-12-10 09:30:56 +00001525#define ACT_OPEN_RETRY_COUNT 2
1526
1527static int c4iw_reconnect(struct c4iw_ep *ep)
1528{
1529 int err = 0;
1530 struct rtable *rt;
1531 struct port_info *pi;
1532 struct net_device *pdev;
1533 int step;
1534 struct neighbour *neigh;
1535
1536 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1537 init_timer(&ep->timer);
1538
1539 /*
1540 * Allocate an active TID to initiate a TCP connection.
1541 */
1542 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1543 if (ep->atid == -1) {
1544 pr_err("%s - cannot alloc atid.\n", __func__);
1545 err = -ENOMEM;
1546 goto fail2;
1547 }
1548 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1549
1550 /* find a route */
1551 rt = find_route(ep->com.dev,
1552 ep->com.cm_id->local_addr.sin_addr.s_addr,
1553 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1554 ep->com.cm_id->local_addr.sin_port,
1555 ep->com.cm_id->remote_addr.sin_port, 0);
1556 if (!rt) {
1557 pr_err("%s - cannot find route.\n", __func__);
1558 err = -EHOSTUNREACH;
1559 goto fail3;
1560 }
1561 ep->dst = &rt->dst;
1562
1563 neigh = dst_neigh_lookup(ep->dst,
1564 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1565 /* get a l2t entry */
1566 if (neigh->dev->flags & IFF_LOOPBACK) {
1567 PDBG("%s LOOPBACK\n", __func__);
1568 pdev = ip_dev_find(&init_net,
1569 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1570 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1571 neigh, pdev, 0);
1572 pi = (struct port_info *)netdev_priv(pdev);
1573 ep->mtu = pdev->mtu;
1574 ep->tx_chan = cxgb4_port_chan(pdev);
1575 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1576 dev_put(pdev);
1577 } else {
1578 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1579 neigh, neigh->dev, 0);
1580 pi = (struct port_info *)netdev_priv(neigh->dev);
1581 ep->mtu = dst_mtu(ep->dst);
1582 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1583 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1584 0x7F) << 1;
1585 }
1586
1587 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1588 ep->txq_idx = pi->port_id * step;
1589 ep->ctrlq_idx = pi->port_id;
1590 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1591 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1592
1593 if (!ep->l2t) {
1594 pr_err("%s - cannot alloc l2e.\n", __func__);
1595 err = -ENOMEM;
1596 goto fail4;
1597 }
1598
1599 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1600 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1601 ep->l2t->idx);
1602
1603 state_set(&ep->com, CONNECTING);
1604 ep->tos = 0;
1605
1606 /* send connect request to rnic */
1607 err = send_connect(ep);
1608 if (!err)
1609 goto out;
1610
1611 cxgb4_l2t_release(ep->l2t);
1612fail4:
1613 dst_release(ep->dst);
1614fail3:
1615 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1616 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1617fail2:
1618 /*
1619 * remember to send notification to upper layer.
1620 * We are in here so the upper layer is not aware that this is
1621 * re-connect attempt and so, upper layer is still waiting for
1622 * response of 1st connect request.
1623 */
1624 connect_reply_upcall(ep, -ECONNRESET);
1625 c4iw_put_ep(&ep->com);
1626out:
1627 return err;
1628}
1629
Steve Wisecfdda9d2010-04-21 15:30:06 -07001630static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1631{
1632 struct c4iw_ep *ep;
1633 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1634 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1635 ntohl(rpl->atid_status)));
1636 struct tid_info *t = dev->rdev.lldi.tids;
1637 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1638
1639 ep = lookup_atid(t, atid);
1640
1641 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1642 status, status2errno(status));
1643
1644 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1645 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1646 atid);
1647 return 0;
1648 }
1649
Vipul Pandya793dad92012-12-10 09:30:56 +00001650 set_bit(ACT_OPEN_RPL, &ep->com.history);
1651
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301652 /*
1653 * Log interesting failures.
1654 */
1655 switch (status) {
1656 case CPL_ERR_CONN_RESET:
1657 case CPL_ERR_CONN_TIMEDOUT:
1658 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001659 case CPL_ERR_TCAM_FULL:
Vipul Pandya793dad92012-12-10 09:30:56 +00001660 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1661 mutex_lock(&dev->rdev.stats.lock);
1662 dev->rdev.stats.tcam_full++;
1663 mutex_unlock(&dev->rdev.stats.lock);
1664 send_fw_act_open_req(ep,
1665 GET_TID_TID(GET_AOPEN_ATID(
1666 ntohl(rpl->atid_status))));
1667 return 0;
1668 }
1669 break;
1670 case CPL_ERR_CONN_EXIST:
1671 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1672 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1673 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1674 atid);
1675 cxgb4_free_atid(t, atid);
1676 dst_release(ep->dst);
1677 cxgb4_l2t_release(ep->l2t);
1678 c4iw_reconnect(ep);
1679 return 0;
1680 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001681 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301682 default:
1683 printk(KERN_INFO MOD "Active open failure - "
1684 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1685 atid, status, status2errno(status),
1686 &ep->com.local_addr.sin_addr.s_addr,
1687 ntohs(ep->com.local_addr.sin_port),
1688 &ep->com.remote_addr.sin_addr.s_addr,
1689 ntohs(ep->com.remote_addr.sin_port));
1690 break;
1691 }
1692
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693 connect_reply_upcall(ep, status2errno(status));
1694 state_set(&ep->com, DEAD);
1695
1696 if (status && act_open_has_tid(status))
1697 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1698
Vipul Pandya793dad92012-12-10 09:30:56 +00001699 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001700 cxgb4_free_atid(t, atid);
1701 dst_release(ep->dst);
1702 cxgb4_l2t_release(ep->l2t);
1703 c4iw_put_ep(&ep->com);
1704
1705 return 0;
1706}
1707
1708static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1709{
1710 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1711 struct tid_info *t = dev->rdev.lldi.tids;
1712 unsigned int stid = GET_TID(rpl);
1713 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1714
1715 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001716 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1717 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718 }
1719 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1720 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001721 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001722
Vipul Pandya1cab7752012-12-10 09:30:55 +00001723out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001724 return 0;
1725}
1726
1727static int listen_stop(struct c4iw_listen_ep *ep)
1728{
1729 struct sk_buff *skb;
1730 struct cpl_close_listsvr_req *req;
1731
1732 PDBG("%s ep %p\n", __func__, ep);
1733 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1734 if (!skb) {
1735 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1736 return -ENOMEM;
1737 }
1738 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1739 INIT_TP_WR(req, 0);
1740 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1741 ep->stid));
1742 req->reply_ctrl = cpu_to_be16(
1743 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1744 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1745 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1746}
1747
1748static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1749{
1750 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1751 struct tid_info *t = dev->rdev.lldi.tids;
1752 unsigned int stid = GET_TID(rpl);
1753 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1754
1755 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001756 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757 return 0;
1758}
1759
1760static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1761 struct cpl_pass_accept_req *req)
1762{
1763 struct cpl_pass_accept_rpl *rpl;
1764 unsigned int mtu_idx;
1765 u64 opt0;
1766 u32 opt2;
1767 int wscale;
1768
1769 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1770 BUG_ON(skb_cloned(skb));
1771 skb_trim(skb, sizeof(*rpl));
1772 skb_get(skb);
1773 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1774 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001775 opt0 = (nocong ? NO_CONG(1) : 0) |
1776 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001777 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001778 WND_SCALE(wscale) |
1779 MSS_IDX(mtu_idx) |
1780 L2T_IDX(ep->l2t->idx) |
1781 TX_CHAN(ep->tx_chan) |
1782 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001783 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001784 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001785 RCV_BUFSIZ(rcv_win>>10);
1786 opt2 = RX_CHANNEL(0) |
1787 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1788
1789 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1790 opt2 |= TSTAMPS_EN(1);
1791 if (enable_tcp_sack && req->tcpopt.sack)
1792 opt2 |= SACK_EN(1);
1793 if (wscale && enable_tcp_window_scaling)
1794 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001795 if (enable_ecn) {
1796 const struct tcphdr *tcph;
1797 u32 hlen = ntohl(req->hdr_len);
1798
1799 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1800 G_IP_HDR_LEN(hlen);
1801 if (tcph->ece && tcph->cwr)
1802 opt2 |= CCTRL_ECN(1);
1803 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804
1805 rpl = cplhdr(skb);
1806 INIT_TP_WR(rpl, ep->hwtid);
1807 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1808 ep->hwtid));
1809 rpl->opt0 = cpu_to_be64(opt0);
1810 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001811 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1813
1814 return;
1815}
1816
1817static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1818 struct sk_buff *skb)
1819{
1820 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1821 peer_ip);
1822 BUG_ON(skb_cloned(skb));
1823 skb_trim(skb, sizeof(struct cpl_tid_release));
1824 skb_get(skb);
1825 release_tid(&dev->rdev, hwtid, skb);
1826 return;
1827}
1828
1829static void get_4tuple(struct cpl_pass_accept_req *req,
1830 __be32 *local_ip, __be32 *peer_ip,
1831 __be16 *local_port, __be16 *peer_port)
1832{
1833 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1834 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1835 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1836 struct tcphdr *tcp = (struct tcphdr *)
1837 ((u8 *)(req + 1) + eth_len + ip_len);
1838
1839 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1840 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1841 ntohs(tcp->dest));
1842
1843 *peer_ip = ip->saddr;
1844 *local_ip = ip->daddr;
1845 *peer_port = tcp->source;
1846 *local_port = tcp->dest;
1847
1848 return;
1849}
1850
David Miller3786cf12011-12-02 16:52:31 +00001851static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1852 struct c4iw_dev *cdev, bool clear_mpa_v1)
1853{
1854 struct neighbour *n;
1855 int err, step;
1856
David Miller64b70072012-01-24 13:15:57 +00001857 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001858 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001859 return -ENODEV;
1860
1861 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001862 err = -ENOMEM;
1863 if (n->dev->flags & IFF_LOOPBACK) {
1864 struct net_device *pdev;
1865
1866 pdev = ip_dev_find(&init_net, peer_ip);
Thadeu Lima de Souza Cascardo71b43fd2012-05-17 17:51:53 -03001867 if (!pdev) {
1868 err = -ENODEV;
1869 goto out;
1870 }
David Miller3786cf12011-12-02 16:52:31 +00001871 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1872 n, pdev, 0);
1873 if (!ep->l2t)
1874 goto out;
1875 ep->mtu = pdev->mtu;
1876 ep->tx_chan = cxgb4_port_chan(pdev);
1877 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1878 step = cdev->rdev.lldi.ntxq /
1879 cdev->rdev.lldi.nchan;
1880 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1881 step = cdev->rdev.lldi.nrxq /
1882 cdev->rdev.lldi.nchan;
1883 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1884 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1885 cxgb4_port_idx(pdev) * step];
1886 dev_put(pdev);
1887 } else {
1888 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1889 n, n->dev, 0);
1890 if (!ep->l2t)
1891 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001892 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001893 ep->tx_chan = cxgb4_port_chan(n->dev);
1894 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1895 step = cdev->rdev.lldi.ntxq /
1896 cdev->rdev.lldi.nchan;
1897 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1898 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1899 step = cdev->rdev.lldi.nrxq /
1900 cdev->rdev.lldi.nchan;
1901 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1902 cxgb4_port_idx(n->dev) * step];
1903
1904 if (clear_mpa_v1) {
1905 ep->retry_with_mpa_v1 = 0;
1906 ep->tried_with_mpa_v1 = 0;
1907 }
1908 }
1909 err = 0;
1910out:
1911 rcu_read_unlock();
1912
David Miller64b70072012-01-24 13:15:57 +00001913 neigh_release(n);
1914
David Miller3786cf12011-12-02 16:52:31 +00001915 return err;
1916}
1917
Steve Wisecfdda9d2010-04-21 15:30:06 -07001918static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1919{
Vipul Pandya793dad92012-12-10 09:30:56 +00001920 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001921 struct cpl_pass_accept_req *req = cplhdr(skb);
1922 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1923 struct tid_info *t = dev->rdev.lldi.tids;
1924 unsigned int hwtid = GET_TID(req);
1925 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001926 struct rtable *rt;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001927 __be32 local_ip, peer_ip = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001928 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001929 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001930 u16 peer_mss = ntohs(req->tcpopt.mss);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001931
1932 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00001933 if (!parent_ep) {
1934 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1935 goto reject;
1936 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001937 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1938
Vipul Pandya1cab7752012-12-10 09:30:55 +00001939 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1940 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1941 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1942 ntohs(peer_port), peer_mss);
1943
Steve Wisecfdda9d2010-04-21 15:30:06 -07001944 if (state_read(&parent_ep->com) != LISTEN) {
1945 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1946 __func__);
1947 goto reject;
1948 }
1949
1950 /* Find output route */
1951 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1952 GET_POPEN_TOS(ntohl(req->tos_stid)));
1953 if (!rt) {
1954 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1955 __func__);
1956 goto reject;
1957 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001958 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001959
1960 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1961 if (!child_ep) {
1962 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1963 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001964 dst_release(dst);
1965 goto reject;
1966 }
David Miller3786cf12011-12-02 16:52:31 +00001967
1968 err = import_ep(child_ep, peer_ip, dst, dev, false);
1969 if (err) {
1970 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1971 __func__);
1972 dst_release(dst);
1973 kfree(child_ep);
1974 goto reject;
1975 }
1976
Vipul Pandya1cab7752012-12-10 09:30:55 +00001977 if (peer_mss && child_ep->mtu > (peer_mss + 40))
1978 child_ep->mtu = peer_mss + 40;
1979
Steve Wisecfdda9d2010-04-21 15:30:06 -07001980 state_set(&child_ep->com, CONNECTING);
1981 child_ep->com.dev = dev;
1982 child_ep->com.cm_id = NULL;
1983 child_ep->com.local_addr.sin_family = PF_INET;
1984 child_ep->com.local_addr.sin_port = local_port;
1985 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1986 child_ep->com.remote_addr.sin_family = PF_INET;
1987 child_ep->com.remote_addr.sin_port = peer_port;
1988 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1989 c4iw_get_ep(&parent_ep->com);
1990 child_ep->parent_ep = parent_ep;
1991 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001992 child_ep->dst = dst;
1993 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001994
1995 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00001996 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001997
1998 init_timer(&child_ep->timer);
1999 cxgb4_insert_tid(t, child_ep, hwtid);
2000 accept_cr(child_ep, peer_ip, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002001 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002002 goto out;
2003reject:
2004 reject_cr(dev, hwtid, peer_ip, skb);
2005out:
2006 return 0;
2007}
2008
2009static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2010{
2011 struct c4iw_ep *ep;
2012 struct cpl_pass_establish *req = cplhdr(skb);
2013 struct tid_info *t = dev->rdev.lldi.tids;
2014 unsigned int tid = GET_TID(req);
2015
2016 ep = lookup_tid(t, tid);
2017 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2018 ep->snd_seq = be32_to_cpu(req->snd_isn);
2019 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2020
Vipul Pandya1cab7752012-12-10 09:30:55 +00002021 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2022 ntohs(req->tcp_opt));
2023
Steve Wisecfdda9d2010-04-21 15:30:06 -07002024 set_emss(ep, ntohs(req->tcp_opt));
Vipul Pandya793dad92012-12-10 09:30:56 +00002025 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002026
2027 dst_confirm(ep->dst);
2028 state_set(&ep->com, MPA_REQ_WAIT);
2029 start_ep_timer(ep);
2030 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002031 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002032
2033 return 0;
2034}
2035
2036static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2037{
2038 struct cpl_peer_close *hdr = cplhdr(skb);
2039 struct c4iw_ep *ep;
2040 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002041 int disconnect = 1;
2042 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043 struct tid_info *t = dev->rdev.lldi.tids;
2044 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002045 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002046
2047 ep = lookup_tid(t, tid);
2048 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2049 dst_confirm(ep->dst);
2050
Vipul Pandya793dad92012-12-10 09:30:56 +00002051 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002052 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002053 switch (ep->com.state) {
2054 case MPA_REQ_WAIT:
2055 __state_set(&ep->com, CLOSING);
2056 break;
2057 case MPA_REQ_SENT:
2058 __state_set(&ep->com, CLOSING);
2059 connect_reply_upcall(ep, -ECONNRESET);
2060 break;
2061 case MPA_REQ_RCVD:
2062
2063 /*
2064 * We're gonna mark this puppy DEAD, but keep
2065 * the reference on it until the ULP accepts or
2066 * rejects the CR. Also wake up anyone waiting
2067 * in rdma connection migration (see c4iw_accept_cr()).
2068 */
2069 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002070 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002071 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002072 break;
2073 case MPA_REP_SENT:
2074 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002075 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002076 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077 break;
2078 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002079 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002080 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002081 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002082 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002083 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002084 if (ret != -ECONNRESET) {
2085 peer_close_upcall(ep);
2086 disconnect = 1;
2087 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002088 break;
2089 case ABORTING:
2090 disconnect = 0;
2091 break;
2092 case CLOSING:
2093 __state_set(&ep->com, MORIBUND);
2094 disconnect = 0;
2095 break;
2096 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002097 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002098 if (ep->com.cm_id && ep->com.qp) {
2099 attrs.next_state = C4IW_QP_STATE_IDLE;
2100 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2101 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2102 }
2103 close_complete_upcall(ep);
2104 __state_set(&ep->com, DEAD);
2105 release = 1;
2106 disconnect = 0;
2107 break;
2108 case DEAD:
2109 disconnect = 0;
2110 break;
2111 default:
2112 BUG_ON(1);
2113 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002114 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002115 if (disconnect)
2116 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2117 if (release)
2118 release_ep_resources(ep);
2119 return 0;
2120}
2121
2122/*
2123 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2124 */
2125static int is_neg_adv_abort(unsigned int status)
2126{
2127 return status == CPL_ERR_RTX_NEG_ADVICE ||
2128 status == CPL_ERR_PERSIST_NEG_ADVICE;
2129}
2130
2131static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2132{
2133 struct cpl_abort_req_rss *req = cplhdr(skb);
2134 struct c4iw_ep *ep;
2135 struct cpl_abort_rpl *rpl;
2136 struct sk_buff *rpl_skb;
2137 struct c4iw_qp_attributes attrs;
2138 int ret;
2139 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002140 struct tid_info *t = dev->rdev.lldi.tids;
2141 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002142
2143 ep = lookup_tid(t, tid);
2144 if (is_neg_adv_abort(req->status)) {
2145 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2146 ep->hwtid);
2147 return 0;
2148 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2150 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002151 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002152
2153 /*
2154 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302155 * However, this is not needed if com state is just
2156 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002157 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302158 if (ep->com.state != MPA_REQ_SENT)
2159 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002160
2161 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002162 switch (ep->com.state) {
2163 case CONNECTING:
2164 break;
2165 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002166 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002167 break;
2168 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002169 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302170 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
2171 connect_reply_upcall(ep, -ECONNRESET);
2172 else {
2173 /*
2174 * we just don't send notification upwards because we
2175 * want to retry with mpa_v1 without upper layers even
2176 * knowing it.
2177 *
2178 * do some housekeeping so as to re-initiate the
2179 * connection
2180 */
2181 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2182 mpa_rev);
2183 ep->retry_with_mpa_v1 = 1;
2184 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002185 break;
2186 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002187 break;
2188 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002189 break;
2190 case MORIBUND:
2191 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002192 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002193 /*FALLTHROUGH*/
2194 case FPDU_MODE:
2195 if (ep->com.cm_id && ep->com.qp) {
2196 attrs.next_state = C4IW_QP_STATE_ERROR;
2197 ret = c4iw_modify_qp(ep->com.qp->rhp,
2198 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2199 &attrs, 1);
2200 if (ret)
2201 printk(KERN_ERR MOD
2202 "%s - qp <- error failed!\n",
2203 __func__);
2204 }
2205 peer_abort_upcall(ep);
2206 break;
2207 case ABORTING:
2208 break;
2209 case DEAD:
2210 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002211 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002212 return 0;
2213 default:
2214 BUG_ON(1);
2215 break;
2216 }
2217 dst_confirm(ep->dst);
2218 if (ep->com.state != ABORTING) {
2219 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302220 /* we don't release if we want to retry with mpa_v1 */
2221 if (!ep->retry_with_mpa_v1)
2222 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002223 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002224 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225
2226 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2227 if (!rpl_skb) {
2228 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2229 __func__);
2230 release = 1;
2231 goto out;
2232 }
2233 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2234 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2235 INIT_TP_WR(rpl, ep->hwtid);
2236 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2237 rpl->cmd = CPL_ABORT_NO_RST;
2238 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2239out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 if (release)
2241 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302242
2243 /* retry with mpa-v1 */
2244 if (ep && ep->retry_with_mpa_v1) {
2245 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2246 dst_release(ep->dst);
2247 cxgb4_l2t_release(ep->l2t);
2248 c4iw_reconnect(ep);
2249 }
2250
Steve Wisecfdda9d2010-04-21 15:30:06 -07002251 return 0;
2252}
2253
2254static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2255{
2256 struct c4iw_ep *ep;
2257 struct c4iw_qp_attributes attrs;
2258 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259 int release = 0;
2260 struct tid_info *t = dev->rdev.lldi.tids;
2261 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002262
2263 ep = lookup_tid(t, tid);
2264
2265 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2266 BUG_ON(!ep);
2267
2268 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002269 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002270 switch (ep->com.state) {
2271 case CLOSING:
2272 __state_set(&ep->com, MORIBUND);
2273 break;
2274 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002275 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276 if ((ep->com.cm_id) && (ep->com.qp)) {
2277 attrs.next_state = C4IW_QP_STATE_IDLE;
2278 c4iw_modify_qp(ep->com.qp->rhp,
2279 ep->com.qp,
2280 C4IW_QP_ATTR_NEXT_STATE,
2281 &attrs, 1);
2282 }
2283 close_complete_upcall(ep);
2284 __state_set(&ep->com, DEAD);
2285 release = 1;
2286 break;
2287 case ABORTING:
2288 case DEAD:
2289 break;
2290 default:
2291 BUG_ON(1);
2292 break;
2293 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002294 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295 if (release)
2296 release_ep_resources(ep);
2297 return 0;
2298}
2299
2300static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2301{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002302 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002303 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002304 unsigned int tid = GET_TID(rpl);
2305 struct c4iw_ep *ep;
2306 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307
2308 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002309 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002310
Steve Wise30c95c22011-05-09 22:06:22 -07002311 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002312 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2313 ep->com.qp->wq.sq.qid);
2314 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2315 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2316 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2317 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002318 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 return 0;
2321}
2322
2323/*
2324 * Upcall from the adapter indicating data has been transmitted.
2325 * For us its just the single MPA request or reply. We can now free
2326 * the skb holding the mpa message.
2327 */
2328static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2329{
2330 struct c4iw_ep *ep;
2331 struct cpl_fw4_ack *hdr = cplhdr(skb);
2332 u8 credits = hdr->credits;
2333 unsigned int tid = GET_TID(hdr);
2334 struct tid_info *t = dev->rdev.lldi.tids;
2335
2336
2337 ep = lookup_tid(t, tid);
2338 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2339 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002340 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2341 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 return 0;
2343 }
2344
2345 dst_confirm(ep->dst);
2346 if (ep->mpa_skb) {
2347 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2348 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2349 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2350 kfree_skb(ep->mpa_skb);
2351 ep->mpa_skb = NULL;
2352 }
2353 return 0;
2354}
2355
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2357{
2358 int err;
2359 struct c4iw_ep *ep = to_ep(cm_id);
2360 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2361
2362 if (state_read(&ep->com) == DEAD) {
2363 c4iw_put_ep(&ep->com);
2364 return -ECONNRESET;
2365 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002366 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002367 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2368 if (mpa_rev == 0)
2369 abort_connection(ep, NULL, GFP_KERNEL);
2370 else {
2371 err = send_mpa_reject(ep, pdata, pdata_len);
2372 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2373 }
2374 c4iw_put_ep(&ep->com);
2375 return 0;
2376}
2377
2378int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2379{
2380 int err;
2381 struct c4iw_qp_attributes attrs;
2382 enum c4iw_qp_attr_mask mask;
2383 struct c4iw_ep *ep = to_ep(cm_id);
2384 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2385 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2386
2387 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2388 if (state_read(&ep->com) == DEAD) {
2389 err = -ECONNRESET;
2390 goto err;
2391 }
2392
2393 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2394 BUG_ON(!qp);
2395
Vipul Pandya793dad92012-12-10 09:30:56 +00002396 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002397 if ((conn_param->ord > c4iw_max_read_depth) ||
2398 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002399 abort_connection(ep, NULL, GFP_KERNEL);
2400 err = -EINVAL;
2401 goto err;
2402 }
2403
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302404 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2405 if (conn_param->ord > ep->ird) {
2406 ep->ird = conn_param->ird;
2407 ep->ord = conn_param->ord;
2408 send_mpa_reject(ep, conn_param->private_data,
2409 conn_param->private_data_len);
2410 abort_connection(ep, NULL, GFP_KERNEL);
2411 err = -ENOMEM;
2412 goto err;
2413 }
2414 if (conn_param->ird > ep->ord) {
2415 if (!ep->ord)
2416 conn_param->ird = 1;
2417 else {
2418 abort_connection(ep, NULL, GFP_KERNEL);
2419 err = -ENOMEM;
2420 goto err;
2421 }
2422 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302424 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425 ep->ird = conn_param->ird;
2426 ep->ord = conn_param->ord;
2427
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302428 if (ep->mpa_attr.version != 2)
2429 if (peer2peer && ep->ird == 0)
2430 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002431
2432 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2433
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302434 cm_id->add_ref(cm_id);
2435 ep->com.cm_id = cm_id;
2436 ep->com.qp = qp;
2437
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438 /* bind QP to EP and move to RTS */
2439 attrs.mpa_attr = ep->mpa_attr;
2440 attrs.max_ird = ep->ird;
2441 attrs.max_ord = ep->ord;
2442 attrs.llp_stream_handle = ep;
2443 attrs.next_state = C4IW_QP_STATE_RTS;
2444
2445 /* bind QP and TID with INIT_WR */
2446 mask = C4IW_QP_ATTR_NEXT_STATE |
2447 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2448 C4IW_QP_ATTR_MPA_ATTR |
2449 C4IW_QP_ATTR_MAX_IRD |
2450 C4IW_QP_ATTR_MAX_ORD;
2451
2452 err = c4iw_modify_qp(ep->com.qp->rhp,
2453 ep->com.qp, mask, &attrs, 1);
2454 if (err)
2455 goto err1;
2456 err = send_mpa_reply(ep, conn_param->private_data,
2457 conn_param->private_data_len);
2458 if (err)
2459 goto err1;
2460
2461 state_set(&ep->com, FPDU_MODE);
2462 established_upcall(ep);
2463 c4iw_put_ep(&ep->com);
2464 return 0;
2465err1:
2466 ep->com.cm_id = NULL;
2467 ep->com.qp = NULL;
2468 cm_id->rem_ref(cm_id);
2469err:
2470 c4iw_put_ep(&ep->com);
2471 return err;
2472}
2473
2474int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2475{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002476 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2477 struct c4iw_ep *ep;
2478 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002479 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002481 if ((conn_param->ord > c4iw_max_read_depth) ||
2482 (conn_param->ird > c4iw_max_read_depth)) {
2483 err = -EINVAL;
2484 goto out;
2485 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2487 if (!ep) {
2488 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2489 err = -ENOMEM;
2490 goto out;
2491 }
2492 init_timer(&ep->timer);
2493 ep->plen = conn_param->private_data_len;
2494 if (ep->plen)
2495 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2496 conn_param->private_data, ep->plen);
2497 ep->ird = conn_param->ird;
2498 ep->ord = conn_param->ord;
2499
2500 if (peer2peer && ep->ord == 0)
2501 ep->ord = 1;
2502
2503 cm_id->add_ref(cm_id);
2504 ep->com.dev = dev;
2505 ep->com.cm_id = cm_id;
2506 ep->com.qp = get_qhp(dev, conn_param->qpn);
2507 BUG_ON(!ep->com.qp);
2508 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2509 ep->com.qp, cm_id);
2510
2511 /*
2512 * Allocate an active TID to initiate a TCP connection.
2513 */
2514 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2515 if (ep->atid == -1) {
2516 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2517 err = -ENOMEM;
2518 goto fail2;
2519 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002520 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002521
2522 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2523 ntohl(cm_id->local_addr.sin_addr.s_addr),
2524 ntohs(cm_id->local_addr.sin_port),
2525 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2526 ntohs(cm_id->remote_addr.sin_port));
2527
2528 /* find a route */
2529 rt = find_route(dev,
2530 cm_id->local_addr.sin_addr.s_addr,
2531 cm_id->remote_addr.sin_addr.s_addr,
2532 cm_id->local_addr.sin_port,
2533 cm_id->remote_addr.sin_port, 0);
2534 if (!rt) {
2535 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2536 err = -EHOSTUNREACH;
2537 goto fail3;
2538 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002539 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002540
David Miller3786cf12011-12-02 16:52:31 +00002541 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2542 ep->dst, ep->com.dev, true);
2543 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002544 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 goto fail4;
2546 }
2547
2548 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2549 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2550 ep->l2t->idx);
2551
2552 state_set(&ep->com, CONNECTING);
2553 ep->tos = 0;
2554 ep->com.local_addr = cm_id->local_addr;
2555 ep->com.remote_addr = cm_id->remote_addr;
2556
2557 /* send connect request to rnic */
2558 err = send_connect(ep);
2559 if (!err)
2560 goto out;
2561
2562 cxgb4_l2t_release(ep->l2t);
2563fail4:
2564 dst_release(ep->dst);
2565fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002566 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2568fail2:
2569 cm_id->rem_ref(cm_id);
2570 c4iw_put_ep(&ep->com);
2571out:
2572 return err;
2573}
2574
2575int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2576{
2577 int err = 0;
2578 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2579 struct c4iw_listen_ep *ep;
2580
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581 might_sleep();
2582
2583 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2584 if (!ep) {
2585 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2586 err = -ENOMEM;
2587 goto fail1;
2588 }
2589 PDBG("%s ep %p\n", __func__, ep);
2590 cm_id->add_ref(cm_id);
2591 ep->com.cm_id = cm_id;
2592 ep->com.dev = dev;
2593 ep->backlog = backlog;
2594 ep->com.local_addr = cm_id->local_addr;
2595
2596 /*
2597 * Allocate a server TID.
2598 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002599 if (dev->rdev.lldi.enable_fw_ofld_conn)
2600 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2601 else
2602 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2603
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002605 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002606 err = -ENOMEM;
2607 goto fail2;
2608 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002609 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002610 state_set(&ep->com, LISTEN);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002611 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2612 do {
2613 err = cxgb4_create_server_filter(
2614 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2615 ep->com.local_addr.sin_addr.s_addr,
2616 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002617 0,
2618 ep->com.dev->rdev.lldi.rxq_ids[0],
2619 0,
2620 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002621 if (err == -EBUSY) {
2622 set_current_state(TASK_UNINTERRUPTIBLE);
2623 schedule_timeout(usecs_to_jiffies(100));
2624 }
2625 } while (err == -EBUSY);
2626 } else {
2627 c4iw_init_wr_wait(&ep->com.wr_wait);
2628 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2629 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2630 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002631 0,
Vipul Pandya1cab7752012-12-10 09:30:55 +00002632 ep->com.dev->rdev.lldi.rxq_ids[0]);
2633 if (!err)
2634 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2635 &ep->com.wr_wait,
2636 0, 0, __func__);
2637 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002638 if (!err) {
2639 cm_id->provider_data = ep;
2640 goto out;
2641 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002642 pr_err("%s cxgb4_create_server/filter failed err %d " \
2643 "stid %d laddr %08x lport %d\n", \
2644 __func__, err, ep->stid,
2645 ntohl(ep->com.local_addr.sin_addr.s_addr),
2646 ntohs(ep->com.local_addr.sin_port));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2648fail2:
2649 cm_id->rem_ref(cm_id);
2650 c4iw_put_ep(&ep->com);
2651fail1:
2652out:
2653 return err;
2654}
2655
2656int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2657{
2658 int err;
2659 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2660
2661 PDBG("%s ep %p\n", __func__, ep);
2662
2663 might_sleep();
2664 state_set(&ep->com, DEAD);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002665 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2666 err = cxgb4_remove_server_filter(
2667 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2668 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2669 } else {
2670 c4iw_init_wr_wait(&ep->com.wr_wait);
2671 err = listen_stop(ep);
2672 if (err)
2673 goto done;
2674 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2675 0, 0, __func__);
2676 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002677 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002678 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2679done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 cm_id->rem_ref(cm_id);
2681 c4iw_put_ep(&ep->com);
2682 return err;
2683}
2684
2685int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2686{
2687 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 int close = 0;
2689 int fatal = 0;
2690 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691
Steve Wise2f5b48c2010-09-10 11:15:36 -05002692 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693
2694 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2695 states[ep->com.state], abrupt);
2696
2697 rdev = &ep->com.dev->rdev;
2698 if (c4iw_fatal_error(rdev)) {
2699 fatal = 1;
2700 close_complete_upcall(ep);
2701 ep->com.state = DEAD;
2702 }
2703 switch (ep->com.state) {
2704 case MPA_REQ_WAIT:
2705 case MPA_REQ_SENT:
2706 case MPA_REQ_RCVD:
2707 case MPA_REP_SENT:
2708 case FPDU_MODE:
2709 close = 1;
2710 if (abrupt)
2711 ep->com.state = ABORTING;
2712 else {
2713 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002714 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 }
2716 set_bit(CLOSE_SENT, &ep->com.flags);
2717 break;
2718 case CLOSING:
2719 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2720 close = 1;
2721 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002722 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002723 ep->com.state = ABORTING;
2724 } else
2725 ep->com.state = MORIBUND;
2726 }
2727 break;
2728 case MORIBUND:
2729 case ABORTING:
2730 case DEAD:
2731 PDBG("%s ignoring disconnect ep %p state %u\n",
2732 __func__, ep, ep->com.state);
2733 break;
2734 default:
2735 BUG();
2736 break;
2737 }
2738
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002740 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002741 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002742 close_complete_upcall(ep);
2743 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002744 } else {
2745 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002746 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002747 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748 if (ret)
2749 fatal = 1;
2750 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002751 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 if (fatal)
2753 release_ep_resources(ep);
2754 return ret;
2755}
2756
Vipul Pandya1cab7752012-12-10 09:30:55 +00002757static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2758 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2759{
2760 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00002761 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002762
2763 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, req->tid);
2764 if (!ep)
2765 return;
2766
2767 switch (req->retval) {
2768 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00002769 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2770 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2771 send_fw_act_open_req(ep, atid);
2772 return;
2773 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002774 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00002775 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2776 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2777 send_fw_act_open_req(ep, atid);
2778 return;
2779 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002780 break;
2781 default:
2782 pr_info("%s unexpected ofld conn wr retval %d\n",
2783 __func__, req->retval);
2784 break;
2785 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002786 pr_err("active ofld_connect_wr failure %d atid %d\n",
2787 req->retval, atid);
2788 mutex_lock(&dev->rdev.stats.lock);
2789 dev->rdev.stats.act_ofld_conn_fails++;
2790 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002791 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00002792 state_set(&ep->com, DEAD);
2793 remove_handle(dev, &dev->atid_idr, atid);
2794 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2795 dst_release(ep->dst);
2796 cxgb4_l2t_release(ep->l2t);
2797 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002798}
2799
2800static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2801 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2802{
2803 struct sk_buff *rpl_skb;
2804 struct cpl_pass_accept_req *cpl;
2805 int ret;
2806
2807 rpl_skb = (struct sk_buff *)cpu_to_be64(req->cookie);
2808 BUG_ON(!rpl_skb);
2809 if (req->retval) {
2810 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00002811 mutex_lock(&dev->rdev.stats.lock);
2812 dev->rdev.stats.pas_ofld_conn_fails++;
2813 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002814 kfree_skb(rpl_skb);
2815 } else {
2816 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2817 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2818 htonl(req->tid)));
2819 ret = pass_accept_req(dev, rpl_skb);
2820 if (!ret)
2821 kfree_skb(rpl_skb);
2822 }
2823 return;
2824}
2825
2826static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05002827{
2828 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002829 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2830
2831 switch (rpl->type) {
2832 case FW6_TYPE_CQE:
2833 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2834 break;
2835 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2836 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2837 switch (req->t_state) {
2838 case TCP_SYN_SENT:
2839 active_ofld_conn_reply(dev, skb, req);
2840 break;
2841 case TCP_SYN_RECV:
2842 passive_ofld_conn_reply(dev, skb, req);
2843 break;
2844 default:
2845 pr_err("%s unexpected ofld conn wr state %d\n",
2846 __func__, req->t_state);
2847 break;
2848 }
2849 break;
2850 }
2851 return 0;
2852}
2853
2854static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2855{
2856 u32 l2info;
2857 u16 vlantag, len, hdr_len;
2858 u8 intf;
2859 struct cpl_rx_pkt *cpl = cplhdr(skb);
2860 struct cpl_pass_accept_req *req;
2861 struct tcp_options_received tmp_opt;
2862
2863 /* Store values from cpl_rx_pkt in temporary location. */
2864 vlantag = cpl->vlan;
2865 len = cpl->len;
2866 l2info = cpl->l2info;
2867 hdr_len = cpl->hdr_len;
2868 intf = cpl->iff;
2869
2870 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2871
2872 /*
2873 * We need to parse the TCP options from SYN packet.
2874 * to generate cpl_pass_accept_req.
2875 */
2876 memset(&tmp_opt, 0, sizeof(tmp_opt));
2877 tcp_clear_options(&tmp_opt);
2878 tcp_parse_options(skb, &tmp_opt, 0, 0, NULL);
2879
2880 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2881 memset(req, 0, sizeof(*req));
2882 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2883 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info))) |
2884 F_SYN_XACT_MATCH);
2885 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info))) |
2886 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len))) |
2887 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len))) |
2888 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info))));
2889 req->vlan = vlantag;
2890 req->len = len;
2891 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2892 PASS_OPEN_TOS(tos));
2893 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2894 if (tmp_opt.wscale_ok)
2895 req->tcpopt.wsf = tmp_opt.snd_wscale;
2896 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2897 if (tmp_opt.sack_ok)
2898 req->tcpopt.sack = 1;
2899 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2900 return;
2901}
2902
2903static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2904 __be32 laddr, __be16 lport,
2905 __be32 raddr, __be16 rport,
2906 u32 rcv_isn, u32 filter, u16 window,
2907 u32 rss_qid, u8 port_id)
2908{
2909 struct sk_buff *req_skb;
2910 struct fw_ofld_connection_wr *req;
2911 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2912
2913 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2914 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2915 memset(req, 0, sizeof(*req));
2916 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2917 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2918 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2919 req->le.filter = filter;
2920 req->le.lport = lport;
2921 req->le.pport = rport;
2922 req->le.u.ipv4.lip = laddr;
2923 req->le.u.ipv4.pip = raddr;
2924 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2925 req->tcb.rcv_adv = htons(window);
2926 req->tcb.t_state_to_astid =
2927 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2928 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2929 V_FW_OFLD_CONNECTION_WR_ASTID(
2930 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2931
2932 /*
2933 * We store the qid in opt2 which will be used by the firmware
2934 * to send us the wr response.
2935 */
2936 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2937
2938 /*
2939 * We initialize the MSS index in TCB to 0xF.
2940 * So that when driver sends cpl_pass_accept_rpl
2941 * TCB picks up the correct value. If this was 0
2942 * TP will ignore any value > 0 for MSS index.
2943 */
2944 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2945 req->cookie = cpu_to_be64((u64)skb);
2946
2947 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2948 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2949}
2950
2951/*
2952 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2953 * messages when a filter is being used instead of server to
2954 * redirect a syn packet. When packets hit filter they are redirected
2955 * to the offload queue and driver tries to establish the connection
2956 * using firmware work request.
2957 */
2958static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
2959{
2960 int stid;
2961 unsigned int filter;
2962 struct ethhdr *eh = NULL;
2963 struct vlan_ethhdr *vlan_eh = NULL;
2964 struct iphdr *iph;
2965 struct tcphdr *tcph;
2966 struct rss_header *rss = (void *)skb->data;
2967 struct cpl_rx_pkt *cpl = (void *)skb->data;
2968 struct cpl_pass_accept_req *req = (void *)(rss + 1);
2969 struct l2t_entry *e;
2970 struct dst_entry *dst;
2971 struct rtable *rt;
2972 struct c4iw_ep *lep;
2973 u16 window;
2974 struct port_info *pi;
2975 struct net_device *pdev;
2976 u16 rss_qid;
2977 int step;
2978 u32 tx_chan;
2979 struct neighbour *neigh;
2980
2981 /* Drop all non-SYN packets */
2982 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
2983 goto reject;
2984
2985 /*
2986 * Drop all packets which did not hit the filter.
2987 * Unlikely to happen.
2988 */
2989 if (!(rss->filter_hit && rss->filter_tid))
2990 goto reject;
2991
2992 /*
2993 * Calculate the server tid from filter hit index from cpl_rx_pkt.
2994 */
2995 stid = cpu_to_be32(rss->hash_val) - dev->rdev.lldi.tids->sftid_base
2996 + dev->rdev.lldi.tids->nstids;
2997
2998 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
2999 if (!lep) {
3000 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3001 goto reject;
3002 }
3003
3004 if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
3005 eh = (struct ethhdr *)(req + 1);
3006 iph = (struct iphdr *)(eh + 1);
3007 } else {
3008 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3009 iph = (struct iphdr *)(vlan_eh + 1);
3010 skb->vlan_tci = ntohs(cpl->vlan);
3011 }
3012
3013 if (iph->version != 0x4)
3014 goto reject;
3015
3016 tcph = (struct tcphdr *)(iph + 1);
3017 skb_set_network_header(skb, (void *)iph - (void *)rss);
3018 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3019 skb_get(skb);
3020
3021 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3022 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3023 ntohs(tcph->source), iph->tos);
3024
3025 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3026 iph->tos);
3027 if (!rt) {
3028 pr_err("%s - failed to find dst entry!\n",
3029 __func__);
3030 goto reject;
3031 }
3032 dst = &rt->dst;
3033 neigh = dst_neigh_lookup_skb(dst, skb);
3034
3035 if (neigh->dev->flags & IFF_LOOPBACK) {
3036 pdev = ip_dev_find(&init_net, iph->daddr);
3037 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3038 pdev, 0);
3039 pi = (struct port_info *)netdev_priv(pdev);
3040 tx_chan = cxgb4_port_chan(pdev);
3041 dev_put(pdev);
3042 } else {
3043 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3044 neigh->dev, 0);
3045 pi = (struct port_info *)netdev_priv(neigh->dev);
3046 tx_chan = cxgb4_port_chan(neigh->dev);
3047 }
3048 if (!e) {
3049 pr_err("%s - failed to allocate l2t entry!\n",
3050 __func__);
3051 goto free_dst;
3052 }
3053
3054 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3055 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3056 window = htons(tcph->window);
3057
3058 /* Calcuate filter portion for LE region. */
3059 filter = cpu_to_be32(select_ntuple(dev, dst, e));
3060
3061 /*
3062 * Synthesize the cpl_pass_accept_req. We have everything except the
3063 * TID. Once firmware sends a reply with TID we update the TID field
3064 * in cpl and pass it through the regular cpl_pass_accept_req path.
3065 */
3066 build_cpl_pass_accept_req(skb, stid, iph->tos);
3067 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3068 tcph->source, ntohl(tcph->seq), filter, window,
3069 rss_qid, pi->port_id);
3070 cxgb4_l2t_release(e);
3071free_dst:
3072 dst_release(dst);
3073reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003074 return 0;
3075}
3076
Steve Wisecfdda9d2010-04-21 15:30:06 -07003077/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003078 * These are the real handlers that are called from a
3079 * work queue.
3080 */
3081static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3082 [CPL_ACT_ESTABLISH] = act_establish,
3083 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3084 [CPL_RX_DATA] = rx_data,
3085 [CPL_ABORT_RPL_RSS] = abort_rpl,
3086 [CPL_ABORT_RPL] = abort_rpl,
3087 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3088 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3089 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3090 [CPL_PASS_ESTABLISH] = pass_establish,
3091 [CPL_PEER_CLOSE] = peer_close,
3092 [CPL_ABORT_REQ_RSS] = peer_abort,
3093 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3094 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003095 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003096 [CPL_FW6_MSG] = deferred_fw6_msg,
3097 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003098};
3099
3100static void process_timeout(struct c4iw_ep *ep)
3101{
3102 struct c4iw_qp_attributes attrs;
3103 int abort = 1;
3104
Steve Wise2f5b48c2010-09-10 11:15:36 -05003105 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003106 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3107 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003108 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003109 switch (ep->com.state) {
3110 case MPA_REQ_SENT:
3111 __state_set(&ep->com, ABORTING);
3112 connect_reply_upcall(ep, -ETIMEDOUT);
3113 break;
3114 case MPA_REQ_WAIT:
3115 __state_set(&ep->com, ABORTING);
3116 break;
3117 case CLOSING:
3118 case MORIBUND:
3119 if (ep->com.cm_id && ep->com.qp) {
3120 attrs.next_state = C4IW_QP_STATE_ERROR;
3121 c4iw_modify_qp(ep->com.qp->rhp,
3122 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3123 &attrs, 1);
3124 }
3125 __state_set(&ep->com, ABORTING);
3126 break;
3127 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003128 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003129 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003130 abort = 0;
3131 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003132 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003133 if (abort)
3134 abort_connection(ep, NULL, GFP_KERNEL);
3135 c4iw_put_ep(&ep->com);
3136}
3137
3138static void process_timedout_eps(void)
3139{
3140 struct c4iw_ep *ep;
3141
3142 spin_lock_irq(&timeout_lock);
3143 while (!list_empty(&timeout_list)) {
3144 struct list_head *tmp;
3145
3146 tmp = timeout_list.next;
3147 list_del(tmp);
3148 spin_unlock_irq(&timeout_lock);
3149 ep = list_entry(tmp, struct c4iw_ep, entry);
3150 process_timeout(ep);
3151 spin_lock_irq(&timeout_lock);
3152 }
3153 spin_unlock_irq(&timeout_lock);
3154}
3155
3156static void process_work(struct work_struct *work)
3157{
3158 struct sk_buff *skb = NULL;
3159 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003160 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003161 unsigned int opcode;
3162 int ret;
3163
3164 while ((skb = skb_dequeue(&rxq))) {
3165 rpl = cplhdr(skb);
3166 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3167 opcode = rpl->ot.opcode;
3168
3169 BUG_ON(!work_handlers[opcode]);
3170 ret = work_handlers[opcode](dev, skb);
3171 if (!ret)
3172 kfree_skb(skb);
3173 }
3174 process_timedout_eps();
3175}
3176
3177static DECLARE_WORK(skb_work, process_work);
3178
3179static void ep_timeout(unsigned long arg)
3180{
3181 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
3182
3183 spin_lock(&timeout_lock);
3184 list_add_tail(&ep->entry, &timeout_list);
3185 spin_unlock(&timeout_lock);
3186 queue_work(workq, &skb_work);
3187}
3188
3189/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003190 * All the CM events are handled on a work queue to have a safe context.
3191 */
3192static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3193{
3194
3195 /*
3196 * Save dev in the skb->cb area.
3197 */
3198 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3199
3200 /*
3201 * Queue the skb and schedule the worker thread.
3202 */
3203 skb_queue_tail(&rxq, skb);
3204 queue_work(workq, &skb_work);
3205 return 0;
3206}
3207
3208static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3209{
3210 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3211
3212 if (rpl->status != CPL_ERR_NONE) {
3213 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3214 "for tid %u\n", rpl->status, GET_TID(rpl));
3215 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003216 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003217 return 0;
3218}
3219
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003220static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3221{
3222 struct cpl_fw6_msg *rpl = cplhdr(skb);
3223 struct c4iw_wr_wait *wr_waitp;
3224 int ret;
3225
3226 PDBG("%s type %u\n", __func__, rpl->type);
3227
3228 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003229 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003230 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003231 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003232 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003233 if (wr_waitp)
3234 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003235 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003236 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003237 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003238 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003239 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003240 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003241 default:
3242 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3243 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003244 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003245 break;
3246 }
3247 return 0;
3248}
3249
Steve Wise8da7e7a2011-06-14 20:59:27 +00003250static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3251{
3252 struct cpl_abort_req_rss *req = cplhdr(skb);
3253 struct c4iw_ep *ep;
3254 struct tid_info *t = dev->rdev.lldi.tids;
3255 unsigned int tid = GET_TID(req);
3256
3257 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003258 if (!ep) {
3259 printk(KERN_WARNING MOD
3260 "Abort on non-existent endpoint, tid %d\n", tid);
3261 kfree_skb(skb);
3262 return 0;
3263 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003264 if (is_neg_adv_abort(req->status)) {
3265 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3266 ep->hwtid);
3267 kfree_skb(skb);
3268 return 0;
3269 }
3270 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3271 ep->com.state);
3272
3273 /*
3274 * Wake up any threads in rdma_init() or rdma_fini().
3275 */
Steve Wise0f1dcfa2012-04-27 09:59:16 -05003276 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003277 sched(dev, skb);
3278 return 0;
3279}
3280
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003281/*
3282 * Most upcalls from the T4 Core go to sched() to
3283 * schedule the processing on a work queue.
3284 */
3285c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3286 [CPL_ACT_ESTABLISH] = sched,
3287 [CPL_ACT_OPEN_RPL] = sched,
3288 [CPL_RX_DATA] = sched,
3289 [CPL_ABORT_RPL_RSS] = sched,
3290 [CPL_ABORT_RPL] = sched,
3291 [CPL_PASS_OPEN_RPL] = sched,
3292 [CPL_CLOSE_LISTSRV_RPL] = sched,
3293 [CPL_PASS_ACCEPT_REQ] = sched,
3294 [CPL_PASS_ESTABLISH] = sched,
3295 [CPL_PEER_CLOSE] = sched,
3296 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003297 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003298 [CPL_RDMA_TERMINATE] = sched,
3299 [CPL_FW4_ACK] = sched,
3300 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003301 [CPL_FW6_MSG] = fw6_msg,
3302 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003303};
3304
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305int __init c4iw_cm_init(void)
3306{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003307 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003308 skb_queue_head_init(&rxq);
3309
3310 workq = create_singlethread_workqueue("iw_cxgb4");
3311 if (!workq)
3312 return -ENOMEM;
3313
Steve Wisecfdda9d2010-04-21 15:30:06 -07003314 return 0;
3315}
3316
3317void __exit c4iw_cm_term(void)
3318{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003319 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003320 flush_workqueue(workq);
3321 destroy_workqueue(workq);
3322}