blob: ab5b4dd39dec0eb6bc6942cb0558780e0cd27656 [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
Vipul Pandya325abea2013-01-07 13:11:53 +0000146static void deref_qp(struct c4iw_ep *ep)
147{
148 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
149 clear_bit(QP_REFERENCED, &ep->com.flags);
150}
151
152static void ref_qp(struct c4iw_ep *ep)
153{
154 set_bit(QP_REFERENCED, &ep->com.flags);
155 c4iw_qp_add_ref(&ep->com.qp->ibqp);
156}
157
Steve Wisecfdda9d2010-04-21 15:30:06 -0700158static void start_ep_timer(struct c4iw_ep *ep)
159{
160 PDBG("%s ep %p\n", __func__, ep);
161 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000162 pr_err("%s timer already started! ep %p\n",
163 __func__, ep);
164 return;
165 }
166 clear_bit(TIMEOUT, &ep->com.flags);
167 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700168 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
169 ep->timer.data = (unsigned long)ep;
170 ep->timer.function = ep_timeout;
171 add_timer(&ep->timer);
172}
173
174static void stop_ep_timer(struct c4iw_ep *ep)
175{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000176 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700177 del_timer_sync(&ep->timer);
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000178 if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
179 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180}
181
182static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
183 struct l2t_entry *l2e)
184{
185 int error = 0;
186
187 if (c4iw_fatal_error(rdev)) {
188 kfree_skb(skb);
189 PDBG("%s - device in error state - dropping\n", __func__);
190 return -EIO;
191 }
192 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
193 if (error < 0)
194 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500195 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700196}
197
198int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
199{
200 int error = 0;
201
202 if (c4iw_fatal_error(rdev)) {
203 kfree_skb(skb);
204 PDBG("%s - device in error state - dropping\n", __func__);
205 return -EIO;
206 }
207 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
208 if (error < 0)
209 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500210 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700211}
212
213static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
214{
215 struct cpl_tid_release *req;
216
217 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
218 if (!skb)
219 return;
220 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
221 INIT_TP_WR(req, hwtid);
222 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
223 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
224 c4iw_ofld_send(rdev, skb);
225 return;
226}
227
228static void set_emss(struct c4iw_ep *ep, u16 opt)
229{
230 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
231 ep->mss = ep->emss;
232 if (GET_TCPOPT_TSTAMP(opt))
233 ep->emss -= 12;
234 if (ep->emss < 128)
235 ep->emss = 128;
236 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
237 ep->mss, ep->emss);
238}
239
240static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
241{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700242 enum c4iw_ep_state state;
243
Steve Wise2f5b48c2010-09-10 11:15:36 -0500244 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700245 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500246 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 return state;
248}
249
250static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
251{
252 epc->state = new;
253}
254
255static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
256{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500257 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700258 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
259 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500260 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 return;
262}
263
264static void *alloc_ep(int size, gfp_t gfp)
265{
266 struct c4iw_ep_common *epc;
267
268 epc = kzalloc(size, gfp);
269 if (epc) {
270 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500271 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500272 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700273 }
274 PDBG("%s alloc ep %p\n", __func__, epc);
275 return epc;
276}
277
278void _c4iw_free_ep(struct kref *kref)
279{
280 struct c4iw_ep *ep;
281
282 ep = container_of(kref, struct c4iw_ep, com.kref);
283 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000284 if (test_bit(QP_REFERENCED, &ep->com.flags))
285 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700286 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
287 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
288 dst_release(ep->dst);
289 cxgb4_l2t_release(ep->l2t);
Vipul Pandya793dad92012-12-10 09:30:56 +0000290 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 }
292 kfree(ep);
293}
294
295static void release_ep_resources(struct c4iw_ep *ep)
296{
297 set_bit(RELEASE_RESOURCES, &ep->com.flags);
298 c4iw_put_ep(&ep->com);
299}
300
Steve Wisecfdda9d2010-04-21 15:30:06 -0700301static int status2errno(int status)
302{
303 switch (status) {
304 case CPL_ERR_NONE:
305 return 0;
306 case CPL_ERR_CONN_RESET:
307 return -ECONNRESET;
308 case CPL_ERR_ARP_MISS:
309 return -EHOSTUNREACH;
310 case CPL_ERR_CONN_TIMEDOUT:
311 return -ETIMEDOUT;
312 case CPL_ERR_TCAM_FULL:
313 return -ENOMEM;
314 case CPL_ERR_CONN_EXIST:
315 return -EADDRINUSE;
316 default:
317 return -EIO;
318 }
319}
320
321/*
322 * Try and reuse skbs already allocated...
323 */
324static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
325{
326 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
327 skb_trim(skb, 0);
328 skb_get(skb);
329 skb_reset_transport_header(skb);
330 } else {
331 skb = alloc_skb(len, gfp);
332 }
333 return skb;
334}
335
336static struct rtable *find_route(struct c4iw_dev *dev, __be32 local_ip,
337 __be32 peer_ip, __be16 local_port,
338 __be16 peer_port, u8 tos)
339{
340 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700341 struct flowi4 fl4;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700342
David S. Miller31e4543d2011-05-03 20:25:42 -0700343 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500344 peer_port, local_port, IPPROTO_TCP,
345 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800346 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700347 return NULL;
348 return rt;
349}
350
351static void arp_failure_discard(void *handle, struct sk_buff *skb)
352{
353 PDBG("%s c4iw_dev %p\n", __func__, handle);
354 kfree_skb(skb);
355}
356
357/*
358 * Handle an ARP failure for an active open.
359 */
360static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
361{
362 printk(KERN_ERR MOD "ARP failure duing connect\n");
363 kfree_skb(skb);
364}
365
366/*
367 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
368 * and send it along.
369 */
370static void abort_arp_failure(void *handle, struct sk_buff *skb)
371{
372 struct c4iw_rdev *rdev = handle;
373 struct cpl_abort_req *req = cplhdr(skb);
374
375 PDBG("%s rdev %p\n", __func__, rdev);
376 req->cmd = CPL_ABORT_NO_RST;
377 c4iw_ofld_send(rdev, skb);
378}
379
380static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
381{
382 unsigned int flowclen = 80;
383 struct fw_flowc_wr *flowc;
384 int i;
385
386 skb = get_skb(skb, flowclen, GFP_KERNEL);
387 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
388
389 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
390 FW_FLOWC_WR_NPARAMS(8));
391 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
392 16)) | FW_WR_FLOWID(ep->hwtid));
393
394 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000395 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700396 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
397 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
398 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
399 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
400 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
401 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
402 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
403 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
404 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
405 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
406 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
407 flowc->mnemval[6].val = cpu_to_be32(snd_win);
408 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
409 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
410 /* Pad WR to 16 byte boundary */
411 flowc->mnemval[8].mnemonic = 0;
412 flowc->mnemval[8].val = 0;
413 for (i = 0; i < 9; i++) {
414 flowc->mnemval[i].r4[0] = 0;
415 flowc->mnemval[i].r4[1] = 0;
416 flowc->mnemval[i].r4[2] = 0;
417 }
418
419 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
420 c4iw_ofld_send(&ep->com.dev->rdev, skb);
421}
422
423static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
424{
425 struct cpl_close_con_req *req;
426 struct sk_buff *skb;
427 int wrlen = roundup(sizeof *req, 16);
428
429 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
430 skb = get_skb(NULL, wrlen, gfp);
431 if (!skb) {
432 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
433 return -ENOMEM;
434 }
435 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
436 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
437 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
438 memset(req, 0, wrlen);
439 INIT_TP_WR(req, ep->hwtid);
440 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
441 ep->hwtid));
442 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
443}
444
445static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
446{
447 struct cpl_abort_req *req;
448 int wrlen = roundup(sizeof *req, 16);
449
450 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
451 skb = get_skb(skb, wrlen, gfp);
452 if (!skb) {
453 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
454 __func__);
455 return -ENOMEM;
456 }
457 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
458 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
459 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
460 memset(req, 0, wrlen);
461 INIT_TP_WR(req, ep->hwtid);
462 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
463 req->cmd = CPL_ABORT_SEND_RST;
464 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
465}
466
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000467#define VLAN_NONE 0xfff
468#define FILTER_SEL_VLAN_NONE 0xffff
469#define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
470#define FILTER_SEL_WIDTH_VIN_P_FC \
471 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
472#define FILTER_SEL_WIDTH_TAG_P_FC \
473 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
474#define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
475
476static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
477 struct l2t_entry *l2t)
478{
479 unsigned int ntuple = 0;
480 u32 viid;
481
482 switch (dev->rdev.lldi.filt_mode) {
483
484 /* default filter mode */
485 case HW_TPL_FR_MT_PR_IV_P_FC:
486 if (l2t->vlan == VLAN_NONE)
487 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
488 else {
489 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
490 ntuple |= 1 << FILTER_SEL_WIDTH_VLD_TAG_P_FC;
491 }
492 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
493 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
494 break;
495 case HW_TPL_FR_MT_PR_OV_P_FC: {
496 viid = cxgb4_port_viid(l2t->neigh->dev);
497
498 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
499 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
500 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
501 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
502 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
503 break;
504 }
505 default:
506 break;
507 }
508 return ntuple;
509}
510
Steve Wisecfdda9d2010-04-21 15:30:06 -0700511static int send_connect(struct c4iw_ep *ep)
512{
513 struct cpl_act_open_req *req;
514 struct sk_buff *skb;
515 u64 opt0;
516 u32 opt2;
517 unsigned int mtu_idx;
518 int wscale;
519 int wrlen = roundup(sizeof *req, 16);
520
521 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
522
523 skb = get_skb(NULL, wrlen, GFP_KERNEL);
524 if (!skb) {
525 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
526 __func__);
527 return -ENOMEM;
528 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000529 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700530
531 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
532 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000533 opt0 = (nocong ? NO_CONG(1) : 0) |
534 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000535 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700536 WND_SCALE(wscale) |
537 MSS_IDX(mtu_idx) |
538 L2T_IDX(ep->l2t->idx) |
539 TX_CHAN(ep->tx_chan) |
540 SMAC_SEL(ep->smac_idx) |
541 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000542 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700543 RCV_BUFSIZ(rcv_win>>10);
544 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000545 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700546 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
547 if (enable_tcp_timestamps)
548 opt2 |= TSTAMPS_EN(1);
549 if (enable_tcp_sack)
550 opt2 |= SACK_EN(1);
551 if (wscale && enable_tcp_window_scaling)
552 opt2 |= WND_SCALE_EN(1);
553 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
554
555 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
556 INIT_TP_WR(req, 0);
557 OPCODE_TID(req) = cpu_to_be32(
558 MK_OPCODE_TID(CPL_ACT_OPEN_REQ, ((ep->rss_qid<<14)|ep->atid)));
559 req->local_port = ep->com.local_addr.sin_port;
560 req->peer_port = ep->com.remote_addr.sin_port;
561 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
562 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
563 req->opt0 = cpu_to_be64(opt0);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000564 req->params = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst, ep->l2t));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700565 req->opt2 = cpu_to_be32(opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +0000566 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700567 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
568}
569
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530570static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
571 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700572{
573 int mpalen, wrlen;
574 struct fw_ofld_tx_data_wr *req;
575 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530576 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577
578 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
579
580 BUG_ON(skb_cloned(skb));
581
582 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530583 if (mpa_rev_to_use == 2)
584 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700585 wrlen = roundup(mpalen + sizeof *req, 16);
586 skb = get_skb(skb, wrlen, GFP_KERNEL);
587 if (!skb) {
588 connect_reply_upcall(ep, -ENOMEM);
589 return;
590 }
591 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
592
593 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
594 memset(req, 0, wrlen);
595 req->op_to_immdlen = cpu_to_be32(
596 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
597 FW_WR_COMPL(1) |
598 FW_WR_IMMDLEN(mpalen));
599 req->flowid_len16 = cpu_to_be32(
600 FW_WR_FLOWID(ep->hwtid) |
601 FW_WR_LEN16(wrlen >> 4));
602 req->plen = cpu_to_be32(mpalen);
603 req->tunnel_to_proxy = cpu_to_be32(
604 FW_OFLD_TX_DATA_WR_FLUSH(1) |
605 FW_OFLD_TX_DATA_WR_SHOVE(1));
606
607 mpa = (struct mpa_message *)(req + 1);
608 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
609 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530610 (markers_enabled ? MPA_MARKERS : 0) |
611 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700612 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530613 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530614 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530615 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530616 ep->retry_with_mpa_v1 = 0;
617 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700618
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530619 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700620 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
621 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530622 mpa_v2_params.ird = htons((u16)ep->ird);
623 mpa_v2_params.ord = htons((u16)ep->ord);
624
625 if (peer2peer) {
626 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
627 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
628 mpa_v2_params.ord |=
629 htons(MPA_V2_RDMA_WRITE_RTR);
630 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
631 mpa_v2_params.ord |=
632 htons(MPA_V2_RDMA_READ_RTR);
633 }
634 memcpy(mpa->private_data, &mpa_v2_params,
635 sizeof(struct mpa_v2_conn_params));
636
637 if (ep->plen)
638 memcpy(mpa->private_data +
639 sizeof(struct mpa_v2_conn_params),
640 ep->mpa_pkt + sizeof(*mpa), ep->plen);
641 } else
642 if (ep->plen)
643 memcpy(mpa->private_data,
644 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645
646 /*
647 * Reference the mpa skb. This ensures the data area
648 * will remain in memory until the hw acks the tx.
649 * Function fw4_ack() will deref it.
650 */
651 skb_get(skb);
652 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
653 BUG_ON(ep->mpa_skb);
654 ep->mpa_skb = skb;
655 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
656 start_ep_timer(ep);
657 state_set(&ep->com, MPA_REQ_SENT);
658 ep->mpa_attr.initiator = 1;
659 return;
660}
661
662static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
663{
664 int mpalen, wrlen;
665 struct fw_ofld_tx_data_wr *req;
666 struct mpa_message *mpa;
667 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530668 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700669
670 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
671
672 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530673 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
674 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700675 wrlen = roundup(mpalen + sizeof *req, 16);
676
677 skb = get_skb(NULL, wrlen, GFP_KERNEL);
678 if (!skb) {
679 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
680 return -ENOMEM;
681 }
682 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
683
684 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
685 memset(req, 0, wrlen);
686 req->op_to_immdlen = cpu_to_be32(
687 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
688 FW_WR_COMPL(1) |
689 FW_WR_IMMDLEN(mpalen));
690 req->flowid_len16 = cpu_to_be32(
691 FW_WR_FLOWID(ep->hwtid) |
692 FW_WR_LEN16(wrlen >> 4));
693 req->plen = cpu_to_be32(mpalen);
694 req->tunnel_to_proxy = cpu_to_be32(
695 FW_OFLD_TX_DATA_WR_FLUSH(1) |
696 FW_OFLD_TX_DATA_WR_SHOVE(1));
697
698 mpa = (struct mpa_message *)(req + 1);
699 memset(mpa, 0, sizeof(*mpa));
700 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
701 mpa->flags = MPA_REJECT;
702 mpa->revision = mpa_rev;
703 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530704
705 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
706 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700707 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
708 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530709 mpa_v2_params.ird = htons(((u16)ep->ird) |
710 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
711 0));
712 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
713 (p2p_type ==
714 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
715 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
716 FW_RI_INIT_P2PTYPE_READ_REQ ?
717 MPA_V2_RDMA_READ_RTR : 0) : 0));
718 memcpy(mpa->private_data, &mpa_v2_params,
719 sizeof(struct mpa_v2_conn_params));
720
721 if (ep->plen)
722 memcpy(mpa->private_data +
723 sizeof(struct mpa_v2_conn_params), pdata, plen);
724 } else
725 if (plen)
726 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700727
728 /*
729 * Reference the mpa skb again. This ensures the data area
730 * will remain in memory until the hw acks the tx.
731 * Function fw4_ack() will deref it.
732 */
733 skb_get(skb);
734 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
735 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
736 BUG_ON(ep->mpa_skb);
737 ep->mpa_skb = skb;
738 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
739}
740
741static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
742{
743 int mpalen, wrlen;
744 struct fw_ofld_tx_data_wr *req;
745 struct mpa_message *mpa;
746 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530747 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700748
749 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
750
751 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530752 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
753 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754 wrlen = roundup(mpalen + sizeof *req, 16);
755
756 skb = get_skb(NULL, wrlen, GFP_KERNEL);
757 if (!skb) {
758 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
759 return -ENOMEM;
760 }
761 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
762
763 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
764 memset(req, 0, wrlen);
765 req->op_to_immdlen = cpu_to_be32(
766 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
767 FW_WR_COMPL(1) |
768 FW_WR_IMMDLEN(mpalen));
769 req->flowid_len16 = cpu_to_be32(
770 FW_WR_FLOWID(ep->hwtid) |
771 FW_WR_LEN16(wrlen >> 4));
772 req->plen = cpu_to_be32(mpalen);
773 req->tunnel_to_proxy = cpu_to_be32(
774 FW_OFLD_TX_DATA_WR_FLUSH(1) |
775 FW_OFLD_TX_DATA_WR_SHOVE(1));
776
777 mpa = (struct mpa_message *)(req + 1);
778 memset(mpa, 0, sizeof(*mpa));
779 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
780 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
781 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530782 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700783 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530784
785 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
786 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700787 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
788 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530789 mpa_v2_params.ird = htons((u16)ep->ird);
790 mpa_v2_params.ord = htons((u16)ep->ord);
791 if (peer2peer && (ep->mpa_attr.p2p_type !=
792 FW_RI_INIT_P2PTYPE_DISABLED)) {
793 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
794
795 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
796 mpa_v2_params.ord |=
797 htons(MPA_V2_RDMA_WRITE_RTR);
798 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
799 mpa_v2_params.ord |=
800 htons(MPA_V2_RDMA_READ_RTR);
801 }
802
803 memcpy(mpa->private_data, &mpa_v2_params,
804 sizeof(struct mpa_v2_conn_params));
805
806 if (ep->plen)
807 memcpy(mpa->private_data +
808 sizeof(struct mpa_v2_conn_params), pdata, plen);
809 } else
810 if (plen)
811 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700812
813 /*
814 * Reference the mpa skb. This ensures the data area
815 * will remain in memory until the hw acks the tx.
816 * Function fw4_ack() will deref it.
817 */
818 skb_get(skb);
819 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
820 ep->mpa_skb = skb;
821 state_set(&ep->com, MPA_REP_SENT);
822 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
823}
824
825static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
826{
827 struct c4iw_ep *ep;
828 struct cpl_act_establish *req = cplhdr(skb);
829 unsigned int tid = GET_TID(req);
830 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
831 struct tid_info *t = dev->rdev.lldi.tids;
832
833 ep = lookup_atid(t, atid);
834
835 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
836 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
837
838 dst_confirm(ep->dst);
839
840 /* setup the hwtid for this connection */
841 ep->hwtid = tid;
842 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000843 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700844
845 ep->snd_seq = be32_to_cpu(req->snd_isn);
846 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
847
848 set_emss(ep, ntohs(req->tcp_opt));
849
850 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000851 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700852 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000853 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700854
855 /* start MPA negotiation */
856 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530857 if (ep->retry_with_mpa_v1)
858 send_mpa_req(ep, skb, 1);
859 else
860 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700861
862 return 0;
863}
864
865static void close_complete_upcall(struct c4iw_ep *ep)
866{
867 struct iw_cm_event event;
868
869 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
870 memset(&event, 0, sizeof(event));
871 event.event = IW_CM_EVENT_CLOSE;
872 if (ep->com.cm_id) {
873 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
874 ep, ep->com.cm_id, ep->hwtid);
875 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
876 ep->com.cm_id->rem_ref(ep->com.cm_id);
877 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000878 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700879 }
880}
881
882static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
883{
884 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
885 close_complete_upcall(ep);
886 state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +0000887 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888 return send_abort(ep, skb, gfp);
889}
890
891static void peer_close_upcall(struct c4iw_ep *ep)
892{
893 struct iw_cm_event event;
894
895 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
896 memset(&event, 0, sizeof(event));
897 event.event = IW_CM_EVENT_DISCONNECT;
898 if (ep->com.cm_id) {
899 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
900 ep, ep->com.cm_id, ep->hwtid);
901 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +0000902 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903 }
904}
905
906static void peer_abort_upcall(struct c4iw_ep *ep)
907{
908 struct iw_cm_event event;
909
910 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
911 memset(&event, 0, sizeof(event));
912 event.event = IW_CM_EVENT_CLOSE;
913 event.status = -ECONNRESET;
914 if (ep->com.cm_id) {
915 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
916 ep->com.cm_id, ep->hwtid);
917 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
918 ep->com.cm_id->rem_ref(ep->com.cm_id);
919 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000920 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700921 }
922}
923
924static void connect_reply_upcall(struct c4iw_ep *ep, int status)
925{
926 struct iw_cm_event event;
927
928 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
929 memset(&event, 0, sizeof(event));
930 event.event = IW_CM_EVENT_CONNECT_REPLY;
931 event.status = status;
932 event.local_addr = ep->com.local_addr;
933 event.remote_addr = ep->com.remote_addr;
934
935 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530936 if (!ep->tried_with_mpa_v1) {
937 /* this means MPA_v2 is used */
938 event.private_data_len = ep->plen -
939 sizeof(struct mpa_v2_conn_params);
940 event.private_data = ep->mpa_pkt +
941 sizeof(struct mpa_message) +
942 sizeof(struct mpa_v2_conn_params);
943 } else {
944 /* this means MPA_v1 is used */
945 event.private_data_len = ep->plen;
946 event.private_data = ep->mpa_pkt +
947 sizeof(struct mpa_message);
948 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700949 }
Roland Dreier85963e42010-07-19 13:13:09 -0700950
951 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
952 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +0000953 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -0700954 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
955
Steve Wisecfdda9d2010-04-21 15:30:06 -0700956 if (status < 0) {
957 ep->com.cm_id->rem_ref(ep->com.cm_id);
958 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700959 }
960}
961
962static void connect_request_upcall(struct c4iw_ep *ep)
963{
964 struct iw_cm_event event;
965
966 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
967 memset(&event, 0, sizeof(event));
968 event.event = IW_CM_EVENT_CONNECT_REQUEST;
969 event.local_addr = ep->com.local_addr;
970 event.remote_addr = ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700971 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530972 if (!ep->tried_with_mpa_v1) {
973 /* this means MPA_v2 is used */
974 event.ord = ep->ord;
975 event.ird = ep->ird;
976 event.private_data_len = ep->plen -
977 sizeof(struct mpa_v2_conn_params);
978 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
979 sizeof(struct mpa_v2_conn_params);
980 } else {
981 /* this means MPA_v1 is used. Send max supported */
982 event.ord = c4iw_max_read_depth;
983 event.ird = c4iw_max_read_depth;
984 event.private_data_len = ep->plen;
985 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
986 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700987 if (state_read(&ep->parent_ep->com) != DEAD) {
988 c4iw_get_ep(&ep->com);
989 ep->parent_ep->com.cm_id->event_handler(
990 ep->parent_ep->com.cm_id,
991 &event);
992 }
Vipul Pandya793dad92012-12-10 09:30:56 +0000993 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994 c4iw_put_ep(&ep->parent_ep->com);
995 ep->parent_ep = NULL;
996}
997
998static void established_upcall(struct c4iw_ep *ep)
999{
1000 struct iw_cm_event event;
1001
1002 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1003 memset(&event, 0, sizeof(event));
1004 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301005 event.ird = ep->ird;
1006 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001007 if (ep->com.cm_id) {
1008 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1009 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001010 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011 }
1012}
1013
1014static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1015{
1016 struct cpl_rx_data_ack *req;
1017 struct sk_buff *skb;
1018 int wrlen = roundup(sizeof *req, 16);
1019
1020 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1021 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1022 if (!skb) {
1023 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1024 return 0;
1025 }
1026
1027 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1028 memset(req, 0, wrlen);
1029 INIT_TP_WR(req, ep->hwtid);
1030 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1031 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001032 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1033 F_RX_DACK_CHANGE |
1034 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001035 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001036 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1037 return credits;
1038}
1039
1040static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1041{
1042 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301043 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001044 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301045 u16 resp_ird, resp_ord;
1046 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001047 struct c4iw_qp_attributes attrs;
1048 enum c4iw_qp_attr_mask mask;
1049 int err;
1050
1051 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1052
1053 /*
1054 * Stop mpa timer. If it expired, then the state has
1055 * changed and we bail since ep_timeout already aborted
1056 * the connection.
1057 */
1058 stop_ep_timer(ep);
1059 if (state_read(&ep->com) != MPA_REQ_SENT)
1060 return;
1061
1062 /*
1063 * If we get more than the supported amount of private data
1064 * then we must fail this connection.
1065 */
1066 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1067 err = -EINVAL;
1068 goto err;
1069 }
1070
1071 /*
1072 * copy the new data into our accumulation buffer.
1073 */
1074 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1075 skb->len);
1076 ep->mpa_pkt_len += skb->len;
1077
1078 /*
1079 * if we don't even have the mpa message, then bail.
1080 */
1081 if (ep->mpa_pkt_len < sizeof(*mpa))
1082 return;
1083 mpa = (struct mpa_message *) ep->mpa_pkt;
1084
1085 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301086 if (mpa->revision > mpa_rev) {
1087 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1088 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 err = -EPROTO;
1090 goto err;
1091 }
1092 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1093 err = -EPROTO;
1094 goto err;
1095 }
1096
1097 plen = ntohs(mpa->private_data_size);
1098
1099 /*
1100 * Fail if there's too much private data.
1101 */
1102 if (plen > MPA_MAX_PRIVATE_DATA) {
1103 err = -EPROTO;
1104 goto err;
1105 }
1106
1107 /*
1108 * If plen does not account for pkt size
1109 */
1110 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1111 err = -EPROTO;
1112 goto err;
1113 }
1114
1115 ep->plen = (u8) plen;
1116
1117 /*
1118 * If we don't have all the pdata yet, then bail.
1119 * We'll continue process when more data arrives.
1120 */
1121 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1122 return;
1123
1124 if (mpa->flags & MPA_REJECT) {
1125 err = -ECONNREFUSED;
1126 goto err;
1127 }
1128
1129 /*
1130 * If we get here we have accumulated the entire mpa
1131 * start reply message including private data. And
1132 * the MPA header is valid.
1133 */
1134 state_set(&ep->com, FPDU_MODE);
1135 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1136 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1137 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301138 ep->mpa_attr.version = mpa->revision;
1139 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1140
1141 if (mpa->revision == 2) {
1142 ep->mpa_attr.enhanced_rdma_conn =
1143 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1144 if (ep->mpa_attr.enhanced_rdma_conn) {
1145 mpa_v2_params = (struct mpa_v2_conn_params *)
1146 (ep->mpa_pkt + sizeof(*mpa));
1147 resp_ird = ntohs(mpa_v2_params->ird) &
1148 MPA_V2_IRD_ORD_MASK;
1149 resp_ord = ntohs(mpa_v2_params->ord) &
1150 MPA_V2_IRD_ORD_MASK;
1151
1152 /*
1153 * This is a double-check. Ideally, below checks are
1154 * not required since ird/ord stuff has been taken
1155 * care of in c4iw_accept_cr
1156 */
1157 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1158 err = -ENOMEM;
1159 ep->ird = resp_ord;
1160 ep->ord = resp_ird;
1161 insuff_ird = 1;
1162 }
1163
1164 if (ntohs(mpa_v2_params->ird) &
1165 MPA_V2_PEER2PEER_MODEL) {
1166 if (ntohs(mpa_v2_params->ord) &
1167 MPA_V2_RDMA_WRITE_RTR)
1168 ep->mpa_attr.p2p_type =
1169 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1170 else if (ntohs(mpa_v2_params->ord) &
1171 MPA_V2_RDMA_READ_RTR)
1172 ep->mpa_attr.p2p_type =
1173 FW_RI_INIT_P2PTYPE_READ_REQ;
1174 }
1175 }
1176 } else if (mpa->revision == 1)
1177 if (peer2peer)
1178 ep->mpa_attr.p2p_type = p2p_type;
1179
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301181 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1182 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1183 ep->mpa_attr.recv_marker_enabled,
1184 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1185 ep->mpa_attr.p2p_type, p2p_type);
1186
1187 /*
1188 * If responder's RTR does not match with that of initiator, assign
1189 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1190 * generated when moving QP to RTS state.
1191 * A TERM message will be sent after QP has moved to RTS state
1192 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001193 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301194 (ep->mpa_attr.p2p_type != p2p_type)) {
1195 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1196 rtr_mismatch = 1;
1197 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198
1199 attrs.mpa_attr = ep->mpa_attr;
1200 attrs.max_ird = ep->ird;
1201 attrs.max_ord = ep->ord;
1202 attrs.llp_stream_handle = ep;
1203 attrs.next_state = C4IW_QP_STATE_RTS;
1204
1205 mask = C4IW_QP_ATTR_NEXT_STATE |
1206 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1207 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1208
1209 /* bind QP and TID with INIT_WR */
1210 err = c4iw_modify_qp(ep->com.qp->rhp,
1211 ep->com.qp, mask, &attrs, 1);
1212 if (err)
1213 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301214
1215 /*
1216 * If responder's RTR requirement did not match with what initiator
1217 * supports, generate TERM message
1218 */
1219 if (rtr_mismatch) {
1220 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1221 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1222 attrs.ecode = MPA_NOMATCH_RTR;
1223 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1224 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1225 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1226 err = -ENOMEM;
1227 goto out;
1228 }
1229
1230 /*
1231 * Generate TERM if initiator IRD is not sufficient for responder
1232 * provided ORD. Currently, we do the same behaviour even when
1233 * responder provided IRD is also not sufficient as regards to
1234 * initiator ORD.
1235 */
1236 if (insuff_ird) {
1237 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1238 __func__);
1239 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1240 attrs.ecode = MPA_INSUFF_IRD;
1241 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1242 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1243 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1244 err = -ENOMEM;
1245 goto out;
1246 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001247 goto out;
1248err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001249 state_set(&ep->com, ABORTING);
1250 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251out:
1252 connect_reply_upcall(ep, err);
1253 return;
1254}
1255
1256static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1257{
1258 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301259 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260 u16 plen;
1261
1262 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1263
1264 if (state_read(&ep->com) != MPA_REQ_WAIT)
1265 return;
1266
1267 /*
1268 * If we get more than the supported amount of private data
1269 * then we must fail this connection.
1270 */
1271 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1272 stop_ep_timer(ep);
1273 abort_connection(ep, skb, GFP_KERNEL);
1274 return;
1275 }
1276
1277 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1278
1279 /*
1280 * Copy the new data into our accumulation buffer.
1281 */
1282 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1283 skb->len);
1284 ep->mpa_pkt_len += skb->len;
1285
1286 /*
1287 * If we don't even have the mpa message, then bail.
1288 * We'll continue process when more data arrives.
1289 */
1290 if (ep->mpa_pkt_len < sizeof(*mpa))
1291 return;
1292
1293 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1294 stop_ep_timer(ep);
1295 mpa = (struct mpa_message *) ep->mpa_pkt;
1296
1297 /*
1298 * Validate MPA Header.
1299 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301300 if (mpa->revision > mpa_rev) {
1301 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1302 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001303 abort_connection(ep, skb, GFP_KERNEL);
1304 return;
1305 }
1306
1307 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
1308 abort_connection(ep, skb, GFP_KERNEL);
1309 return;
1310 }
1311
1312 plen = ntohs(mpa->private_data_size);
1313
1314 /*
1315 * Fail if there's too much private data.
1316 */
1317 if (plen > MPA_MAX_PRIVATE_DATA) {
1318 abort_connection(ep, skb, GFP_KERNEL);
1319 return;
1320 }
1321
1322 /*
1323 * If plen does not account for pkt size
1324 */
1325 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1326 abort_connection(ep, skb, GFP_KERNEL);
1327 return;
1328 }
1329 ep->plen = (u8) plen;
1330
1331 /*
1332 * If we don't have all the pdata yet, then bail.
1333 */
1334 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1335 return;
1336
1337 /*
1338 * If we get here we have accumulated the entire mpa
1339 * start reply message including private data.
1340 */
1341 ep->mpa_attr.initiator = 0;
1342 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1343 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1344 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301345 ep->mpa_attr.version = mpa->revision;
1346 if (mpa->revision == 1)
1347 ep->tried_with_mpa_v1 = 1;
1348 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1349
1350 if (mpa->revision == 2) {
1351 ep->mpa_attr.enhanced_rdma_conn =
1352 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1353 if (ep->mpa_attr.enhanced_rdma_conn) {
1354 mpa_v2_params = (struct mpa_v2_conn_params *)
1355 (ep->mpa_pkt + sizeof(*mpa));
1356 ep->ird = ntohs(mpa_v2_params->ird) &
1357 MPA_V2_IRD_ORD_MASK;
1358 ep->ord = ntohs(mpa_v2_params->ord) &
1359 MPA_V2_IRD_ORD_MASK;
1360 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1361 if (peer2peer) {
1362 if (ntohs(mpa_v2_params->ord) &
1363 MPA_V2_RDMA_WRITE_RTR)
1364 ep->mpa_attr.p2p_type =
1365 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1366 else if (ntohs(mpa_v2_params->ord) &
1367 MPA_V2_RDMA_READ_RTR)
1368 ep->mpa_attr.p2p_type =
1369 FW_RI_INIT_P2PTYPE_READ_REQ;
1370 }
1371 }
1372 } else if (mpa->revision == 1)
1373 if (peer2peer)
1374 ep->mpa_attr.p2p_type = p2p_type;
1375
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1377 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1378 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1379 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1380 ep->mpa_attr.p2p_type);
1381
1382 state_set(&ep->com, MPA_REQ_RCVD);
1383
1384 /* drive upcall */
1385 connect_request_upcall(ep);
1386 return;
1387}
1388
1389static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1390{
1391 struct c4iw_ep *ep;
1392 struct cpl_rx_data *hdr = cplhdr(skb);
1393 unsigned int dlen = ntohs(hdr->len);
1394 unsigned int tid = GET_TID(hdr);
1395 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001396 __u8 status = hdr->status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001397
1398 ep = lookup_tid(t, tid);
1399 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1400 skb_pull(skb, sizeof(*hdr));
1401 skb_trim(skb, dlen);
1402
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403 /* update RX credits */
1404 update_rx_credits(ep, dlen);
1405
1406 switch (state_read(&ep->com)) {
1407 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001408 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 process_mpa_reply(ep, skb);
1410 break;
1411 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001412 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001413 process_mpa_request(ep, skb);
1414 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001415 case FPDU_MODE: {
1416 struct c4iw_qp_attributes attrs;
1417 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001418 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001419 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001420 " qpid %u ep %p state %d tid %u status %d\n",
1421 __func__, ep->com.qp->wq.sq.qid, ep,
1422 state_read(&ep->com), ep->hwtid, status);
Vipul Pandya15579672013-01-07 13:11:52 +00001423 attrs.next_state = C4IW_QP_STATE_ERROR;
1424 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1425 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001426 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427 break;
1428 }
Vipul Pandya15579672013-01-07 13:11:52 +00001429 default:
1430 break;
1431 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001432 return 0;
1433}
1434
1435static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1436{
1437 struct c4iw_ep *ep;
1438 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439 int release = 0;
1440 unsigned int tid = GET_TID(rpl);
1441 struct tid_info *t = dev->rdev.lldi.tids;
1442
1443 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301444 if (!ep) {
1445 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1446 return 0;
1447 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001448 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001449 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001450 switch (ep->com.state) {
1451 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001452 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001453 __state_set(&ep->com, DEAD);
1454 release = 1;
1455 break;
1456 default:
1457 printk(KERN_ERR "%s ep %p state %d\n",
1458 __func__, ep, ep->com.state);
1459 break;
1460 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001461 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001462
1463 if (release)
1464 release_ep_resources(ep);
1465 return 0;
1466}
1467
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001468static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1469{
1470 struct sk_buff *skb;
1471 struct fw_ofld_connection_wr *req;
1472 unsigned int mtu_idx;
1473 int wscale;
1474
1475 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1476 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1477 memset(req, 0, sizeof(*req));
1478 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1479 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1480 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1481 ep->l2t));
1482 req->le.lport = ep->com.local_addr.sin_port;
1483 req->le.pport = ep->com.remote_addr.sin_port;
1484 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1485 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1486 req->tcb.t_state_to_astid =
1487 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1488 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1489 req->tcb.cplrxdataack_cplpassacceptrpl =
1490 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
1491 req->tcb.tx_max = jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001492 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001493 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1494 wscale = compute_wscale(rcv_win);
1495 req->tcb.opt0 = TCAM_BYPASS(1) |
1496 (nocong ? NO_CONG(1) : 0) |
1497 KEEP_ALIVE(1) |
1498 DELACK(1) |
1499 WND_SCALE(wscale) |
1500 MSS_IDX(mtu_idx) |
1501 L2T_IDX(ep->l2t->idx) |
1502 TX_CHAN(ep->tx_chan) |
1503 SMAC_SEL(ep->smac_idx) |
1504 DSCP(ep->tos) |
1505 ULP_MODE(ULP_MODE_TCPDDP) |
1506 RCV_BUFSIZ(rcv_win >> 10);
1507 req->tcb.opt2 = PACE(1) |
1508 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1509 RX_CHANNEL(0) |
1510 CCTRL_ECN(enable_ecn) |
1511 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1512 if (enable_tcp_timestamps)
1513 req->tcb.opt2 |= TSTAMPS_EN(1);
1514 if (enable_tcp_sack)
1515 req->tcb.opt2 |= SACK_EN(1);
1516 if (wscale && enable_tcp_window_scaling)
1517 req->tcb.opt2 |= WND_SCALE_EN(1);
1518 req->tcb.opt0 = cpu_to_be64(req->tcb.opt0);
1519 req->tcb.opt2 = cpu_to_be32(req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001520 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1521 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001522 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1523}
1524
Steve Wisecfdda9d2010-04-21 15:30:06 -07001525/*
1526 * Return whether a failed active open has allocated a TID
1527 */
1528static inline int act_open_has_tid(int status)
1529{
1530 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1531 status != CPL_ERR_ARP_MISS;
1532}
1533
Vipul Pandya793dad92012-12-10 09:30:56 +00001534#define ACT_OPEN_RETRY_COUNT 2
1535
1536static int c4iw_reconnect(struct c4iw_ep *ep)
1537{
1538 int err = 0;
1539 struct rtable *rt;
1540 struct port_info *pi;
1541 struct net_device *pdev;
1542 int step;
1543 struct neighbour *neigh;
1544
1545 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1546 init_timer(&ep->timer);
1547
1548 /*
1549 * Allocate an active TID to initiate a TCP connection.
1550 */
1551 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1552 if (ep->atid == -1) {
1553 pr_err("%s - cannot alloc atid.\n", __func__);
1554 err = -ENOMEM;
1555 goto fail2;
1556 }
1557 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1558
1559 /* find a route */
1560 rt = find_route(ep->com.dev,
1561 ep->com.cm_id->local_addr.sin_addr.s_addr,
1562 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1563 ep->com.cm_id->local_addr.sin_port,
1564 ep->com.cm_id->remote_addr.sin_port, 0);
1565 if (!rt) {
1566 pr_err("%s - cannot find route.\n", __func__);
1567 err = -EHOSTUNREACH;
1568 goto fail3;
1569 }
1570 ep->dst = &rt->dst;
1571
1572 neigh = dst_neigh_lookup(ep->dst,
1573 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
1574 /* get a l2t entry */
1575 if (neigh->dev->flags & IFF_LOOPBACK) {
1576 PDBG("%s LOOPBACK\n", __func__);
1577 pdev = ip_dev_find(&init_net,
1578 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1579 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1580 neigh, pdev, 0);
1581 pi = (struct port_info *)netdev_priv(pdev);
1582 ep->mtu = pdev->mtu;
1583 ep->tx_chan = cxgb4_port_chan(pdev);
1584 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1585 dev_put(pdev);
1586 } else {
1587 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1588 neigh, neigh->dev, 0);
1589 pi = (struct port_info *)netdev_priv(neigh->dev);
1590 ep->mtu = dst_mtu(ep->dst);
1591 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1592 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1593 0x7F) << 1;
1594 }
1595
1596 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1597 ep->txq_idx = pi->port_id * step;
1598 ep->ctrlq_idx = pi->port_id;
1599 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1600 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1601
1602 if (!ep->l2t) {
1603 pr_err("%s - cannot alloc l2e.\n", __func__);
1604 err = -ENOMEM;
1605 goto fail4;
1606 }
1607
1608 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1609 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1610 ep->l2t->idx);
1611
1612 state_set(&ep->com, CONNECTING);
1613 ep->tos = 0;
1614
1615 /* send connect request to rnic */
1616 err = send_connect(ep);
1617 if (!err)
1618 goto out;
1619
1620 cxgb4_l2t_release(ep->l2t);
1621fail4:
1622 dst_release(ep->dst);
1623fail3:
1624 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1625 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1626fail2:
1627 /*
1628 * remember to send notification to upper layer.
1629 * We are in here so the upper layer is not aware that this is
1630 * re-connect attempt and so, upper layer is still waiting for
1631 * response of 1st connect request.
1632 */
1633 connect_reply_upcall(ep, -ECONNRESET);
1634 c4iw_put_ep(&ep->com);
1635out:
1636 return err;
1637}
1638
Steve Wisecfdda9d2010-04-21 15:30:06 -07001639static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1640{
1641 struct c4iw_ep *ep;
1642 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1643 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1644 ntohl(rpl->atid_status)));
1645 struct tid_info *t = dev->rdev.lldi.tids;
1646 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1647
1648 ep = lookup_atid(t, atid);
1649
1650 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1651 status, status2errno(status));
1652
1653 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1654 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1655 atid);
1656 return 0;
1657 }
1658
Vipul Pandya793dad92012-12-10 09:30:56 +00001659 set_bit(ACT_OPEN_RPL, &ep->com.history);
1660
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301661 /*
1662 * Log interesting failures.
1663 */
1664 switch (status) {
1665 case CPL_ERR_CONN_RESET:
1666 case CPL_ERR_CONN_TIMEDOUT:
1667 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001668 case CPL_ERR_TCAM_FULL:
Vipul Pandya793dad92012-12-10 09:30:56 +00001669 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1670 mutex_lock(&dev->rdev.stats.lock);
1671 dev->rdev.stats.tcam_full++;
1672 mutex_unlock(&dev->rdev.stats.lock);
1673 send_fw_act_open_req(ep,
1674 GET_TID_TID(GET_AOPEN_ATID(
1675 ntohl(rpl->atid_status))));
1676 return 0;
1677 }
1678 break;
1679 case CPL_ERR_CONN_EXIST:
1680 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1681 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1682 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1683 atid);
1684 cxgb4_free_atid(t, atid);
1685 dst_release(ep->dst);
1686 cxgb4_l2t_release(ep->l2t);
1687 c4iw_reconnect(ep);
1688 return 0;
1689 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001690 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301691 default:
1692 printk(KERN_INFO MOD "Active open failure - "
1693 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1694 atid, status, status2errno(status),
1695 &ep->com.local_addr.sin_addr.s_addr,
1696 ntohs(ep->com.local_addr.sin_port),
1697 &ep->com.remote_addr.sin_addr.s_addr,
1698 ntohs(ep->com.remote_addr.sin_port));
1699 break;
1700 }
1701
Steve Wisecfdda9d2010-04-21 15:30:06 -07001702 connect_reply_upcall(ep, status2errno(status));
1703 state_set(&ep->com, DEAD);
1704
1705 if (status && act_open_has_tid(status))
1706 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1707
Vipul Pandya793dad92012-12-10 09:30:56 +00001708 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709 cxgb4_free_atid(t, atid);
1710 dst_release(ep->dst);
1711 cxgb4_l2t_release(ep->l2t);
1712 c4iw_put_ep(&ep->com);
1713
1714 return 0;
1715}
1716
1717static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1718{
1719 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1720 struct tid_info *t = dev->rdev.lldi.tids;
1721 unsigned int stid = GET_TID(rpl);
1722 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1723
1724 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001725 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1726 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727 }
1728 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1729 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001730 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001731
Vipul Pandya1cab7752012-12-10 09:30:55 +00001732out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001733 return 0;
1734}
1735
1736static int listen_stop(struct c4iw_listen_ep *ep)
1737{
1738 struct sk_buff *skb;
1739 struct cpl_close_listsvr_req *req;
1740
1741 PDBG("%s ep %p\n", __func__, ep);
1742 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1743 if (!skb) {
1744 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1745 return -ENOMEM;
1746 }
1747 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1748 INIT_TP_WR(req, 0);
1749 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1750 ep->stid));
1751 req->reply_ctrl = cpu_to_be16(
1752 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1753 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1754 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1755}
1756
1757static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1758{
1759 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1760 struct tid_info *t = dev->rdev.lldi.tids;
1761 unsigned int stid = GET_TID(rpl);
1762 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1763
1764 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001765 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001766 return 0;
1767}
1768
1769static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1770 struct cpl_pass_accept_req *req)
1771{
1772 struct cpl_pass_accept_rpl *rpl;
1773 unsigned int mtu_idx;
1774 u64 opt0;
1775 u32 opt2;
1776 int wscale;
1777
1778 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1779 BUG_ON(skb_cloned(skb));
1780 skb_trim(skb, sizeof(*rpl));
1781 skb_get(skb);
1782 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1783 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001784 opt0 = (nocong ? NO_CONG(1) : 0) |
1785 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001786 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001787 WND_SCALE(wscale) |
1788 MSS_IDX(mtu_idx) |
1789 L2T_IDX(ep->l2t->idx) |
1790 TX_CHAN(ep->tx_chan) |
1791 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001792 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001793 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001794 RCV_BUFSIZ(rcv_win>>10);
1795 opt2 = RX_CHANNEL(0) |
1796 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1797
1798 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1799 opt2 |= TSTAMPS_EN(1);
1800 if (enable_tcp_sack && req->tcpopt.sack)
1801 opt2 |= SACK_EN(1);
1802 if (wscale && enable_tcp_window_scaling)
1803 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001804 if (enable_ecn) {
1805 const struct tcphdr *tcph;
1806 u32 hlen = ntohl(req->hdr_len);
1807
1808 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1809 G_IP_HDR_LEN(hlen);
1810 if (tcph->ece && tcph->cwr)
1811 opt2 |= CCTRL_ECN(1);
1812 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001813
1814 rpl = cplhdr(skb);
1815 INIT_TP_WR(rpl, ep->hwtid);
1816 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1817 ep->hwtid));
1818 rpl->opt0 = cpu_to_be64(opt0);
1819 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001820 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001821 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1822
1823 return;
1824}
1825
1826static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1827 struct sk_buff *skb)
1828{
1829 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1830 peer_ip);
1831 BUG_ON(skb_cloned(skb));
1832 skb_trim(skb, sizeof(struct cpl_tid_release));
1833 skb_get(skb);
1834 release_tid(&dev->rdev, hwtid, skb);
1835 return;
1836}
1837
1838static void get_4tuple(struct cpl_pass_accept_req *req,
1839 __be32 *local_ip, __be32 *peer_ip,
1840 __be16 *local_port, __be16 *peer_port)
1841{
1842 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1843 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1844 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1845 struct tcphdr *tcp = (struct tcphdr *)
1846 ((u8 *)(req + 1) + eth_len + ip_len);
1847
1848 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1849 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1850 ntohs(tcp->dest));
1851
1852 *peer_ip = ip->saddr;
1853 *local_ip = ip->daddr;
1854 *peer_port = tcp->source;
1855 *local_port = tcp->dest;
1856
1857 return;
1858}
1859
David Miller3786cf12011-12-02 16:52:31 +00001860static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1861 struct c4iw_dev *cdev, bool clear_mpa_v1)
1862{
1863 struct neighbour *n;
1864 int err, step;
1865
David Miller64b70072012-01-24 13:15:57 +00001866 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001867 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001868 return -ENODEV;
1869
1870 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001871 err = -ENOMEM;
1872 if (n->dev->flags & IFF_LOOPBACK) {
1873 struct net_device *pdev;
1874
1875 pdev = ip_dev_find(&init_net, peer_ip);
Thadeu Lima de Souza Cascardo71b43fd2012-05-17 17:51:53 -03001876 if (!pdev) {
1877 err = -ENODEV;
1878 goto out;
1879 }
David Miller3786cf12011-12-02 16:52:31 +00001880 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1881 n, pdev, 0);
1882 if (!ep->l2t)
1883 goto out;
1884 ep->mtu = pdev->mtu;
1885 ep->tx_chan = cxgb4_port_chan(pdev);
1886 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1887 step = cdev->rdev.lldi.ntxq /
1888 cdev->rdev.lldi.nchan;
1889 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1890 step = cdev->rdev.lldi.nrxq /
1891 cdev->rdev.lldi.nchan;
1892 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1893 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1894 cxgb4_port_idx(pdev) * step];
1895 dev_put(pdev);
1896 } else {
1897 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1898 n, n->dev, 0);
1899 if (!ep->l2t)
1900 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001901 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001902 ep->tx_chan = cxgb4_port_chan(n->dev);
1903 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1904 step = cdev->rdev.lldi.ntxq /
1905 cdev->rdev.lldi.nchan;
1906 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1907 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1908 step = cdev->rdev.lldi.nrxq /
1909 cdev->rdev.lldi.nchan;
1910 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1911 cxgb4_port_idx(n->dev) * step];
1912
1913 if (clear_mpa_v1) {
1914 ep->retry_with_mpa_v1 = 0;
1915 ep->tried_with_mpa_v1 = 0;
1916 }
1917 }
1918 err = 0;
1919out:
1920 rcu_read_unlock();
1921
David Miller64b70072012-01-24 13:15:57 +00001922 neigh_release(n);
1923
David Miller3786cf12011-12-02 16:52:31 +00001924 return err;
1925}
1926
Steve Wisecfdda9d2010-04-21 15:30:06 -07001927static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1928{
Vipul Pandya793dad92012-12-10 09:30:56 +00001929 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001930 struct cpl_pass_accept_req *req = cplhdr(skb);
1931 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1932 struct tid_info *t = dev->rdev.lldi.tids;
1933 unsigned int hwtid = GET_TID(req);
1934 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001935 struct rtable *rt;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001936 __be32 local_ip, peer_ip = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001937 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001938 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001939 u16 peer_mss = ntohs(req->tcpopt.mss);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001940
1941 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00001942 if (!parent_ep) {
1943 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1944 goto reject;
1945 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001946 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1947
Vipul Pandya1cab7752012-12-10 09:30:55 +00001948 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1949 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1950 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1951 ntohs(peer_port), peer_mss);
1952
Steve Wisecfdda9d2010-04-21 15:30:06 -07001953 if (state_read(&parent_ep->com) != LISTEN) {
1954 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1955 __func__);
1956 goto reject;
1957 }
1958
1959 /* Find output route */
1960 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1961 GET_POPEN_TOS(ntohl(req->tos_stid)));
1962 if (!rt) {
1963 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1964 __func__);
1965 goto reject;
1966 }
Changli Gaod8d1f302010-06-10 23:31:35 -07001967 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001968
1969 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
1970 if (!child_ep) {
1971 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
1972 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001973 dst_release(dst);
1974 goto reject;
1975 }
David Miller3786cf12011-12-02 16:52:31 +00001976
1977 err = import_ep(child_ep, peer_ip, dst, dev, false);
1978 if (err) {
1979 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
1980 __func__);
1981 dst_release(dst);
1982 kfree(child_ep);
1983 goto reject;
1984 }
1985
Vipul Pandya1cab7752012-12-10 09:30:55 +00001986 if (peer_mss && child_ep->mtu > (peer_mss + 40))
1987 child_ep->mtu = peer_mss + 40;
1988
Steve Wisecfdda9d2010-04-21 15:30:06 -07001989 state_set(&child_ep->com, CONNECTING);
1990 child_ep->com.dev = dev;
1991 child_ep->com.cm_id = NULL;
1992 child_ep->com.local_addr.sin_family = PF_INET;
1993 child_ep->com.local_addr.sin_port = local_port;
1994 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
1995 child_ep->com.remote_addr.sin_family = PF_INET;
1996 child_ep->com.remote_addr.sin_port = peer_port;
1997 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
1998 c4iw_get_ep(&parent_ep->com);
1999 child_ep->parent_ep = parent_ep;
2000 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002001 child_ep->dst = dst;
2002 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002003
2004 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002005 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002006
2007 init_timer(&child_ep->timer);
2008 cxgb4_insert_tid(t, child_ep, hwtid);
2009 accept_cr(child_ep, peer_ip, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002010 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002011 goto out;
2012reject:
2013 reject_cr(dev, hwtid, peer_ip, skb);
2014out:
2015 return 0;
2016}
2017
2018static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2019{
2020 struct c4iw_ep *ep;
2021 struct cpl_pass_establish *req = cplhdr(skb);
2022 struct tid_info *t = dev->rdev.lldi.tids;
2023 unsigned int tid = GET_TID(req);
2024
2025 ep = lookup_tid(t, tid);
2026 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2027 ep->snd_seq = be32_to_cpu(req->snd_isn);
2028 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2029
Vipul Pandya1cab7752012-12-10 09:30:55 +00002030 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2031 ntohs(req->tcp_opt));
2032
Steve Wisecfdda9d2010-04-21 15:30:06 -07002033 set_emss(ep, ntohs(req->tcp_opt));
Vipul Pandya793dad92012-12-10 09:30:56 +00002034 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002035
2036 dst_confirm(ep->dst);
2037 state_set(&ep->com, MPA_REQ_WAIT);
2038 start_ep_timer(ep);
2039 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002040 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002041
2042 return 0;
2043}
2044
2045static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2046{
2047 struct cpl_peer_close *hdr = cplhdr(skb);
2048 struct c4iw_ep *ep;
2049 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002050 int disconnect = 1;
2051 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002052 struct tid_info *t = dev->rdev.lldi.tids;
2053 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002054 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002055
2056 ep = lookup_tid(t, tid);
2057 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2058 dst_confirm(ep->dst);
2059
Vipul Pandya793dad92012-12-10 09:30:56 +00002060 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002061 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002062 switch (ep->com.state) {
2063 case MPA_REQ_WAIT:
2064 __state_set(&ep->com, CLOSING);
2065 break;
2066 case MPA_REQ_SENT:
2067 __state_set(&ep->com, CLOSING);
2068 connect_reply_upcall(ep, -ECONNRESET);
2069 break;
2070 case MPA_REQ_RCVD:
2071
2072 /*
2073 * We're gonna mark this puppy DEAD, but keep
2074 * the reference on it until the ULP accepts or
2075 * rejects the CR. Also wake up anyone waiting
2076 * in rdma connection migration (see c4iw_accept_cr()).
2077 */
2078 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002079 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002080 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002081 break;
2082 case MPA_REP_SENT:
2083 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002084 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002085 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086 break;
2087 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002088 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002089 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002090 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002091 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002092 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002093 if (ret != -ECONNRESET) {
2094 peer_close_upcall(ep);
2095 disconnect = 1;
2096 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002097 break;
2098 case ABORTING:
2099 disconnect = 0;
2100 break;
2101 case CLOSING:
2102 __state_set(&ep->com, MORIBUND);
2103 disconnect = 0;
2104 break;
2105 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002106 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002107 if (ep->com.cm_id && ep->com.qp) {
2108 attrs.next_state = C4IW_QP_STATE_IDLE;
2109 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2110 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2111 }
2112 close_complete_upcall(ep);
2113 __state_set(&ep->com, DEAD);
2114 release = 1;
2115 disconnect = 0;
2116 break;
2117 case DEAD:
2118 disconnect = 0;
2119 break;
2120 default:
2121 BUG_ON(1);
2122 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002123 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002124 if (disconnect)
2125 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2126 if (release)
2127 release_ep_resources(ep);
2128 return 0;
2129}
2130
2131/*
2132 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2133 */
2134static int is_neg_adv_abort(unsigned int status)
2135{
2136 return status == CPL_ERR_RTX_NEG_ADVICE ||
2137 status == CPL_ERR_PERSIST_NEG_ADVICE;
2138}
2139
2140static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2141{
2142 struct cpl_abort_req_rss *req = cplhdr(skb);
2143 struct c4iw_ep *ep;
2144 struct cpl_abort_rpl *rpl;
2145 struct sk_buff *rpl_skb;
2146 struct c4iw_qp_attributes attrs;
2147 int ret;
2148 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149 struct tid_info *t = dev->rdev.lldi.tids;
2150 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002151
2152 ep = lookup_tid(t, tid);
2153 if (is_neg_adv_abort(req->status)) {
2154 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2155 ep->hwtid);
2156 return 0;
2157 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002158 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2159 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002160 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002161
2162 /*
2163 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302164 * However, this is not needed if com state is just
2165 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002166 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302167 if (ep->com.state != MPA_REQ_SENT)
2168 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002169
2170 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002171 switch (ep->com.state) {
2172 case CONNECTING:
2173 break;
2174 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002175 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002176 break;
2177 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002178 stop_ep_timer(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302179 if (mpa_rev == 2 && ep->tried_with_mpa_v1)
2180 connect_reply_upcall(ep, -ECONNRESET);
2181 else {
2182 /*
2183 * we just don't send notification upwards because we
2184 * want to retry with mpa_v1 without upper layers even
2185 * knowing it.
2186 *
2187 * do some housekeeping so as to re-initiate the
2188 * connection
2189 */
2190 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2191 mpa_rev);
2192 ep->retry_with_mpa_v1 = 1;
2193 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002194 break;
2195 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196 break;
2197 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198 break;
2199 case MORIBUND:
2200 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002201 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002202 /*FALLTHROUGH*/
2203 case FPDU_MODE:
2204 if (ep->com.cm_id && ep->com.qp) {
2205 attrs.next_state = C4IW_QP_STATE_ERROR;
2206 ret = c4iw_modify_qp(ep->com.qp->rhp,
2207 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2208 &attrs, 1);
2209 if (ret)
2210 printk(KERN_ERR MOD
2211 "%s - qp <- error failed!\n",
2212 __func__);
2213 }
2214 peer_abort_upcall(ep);
2215 break;
2216 case ABORTING:
2217 break;
2218 case DEAD:
2219 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002220 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002221 return 0;
2222 default:
2223 BUG_ON(1);
2224 break;
2225 }
2226 dst_confirm(ep->dst);
2227 if (ep->com.state != ABORTING) {
2228 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302229 /* we don't release if we want to retry with mpa_v1 */
2230 if (!ep->retry_with_mpa_v1)
2231 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002232 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002233 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234
2235 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2236 if (!rpl_skb) {
2237 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2238 __func__);
2239 release = 1;
2240 goto out;
2241 }
2242 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2243 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2244 INIT_TP_WR(rpl, ep->hwtid);
2245 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2246 rpl->cmd = CPL_ABORT_NO_RST;
2247 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2248out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002249 if (release)
2250 release_ep_resources(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302251
2252 /* retry with mpa-v1 */
2253 if (ep && ep->retry_with_mpa_v1) {
2254 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2255 dst_release(ep->dst);
2256 cxgb4_l2t_release(ep->l2t);
2257 c4iw_reconnect(ep);
2258 }
2259
Steve Wisecfdda9d2010-04-21 15:30:06 -07002260 return 0;
2261}
2262
2263static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2264{
2265 struct c4iw_ep *ep;
2266 struct c4iw_qp_attributes attrs;
2267 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002268 int release = 0;
2269 struct tid_info *t = dev->rdev.lldi.tids;
2270 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002271
2272 ep = lookup_tid(t, tid);
2273
2274 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2275 BUG_ON(!ep);
2276
2277 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002278 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002279 switch (ep->com.state) {
2280 case CLOSING:
2281 __state_set(&ep->com, MORIBUND);
2282 break;
2283 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002284 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002285 if ((ep->com.cm_id) && (ep->com.qp)) {
2286 attrs.next_state = C4IW_QP_STATE_IDLE;
2287 c4iw_modify_qp(ep->com.qp->rhp,
2288 ep->com.qp,
2289 C4IW_QP_ATTR_NEXT_STATE,
2290 &attrs, 1);
2291 }
2292 close_complete_upcall(ep);
2293 __state_set(&ep->com, DEAD);
2294 release = 1;
2295 break;
2296 case ABORTING:
2297 case DEAD:
2298 break;
2299 default:
2300 BUG_ON(1);
2301 break;
2302 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002303 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304 if (release)
2305 release_ep_resources(ep);
2306 return 0;
2307}
2308
2309static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2310{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002311 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002312 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002313 unsigned int tid = GET_TID(rpl);
2314 struct c4iw_ep *ep;
2315 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316
2317 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002318 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319
Steve Wise30c95c22011-05-09 22:06:22 -07002320 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002321 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2322 ep->com.qp->wq.sq.qid);
2323 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2324 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2325 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2326 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002327 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328
Steve Wisecfdda9d2010-04-21 15:30:06 -07002329 return 0;
2330}
2331
2332/*
2333 * Upcall from the adapter indicating data has been transmitted.
2334 * For us its just the single MPA request or reply. We can now free
2335 * the skb holding the mpa message.
2336 */
2337static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2338{
2339 struct c4iw_ep *ep;
2340 struct cpl_fw4_ack *hdr = cplhdr(skb);
2341 u8 credits = hdr->credits;
2342 unsigned int tid = GET_TID(hdr);
2343 struct tid_info *t = dev->rdev.lldi.tids;
2344
2345
2346 ep = lookup_tid(t, tid);
2347 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2348 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002349 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2350 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 return 0;
2352 }
2353
2354 dst_confirm(ep->dst);
2355 if (ep->mpa_skb) {
2356 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2357 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2358 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2359 kfree_skb(ep->mpa_skb);
2360 ep->mpa_skb = NULL;
2361 }
2362 return 0;
2363}
2364
Steve Wisecfdda9d2010-04-21 15:30:06 -07002365int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2366{
2367 int err;
2368 struct c4iw_ep *ep = to_ep(cm_id);
2369 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2370
2371 if (state_read(&ep->com) == DEAD) {
2372 c4iw_put_ep(&ep->com);
2373 return -ECONNRESET;
2374 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002375 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2377 if (mpa_rev == 0)
2378 abort_connection(ep, NULL, GFP_KERNEL);
2379 else {
2380 err = send_mpa_reject(ep, pdata, pdata_len);
2381 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2382 }
2383 c4iw_put_ep(&ep->com);
2384 return 0;
2385}
2386
2387int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2388{
2389 int err;
2390 struct c4iw_qp_attributes attrs;
2391 enum c4iw_qp_attr_mask mask;
2392 struct c4iw_ep *ep = to_ep(cm_id);
2393 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2394 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2395
2396 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2397 if (state_read(&ep->com) == DEAD) {
2398 err = -ECONNRESET;
2399 goto err;
2400 }
2401
2402 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2403 BUG_ON(!qp);
2404
Vipul Pandya793dad92012-12-10 09:30:56 +00002405 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002406 if ((conn_param->ord > c4iw_max_read_depth) ||
2407 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 abort_connection(ep, NULL, GFP_KERNEL);
2409 err = -EINVAL;
2410 goto err;
2411 }
2412
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302413 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2414 if (conn_param->ord > ep->ird) {
2415 ep->ird = conn_param->ird;
2416 ep->ord = conn_param->ord;
2417 send_mpa_reject(ep, conn_param->private_data,
2418 conn_param->private_data_len);
2419 abort_connection(ep, NULL, GFP_KERNEL);
2420 err = -ENOMEM;
2421 goto err;
2422 }
2423 if (conn_param->ird > ep->ord) {
2424 if (!ep->ord)
2425 conn_param->ird = 1;
2426 else {
2427 abort_connection(ep, NULL, GFP_KERNEL);
2428 err = -ENOMEM;
2429 goto err;
2430 }
2431 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302433 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 ep->ird = conn_param->ird;
2435 ep->ord = conn_param->ord;
2436
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302437 if (ep->mpa_attr.version != 2)
2438 if (peer2peer && ep->ird == 0)
2439 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440
2441 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2442
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302443 cm_id->add_ref(cm_id);
2444 ep->com.cm_id = cm_id;
2445 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002446 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302447
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 /* bind QP to EP and move to RTS */
2449 attrs.mpa_attr = ep->mpa_attr;
2450 attrs.max_ird = ep->ird;
2451 attrs.max_ord = ep->ord;
2452 attrs.llp_stream_handle = ep;
2453 attrs.next_state = C4IW_QP_STATE_RTS;
2454
2455 /* bind QP and TID with INIT_WR */
2456 mask = C4IW_QP_ATTR_NEXT_STATE |
2457 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2458 C4IW_QP_ATTR_MPA_ATTR |
2459 C4IW_QP_ATTR_MAX_IRD |
2460 C4IW_QP_ATTR_MAX_ORD;
2461
2462 err = c4iw_modify_qp(ep->com.qp->rhp,
2463 ep->com.qp, mask, &attrs, 1);
2464 if (err)
2465 goto err1;
2466 err = send_mpa_reply(ep, conn_param->private_data,
2467 conn_param->private_data_len);
2468 if (err)
2469 goto err1;
2470
2471 state_set(&ep->com, FPDU_MODE);
2472 established_upcall(ep);
2473 c4iw_put_ep(&ep->com);
2474 return 0;
2475err1:
2476 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 cm_id->rem_ref(cm_id);
2478err:
2479 c4iw_put_ep(&ep->com);
2480 return err;
2481}
2482
2483int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2484{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2486 struct c4iw_ep *ep;
2487 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002488 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002489
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002490 if ((conn_param->ord > c4iw_max_read_depth) ||
2491 (conn_param->ird > c4iw_max_read_depth)) {
2492 err = -EINVAL;
2493 goto out;
2494 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002495 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2496 if (!ep) {
2497 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2498 err = -ENOMEM;
2499 goto out;
2500 }
2501 init_timer(&ep->timer);
2502 ep->plen = conn_param->private_data_len;
2503 if (ep->plen)
2504 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2505 conn_param->private_data, ep->plen);
2506 ep->ird = conn_param->ird;
2507 ep->ord = conn_param->ord;
2508
2509 if (peer2peer && ep->ord == 0)
2510 ep->ord = 1;
2511
2512 cm_id->add_ref(cm_id);
2513 ep->com.dev = dev;
2514 ep->com.cm_id = cm_id;
2515 ep->com.qp = get_qhp(dev, conn_param->qpn);
2516 BUG_ON(!ep->com.qp);
Vipul Pandya325abea2013-01-07 13:11:53 +00002517 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2519 ep->com.qp, cm_id);
2520
2521 /*
2522 * Allocate an active TID to initiate a TCP connection.
2523 */
2524 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2525 if (ep->atid == -1) {
2526 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2527 err = -ENOMEM;
2528 goto fail2;
2529 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002530 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531
2532 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2533 ntohl(cm_id->local_addr.sin_addr.s_addr),
2534 ntohs(cm_id->local_addr.sin_port),
2535 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2536 ntohs(cm_id->remote_addr.sin_port));
2537
2538 /* find a route */
2539 rt = find_route(dev,
2540 cm_id->local_addr.sin_addr.s_addr,
2541 cm_id->remote_addr.sin_addr.s_addr,
2542 cm_id->local_addr.sin_port,
2543 cm_id->remote_addr.sin_port, 0);
2544 if (!rt) {
2545 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2546 err = -EHOSTUNREACH;
2547 goto fail3;
2548 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002549 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550
David Miller3786cf12011-12-02 16:52:31 +00002551 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2552 ep->dst, ep->com.dev, true);
2553 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002554 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 goto fail4;
2556 }
2557
2558 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2559 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2560 ep->l2t->idx);
2561
2562 state_set(&ep->com, CONNECTING);
2563 ep->tos = 0;
2564 ep->com.local_addr = cm_id->local_addr;
2565 ep->com.remote_addr = cm_id->remote_addr;
2566
2567 /* send connect request to rnic */
2568 err = send_connect(ep);
2569 if (!err)
2570 goto out;
2571
2572 cxgb4_l2t_release(ep->l2t);
2573fail4:
2574 dst_release(ep->dst);
2575fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002576 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2578fail2:
2579 cm_id->rem_ref(cm_id);
2580 c4iw_put_ep(&ep->com);
2581out:
2582 return err;
2583}
2584
2585int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2586{
2587 int err = 0;
2588 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2589 struct c4iw_listen_ep *ep;
2590
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591 might_sleep();
2592
2593 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2594 if (!ep) {
2595 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2596 err = -ENOMEM;
2597 goto fail1;
2598 }
2599 PDBG("%s ep %p\n", __func__, ep);
2600 cm_id->add_ref(cm_id);
2601 ep->com.cm_id = cm_id;
2602 ep->com.dev = dev;
2603 ep->backlog = backlog;
2604 ep->com.local_addr = cm_id->local_addr;
2605
2606 /*
2607 * Allocate a server TID.
2608 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002609 if (dev->rdev.lldi.enable_fw_ofld_conn)
2610 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2611 else
2612 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2613
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002615 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 err = -ENOMEM;
2617 goto fail2;
2618 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002619 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002620 state_set(&ep->com, LISTEN);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002621 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2622 do {
2623 err = cxgb4_create_server_filter(
2624 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2625 ep->com.local_addr.sin_addr.s_addr,
2626 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002627 0,
2628 ep->com.dev->rdev.lldi.rxq_ids[0],
2629 0,
2630 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002631 if (err == -EBUSY) {
2632 set_current_state(TASK_UNINTERRUPTIBLE);
2633 schedule_timeout(usecs_to_jiffies(100));
2634 }
2635 } while (err == -EBUSY);
2636 } else {
2637 c4iw_init_wr_wait(&ep->com.wr_wait);
2638 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2639 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2640 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002641 0,
Vipul Pandya1cab7752012-12-10 09:30:55 +00002642 ep->com.dev->rdev.lldi.rxq_ids[0]);
2643 if (!err)
2644 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2645 &ep->com.wr_wait,
2646 0, 0, __func__);
2647 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 if (!err) {
2649 cm_id->provider_data = ep;
2650 goto out;
2651 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002652 pr_err("%s cxgb4_create_server/filter failed err %d " \
2653 "stid %d laddr %08x lport %d\n", \
2654 __func__, err, ep->stid,
2655 ntohl(ep->com.local_addr.sin_addr.s_addr),
2656 ntohs(ep->com.local_addr.sin_port));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2658fail2:
2659 cm_id->rem_ref(cm_id);
2660 c4iw_put_ep(&ep->com);
2661fail1:
2662out:
2663 return err;
2664}
2665
2666int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2667{
2668 int err;
2669 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2670
2671 PDBG("%s ep %p\n", __func__, ep);
2672
2673 might_sleep();
2674 state_set(&ep->com, DEAD);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002675 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2676 err = cxgb4_remove_server_filter(
2677 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2678 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2679 } else {
2680 c4iw_init_wr_wait(&ep->com.wr_wait);
2681 err = listen_stop(ep);
2682 if (err)
2683 goto done;
2684 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2685 0, 0, __func__);
2686 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002687 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2689done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690 cm_id->rem_ref(cm_id);
2691 c4iw_put_ep(&ep->com);
2692 return err;
2693}
2694
2695int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2696{
2697 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698 int close = 0;
2699 int fatal = 0;
2700 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701
Steve Wise2f5b48c2010-09-10 11:15:36 -05002702 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703
2704 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2705 states[ep->com.state], abrupt);
2706
2707 rdev = &ep->com.dev->rdev;
2708 if (c4iw_fatal_error(rdev)) {
2709 fatal = 1;
2710 close_complete_upcall(ep);
2711 ep->com.state = DEAD;
2712 }
2713 switch (ep->com.state) {
2714 case MPA_REQ_WAIT:
2715 case MPA_REQ_SENT:
2716 case MPA_REQ_RCVD:
2717 case MPA_REP_SENT:
2718 case FPDU_MODE:
2719 close = 1;
2720 if (abrupt)
2721 ep->com.state = ABORTING;
2722 else {
2723 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002724 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 }
2726 set_bit(CLOSE_SENT, &ep->com.flags);
2727 break;
2728 case CLOSING:
2729 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2730 close = 1;
2731 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002732 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733 ep->com.state = ABORTING;
2734 } else
2735 ep->com.state = MORIBUND;
2736 }
2737 break;
2738 case MORIBUND:
2739 case ABORTING:
2740 case DEAD:
2741 PDBG("%s ignoring disconnect ep %p state %u\n",
2742 __func__, ep, ep->com.state);
2743 break;
2744 default:
2745 BUG();
2746 break;
2747 }
2748
Steve Wisecfdda9d2010-04-21 15:30:06 -07002749 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002750 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002751 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002752 close_complete_upcall(ep);
2753 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002754 } else {
2755 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002757 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002758 if (ret)
2759 fatal = 1;
2760 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002761 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002762 if (fatal)
2763 release_ep_resources(ep);
2764 return ret;
2765}
2766
Vipul Pandya1cab7752012-12-10 09:30:55 +00002767static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2768 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2769{
2770 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00002771 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002772
2773 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids, req->tid);
2774 if (!ep)
2775 return;
2776
2777 switch (req->retval) {
2778 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00002779 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2780 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2781 send_fw_act_open_req(ep, atid);
2782 return;
2783 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002784 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00002785 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2786 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2787 send_fw_act_open_req(ep, atid);
2788 return;
2789 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002790 break;
2791 default:
2792 pr_info("%s unexpected ofld conn wr retval %d\n",
2793 __func__, req->retval);
2794 break;
2795 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002796 pr_err("active ofld_connect_wr failure %d atid %d\n",
2797 req->retval, atid);
2798 mutex_lock(&dev->rdev.stats.lock);
2799 dev->rdev.stats.act_ofld_conn_fails++;
2800 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002801 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00002802 state_set(&ep->com, DEAD);
2803 remove_handle(dev, &dev->atid_idr, atid);
2804 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2805 dst_release(ep->dst);
2806 cxgb4_l2t_release(ep->l2t);
2807 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002808}
2809
2810static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2811 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2812{
2813 struct sk_buff *rpl_skb;
2814 struct cpl_pass_accept_req *cpl;
2815 int ret;
2816
2817 rpl_skb = (struct sk_buff *)cpu_to_be64(req->cookie);
2818 BUG_ON(!rpl_skb);
2819 if (req->retval) {
2820 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00002821 mutex_lock(&dev->rdev.stats.lock);
2822 dev->rdev.stats.pas_ofld_conn_fails++;
2823 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002824 kfree_skb(rpl_skb);
2825 } else {
2826 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2827 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
2828 htonl(req->tid)));
2829 ret = pass_accept_req(dev, rpl_skb);
2830 if (!ret)
2831 kfree_skb(rpl_skb);
2832 }
2833 return;
2834}
2835
2836static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05002837{
2838 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002839 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2840
2841 switch (rpl->type) {
2842 case FW6_TYPE_CQE:
2843 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2844 break;
2845 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2846 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2847 switch (req->t_state) {
2848 case TCP_SYN_SENT:
2849 active_ofld_conn_reply(dev, skb, req);
2850 break;
2851 case TCP_SYN_RECV:
2852 passive_ofld_conn_reply(dev, skb, req);
2853 break;
2854 default:
2855 pr_err("%s unexpected ofld conn wr state %d\n",
2856 __func__, req->t_state);
2857 break;
2858 }
2859 break;
2860 }
2861 return 0;
2862}
2863
2864static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2865{
2866 u32 l2info;
2867 u16 vlantag, len, hdr_len;
2868 u8 intf;
2869 struct cpl_rx_pkt *cpl = cplhdr(skb);
2870 struct cpl_pass_accept_req *req;
2871 struct tcp_options_received tmp_opt;
2872
2873 /* Store values from cpl_rx_pkt in temporary location. */
2874 vlantag = cpl->vlan;
2875 len = cpl->len;
2876 l2info = cpl->l2info;
2877 hdr_len = cpl->hdr_len;
2878 intf = cpl->iff;
2879
2880 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2881
2882 /*
2883 * We need to parse the TCP options from SYN packet.
2884 * to generate cpl_pass_accept_req.
2885 */
2886 memset(&tmp_opt, 0, sizeof(tmp_opt));
2887 tcp_clear_options(&tmp_opt);
2888 tcp_parse_options(skb, &tmp_opt, 0, 0, NULL);
2889
2890 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2891 memset(req, 0, sizeof(*req));
2892 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
2893 V_SYN_MAC_IDX(G_RX_MACIDX(htonl(l2info))) |
2894 F_SYN_XACT_MATCH);
2895 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(htonl(l2info))) |
2896 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(htons(hdr_len))) |
2897 V_IP_HDR_LEN(G_RX_IPHDR_LEN(htons(hdr_len))) |
2898 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(htonl(l2info))));
2899 req->vlan = vlantag;
2900 req->len = len;
2901 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2902 PASS_OPEN_TOS(tos));
2903 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2904 if (tmp_opt.wscale_ok)
2905 req->tcpopt.wsf = tmp_opt.snd_wscale;
2906 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2907 if (tmp_opt.sack_ok)
2908 req->tcpopt.sack = 1;
2909 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2910 return;
2911}
2912
2913static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2914 __be32 laddr, __be16 lport,
2915 __be32 raddr, __be16 rport,
2916 u32 rcv_isn, u32 filter, u16 window,
2917 u32 rss_qid, u8 port_id)
2918{
2919 struct sk_buff *req_skb;
2920 struct fw_ofld_connection_wr *req;
2921 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2922
2923 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2924 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2925 memset(req, 0, sizeof(*req));
2926 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2927 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2928 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
2929 req->le.filter = filter;
2930 req->le.lport = lport;
2931 req->le.pport = rport;
2932 req->le.u.ipv4.lip = laddr;
2933 req->le.u.ipv4.pip = raddr;
2934 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2935 req->tcb.rcv_adv = htons(window);
2936 req->tcb.t_state_to_astid =
2937 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2938 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2939 V_FW_OFLD_CONNECTION_WR_ASTID(
2940 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2941
2942 /*
2943 * We store the qid in opt2 which will be used by the firmware
2944 * to send us the wr response.
2945 */
2946 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2947
2948 /*
2949 * We initialize the MSS index in TCB to 0xF.
2950 * So that when driver sends cpl_pass_accept_rpl
2951 * TCB picks up the correct value. If this was 0
2952 * TP will ignore any value > 0 for MSS index.
2953 */
2954 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
2955 req->cookie = cpu_to_be64((u64)skb);
2956
2957 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
2958 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
2959}
2960
2961/*
2962 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
2963 * messages when a filter is being used instead of server to
2964 * redirect a syn packet. When packets hit filter they are redirected
2965 * to the offload queue and driver tries to establish the connection
2966 * using firmware work request.
2967 */
2968static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
2969{
2970 int stid;
2971 unsigned int filter;
2972 struct ethhdr *eh = NULL;
2973 struct vlan_ethhdr *vlan_eh = NULL;
2974 struct iphdr *iph;
2975 struct tcphdr *tcph;
2976 struct rss_header *rss = (void *)skb->data;
2977 struct cpl_rx_pkt *cpl = (void *)skb->data;
2978 struct cpl_pass_accept_req *req = (void *)(rss + 1);
2979 struct l2t_entry *e;
2980 struct dst_entry *dst;
2981 struct rtable *rt;
2982 struct c4iw_ep *lep;
2983 u16 window;
2984 struct port_info *pi;
2985 struct net_device *pdev;
2986 u16 rss_qid;
2987 int step;
2988 u32 tx_chan;
2989 struct neighbour *neigh;
2990
2991 /* Drop all non-SYN packets */
2992 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
2993 goto reject;
2994
2995 /*
2996 * Drop all packets which did not hit the filter.
2997 * Unlikely to happen.
2998 */
2999 if (!(rss->filter_hit && rss->filter_tid))
3000 goto reject;
3001
3002 /*
3003 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3004 */
3005 stid = cpu_to_be32(rss->hash_val) - dev->rdev.lldi.tids->sftid_base
3006 + dev->rdev.lldi.tids->nstids;
3007
3008 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3009 if (!lep) {
3010 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3011 goto reject;
3012 }
3013
3014 if (G_RX_ETHHDR_LEN(ntohl(cpl->l2info)) == ETH_HLEN) {
3015 eh = (struct ethhdr *)(req + 1);
3016 iph = (struct iphdr *)(eh + 1);
3017 } else {
3018 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3019 iph = (struct iphdr *)(vlan_eh + 1);
3020 skb->vlan_tci = ntohs(cpl->vlan);
3021 }
3022
3023 if (iph->version != 0x4)
3024 goto reject;
3025
3026 tcph = (struct tcphdr *)(iph + 1);
3027 skb_set_network_header(skb, (void *)iph - (void *)rss);
3028 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3029 skb_get(skb);
3030
3031 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3032 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3033 ntohs(tcph->source), iph->tos);
3034
3035 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3036 iph->tos);
3037 if (!rt) {
3038 pr_err("%s - failed to find dst entry!\n",
3039 __func__);
3040 goto reject;
3041 }
3042 dst = &rt->dst;
3043 neigh = dst_neigh_lookup_skb(dst, skb);
3044
3045 if (neigh->dev->flags & IFF_LOOPBACK) {
3046 pdev = ip_dev_find(&init_net, iph->daddr);
3047 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3048 pdev, 0);
3049 pi = (struct port_info *)netdev_priv(pdev);
3050 tx_chan = cxgb4_port_chan(pdev);
3051 dev_put(pdev);
3052 } else {
3053 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3054 neigh->dev, 0);
3055 pi = (struct port_info *)netdev_priv(neigh->dev);
3056 tx_chan = cxgb4_port_chan(neigh->dev);
3057 }
3058 if (!e) {
3059 pr_err("%s - failed to allocate l2t entry!\n",
3060 __func__);
3061 goto free_dst;
3062 }
3063
3064 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3065 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
3066 window = htons(tcph->window);
3067
3068 /* Calcuate filter portion for LE region. */
3069 filter = cpu_to_be32(select_ntuple(dev, dst, e));
3070
3071 /*
3072 * Synthesize the cpl_pass_accept_req. We have everything except the
3073 * TID. Once firmware sends a reply with TID we update the TID field
3074 * in cpl and pass it through the regular cpl_pass_accept_req path.
3075 */
3076 build_cpl_pass_accept_req(skb, stid, iph->tos);
3077 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3078 tcph->source, ntohl(tcph->seq), filter, window,
3079 rss_qid, pi->port_id);
3080 cxgb4_l2t_release(e);
3081free_dst:
3082 dst_release(dst);
3083reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003084 return 0;
3085}
3086
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003088 * These are the real handlers that are called from a
3089 * work queue.
3090 */
3091static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3092 [CPL_ACT_ESTABLISH] = act_establish,
3093 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3094 [CPL_RX_DATA] = rx_data,
3095 [CPL_ABORT_RPL_RSS] = abort_rpl,
3096 [CPL_ABORT_RPL] = abort_rpl,
3097 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3098 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3099 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3100 [CPL_PASS_ESTABLISH] = pass_establish,
3101 [CPL_PEER_CLOSE] = peer_close,
3102 [CPL_ABORT_REQ_RSS] = peer_abort,
3103 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3104 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003105 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003106 [CPL_FW6_MSG] = deferred_fw6_msg,
3107 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003108};
3109
3110static void process_timeout(struct c4iw_ep *ep)
3111{
3112 struct c4iw_qp_attributes attrs;
3113 int abort = 1;
3114
Steve Wise2f5b48c2010-09-10 11:15:36 -05003115 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003116 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3117 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003118 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003119 switch (ep->com.state) {
3120 case MPA_REQ_SENT:
3121 __state_set(&ep->com, ABORTING);
3122 connect_reply_upcall(ep, -ETIMEDOUT);
3123 break;
3124 case MPA_REQ_WAIT:
3125 __state_set(&ep->com, ABORTING);
3126 break;
3127 case CLOSING:
3128 case MORIBUND:
3129 if (ep->com.cm_id && ep->com.qp) {
3130 attrs.next_state = C4IW_QP_STATE_ERROR;
3131 c4iw_modify_qp(ep->com.qp->rhp,
3132 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3133 &attrs, 1);
3134 }
3135 __state_set(&ep->com, ABORTING);
3136 break;
3137 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003138 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003139 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003140 abort = 0;
3141 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003142 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003143 if (abort)
3144 abort_connection(ep, NULL, GFP_KERNEL);
3145 c4iw_put_ep(&ep->com);
3146}
3147
3148static void process_timedout_eps(void)
3149{
3150 struct c4iw_ep *ep;
3151
3152 spin_lock_irq(&timeout_lock);
3153 while (!list_empty(&timeout_list)) {
3154 struct list_head *tmp;
3155
3156 tmp = timeout_list.next;
3157 list_del(tmp);
3158 spin_unlock_irq(&timeout_lock);
3159 ep = list_entry(tmp, struct c4iw_ep, entry);
3160 process_timeout(ep);
3161 spin_lock_irq(&timeout_lock);
3162 }
3163 spin_unlock_irq(&timeout_lock);
3164}
3165
3166static void process_work(struct work_struct *work)
3167{
3168 struct sk_buff *skb = NULL;
3169 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003170 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003171 unsigned int opcode;
3172 int ret;
3173
3174 while ((skb = skb_dequeue(&rxq))) {
3175 rpl = cplhdr(skb);
3176 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3177 opcode = rpl->ot.opcode;
3178
3179 BUG_ON(!work_handlers[opcode]);
3180 ret = work_handlers[opcode](dev, skb);
3181 if (!ret)
3182 kfree_skb(skb);
3183 }
3184 process_timedout_eps();
3185}
3186
3187static DECLARE_WORK(skb_work, process_work);
3188
3189static void ep_timeout(unsigned long arg)
3190{
3191 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003192 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003193
3194 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003195 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3196 list_add_tail(&ep->entry, &timeout_list);
3197 kickit = 1;
3198 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003199 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003200 if (kickit)
3201 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003202}
3203
3204/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003205 * All the CM events are handled on a work queue to have a safe context.
3206 */
3207static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3208{
3209
3210 /*
3211 * Save dev in the skb->cb area.
3212 */
3213 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3214
3215 /*
3216 * Queue the skb and schedule the worker thread.
3217 */
3218 skb_queue_tail(&rxq, skb);
3219 queue_work(workq, &skb_work);
3220 return 0;
3221}
3222
3223static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3224{
3225 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3226
3227 if (rpl->status != CPL_ERR_NONE) {
3228 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3229 "for tid %u\n", rpl->status, GET_TID(rpl));
3230 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003231 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232 return 0;
3233}
3234
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003235static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3236{
3237 struct cpl_fw6_msg *rpl = cplhdr(skb);
3238 struct c4iw_wr_wait *wr_waitp;
3239 int ret;
3240
3241 PDBG("%s type %u\n", __func__, rpl->type);
3242
3243 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003244 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003245 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003246 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003247 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003248 if (wr_waitp)
3249 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003250 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003251 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003252 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003253 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003254 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003255 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003256 default:
3257 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3258 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003259 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003260 break;
3261 }
3262 return 0;
3263}
3264
Steve Wise8da7e7a2011-06-14 20:59:27 +00003265static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3266{
3267 struct cpl_abort_req_rss *req = cplhdr(skb);
3268 struct c4iw_ep *ep;
3269 struct tid_info *t = dev->rdev.lldi.tids;
3270 unsigned int tid = GET_TID(req);
3271
3272 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003273 if (!ep) {
3274 printk(KERN_WARNING MOD
3275 "Abort on non-existent endpoint, tid %d\n", tid);
3276 kfree_skb(skb);
3277 return 0;
3278 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003279 if (is_neg_adv_abort(req->status)) {
3280 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3281 ep->hwtid);
3282 kfree_skb(skb);
3283 return 0;
3284 }
3285 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3286 ep->com.state);
3287
3288 /*
3289 * Wake up any threads in rdma_init() or rdma_fini().
3290 */
Steve Wise0f1dcfa2012-04-27 09:59:16 -05003291 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003292 sched(dev, skb);
3293 return 0;
3294}
3295
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003296/*
3297 * Most upcalls from the T4 Core go to sched() to
3298 * schedule the processing on a work queue.
3299 */
3300c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3301 [CPL_ACT_ESTABLISH] = sched,
3302 [CPL_ACT_OPEN_RPL] = sched,
3303 [CPL_RX_DATA] = sched,
3304 [CPL_ABORT_RPL_RSS] = sched,
3305 [CPL_ABORT_RPL] = sched,
3306 [CPL_PASS_OPEN_RPL] = sched,
3307 [CPL_CLOSE_LISTSRV_RPL] = sched,
3308 [CPL_PASS_ACCEPT_REQ] = sched,
3309 [CPL_PASS_ESTABLISH] = sched,
3310 [CPL_PEER_CLOSE] = sched,
3311 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003312 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003313 [CPL_RDMA_TERMINATE] = sched,
3314 [CPL_FW4_ACK] = sched,
3315 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003316 [CPL_FW6_MSG] = fw6_msg,
3317 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003318};
3319
Steve Wisecfdda9d2010-04-21 15:30:06 -07003320int __init c4iw_cm_init(void)
3321{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003322 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003323 skb_queue_head_init(&rxq);
3324
3325 workq = create_singlethread_workqueue("iw_cxgb4");
3326 if (!workq)
3327 return -ENOMEM;
3328
Steve Wisecfdda9d2010-04-21 15:30:06 -07003329 return 0;
3330}
3331
3332void __exit c4iw_cm_term(void)
3333{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003334 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003335 flush_workqueue(workq);
3336 destroy_workqueue(workq);
3337}