blob: 65c30ea8c1a156f0f7d81bc4e039723b321be8dd [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)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000287 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700288 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
289 dst_release(ep->dst);
290 cxgb4_l2t_release(ep->l2t);
291 }
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;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000514 struct cpl_t5_act_open_req *t5_req;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700515 struct sk_buff *skb;
516 u64 opt0;
517 u32 opt2;
518 unsigned int mtu_idx;
519 int wscale;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000520 int size = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
521 sizeof(struct cpl_act_open_req) :
522 sizeof(struct cpl_t5_act_open_req);
523 int wrlen = roundup(size, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700524
525 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
526
527 skb = get_skb(NULL, wrlen, GFP_KERNEL);
528 if (!skb) {
529 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
530 __func__);
531 return -ENOMEM;
532 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000533 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700534
535 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
536 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000537 opt0 = (nocong ? NO_CONG(1) : 0) |
538 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000539 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700540 WND_SCALE(wscale) |
541 MSS_IDX(mtu_idx) |
542 L2T_IDX(ep->l2t->idx) |
543 TX_CHAN(ep->tx_chan) |
544 SMAC_SEL(ep->smac_idx) |
545 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000546 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700547 RCV_BUFSIZ(rcv_win>>10);
548 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000549 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700550 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
551 if (enable_tcp_timestamps)
552 opt2 |= TSTAMPS_EN(1);
553 if (enable_tcp_sack)
554 opt2 |= SACK_EN(1);
555 if (wscale && enable_tcp_window_scaling)
556 opt2 |= WND_SCALE_EN(1);
557 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
558
Vipul Pandyaf079af72013-03-14 05:08:58 +0000559 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
560 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
561 INIT_TP_WR(req, 0);
562 OPCODE_TID(req) = cpu_to_be32(
563 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
564 ((ep->rss_qid << 14) | ep->atid)));
565 req->local_port = ep->com.local_addr.sin_port;
566 req->peer_port = ep->com.remote_addr.sin_port;
567 req->local_ip = ep->com.local_addr.sin_addr.s_addr;
568 req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
569 req->opt0 = cpu_to_be64(opt0);
570 req->params = cpu_to_be32(select_ntuple(ep->com.dev,
571 ep->dst, ep->l2t));
572 req->opt2 = cpu_to_be32(opt2);
573 } else {
574 t5_req = (struct cpl_t5_act_open_req *) skb_put(skb, wrlen);
575 INIT_TP_WR(t5_req, 0);
576 OPCODE_TID(t5_req) = cpu_to_be32(
577 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
578 ((ep->rss_qid << 14) | ep->atid)));
579 t5_req->local_port = ep->com.local_addr.sin_port;
580 t5_req->peer_port = ep->com.remote_addr.sin_port;
581 t5_req->local_ip = ep->com.local_addr.sin_addr.s_addr;
582 t5_req->peer_ip = ep->com.remote_addr.sin_addr.s_addr;
583 t5_req->opt0 = cpu_to_be64(opt0);
584 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
585 select_ntuple(ep->com.dev, ep->dst, ep->l2t)));
586 t5_req->opt2 = cpu_to_be32(opt2);
587 }
588
Vipul Pandya793dad92012-12-10 09:30:56 +0000589 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700590 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
591}
592
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530593static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
594 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700595{
596 int mpalen, wrlen;
597 struct fw_ofld_tx_data_wr *req;
598 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530599 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600
601 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
602
603 BUG_ON(skb_cloned(skb));
604
605 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530606 if (mpa_rev_to_use == 2)
607 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700608 wrlen = roundup(mpalen + sizeof *req, 16);
609 skb = get_skb(skb, wrlen, GFP_KERNEL);
610 if (!skb) {
611 connect_reply_upcall(ep, -ENOMEM);
612 return;
613 }
614 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
615
616 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
617 memset(req, 0, wrlen);
618 req->op_to_immdlen = cpu_to_be32(
619 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
620 FW_WR_COMPL(1) |
621 FW_WR_IMMDLEN(mpalen));
622 req->flowid_len16 = cpu_to_be32(
623 FW_WR_FLOWID(ep->hwtid) |
624 FW_WR_LEN16(wrlen >> 4));
625 req->plen = cpu_to_be32(mpalen);
626 req->tunnel_to_proxy = cpu_to_be32(
627 FW_OFLD_TX_DATA_WR_FLUSH(1) |
628 FW_OFLD_TX_DATA_WR_SHOVE(1));
629
630 mpa = (struct mpa_message *)(req + 1);
631 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
632 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530633 (markers_enabled ? MPA_MARKERS : 0) |
634 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700635 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530636 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530637 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530638 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530639 ep->retry_with_mpa_v1 = 0;
640 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530642 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700643 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
644 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530645 mpa_v2_params.ird = htons((u16)ep->ird);
646 mpa_v2_params.ord = htons((u16)ep->ord);
647
648 if (peer2peer) {
649 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
650 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
651 mpa_v2_params.ord |=
652 htons(MPA_V2_RDMA_WRITE_RTR);
653 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
654 mpa_v2_params.ord |=
655 htons(MPA_V2_RDMA_READ_RTR);
656 }
657 memcpy(mpa->private_data, &mpa_v2_params,
658 sizeof(struct mpa_v2_conn_params));
659
660 if (ep->plen)
661 memcpy(mpa->private_data +
662 sizeof(struct mpa_v2_conn_params),
663 ep->mpa_pkt + sizeof(*mpa), ep->plen);
664 } else
665 if (ep->plen)
666 memcpy(mpa->private_data,
667 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668
669 /*
670 * Reference the mpa skb. This ensures the data area
671 * will remain in memory until the hw acks the tx.
672 * Function fw4_ack() will deref it.
673 */
674 skb_get(skb);
675 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
676 BUG_ON(ep->mpa_skb);
677 ep->mpa_skb = skb;
678 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
679 start_ep_timer(ep);
680 state_set(&ep->com, MPA_REQ_SENT);
681 ep->mpa_attr.initiator = 1;
682 return;
683}
684
685static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
686{
687 int mpalen, wrlen;
688 struct fw_ofld_tx_data_wr *req;
689 struct mpa_message *mpa;
690 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530691 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700692
693 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
694
695 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530696 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
697 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700698 wrlen = roundup(mpalen + sizeof *req, 16);
699
700 skb = get_skb(NULL, wrlen, GFP_KERNEL);
701 if (!skb) {
702 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
703 return -ENOMEM;
704 }
705 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
706
707 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
708 memset(req, 0, wrlen);
709 req->op_to_immdlen = cpu_to_be32(
710 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
711 FW_WR_COMPL(1) |
712 FW_WR_IMMDLEN(mpalen));
713 req->flowid_len16 = cpu_to_be32(
714 FW_WR_FLOWID(ep->hwtid) |
715 FW_WR_LEN16(wrlen >> 4));
716 req->plen = cpu_to_be32(mpalen);
717 req->tunnel_to_proxy = cpu_to_be32(
718 FW_OFLD_TX_DATA_WR_FLUSH(1) |
719 FW_OFLD_TX_DATA_WR_SHOVE(1));
720
721 mpa = (struct mpa_message *)(req + 1);
722 memset(mpa, 0, sizeof(*mpa));
723 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
724 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000725 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530727
728 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
729 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700730 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
731 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530732 mpa_v2_params.ird = htons(((u16)ep->ird) |
733 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
734 0));
735 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
736 (p2p_type ==
737 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
738 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
739 FW_RI_INIT_P2PTYPE_READ_REQ ?
740 MPA_V2_RDMA_READ_RTR : 0) : 0));
741 memcpy(mpa->private_data, &mpa_v2_params,
742 sizeof(struct mpa_v2_conn_params));
743
744 if (ep->plen)
745 memcpy(mpa->private_data +
746 sizeof(struct mpa_v2_conn_params), pdata, plen);
747 } else
748 if (plen)
749 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700750
751 /*
752 * Reference the mpa skb again. This ensures the data area
753 * will remain in memory until the hw acks the tx.
754 * Function fw4_ack() will deref it.
755 */
756 skb_get(skb);
757 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
758 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
759 BUG_ON(ep->mpa_skb);
760 ep->mpa_skb = skb;
761 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
762}
763
764static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
765{
766 int mpalen, wrlen;
767 struct fw_ofld_tx_data_wr *req;
768 struct mpa_message *mpa;
769 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530770 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700771
772 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
773
774 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530775 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
776 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700777 wrlen = roundup(mpalen + sizeof *req, 16);
778
779 skb = get_skb(NULL, wrlen, GFP_KERNEL);
780 if (!skb) {
781 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
782 return -ENOMEM;
783 }
784 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
785
786 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
787 memset(req, 0, wrlen);
788 req->op_to_immdlen = cpu_to_be32(
789 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
790 FW_WR_COMPL(1) |
791 FW_WR_IMMDLEN(mpalen));
792 req->flowid_len16 = cpu_to_be32(
793 FW_WR_FLOWID(ep->hwtid) |
794 FW_WR_LEN16(wrlen >> 4));
795 req->plen = cpu_to_be32(mpalen);
796 req->tunnel_to_proxy = cpu_to_be32(
797 FW_OFLD_TX_DATA_WR_FLUSH(1) |
798 FW_OFLD_TX_DATA_WR_SHOVE(1));
799
800 mpa = (struct mpa_message *)(req + 1);
801 memset(mpa, 0, sizeof(*mpa));
802 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
803 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
804 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530805 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700806 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530807
808 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
809 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700810 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
811 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530812 mpa_v2_params.ird = htons((u16)ep->ird);
813 mpa_v2_params.ord = htons((u16)ep->ord);
814 if (peer2peer && (ep->mpa_attr.p2p_type !=
815 FW_RI_INIT_P2PTYPE_DISABLED)) {
816 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
817
818 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
819 mpa_v2_params.ord |=
820 htons(MPA_V2_RDMA_WRITE_RTR);
821 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
822 mpa_v2_params.ord |=
823 htons(MPA_V2_RDMA_READ_RTR);
824 }
825
826 memcpy(mpa->private_data, &mpa_v2_params,
827 sizeof(struct mpa_v2_conn_params));
828
829 if (ep->plen)
830 memcpy(mpa->private_data +
831 sizeof(struct mpa_v2_conn_params), pdata, plen);
832 } else
833 if (plen)
834 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700835
836 /*
837 * Reference the mpa skb. This ensures the data area
838 * will remain in memory until the hw acks the tx.
839 * Function fw4_ack() will deref it.
840 */
841 skb_get(skb);
842 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
843 ep->mpa_skb = skb;
844 state_set(&ep->com, MPA_REP_SENT);
845 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
846}
847
848static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
849{
850 struct c4iw_ep *ep;
851 struct cpl_act_establish *req = cplhdr(skb);
852 unsigned int tid = GET_TID(req);
853 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
854 struct tid_info *t = dev->rdev.lldi.tids;
855
856 ep = lookup_atid(t, atid);
857
858 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
859 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
860
861 dst_confirm(ep->dst);
862
863 /* setup the hwtid for this connection */
864 ep->hwtid = tid;
865 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000866 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700867
868 ep->snd_seq = be32_to_cpu(req->snd_isn);
869 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
870
871 set_emss(ep, ntohs(req->tcp_opt));
872
873 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000874 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700875 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000876 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700877
878 /* start MPA negotiation */
879 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530880 if (ep->retry_with_mpa_v1)
881 send_mpa_req(ep, skb, 1);
882 else
883 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700884
885 return 0;
886}
887
888static void close_complete_upcall(struct c4iw_ep *ep)
889{
890 struct iw_cm_event event;
891
892 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
893 memset(&event, 0, sizeof(event));
894 event.event = IW_CM_EVENT_CLOSE;
895 if (ep->com.cm_id) {
896 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
897 ep, ep->com.cm_id, ep->hwtid);
898 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
899 ep->com.cm_id->rem_ref(ep->com.cm_id);
900 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000901 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700902 }
903}
904
905static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
906{
907 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
908 close_complete_upcall(ep);
909 state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +0000910 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700911 return send_abort(ep, skb, gfp);
912}
913
914static void peer_close_upcall(struct c4iw_ep *ep)
915{
916 struct iw_cm_event event;
917
918 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
919 memset(&event, 0, sizeof(event));
920 event.event = IW_CM_EVENT_DISCONNECT;
921 if (ep->com.cm_id) {
922 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
923 ep, ep->com.cm_id, ep->hwtid);
924 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +0000925 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926 }
927}
928
929static void peer_abort_upcall(struct c4iw_ep *ep)
930{
931 struct iw_cm_event event;
932
933 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
934 memset(&event, 0, sizeof(event));
935 event.event = IW_CM_EVENT_CLOSE;
936 event.status = -ECONNRESET;
937 if (ep->com.cm_id) {
938 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
939 ep->com.cm_id, ep->hwtid);
940 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
941 ep->com.cm_id->rem_ref(ep->com.cm_id);
942 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000943 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700944 }
945}
946
947static void connect_reply_upcall(struct c4iw_ep *ep, int status)
948{
949 struct iw_cm_event event;
950
951 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
952 memset(&event, 0, sizeof(event));
953 event.event = IW_CM_EVENT_CONNECT_REPLY;
954 event.status = status;
955 event.local_addr = ep->com.local_addr;
956 event.remote_addr = ep->com.remote_addr;
957
958 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530959 if (!ep->tried_with_mpa_v1) {
960 /* this means MPA_v2 is used */
961 event.private_data_len = ep->plen -
962 sizeof(struct mpa_v2_conn_params);
963 event.private_data = ep->mpa_pkt +
964 sizeof(struct mpa_message) +
965 sizeof(struct mpa_v2_conn_params);
966 } else {
967 /* this means MPA_v1 is used */
968 event.private_data_len = ep->plen;
969 event.private_data = ep->mpa_pkt +
970 sizeof(struct mpa_message);
971 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700972 }
Roland Dreier85963e42010-07-19 13:13:09 -0700973
974 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
975 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +0000976 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -0700977 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
978
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979 if (status < 0) {
980 ep->com.cm_id->rem_ref(ep->com.cm_id);
981 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982 }
983}
984
985static void connect_request_upcall(struct c4iw_ep *ep)
986{
987 struct iw_cm_event event;
988
989 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
990 memset(&event, 0, sizeof(event));
991 event.event = IW_CM_EVENT_CONNECT_REQUEST;
992 event.local_addr = ep->com.local_addr;
993 event.remote_addr = ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530995 if (!ep->tried_with_mpa_v1) {
996 /* this means MPA_v2 is used */
997 event.ord = ep->ord;
998 event.ird = ep->ird;
999 event.private_data_len = ep->plen -
1000 sizeof(struct mpa_v2_conn_params);
1001 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1002 sizeof(struct mpa_v2_conn_params);
1003 } else {
1004 /* this means MPA_v1 is used. Send max supported */
1005 event.ord = c4iw_max_read_depth;
1006 event.ird = c4iw_max_read_depth;
1007 event.private_data_len = ep->plen;
1008 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1009 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001010 if (state_read(&ep->parent_ep->com) != DEAD) {
1011 c4iw_get_ep(&ep->com);
1012 ep->parent_ep->com.cm_id->event_handler(
1013 ep->parent_ep->com.cm_id,
1014 &event);
1015 }
Vipul Pandya793dad92012-12-10 09:30:56 +00001016 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001017 c4iw_put_ep(&ep->parent_ep->com);
1018 ep->parent_ep = NULL;
1019}
1020
1021static void established_upcall(struct c4iw_ep *ep)
1022{
1023 struct iw_cm_event event;
1024
1025 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1026 memset(&event, 0, sizeof(event));
1027 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301028 event.ird = ep->ird;
1029 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001030 if (ep->com.cm_id) {
1031 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1032 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001033 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001034 }
1035}
1036
1037static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1038{
1039 struct cpl_rx_data_ack *req;
1040 struct sk_buff *skb;
1041 int wrlen = roundup(sizeof *req, 16);
1042
1043 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1044 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1045 if (!skb) {
1046 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1047 return 0;
1048 }
1049
1050 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1051 memset(req, 0, wrlen);
1052 INIT_TP_WR(req, ep->hwtid);
1053 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1054 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001055 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1056 F_RX_DACK_CHANGE |
1057 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001058 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001059 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1060 return credits;
1061}
1062
1063static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1064{
1065 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301066 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301068 u16 resp_ird, resp_ord;
1069 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 struct c4iw_qp_attributes attrs;
1071 enum c4iw_qp_attr_mask mask;
1072 int err;
1073
1074 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1075
1076 /*
1077 * Stop mpa timer. If it expired, then the state has
1078 * changed and we bail since ep_timeout already aborted
1079 * the connection.
1080 */
1081 stop_ep_timer(ep);
1082 if (state_read(&ep->com) != MPA_REQ_SENT)
1083 return;
1084
1085 /*
1086 * If we get more than the supported amount of private data
1087 * then we must fail this connection.
1088 */
1089 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1090 err = -EINVAL;
1091 goto err;
1092 }
1093
1094 /*
1095 * copy the new data into our accumulation buffer.
1096 */
1097 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1098 skb->len);
1099 ep->mpa_pkt_len += skb->len;
1100
1101 /*
1102 * if we don't even have the mpa message, then bail.
1103 */
1104 if (ep->mpa_pkt_len < sizeof(*mpa))
1105 return;
1106 mpa = (struct mpa_message *) ep->mpa_pkt;
1107
1108 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301109 if (mpa->revision > mpa_rev) {
1110 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1111 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001112 err = -EPROTO;
1113 goto err;
1114 }
1115 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1116 err = -EPROTO;
1117 goto err;
1118 }
1119
1120 plen = ntohs(mpa->private_data_size);
1121
1122 /*
1123 * Fail if there's too much private data.
1124 */
1125 if (plen > MPA_MAX_PRIVATE_DATA) {
1126 err = -EPROTO;
1127 goto err;
1128 }
1129
1130 /*
1131 * If plen does not account for pkt size
1132 */
1133 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1134 err = -EPROTO;
1135 goto err;
1136 }
1137
1138 ep->plen = (u8) plen;
1139
1140 /*
1141 * If we don't have all the pdata yet, then bail.
1142 * We'll continue process when more data arrives.
1143 */
1144 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1145 return;
1146
1147 if (mpa->flags & MPA_REJECT) {
1148 err = -ECONNREFUSED;
1149 goto err;
1150 }
1151
1152 /*
1153 * If we get here we have accumulated the entire mpa
1154 * start reply message including private data. And
1155 * the MPA header is valid.
1156 */
1157 state_set(&ep->com, FPDU_MODE);
1158 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1159 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1160 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301161 ep->mpa_attr.version = mpa->revision;
1162 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1163
1164 if (mpa->revision == 2) {
1165 ep->mpa_attr.enhanced_rdma_conn =
1166 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1167 if (ep->mpa_attr.enhanced_rdma_conn) {
1168 mpa_v2_params = (struct mpa_v2_conn_params *)
1169 (ep->mpa_pkt + sizeof(*mpa));
1170 resp_ird = ntohs(mpa_v2_params->ird) &
1171 MPA_V2_IRD_ORD_MASK;
1172 resp_ord = ntohs(mpa_v2_params->ord) &
1173 MPA_V2_IRD_ORD_MASK;
1174
1175 /*
1176 * This is a double-check. Ideally, below checks are
1177 * not required since ird/ord stuff has been taken
1178 * care of in c4iw_accept_cr
1179 */
1180 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1181 err = -ENOMEM;
1182 ep->ird = resp_ord;
1183 ep->ord = resp_ird;
1184 insuff_ird = 1;
1185 }
1186
1187 if (ntohs(mpa_v2_params->ird) &
1188 MPA_V2_PEER2PEER_MODEL) {
1189 if (ntohs(mpa_v2_params->ord) &
1190 MPA_V2_RDMA_WRITE_RTR)
1191 ep->mpa_attr.p2p_type =
1192 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1193 else if (ntohs(mpa_v2_params->ord) &
1194 MPA_V2_RDMA_READ_RTR)
1195 ep->mpa_attr.p2p_type =
1196 FW_RI_INIT_P2PTYPE_READ_REQ;
1197 }
1198 }
1199 } else if (mpa->revision == 1)
1200 if (peer2peer)
1201 ep->mpa_attr.p2p_type = p2p_type;
1202
Steve Wisecfdda9d2010-04-21 15:30:06 -07001203 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301204 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1205 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1206 ep->mpa_attr.recv_marker_enabled,
1207 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1208 ep->mpa_attr.p2p_type, p2p_type);
1209
1210 /*
1211 * If responder's RTR does not match with that of initiator, assign
1212 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1213 * generated when moving QP to RTS state.
1214 * A TERM message will be sent after QP has moved to RTS state
1215 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001216 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301217 (ep->mpa_attr.p2p_type != p2p_type)) {
1218 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1219 rtr_mismatch = 1;
1220 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221
1222 attrs.mpa_attr = ep->mpa_attr;
1223 attrs.max_ird = ep->ird;
1224 attrs.max_ord = ep->ord;
1225 attrs.llp_stream_handle = ep;
1226 attrs.next_state = C4IW_QP_STATE_RTS;
1227
1228 mask = C4IW_QP_ATTR_NEXT_STATE |
1229 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1230 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1231
1232 /* bind QP and TID with INIT_WR */
1233 err = c4iw_modify_qp(ep->com.qp->rhp,
1234 ep->com.qp, mask, &attrs, 1);
1235 if (err)
1236 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301237
1238 /*
1239 * If responder's RTR requirement did not match with what initiator
1240 * supports, generate TERM message
1241 */
1242 if (rtr_mismatch) {
1243 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1244 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1245 attrs.ecode = MPA_NOMATCH_RTR;
1246 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1247 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1248 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1249 err = -ENOMEM;
1250 goto out;
1251 }
1252
1253 /*
1254 * Generate TERM if initiator IRD is not sufficient for responder
1255 * provided ORD. Currently, we do the same behaviour even when
1256 * responder provided IRD is also not sufficient as regards to
1257 * initiator ORD.
1258 */
1259 if (insuff_ird) {
1260 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1261 __func__);
1262 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1263 attrs.ecode = MPA_INSUFF_IRD;
1264 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1265 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1266 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1267 err = -ENOMEM;
1268 goto out;
1269 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001270 goto out;
1271err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001272 state_set(&ep->com, ABORTING);
1273 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274out:
1275 connect_reply_upcall(ep, err);
1276 return;
1277}
1278
1279static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1280{
1281 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301282 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001283 u16 plen;
1284
1285 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1286
1287 if (state_read(&ep->com) != MPA_REQ_WAIT)
1288 return;
1289
1290 /*
1291 * If we get more than the supported amount of private data
1292 * then we must fail this connection.
1293 */
1294 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1295 stop_ep_timer(ep);
1296 abort_connection(ep, skb, GFP_KERNEL);
1297 return;
1298 }
1299
1300 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1301
1302 /*
1303 * Copy the new data into our accumulation buffer.
1304 */
1305 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1306 skb->len);
1307 ep->mpa_pkt_len += skb->len;
1308
1309 /*
1310 * If we don't even have the mpa message, then bail.
1311 * We'll continue process when more data arrives.
1312 */
1313 if (ep->mpa_pkt_len < sizeof(*mpa))
1314 return;
1315
1316 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1317 stop_ep_timer(ep);
1318 mpa = (struct mpa_message *) ep->mpa_pkt;
1319
1320 /*
1321 * Validate MPA Header.
1322 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301323 if (mpa->revision > mpa_rev) {
1324 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1325 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001326 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001327 abort_connection(ep, skb, GFP_KERNEL);
1328 return;
1329 }
1330
1331 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001332 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001333 abort_connection(ep, skb, GFP_KERNEL);
1334 return;
1335 }
1336
1337 plen = ntohs(mpa->private_data_size);
1338
1339 /*
1340 * Fail if there's too much private data.
1341 */
1342 if (plen > MPA_MAX_PRIVATE_DATA) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001343 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001344 abort_connection(ep, skb, GFP_KERNEL);
1345 return;
1346 }
1347
1348 /*
1349 * If plen does not account for pkt size
1350 */
1351 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001352 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001353 abort_connection(ep, skb, GFP_KERNEL);
1354 return;
1355 }
1356 ep->plen = (u8) plen;
1357
1358 /*
1359 * If we don't have all the pdata yet, then bail.
1360 */
1361 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1362 return;
1363
1364 /*
1365 * If we get here we have accumulated the entire mpa
1366 * start reply message including private data.
1367 */
1368 ep->mpa_attr.initiator = 0;
1369 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1370 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1371 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301372 ep->mpa_attr.version = mpa->revision;
1373 if (mpa->revision == 1)
1374 ep->tried_with_mpa_v1 = 1;
1375 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1376
1377 if (mpa->revision == 2) {
1378 ep->mpa_attr.enhanced_rdma_conn =
1379 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1380 if (ep->mpa_attr.enhanced_rdma_conn) {
1381 mpa_v2_params = (struct mpa_v2_conn_params *)
1382 (ep->mpa_pkt + sizeof(*mpa));
1383 ep->ird = ntohs(mpa_v2_params->ird) &
1384 MPA_V2_IRD_ORD_MASK;
1385 ep->ord = ntohs(mpa_v2_params->ord) &
1386 MPA_V2_IRD_ORD_MASK;
1387 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1388 if (peer2peer) {
1389 if (ntohs(mpa_v2_params->ord) &
1390 MPA_V2_RDMA_WRITE_RTR)
1391 ep->mpa_attr.p2p_type =
1392 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1393 else if (ntohs(mpa_v2_params->ord) &
1394 MPA_V2_RDMA_READ_RTR)
1395 ep->mpa_attr.p2p_type =
1396 FW_RI_INIT_P2PTYPE_READ_REQ;
1397 }
1398 }
1399 } else if (mpa->revision == 1)
1400 if (peer2peer)
1401 ep->mpa_attr.p2p_type = p2p_type;
1402
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1404 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1405 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1406 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1407 ep->mpa_attr.p2p_type);
1408
1409 state_set(&ep->com, MPA_REQ_RCVD);
1410
1411 /* drive upcall */
1412 connect_request_upcall(ep);
1413 return;
1414}
1415
1416static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1417{
1418 struct c4iw_ep *ep;
1419 struct cpl_rx_data *hdr = cplhdr(skb);
1420 unsigned int dlen = ntohs(hdr->len);
1421 unsigned int tid = GET_TID(hdr);
1422 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001423 __u8 status = hdr->status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001424
1425 ep = lookup_tid(t, tid);
1426 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1427 skb_pull(skb, sizeof(*hdr));
1428 skb_trim(skb, dlen);
1429
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430 /* update RX credits */
1431 update_rx_credits(ep, dlen);
1432
1433 switch (state_read(&ep->com)) {
1434 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001435 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001436 process_mpa_reply(ep, skb);
1437 break;
1438 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001439 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001440 process_mpa_request(ep, skb);
1441 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001442 case FPDU_MODE: {
1443 struct c4iw_qp_attributes attrs;
1444 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001445 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001446 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001447 " qpid %u ep %p state %d tid %u status %d\n",
1448 __func__, ep->com.qp->wq.sq.qid, ep,
1449 state_read(&ep->com), ep->hwtid, status);
Vipul Pandya15579672013-01-07 13:11:52 +00001450 attrs.next_state = C4IW_QP_STATE_ERROR;
1451 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1452 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001453 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001454 break;
1455 }
Vipul Pandya15579672013-01-07 13:11:52 +00001456 default:
1457 break;
1458 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459 return 0;
1460}
1461
1462static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1463{
1464 struct c4iw_ep *ep;
1465 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001466 int release = 0;
1467 unsigned int tid = GET_TID(rpl);
1468 struct tid_info *t = dev->rdev.lldi.tids;
1469
1470 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301471 if (!ep) {
1472 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1473 return 0;
1474 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001475 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001476 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 switch (ep->com.state) {
1478 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001479 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001480 __state_set(&ep->com, DEAD);
1481 release = 1;
1482 break;
1483 default:
1484 printk(KERN_ERR "%s ep %p state %d\n",
1485 __func__, ep, ep->com.state);
1486 break;
1487 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001488 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001489
1490 if (release)
1491 release_ep_resources(ep);
1492 return 0;
1493}
1494
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001495static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1496{
1497 struct sk_buff *skb;
1498 struct fw_ofld_connection_wr *req;
1499 unsigned int mtu_idx;
1500 int wscale;
1501
1502 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1503 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1504 memset(req, 0, sizeof(*req));
1505 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1506 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1507 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1508 ep->l2t));
1509 req->le.lport = ep->com.local_addr.sin_port;
1510 req->le.pport = ep->com.remote_addr.sin_port;
1511 req->le.u.ipv4.lip = ep->com.local_addr.sin_addr.s_addr;
1512 req->le.u.ipv4.pip = ep->com.remote_addr.sin_addr.s_addr;
1513 req->tcb.t_state_to_astid =
1514 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1515 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1516 req->tcb.cplrxdataack_cplpassacceptrpl =
1517 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001518 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001519 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001520 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1521 wscale = compute_wscale(rcv_win);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001522 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001523 (nocong ? NO_CONG(1) : 0) |
1524 KEEP_ALIVE(1) |
1525 DELACK(1) |
1526 WND_SCALE(wscale) |
1527 MSS_IDX(mtu_idx) |
1528 L2T_IDX(ep->l2t->idx) |
1529 TX_CHAN(ep->tx_chan) |
1530 SMAC_SEL(ep->smac_idx) |
1531 DSCP(ep->tos) |
1532 ULP_MODE(ULP_MODE_TCPDDP) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001533 RCV_BUFSIZ(rcv_win >> 10));
1534 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001535 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1536 RX_CHANNEL(0) |
1537 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001538 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001539 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001540 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001541 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001542 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001543 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001544 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1545 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1546 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001547 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1548 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001549 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1550}
1551
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552/*
1553 * Return whether a failed active open has allocated a TID
1554 */
1555static inline int act_open_has_tid(int status)
1556{
1557 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1558 status != CPL_ERR_ARP_MISS;
1559}
1560
Vipul Pandya793dad92012-12-10 09:30:56 +00001561#define ACT_OPEN_RETRY_COUNT 2
1562
1563static int c4iw_reconnect(struct c4iw_ep *ep)
1564{
1565 int err = 0;
1566 struct rtable *rt;
1567 struct port_info *pi;
1568 struct net_device *pdev;
1569 int step;
1570 struct neighbour *neigh;
1571
1572 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1573 init_timer(&ep->timer);
1574
1575 /*
1576 * Allocate an active TID to initiate a TCP connection.
1577 */
1578 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1579 if (ep->atid == -1) {
1580 pr_err("%s - cannot alloc atid.\n", __func__);
1581 err = -ENOMEM;
1582 goto fail2;
1583 }
1584 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1585
1586 /* find a route */
1587 rt = find_route(ep->com.dev,
1588 ep->com.cm_id->local_addr.sin_addr.s_addr,
1589 ep->com.cm_id->remote_addr.sin_addr.s_addr,
1590 ep->com.cm_id->local_addr.sin_port,
1591 ep->com.cm_id->remote_addr.sin_port, 0);
1592 if (!rt) {
1593 pr_err("%s - cannot find route.\n", __func__);
1594 err = -EHOSTUNREACH;
1595 goto fail3;
1596 }
1597 ep->dst = &rt->dst;
1598
1599 neigh = dst_neigh_lookup(ep->dst,
1600 &ep->com.cm_id->remote_addr.sin_addr.s_addr);
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00001601 if (!neigh) {
1602 pr_err("%s - cannot alloc neigh.\n", __func__);
1603 err = -ENOMEM;
1604 goto fail4;
1605 }
1606
Vipul Pandya793dad92012-12-10 09:30:56 +00001607 /* get a l2t entry */
1608 if (neigh->dev->flags & IFF_LOOPBACK) {
1609 PDBG("%s LOOPBACK\n", __func__);
1610 pdev = ip_dev_find(&init_net,
1611 ep->com.cm_id->remote_addr.sin_addr.s_addr);
1612 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1613 neigh, pdev, 0);
1614 pi = (struct port_info *)netdev_priv(pdev);
1615 ep->mtu = pdev->mtu;
1616 ep->tx_chan = cxgb4_port_chan(pdev);
1617 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1618 dev_put(pdev);
1619 } else {
1620 ep->l2t = cxgb4_l2t_get(ep->com.dev->rdev.lldi.l2t,
1621 neigh, neigh->dev, 0);
1622 pi = (struct port_info *)netdev_priv(neigh->dev);
1623 ep->mtu = dst_mtu(ep->dst);
1624 ep->tx_chan = cxgb4_port_chan(neigh->dev);
1625 ep->smac_idx = (cxgb4_port_viid(neigh->dev) &
1626 0x7F) << 1;
1627 }
1628
1629 step = ep->com.dev->rdev.lldi.ntxq / ep->com.dev->rdev.lldi.nchan;
1630 ep->txq_idx = pi->port_id * step;
1631 ep->ctrlq_idx = pi->port_id;
1632 step = ep->com.dev->rdev.lldi.nrxq / ep->com.dev->rdev.lldi.nchan;
1633 ep->rss_qid = ep->com.dev->rdev.lldi.rxq_ids[pi->port_id * step];
1634
1635 if (!ep->l2t) {
1636 pr_err("%s - cannot alloc l2e.\n", __func__);
1637 err = -ENOMEM;
1638 goto fail4;
1639 }
1640
1641 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1642 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1643 ep->l2t->idx);
1644
1645 state_set(&ep->com, CONNECTING);
1646 ep->tos = 0;
1647
1648 /* send connect request to rnic */
1649 err = send_connect(ep);
1650 if (!err)
1651 goto out;
1652
1653 cxgb4_l2t_release(ep->l2t);
1654fail4:
1655 dst_release(ep->dst);
1656fail3:
1657 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1658 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1659fail2:
1660 /*
1661 * remember to send notification to upper layer.
1662 * We are in here so the upper layer is not aware that this is
1663 * re-connect attempt and so, upper layer is still waiting for
1664 * response of 1st connect request.
1665 */
1666 connect_reply_upcall(ep, -ECONNRESET);
1667 c4iw_put_ep(&ep->com);
1668out:
1669 return err;
1670}
1671
Steve Wisecfdda9d2010-04-21 15:30:06 -07001672static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1673{
1674 struct c4iw_ep *ep;
1675 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1676 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1677 ntohl(rpl->atid_status)));
1678 struct tid_info *t = dev->rdev.lldi.tids;
1679 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
1680
1681 ep = lookup_atid(t, atid);
1682
1683 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1684 status, status2errno(status));
1685
1686 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1687 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1688 atid);
1689 return 0;
1690 }
1691
Vipul Pandya793dad92012-12-10 09:30:56 +00001692 set_bit(ACT_OPEN_RPL, &ep->com.history);
1693
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301694 /*
1695 * Log interesting failures.
1696 */
1697 switch (status) {
1698 case CPL_ERR_CONN_RESET:
1699 case CPL_ERR_CONN_TIMEDOUT:
1700 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001701 case CPL_ERR_TCAM_FULL:
Vipul Pandya3b174d92013-03-14 05:09:03 +00001702 dev->rdev.stats.tcam_full++;
Vipul Pandya793dad92012-12-10 09:30:56 +00001703 if (dev->rdev.lldi.enable_fw_ofld_conn) {
1704 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya793dad92012-12-10 09:30:56 +00001705 mutex_unlock(&dev->rdev.stats.lock);
1706 send_fw_act_open_req(ep,
1707 GET_TID_TID(GET_AOPEN_ATID(
1708 ntohl(rpl->atid_status))));
1709 return 0;
1710 }
1711 break;
1712 case CPL_ERR_CONN_EXIST:
1713 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1714 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1715 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1716 atid);
1717 cxgb4_free_atid(t, atid);
1718 dst_release(ep->dst);
1719 cxgb4_l2t_release(ep->l2t);
1720 c4iw_reconnect(ep);
1721 return 0;
1722 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001723 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301724 default:
1725 printk(KERN_INFO MOD "Active open failure - "
1726 "atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1727 atid, status, status2errno(status),
1728 &ep->com.local_addr.sin_addr.s_addr,
1729 ntohs(ep->com.local_addr.sin_port),
1730 &ep->com.remote_addr.sin_addr.s_addr,
1731 ntohs(ep->com.remote_addr.sin_port));
1732 break;
1733 }
1734
Steve Wisecfdda9d2010-04-21 15:30:06 -07001735 connect_reply_upcall(ep, status2errno(status));
1736 state_set(&ep->com, DEAD);
1737
1738 if (status && act_open_has_tid(status))
1739 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1740
Vipul Pandya793dad92012-12-10 09:30:56 +00001741 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001742 cxgb4_free_atid(t, atid);
1743 dst_release(ep->dst);
1744 cxgb4_l2t_release(ep->l2t);
1745 c4iw_put_ep(&ep->com);
1746
1747 return 0;
1748}
1749
1750static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1751{
1752 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1753 struct tid_info *t = dev->rdev.lldi.tids;
1754 unsigned int stid = GET_TID(rpl);
1755 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1756
1757 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001758 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1759 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001760 }
1761 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1762 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001763 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001764
Vipul Pandya1cab7752012-12-10 09:30:55 +00001765out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001766 return 0;
1767}
1768
1769static int listen_stop(struct c4iw_listen_ep *ep)
1770{
1771 struct sk_buff *skb;
1772 struct cpl_close_listsvr_req *req;
1773
1774 PDBG("%s ep %p\n", __func__, ep);
1775 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1776 if (!skb) {
1777 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
1778 return -ENOMEM;
1779 }
1780 req = (struct cpl_close_listsvr_req *) skb_put(skb, sizeof(*req));
1781 INIT_TP_WR(req, 0);
1782 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_LISTSRV_REQ,
1783 ep->stid));
1784 req->reply_ctrl = cpu_to_be16(
1785 QUEUENO(ep->com.dev->rdev.lldi.rxq_ids[0]));
1786 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
1787 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
1788}
1789
1790static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1791{
1792 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1793 struct tid_info *t = dev->rdev.lldi.tids;
1794 unsigned int stid = GET_TID(rpl);
1795 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1796
1797 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001798 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001799 return 0;
1800}
1801
1802static void accept_cr(struct c4iw_ep *ep, __be32 peer_ip, struct sk_buff *skb,
1803 struct cpl_pass_accept_req *req)
1804{
1805 struct cpl_pass_accept_rpl *rpl;
1806 unsigned int mtu_idx;
1807 u64 opt0;
1808 u32 opt2;
1809 int wscale;
1810
1811 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1812 BUG_ON(skb_cloned(skb));
1813 skb_trim(skb, sizeof(*rpl));
1814 skb_get(skb);
1815 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1816 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001817 opt0 = (nocong ? NO_CONG(1) : 0) |
1818 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001819 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820 WND_SCALE(wscale) |
1821 MSS_IDX(mtu_idx) |
1822 L2T_IDX(ep->l2t->idx) |
1823 TX_CHAN(ep->tx_chan) |
1824 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001825 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001826 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001827 RCV_BUFSIZ(rcv_win>>10);
1828 opt2 = RX_CHANNEL(0) |
1829 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1830
1831 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1832 opt2 |= TSTAMPS_EN(1);
1833 if (enable_tcp_sack && req->tcpopt.sack)
1834 opt2 |= SACK_EN(1);
1835 if (wscale && enable_tcp_window_scaling)
1836 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001837 if (enable_ecn) {
1838 const struct tcphdr *tcph;
1839 u32 hlen = ntohl(req->hdr_len);
1840
1841 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1842 G_IP_HDR_LEN(hlen);
1843 if (tcph->ece && tcph->cwr)
1844 opt2 |= CCTRL_ECN(1);
1845 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001846
1847 rpl = cplhdr(skb);
1848 INIT_TP_WR(rpl, ep->hwtid);
1849 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1850 ep->hwtid));
1851 rpl->opt0 = cpu_to_be64(opt0);
1852 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00001853 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001854 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1855
1856 return;
1857}
1858
1859static void reject_cr(struct c4iw_dev *dev, u32 hwtid, __be32 peer_ip,
1860 struct sk_buff *skb)
1861{
1862 PDBG("%s c4iw_dev %p tid %u peer_ip %x\n", __func__, dev, hwtid,
1863 peer_ip);
1864 BUG_ON(skb_cloned(skb));
1865 skb_trim(skb, sizeof(struct cpl_tid_release));
1866 skb_get(skb);
1867 release_tid(&dev->rdev, hwtid, skb);
1868 return;
1869}
1870
1871static void get_4tuple(struct cpl_pass_accept_req *req,
1872 __be32 *local_ip, __be32 *peer_ip,
1873 __be16 *local_port, __be16 *peer_port)
1874{
1875 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
1876 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
1877 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
1878 struct tcphdr *tcp = (struct tcphdr *)
1879 ((u8 *)(req + 1) + eth_len + ip_len);
1880
1881 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
1882 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
1883 ntohs(tcp->dest));
1884
1885 *peer_ip = ip->saddr;
1886 *local_ip = ip->daddr;
1887 *peer_port = tcp->source;
1888 *local_port = tcp->dest;
1889
1890 return;
1891}
1892
David Miller3786cf12011-12-02 16:52:31 +00001893static int import_ep(struct c4iw_ep *ep, __be32 peer_ip, struct dst_entry *dst,
1894 struct c4iw_dev *cdev, bool clear_mpa_v1)
1895{
1896 struct neighbour *n;
1897 int err, step;
1898
David Miller64b70072012-01-24 13:15:57 +00001899 n = dst_neigh_lookup(dst, &peer_ip);
David Miller3786cf12011-12-02 16:52:31 +00001900 if (!n)
David Miller64b70072012-01-24 13:15:57 +00001901 return -ENODEV;
1902
1903 rcu_read_lock();
David Miller3786cf12011-12-02 16:52:31 +00001904 err = -ENOMEM;
1905 if (n->dev->flags & IFF_LOOPBACK) {
1906 struct net_device *pdev;
1907
1908 pdev = ip_dev_find(&init_net, peer_ip);
Thadeu Lima de Souza Cascardo71b43fd2012-05-17 17:51:53 -03001909 if (!pdev) {
1910 err = -ENODEV;
1911 goto out;
1912 }
David Miller3786cf12011-12-02 16:52:31 +00001913 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1914 n, pdev, 0);
1915 if (!ep->l2t)
1916 goto out;
1917 ep->mtu = pdev->mtu;
1918 ep->tx_chan = cxgb4_port_chan(pdev);
1919 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1920 step = cdev->rdev.lldi.ntxq /
1921 cdev->rdev.lldi.nchan;
1922 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1923 step = cdev->rdev.lldi.nrxq /
1924 cdev->rdev.lldi.nchan;
1925 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1926 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1927 cxgb4_port_idx(pdev) * step];
1928 dev_put(pdev);
1929 } else {
1930 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1931 n, n->dev, 0);
1932 if (!ep->l2t)
1933 goto out;
Steve Wisebd61baa2012-04-27 10:24:33 -05001934 ep->mtu = dst_mtu(dst);
David Miller3786cf12011-12-02 16:52:31 +00001935 ep->tx_chan = cxgb4_port_chan(n->dev);
1936 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1937 step = cdev->rdev.lldi.ntxq /
1938 cdev->rdev.lldi.nchan;
1939 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1940 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1941 step = cdev->rdev.lldi.nrxq /
1942 cdev->rdev.lldi.nchan;
1943 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1944 cxgb4_port_idx(n->dev) * step];
1945
1946 if (clear_mpa_v1) {
1947 ep->retry_with_mpa_v1 = 0;
1948 ep->tried_with_mpa_v1 = 0;
1949 }
1950 }
1951 err = 0;
1952out:
1953 rcu_read_unlock();
1954
David Miller64b70072012-01-24 13:15:57 +00001955 neigh_release(n);
1956
David Miller3786cf12011-12-02 16:52:31 +00001957 return err;
1958}
1959
Steve Wisecfdda9d2010-04-21 15:30:06 -07001960static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
1961{
Vipul Pandya793dad92012-12-10 09:30:56 +00001962 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001963 struct cpl_pass_accept_req *req = cplhdr(skb);
1964 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
1965 struct tid_info *t = dev->rdev.lldi.tids;
1966 unsigned int hwtid = GET_TID(req);
1967 struct dst_entry *dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001968 struct rtable *rt;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001969 __be32 local_ip, peer_ip = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001970 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00001971 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00001972 u16 peer_mss = ntohs(req->tcpopt.mss);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001973
1974 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00001975 if (!parent_ep) {
1976 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
1977 goto reject;
1978 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001979 get_4tuple(req, &local_ip, &peer_ip, &local_port, &peer_port);
1980
Vipul Pandya1cab7752012-12-10 09:30:55 +00001981 PDBG("%s parent ep %p hwtid %u laddr 0x%x raddr 0x%x lport %d " \
1982 "rport %d peer_mss %d\n", __func__, parent_ep, hwtid,
1983 ntohl(local_ip), ntohl(peer_ip), ntohs(local_port),
1984 ntohs(peer_port), peer_mss);
1985
Steve Wisecfdda9d2010-04-21 15:30:06 -07001986 if (state_read(&parent_ep->com) != LISTEN) {
1987 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
1988 __func__);
1989 goto reject;
1990 }
1991
1992 /* Find output route */
1993 rt = find_route(dev, local_ip, peer_ip, local_port, peer_port,
1994 GET_POPEN_TOS(ntohl(req->tos_stid)));
1995 if (!rt) {
1996 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
1997 __func__);
1998 goto reject;
1999 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002000 dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002001
2002 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2003 if (!child_ep) {
2004 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2005 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002006 dst_release(dst);
2007 goto reject;
2008 }
David Miller3786cf12011-12-02 16:52:31 +00002009
2010 err = import_ep(child_ep, peer_ip, dst, dev, false);
2011 if (err) {
2012 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2013 __func__);
2014 dst_release(dst);
2015 kfree(child_ep);
2016 goto reject;
2017 }
2018
Vipul Pandya1cab7752012-12-10 09:30:55 +00002019 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2020 child_ep->mtu = peer_mss + 40;
2021
Steve Wisecfdda9d2010-04-21 15:30:06 -07002022 state_set(&child_ep->com, CONNECTING);
2023 child_ep->com.dev = dev;
2024 child_ep->com.cm_id = NULL;
2025 child_ep->com.local_addr.sin_family = PF_INET;
2026 child_ep->com.local_addr.sin_port = local_port;
2027 child_ep->com.local_addr.sin_addr.s_addr = local_ip;
2028 child_ep->com.remote_addr.sin_family = PF_INET;
2029 child_ep->com.remote_addr.sin_port = peer_port;
2030 child_ep->com.remote_addr.sin_addr.s_addr = peer_ip;
2031 c4iw_get_ep(&parent_ep->com);
2032 child_ep->parent_ep = parent_ep;
2033 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002034 child_ep->dst = dst;
2035 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002036
2037 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002038 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002039
2040 init_timer(&child_ep->timer);
2041 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002042 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043 accept_cr(child_ep, peer_ip, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002044 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002045 goto out;
2046reject:
2047 reject_cr(dev, hwtid, peer_ip, skb);
2048out:
2049 return 0;
2050}
2051
2052static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2053{
2054 struct c4iw_ep *ep;
2055 struct cpl_pass_establish *req = cplhdr(skb);
2056 struct tid_info *t = dev->rdev.lldi.tids;
2057 unsigned int tid = GET_TID(req);
2058
2059 ep = lookup_tid(t, tid);
2060 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2061 ep->snd_seq = be32_to_cpu(req->snd_isn);
2062 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2063
Vipul Pandya1cab7752012-12-10 09:30:55 +00002064 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2065 ntohs(req->tcp_opt));
2066
Steve Wisecfdda9d2010-04-21 15:30:06 -07002067 set_emss(ep, ntohs(req->tcp_opt));
2068
2069 dst_confirm(ep->dst);
2070 state_set(&ep->com, MPA_REQ_WAIT);
2071 start_ep_timer(ep);
2072 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002073 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002074
2075 return 0;
2076}
2077
2078static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2079{
2080 struct cpl_peer_close *hdr = cplhdr(skb);
2081 struct c4iw_ep *ep;
2082 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002083 int disconnect = 1;
2084 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002085 struct tid_info *t = dev->rdev.lldi.tids;
2086 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002087 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002088
2089 ep = lookup_tid(t, tid);
2090 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2091 dst_confirm(ep->dst);
2092
Vipul Pandya793dad92012-12-10 09:30:56 +00002093 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002094 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002095 switch (ep->com.state) {
2096 case MPA_REQ_WAIT:
2097 __state_set(&ep->com, CLOSING);
2098 break;
2099 case MPA_REQ_SENT:
2100 __state_set(&ep->com, CLOSING);
2101 connect_reply_upcall(ep, -ECONNRESET);
2102 break;
2103 case MPA_REQ_RCVD:
2104
2105 /*
2106 * We're gonna mark this puppy DEAD, but keep
2107 * the reference on it until the ULP accepts or
2108 * rejects the CR. Also wake up anyone waiting
2109 * in rdma connection migration (see c4iw_accept_cr()).
2110 */
2111 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002112 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002113 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002114 break;
2115 case MPA_REP_SENT:
2116 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002117 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002118 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002119 break;
2120 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002121 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002122 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002123 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002124 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002125 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002126 if (ret != -ECONNRESET) {
2127 peer_close_upcall(ep);
2128 disconnect = 1;
2129 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002130 break;
2131 case ABORTING:
2132 disconnect = 0;
2133 break;
2134 case CLOSING:
2135 __state_set(&ep->com, MORIBUND);
2136 disconnect = 0;
2137 break;
2138 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002139 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002140 if (ep->com.cm_id && ep->com.qp) {
2141 attrs.next_state = C4IW_QP_STATE_IDLE;
2142 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2143 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2144 }
2145 close_complete_upcall(ep);
2146 __state_set(&ep->com, DEAD);
2147 release = 1;
2148 disconnect = 0;
2149 break;
2150 case DEAD:
2151 disconnect = 0;
2152 break;
2153 default:
2154 BUG_ON(1);
2155 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002156 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002157 if (disconnect)
2158 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2159 if (release)
2160 release_ep_resources(ep);
2161 return 0;
2162}
2163
2164/*
2165 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2166 */
2167static int is_neg_adv_abort(unsigned int status)
2168{
2169 return status == CPL_ERR_RTX_NEG_ADVICE ||
2170 status == CPL_ERR_PERSIST_NEG_ADVICE;
2171}
2172
2173static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2174{
2175 struct cpl_abort_req_rss *req = cplhdr(skb);
2176 struct c4iw_ep *ep;
2177 struct cpl_abort_rpl *rpl;
2178 struct sk_buff *rpl_skb;
2179 struct c4iw_qp_attributes attrs;
2180 int ret;
2181 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182 struct tid_info *t = dev->rdev.lldi.tids;
2183 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002184
2185 ep = lookup_tid(t, tid);
2186 if (is_neg_adv_abort(req->status)) {
2187 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2188 ep->hwtid);
2189 return 0;
2190 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2192 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002193 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002194
2195 /*
2196 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302197 * However, this is not needed if com state is just
2198 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002199 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302200 if (ep->com.state != MPA_REQ_SENT)
2201 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002202
2203 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002204 switch (ep->com.state) {
2205 case CONNECTING:
2206 break;
2207 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002208 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002209 break;
2210 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002211 stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002212 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302213 connect_reply_upcall(ep, -ECONNRESET);
2214 else {
2215 /*
2216 * we just don't send notification upwards because we
2217 * want to retry with mpa_v1 without upper layers even
2218 * knowing it.
2219 *
2220 * do some housekeeping so as to re-initiate the
2221 * connection
2222 */
2223 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2224 mpa_rev);
2225 ep->retry_with_mpa_v1 = 1;
2226 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002227 break;
2228 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229 break;
2230 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002231 break;
2232 case MORIBUND:
2233 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002234 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 /*FALLTHROUGH*/
2236 case FPDU_MODE:
2237 if (ep->com.cm_id && ep->com.qp) {
2238 attrs.next_state = C4IW_QP_STATE_ERROR;
2239 ret = c4iw_modify_qp(ep->com.qp->rhp,
2240 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2241 &attrs, 1);
2242 if (ret)
2243 printk(KERN_ERR MOD
2244 "%s - qp <- error failed!\n",
2245 __func__);
2246 }
2247 peer_abort_upcall(ep);
2248 break;
2249 case ABORTING:
2250 break;
2251 case DEAD:
2252 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002253 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 return 0;
2255 default:
2256 BUG_ON(1);
2257 break;
2258 }
2259 dst_confirm(ep->dst);
2260 if (ep->com.state != ABORTING) {
2261 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302262 /* we don't release if we want to retry with mpa_v1 */
2263 if (!ep->retry_with_mpa_v1)
2264 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002266 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002267
2268 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2269 if (!rpl_skb) {
2270 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2271 __func__);
2272 release = 1;
2273 goto out;
2274 }
2275 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2276 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2277 INIT_TP_WR(rpl, ep->hwtid);
2278 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2279 rpl->cmd = CPL_ABORT_NO_RST;
2280 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2281out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 if (release)
2283 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002284 else if (ep->retry_with_mpa_v1) {
2285 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302286 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2287 dst_release(ep->dst);
2288 cxgb4_l2t_release(ep->l2t);
2289 c4iw_reconnect(ep);
2290 }
2291
Steve Wisecfdda9d2010-04-21 15:30:06 -07002292 return 0;
2293}
2294
2295static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2296{
2297 struct c4iw_ep *ep;
2298 struct c4iw_qp_attributes attrs;
2299 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002300 int release = 0;
2301 struct tid_info *t = dev->rdev.lldi.tids;
2302 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002303
2304 ep = lookup_tid(t, tid);
2305
2306 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2307 BUG_ON(!ep);
2308
2309 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002310 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 switch (ep->com.state) {
2312 case CLOSING:
2313 __state_set(&ep->com, MORIBUND);
2314 break;
2315 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002316 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317 if ((ep->com.cm_id) && (ep->com.qp)) {
2318 attrs.next_state = C4IW_QP_STATE_IDLE;
2319 c4iw_modify_qp(ep->com.qp->rhp,
2320 ep->com.qp,
2321 C4IW_QP_ATTR_NEXT_STATE,
2322 &attrs, 1);
2323 }
2324 close_complete_upcall(ep);
2325 __state_set(&ep->com, DEAD);
2326 release = 1;
2327 break;
2328 case ABORTING:
2329 case DEAD:
2330 break;
2331 default:
2332 BUG_ON(1);
2333 break;
2334 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002335 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336 if (release)
2337 release_ep_resources(ep);
2338 return 0;
2339}
2340
2341static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2342{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002343 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002345 unsigned int tid = GET_TID(rpl);
2346 struct c4iw_ep *ep;
2347 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348
2349 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002350 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351
Steve Wise30c95c22011-05-09 22:06:22 -07002352 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002353 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2354 ep->com.qp->wq.sq.qid);
2355 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2356 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2357 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2358 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002359 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 return 0;
2362}
2363
2364/*
2365 * Upcall from the adapter indicating data has been transmitted.
2366 * For us its just the single MPA request or reply. We can now free
2367 * the skb holding the mpa message.
2368 */
2369static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2370{
2371 struct c4iw_ep *ep;
2372 struct cpl_fw4_ack *hdr = cplhdr(skb);
2373 u8 credits = hdr->credits;
2374 unsigned int tid = GET_TID(hdr);
2375 struct tid_info *t = dev->rdev.lldi.tids;
2376
2377
2378 ep = lookup_tid(t, tid);
2379 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2380 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002381 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2382 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383 return 0;
2384 }
2385
2386 dst_confirm(ep->dst);
2387 if (ep->mpa_skb) {
2388 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2389 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2390 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2391 kfree_skb(ep->mpa_skb);
2392 ep->mpa_skb = NULL;
2393 }
2394 return 0;
2395}
2396
Steve Wisecfdda9d2010-04-21 15:30:06 -07002397int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2398{
2399 int err;
2400 struct c4iw_ep *ep = to_ep(cm_id);
2401 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2402
2403 if (state_read(&ep->com) == DEAD) {
2404 c4iw_put_ep(&ep->com);
2405 return -ECONNRESET;
2406 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002407 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2409 if (mpa_rev == 0)
2410 abort_connection(ep, NULL, GFP_KERNEL);
2411 else {
2412 err = send_mpa_reject(ep, pdata, pdata_len);
2413 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2414 }
2415 c4iw_put_ep(&ep->com);
2416 return 0;
2417}
2418
2419int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2420{
2421 int err;
2422 struct c4iw_qp_attributes attrs;
2423 enum c4iw_qp_attr_mask mask;
2424 struct c4iw_ep *ep = to_ep(cm_id);
2425 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2426 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2427
2428 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2429 if (state_read(&ep->com) == DEAD) {
2430 err = -ECONNRESET;
2431 goto err;
2432 }
2433
2434 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2435 BUG_ON(!qp);
2436
Vipul Pandya793dad92012-12-10 09:30:56 +00002437 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002438 if ((conn_param->ord > c4iw_max_read_depth) ||
2439 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 abort_connection(ep, NULL, GFP_KERNEL);
2441 err = -EINVAL;
2442 goto err;
2443 }
2444
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302445 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2446 if (conn_param->ord > ep->ird) {
2447 ep->ird = conn_param->ird;
2448 ep->ord = conn_param->ord;
2449 send_mpa_reject(ep, conn_param->private_data,
2450 conn_param->private_data_len);
2451 abort_connection(ep, NULL, GFP_KERNEL);
2452 err = -ENOMEM;
2453 goto err;
2454 }
2455 if (conn_param->ird > ep->ord) {
2456 if (!ep->ord)
2457 conn_param->ird = 1;
2458 else {
2459 abort_connection(ep, NULL, GFP_KERNEL);
2460 err = -ENOMEM;
2461 goto err;
2462 }
2463 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302465 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 ep->ird = conn_param->ird;
2467 ep->ord = conn_param->ord;
2468
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302469 if (ep->mpa_attr.version != 2)
2470 if (peer2peer && ep->ird == 0)
2471 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002472
2473 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2474
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302475 cm_id->add_ref(cm_id);
2476 ep->com.cm_id = cm_id;
2477 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002478 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302479
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480 /* bind QP to EP and move to RTS */
2481 attrs.mpa_attr = ep->mpa_attr;
2482 attrs.max_ird = ep->ird;
2483 attrs.max_ord = ep->ord;
2484 attrs.llp_stream_handle = ep;
2485 attrs.next_state = C4IW_QP_STATE_RTS;
2486
2487 /* bind QP and TID with INIT_WR */
2488 mask = C4IW_QP_ATTR_NEXT_STATE |
2489 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2490 C4IW_QP_ATTR_MPA_ATTR |
2491 C4IW_QP_ATTR_MAX_IRD |
2492 C4IW_QP_ATTR_MAX_ORD;
2493
2494 err = c4iw_modify_qp(ep->com.qp->rhp,
2495 ep->com.qp, mask, &attrs, 1);
2496 if (err)
2497 goto err1;
2498 err = send_mpa_reply(ep, conn_param->private_data,
2499 conn_param->private_data_len);
2500 if (err)
2501 goto err1;
2502
2503 state_set(&ep->com, FPDU_MODE);
2504 established_upcall(ep);
2505 c4iw_put_ep(&ep->com);
2506 return 0;
2507err1:
2508 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509 cm_id->rem_ref(cm_id);
2510err:
2511 c4iw_put_ep(&ep->com);
2512 return err;
2513}
2514
2515int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2516{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2518 struct c4iw_ep *ep;
2519 struct rtable *rt;
David Miller3786cf12011-12-02 16:52:31 +00002520 int err = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002521
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002522 if ((conn_param->ord > c4iw_max_read_depth) ||
2523 (conn_param->ird > c4iw_max_read_depth)) {
2524 err = -EINVAL;
2525 goto out;
2526 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2528 if (!ep) {
2529 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2530 err = -ENOMEM;
2531 goto out;
2532 }
2533 init_timer(&ep->timer);
2534 ep->plen = conn_param->private_data_len;
2535 if (ep->plen)
2536 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2537 conn_param->private_data, ep->plen);
2538 ep->ird = conn_param->ird;
2539 ep->ord = conn_param->ord;
2540
2541 if (peer2peer && ep->ord == 0)
2542 ep->ord = 1;
2543
2544 cm_id->add_ref(cm_id);
2545 ep->com.dev = dev;
2546 ep->com.cm_id = cm_id;
2547 ep->com.qp = get_qhp(dev, conn_param->qpn);
2548 BUG_ON(!ep->com.qp);
Vipul Pandya325abea2013-01-07 13:11:53 +00002549 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2551 ep->com.qp, cm_id);
2552
2553 /*
2554 * Allocate an active TID to initiate a TCP connection.
2555 */
2556 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2557 if (ep->atid == -1) {
2558 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2559 err = -ENOMEM;
2560 goto fail2;
2561 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002562 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002563
2564 PDBG("%s saddr 0x%x sport 0x%x raddr 0x%x rport 0x%x\n", __func__,
2565 ntohl(cm_id->local_addr.sin_addr.s_addr),
2566 ntohs(cm_id->local_addr.sin_port),
2567 ntohl(cm_id->remote_addr.sin_addr.s_addr),
2568 ntohs(cm_id->remote_addr.sin_port));
2569
2570 /* find a route */
2571 rt = find_route(dev,
2572 cm_id->local_addr.sin_addr.s_addr,
2573 cm_id->remote_addr.sin_addr.s_addr,
2574 cm_id->local_addr.sin_port,
2575 cm_id->remote_addr.sin_port, 0);
2576 if (!rt) {
2577 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2578 err = -EHOSTUNREACH;
2579 goto fail3;
2580 }
Changli Gaod8d1f302010-06-10 23:31:35 -07002581 ep->dst = &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582
David Miller3786cf12011-12-02 16:52:31 +00002583 err = import_ep(ep, cm_id->remote_addr.sin_addr.s_addr,
2584 ep->dst, ep->com.dev, true);
2585 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002586 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002587 goto fail4;
2588 }
2589
2590 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2591 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2592 ep->l2t->idx);
2593
2594 state_set(&ep->com, CONNECTING);
2595 ep->tos = 0;
2596 ep->com.local_addr = cm_id->local_addr;
2597 ep->com.remote_addr = cm_id->remote_addr;
2598
2599 /* send connect request to rnic */
2600 err = send_connect(ep);
2601 if (!err)
2602 goto out;
2603
2604 cxgb4_l2t_release(ep->l2t);
2605fail4:
2606 dst_release(ep->dst);
2607fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002608 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002609 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2610fail2:
2611 cm_id->rem_ref(cm_id);
2612 c4iw_put_ep(&ep->com);
2613out:
2614 return err;
2615}
2616
2617int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2618{
2619 int err = 0;
2620 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2621 struct c4iw_listen_ep *ep;
2622
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 might_sleep();
2624
2625 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2626 if (!ep) {
2627 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2628 err = -ENOMEM;
2629 goto fail1;
2630 }
2631 PDBG("%s ep %p\n", __func__, ep);
2632 cm_id->add_ref(cm_id);
2633 ep->com.cm_id = cm_id;
2634 ep->com.dev = dev;
2635 ep->backlog = backlog;
2636 ep->com.local_addr = cm_id->local_addr;
2637
2638 /*
2639 * Allocate a server TID.
2640 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002641 if (dev->rdev.lldi.enable_fw_ofld_conn)
2642 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids, PF_INET, ep);
2643 else
2644 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids, PF_INET, ep);
2645
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002647 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 err = -ENOMEM;
2649 goto fail2;
2650 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002651 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652 state_set(&ep->com, LISTEN);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002653 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2654 do {
2655 err = cxgb4_create_server_filter(
2656 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2657 ep->com.local_addr.sin_addr.s_addr,
2658 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002659 0,
2660 ep->com.dev->rdev.lldi.rxq_ids[0],
2661 0,
2662 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002663 if (err == -EBUSY) {
2664 set_current_state(TASK_UNINTERRUPTIBLE);
2665 schedule_timeout(usecs_to_jiffies(100));
2666 }
2667 } while (err == -EBUSY);
2668 } else {
2669 c4iw_init_wr_wait(&ep->com.wr_wait);
2670 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2671 ep->stid, ep->com.local_addr.sin_addr.s_addr,
2672 ep->com.local_addr.sin_port,
Vipul Pandya793dad92012-12-10 09:30:56 +00002673 0,
Vipul Pandya1cab7752012-12-10 09:30:55 +00002674 ep->com.dev->rdev.lldi.rxq_ids[0]);
2675 if (!err)
2676 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2677 &ep->com.wr_wait,
2678 0, 0, __func__);
2679 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 if (!err) {
2681 cm_id->provider_data = ep;
2682 goto out;
2683 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002684 pr_err("%s cxgb4_create_server/filter failed err %d " \
2685 "stid %d laddr %08x lport %d\n", \
2686 __func__, err, ep->stid,
2687 ntohl(ep->com.local_addr.sin_addr.s_addr),
2688 ntohs(ep->com.local_addr.sin_port));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2690fail2:
2691 cm_id->rem_ref(cm_id);
2692 c4iw_put_ep(&ep->com);
2693fail1:
2694out:
2695 return err;
2696}
2697
2698int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2699{
2700 int err;
2701 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2702
2703 PDBG("%s ep %p\n", __func__, ep);
2704
2705 might_sleep();
2706 state_set(&ep->com, DEAD);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002707 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn) {
2708 err = cxgb4_remove_server_filter(
2709 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2710 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2711 } else {
2712 c4iw_init_wr_wait(&ep->com.wr_wait);
2713 err = listen_stop(ep);
2714 if (err)
2715 goto done;
2716 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2717 0, 0, __func__);
2718 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002719 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid, PF_INET);
2721done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 cm_id->rem_ref(cm_id);
2723 c4iw_put_ep(&ep->com);
2724 return err;
2725}
2726
2727int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2728{
2729 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 int close = 0;
2731 int fatal = 0;
2732 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733
Steve Wise2f5b48c2010-09-10 11:15:36 -05002734 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002735
2736 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2737 states[ep->com.state], abrupt);
2738
2739 rdev = &ep->com.dev->rdev;
2740 if (c4iw_fatal_error(rdev)) {
2741 fatal = 1;
2742 close_complete_upcall(ep);
2743 ep->com.state = DEAD;
2744 }
2745 switch (ep->com.state) {
2746 case MPA_REQ_WAIT:
2747 case MPA_REQ_SENT:
2748 case MPA_REQ_RCVD:
2749 case MPA_REP_SENT:
2750 case FPDU_MODE:
2751 close = 1;
2752 if (abrupt)
2753 ep->com.state = ABORTING;
2754 else {
2755 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00002756 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 }
2758 set_bit(CLOSE_SENT, &ep->com.flags);
2759 break;
2760 case CLOSING:
2761 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
2762 close = 1;
2763 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00002764 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002765 ep->com.state = ABORTING;
2766 } else
2767 ep->com.state = MORIBUND;
2768 }
2769 break;
2770 case MORIBUND:
2771 case ABORTING:
2772 case DEAD:
2773 PDBG("%s ignoring disconnect ep %p state %u\n",
2774 __func__, ep, ep->com.state);
2775 break;
2776 default:
2777 BUG();
2778 break;
2779 }
2780
Steve Wisecfdda9d2010-04-21 15:30:06 -07002781 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00002782 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002783 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002784 close_complete_upcall(ep);
2785 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002786 } else {
2787 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002788 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00002789 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002790 if (ret)
2791 fatal = 1;
2792 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00002793 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794 if (fatal)
2795 release_ep_resources(ep);
2796 return ret;
2797}
2798
Vipul Pandya1cab7752012-12-10 09:30:55 +00002799static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2800 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2801{
2802 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00002803 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002804
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002805 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
2806 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002807 if (!ep)
2808 return;
2809
2810 switch (req->retval) {
2811 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00002812 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
2813 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2814 send_fw_act_open_req(ep, atid);
2815 return;
2816 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002817 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00002818 set_bit(ACT_RETRY_INUSE, &ep->com.history);
2819 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2820 send_fw_act_open_req(ep, atid);
2821 return;
2822 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002823 break;
2824 default:
2825 pr_info("%s unexpected ofld conn wr retval %d\n",
2826 __func__, req->retval);
2827 break;
2828 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002829 pr_err("active ofld_connect_wr failure %d atid %d\n",
2830 req->retval, atid);
2831 mutex_lock(&dev->rdev.stats.lock);
2832 dev->rdev.stats.act_ofld_conn_fails++;
2833 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002834 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00002835 state_set(&ep->com, DEAD);
2836 remove_handle(dev, &dev->atid_idr, atid);
2837 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
2838 dst_release(ep->dst);
2839 cxgb4_l2t_release(ep->l2t);
2840 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002841}
2842
2843static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
2844 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
2845{
2846 struct sk_buff *rpl_skb;
2847 struct cpl_pass_accept_req *cpl;
2848 int ret;
2849
Paul Bolle710a3112013-02-05 20:51:30 +00002850 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002851 BUG_ON(!rpl_skb);
2852 if (req->retval) {
2853 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00002854 mutex_lock(&dev->rdev.stats.lock);
2855 dev->rdev.stats.pas_ofld_conn_fails++;
2856 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002857 kfree_skb(rpl_skb);
2858 } else {
2859 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
2860 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002861 (__force u32) htonl(
2862 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00002863 ret = pass_accept_req(dev, rpl_skb);
2864 if (!ret)
2865 kfree_skb(rpl_skb);
2866 }
2867 return;
2868}
2869
2870static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05002871{
2872 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002873 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
2874
2875 switch (rpl->type) {
2876 case FW6_TYPE_CQE:
2877 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
2878 break;
2879 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
2880 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
2881 switch (req->t_state) {
2882 case TCP_SYN_SENT:
2883 active_ofld_conn_reply(dev, skb, req);
2884 break;
2885 case TCP_SYN_RECV:
2886 passive_ofld_conn_reply(dev, skb, req);
2887 break;
2888 default:
2889 pr_err("%s unexpected ofld conn wr state %d\n",
2890 __func__, req->t_state);
2891 break;
2892 }
2893 break;
2894 }
2895 return 0;
2896}
2897
2898static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
2899{
2900 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00002901 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002902 u8 intf;
2903 struct cpl_rx_pkt *cpl = cplhdr(skb);
2904 struct cpl_pass_accept_req *req;
2905 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00002906 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002907
Vipul Pandyaf079af72013-03-14 05:08:58 +00002908 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00002909 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002910 vlantag = (__force u16) cpl->vlan;
2911 len = (__force u16) cpl->len;
2912 l2info = (__force u32) cpl->l2info;
2913 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002914 intf = cpl->iff;
2915
2916 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
2917
2918 /*
2919 * We need to parse the TCP options from SYN packet.
2920 * to generate cpl_pass_accept_req.
2921 */
2922 memset(&tmp_opt, 0, sizeof(tmp_opt));
2923 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00002924 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002925
2926 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
2927 memset(req, 0, sizeof(*req));
2928 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002929 V_SYN_MAC_IDX(G_RX_MACIDX(
2930 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00002931 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00002932 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
2933 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
2934 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002935 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
2936 (__force int) htonl(l2info))) |
2937 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
2938 (__force int) htons(hdr_len))) |
2939 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
2940 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00002941 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002942 req->vlan = (__force __be16) vlantag;
2943 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002944 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
2945 PASS_OPEN_TOS(tos));
2946 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
2947 if (tmp_opt.wscale_ok)
2948 req->tcpopt.wsf = tmp_opt.snd_wscale;
2949 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
2950 if (tmp_opt.sack_ok)
2951 req->tcpopt.sack = 1;
2952 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
2953 return;
2954}
2955
2956static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
2957 __be32 laddr, __be16 lport,
2958 __be32 raddr, __be16 rport,
2959 u32 rcv_isn, u32 filter, u16 window,
2960 u32 rss_qid, u8 port_id)
2961{
2962 struct sk_buff *req_skb;
2963 struct fw_ofld_connection_wr *req;
2964 struct cpl_pass_accept_req *cpl = cplhdr(skb);
2965
2966 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
2967 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
2968 memset(req, 0, sizeof(*req));
2969 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
2970 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
2971 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00002972 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002973 req->le.lport = lport;
2974 req->le.pport = rport;
2975 req->le.u.ipv4.lip = laddr;
2976 req->le.u.ipv4.pip = raddr;
2977 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
2978 req->tcb.rcv_adv = htons(window);
2979 req->tcb.t_state_to_astid =
2980 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
2981 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
2982 V_FW_OFLD_CONNECTION_WR_ASTID(
2983 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
2984
2985 /*
2986 * We store the qid in opt2 which will be used by the firmware
2987 * to send us the wr response.
2988 */
2989 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
2990
2991 /*
2992 * We initialize the MSS index in TCB to 0xF.
2993 * So that when driver sends cpl_pass_accept_rpl
2994 * TCB picks up the correct value. If this was 0
2995 * TP will ignore any value > 0 for MSS index.
2996 */
2997 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00002998 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002999
3000 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3001 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3002}
3003
3004/*
3005 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3006 * messages when a filter is being used instead of server to
3007 * redirect a syn packet. When packets hit filter they are redirected
3008 * to the offload queue and driver tries to establish the connection
3009 * using firmware work request.
3010 */
3011static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3012{
3013 int stid;
3014 unsigned int filter;
3015 struct ethhdr *eh = NULL;
3016 struct vlan_ethhdr *vlan_eh = NULL;
3017 struct iphdr *iph;
3018 struct tcphdr *tcph;
3019 struct rss_header *rss = (void *)skb->data;
3020 struct cpl_rx_pkt *cpl = (void *)skb->data;
3021 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3022 struct l2t_entry *e;
3023 struct dst_entry *dst;
3024 struct rtable *rt;
3025 struct c4iw_ep *lep;
3026 u16 window;
3027 struct port_info *pi;
3028 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003029 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003030 int step;
3031 u32 tx_chan;
3032 struct neighbour *neigh;
3033
3034 /* Drop all non-SYN packets */
3035 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3036 goto reject;
3037
3038 /*
3039 * Drop all packets which did not hit the filter.
3040 * Unlikely to happen.
3041 */
3042 if (!(rss->filter_hit && rss->filter_tid))
3043 goto reject;
3044
3045 /*
3046 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3047 */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003048 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
3049 - dev->rdev.lldi.tids->sftid_base
Vipul Pandya1cab7752012-12-10 09:30:55 +00003050 + dev->rdev.lldi.tids->nstids;
3051
3052 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3053 if (!lep) {
3054 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3055 goto reject;
3056 }
3057
Vipul Pandyaf079af72013-03-14 05:08:58 +00003058 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3059 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3060 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3061 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003062 eh = (struct ethhdr *)(req + 1);
3063 iph = (struct iphdr *)(eh + 1);
3064 } else {
3065 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3066 iph = (struct iphdr *)(vlan_eh + 1);
3067 skb->vlan_tci = ntohs(cpl->vlan);
3068 }
3069
3070 if (iph->version != 0x4)
3071 goto reject;
3072
3073 tcph = (struct tcphdr *)(iph + 1);
3074 skb_set_network_header(skb, (void *)iph - (void *)rss);
3075 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3076 skb_get(skb);
3077
3078 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3079 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3080 ntohs(tcph->source), iph->tos);
3081
3082 rt = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3083 iph->tos);
3084 if (!rt) {
3085 pr_err("%s - failed to find dst entry!\n",
3086 __func__);
3087 goto reject;
3088 }
3089 dst = &rt->dst;
3090 neigh = dst_neigh_lookup_skb(dst, skb);
3091
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003092 if (!neigh) {
3093 pr_err("%s - failed to allocate neigh!\n",
3094 __func__);
3095 goto free_dst;
3096 }
3097
Vipul Pandya1cab7752012-12-10 09:30:55 +00003098 if (neigh->dev->flags & IFF_LOOPBACK) {
3099 pdev = ip_dev_find(&init_net, iph->daddr);
3100 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3101 pdev, 0);
3102 pi = (struct port_info *)netdev_priv(pdev);
3103 tx_chan = cxgb4_port_chan(pdev);
3104 dev_put(pdev);
3105 } else {
3106 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3107 neigh->dev, 0);
3108 pi = (struct port_info *)netdev_priv(neigh->dev);
3109 tx_chan = cxgb4_port_chan(neigh->dev);
3110 }
3111 if (!e) {
3112 pr_err("%s - failed to allocate l2t entry!\n",
3113 __func__);
3114 goto free_dst;
3115 }
3116
3117 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3118 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003119 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003120
3121 /* Calcuate filter portion for LE region. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003122 filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003123
3124 /*
3125 * Synthesize the cpl_pass_accept_req. We have everything except the
3126 * TID. Once firmware sends a reply with TID we update the TID field
3127 * in cpl and pass it through the regular cpl_pass_accept_req path.
3128 */
3129 build_cpl_pass_accept_req(skb, stid, iph->tos);
3130 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3131 tcph->source, ntohl(tcph->seq), filter, window,
3132 rss_qid, pi->port_id);
3133 cxgb4_l2t_release(e);
3134free_dst:
3135 dst_release(dst);
3136reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003137 return 0;
3138}
3139
Steve Wisecfdda9d2010-04-21 15:30:06 -07003140/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003141 * These are the real handlers that are called from a
3142 * work queue.
3143 */
3144static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3145 [CPL_ACT_ESTABLISH] = act_establish,
3146 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3147 [CPL_RX_DATA] = rx_data,
3148 [CPL_ABORT_RPL_RSS] = abort_rpl,
3149 [CPL_ABORT_RPL] = abort_rpl,
3150 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3151 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3152 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3153 [CPL_PASS_ESTABLISH] = pass_establish,
3154 [CPL_PEER_CLOSE] = peer_close,
3155 [CPL_ABORT_REQ_RSS] = peer_abort,
3156 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3157 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003158 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003159 [CPL_FW6_MSG] = deferred_fw6_msg,
3160 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003161};
3162
3163static void process_timeout(struct c4iw_ep *ep)
3164{
3165 struct c4iw_qp_attributes attrs;
3166 int abort = 1;
3167
Steve Wise2f5b48c2010-09-10 11:15:36 -05003168 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003169 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3170 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003171 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003172 switch (ep->com.state) {
3173 case MPA_REQ_SENT:
3174 __state_set(&ep->com, ABORTING);
3175 connect_reply_upcall(ep, -ETIMEDOUT);
3176 break;
3177 case MPA_REQ_WAIT:
3178 __state_set(&ep->com, ABORTING);
3179 break;
3180 case CLOSING:
3181 case MORIBUND:
3182 if (ep->com.cm_id && ep->com.qp) {
3183 attrs.next_state = C4IW_QP_STATE_ERROR;
3184 c4iw_modify_qp(ep->com.qp->rhp,
3185 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3186 &attrs, 1);
3187 }
3188 __state_set(&ep->com, ABORTING);
3189 break;
3190 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003191 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003192 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003193 abort = 0;
3194 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003195 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003196 if (abort)
3197 abort_connection(ep, NULL, GFP_KERNEL);
3198 c4iw_put_ep(&ep->com);
3199}
3200
3201static void process_timedout_eps(void)
3202{
3203 struct c4iw_ep *ep;
3204
3205 spin_lock_irq(&timeout_lock);
3206 while (!list_empty(&timeout_list)) {
3207 struct list_head *tmp;
3208
3209 tmp = timeout_list.next;
3210 list_del(tmp);
3211 spin_unlock_irq(&timeout_lock);
3212 ep = list_entry(tmp, struct c4iw_ep, entry);
3213 process_timeout(ep);
3214 spin_lock_irq(&timeout_lock);
3215 }
3216 spin_unlock_irq(&timeout_lock);
3217}
3218
3219static void process_work(struct work_struct *work)
3220{
3221 struct sk_buff *skb = NULL;
3222 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003223 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003224 unsigned int opcode;
3225 int ret;
3226
3227 while ((skb = skb_dequeue(&rxq))) {
3228 rpl = cplhdr(skb);
3229 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3230 opcode = rpl->ot.opcode;
3231
3232 BUG_ON(!work_handlers[opcode]);
3233 ret = work_handlers[opcode](dev, skb);
3234 if (!ret)
3235 kfree_skb(skb);
3236 }
3237 process_timedout_eps();
3238}
3239
3240static DECLARE_WORK(skb_work, process_work);
3241
3242static void ep_timeout(unsigned long arg)
3243{
3244 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003245 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003246
3247 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003248 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3249 list_add_tail(&ep->entry, &timeout_list);
3250 kickit = 1;
3251 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003252 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003253 if (kickit)
3254 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003255}
3256
3257/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003258 * All the CM events are handled on a work queue to have a safe context.
3259 */
3260static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3261{
3262
3263 /*
3264 * Save dev in the skb->cb area.
3265 */
3266 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3267
3268 /*
3269 * Queue the skb and schedule the worker thread.
3270 */
3271 skb_queue_tail(&rxq, skb);
3272 queue_work(workq, &skb_work);
3273 return 0;
3274}
3275
3276static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3277{
3278 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3279
3280 if (rpl->status != CPL_ERR_NONE) {
3281 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3282 "for tid %u\n", rpl->status, GET_TID(rpl));
3283 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003284 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003285 return 0;
3286}
3287
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003288static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3289{
3290 struct cpl_fw6_msg *rpl = cplhdr(skb);
3291 struct c4iw_wr_wait *wr_waitp;
3292 int ret;
3293
3294 PDBG("%s type %u\n", __func__, rpl->type);
3295
3296 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003297 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003298 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003299 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003300 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003301 if (wr_waitp)
3302 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003303 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003304 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003305 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003306 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003307 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003308 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003309 default:
3310 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3311 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003312 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003313 break;
3314 }
3315 return 0;
3316}
3317
Steve Wise8da7e7a2011-06-14 20:59:27 +00003318static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3319{
3320 struct cpl_abort_req_rss *req = cplhdr(skb);
3321 struct c4iw_ep *ep;
3322 struct tid_info *t = dev->rdev.lldi.tids;
3323 unsigned int tid = GET_TID(req);
3324
3325 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003326 if (!ep) {
3327 printk(KERN_WARNING MOD
3328 "Abort on non-existent endpoint, tid %d\n", tid);
3329 kfree_skb(skb);
3330 return 0;
3331 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003332 if (is_neg_adv_abort(req->status)) {
3333 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3334 ep->hwtid);
3335 kfree_skb(skb);
3336 return 0;
3337 }
3338 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3339 ep->com.state);
3340
3341 /*
3342 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003343 * However, if we are on MPAv2 and want to retry with MPAv1
3344 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003345 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003346 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3347 if (ep->com.state != MPA_REQ_SENT)
3348 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3349 } else
3350 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003351 sched(dev, skb);
3352 return 0;
3353}
3354
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003355/*
3356 * Most upcalls from the T4 Core go to sched() to
3357 * schedule the processing on a work queue.
3358 */
3359c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3360 [CPL_ACT_ESTABLISH] = sched,
3361 [CPL_ACT_OPEN_RPL] = sched,
3362 [CPL_RX_DATA] = sched,
3363 [CPL_ABORT_RPL_RSS] = sched,
3364 [CPL_ABORT_RPL] = sched,
3365 [CPL_PASS_OPEN_RPL] = sched,
3366 [CPL_CLOSE_LISTSRV_RPL] = sched,
3367 [CPL_PASS_ACCEPT_REQ] = sched,
3368 [CPL_PASS_ESTABLISH] = sched,
3369 [CPL_PEER_CLOSE] = sched,
3370 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003371 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003372 [CPL_RDMA_TERMINATE] = sched,
3373 [CPL_FW4_ACK] = sched,
3374 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003375 [CPL_FW6_MSG] = fw6_msg,
3376 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003377};
3378
Steve Wisecfdda9d2010-04-21 15:30:06 -07003379int __init c4iw_cm_init(void)
3380{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003381 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003382 skb_queue_head_init(&rxq);
3383
3384 workq = create_singlethread_workqueue("iw_cxgb4");
3385 if (!workq)
3386 return -ENOMEM;
3387
Steve Wisecfdda9d2010-04-21 15:30:06 -07003388 return 0;
3389}
3390
3391void __exit c4iw_cm_term(void)
3392{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003393 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003394 flush_workqueue(workq);
3395 destroy_workqueue(workq);
3396}