blob: 6ee5d8415f58cb34597efd40ace88b205ff60bdc [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>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
50#include "iw_cxgb4.h"
51
52static char *states[] = {
53 "idle",
54 "listen",
55 "connecting",
56 "mpa_wait_req",
57 "mpa_req_sent",
58 "mpa_req_rcvd",
59 "mpa_rep_sent",
60 "fpdu_mode",
61 "aborting",
62 "closing",
63 "moribund",
64 "dead",
65 NULL,
66};
67
Vipul Pandya5be78ee2012-12-10 09:30:54 +000068static int nocong;
69module_param(nocong, int, 0644);
70MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
71
72static int enable_ecn;
73module_param(enable_ecn, int, 0644);
74MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
75
Steve Wiseb52fe092011-03-11 22:30:01 +000076static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000077module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000078MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000079
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070080int c4iw_max_read_depth = 8;
81module_param(c4iw_max_read_depth, int, 0644);
82MODULE_PARM_DESC(c4iw_max_read_depth, "Per-connection max ORD/IRD (default=8)");
83
Steve Wisecfdda9d2010-04-21 15:30:06 -070084static int enable_tcp_timestamps;
85module_param(enable_tcp_timestamps, int, 0644);
86MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
87
88static int enable_tcp_sack;
89module_param(enable_tcp_sack, int, 0644);
90MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
91
92static int enable_tcp_window_scaling = 1;
93module_param(enable_tcp_window_scaling, int, 0644);
94MODULE_PARM_DESC(enable_tcp_window_scaling,
95 "Enable tcp window scaling (default=1)");
96
97int c4iw_debug;
98module_param(c4iw_debug, int, 0644);
99MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
100
101static int peer2peer;
102module_param(peer2peer, int, 0644);
103MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=0)");
104
105static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
106module_param(p2p_type, int, 0644);
107MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
108 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
109
110static int ep_timeout_secs = 60;
111module_param(ep_timeout_secs, int, 0644);
112MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
113 "in seconds (default=60)");
114
115static int mpa_rev = 1;
116module_param(mpa_rev, int, 0644);
117MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530118 "1 is RFC0544 spec compliant, 2 is IETF MPA Peer Connect Draft"
119 " compliant (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120
121static int markers_enabled;
122module_param(markers_enabled, int, 0644);
123MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
124
125static int crc_enabled = 1;
126module_param(crc_enabled, int, 0644);
127MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
128
129static int rcv_win = 256 * 1024;
130module_param(rcv_win, int, 0644);
131MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
132
Steve Wise98ae68b2010-09-10 11:15:41 -0500133static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700134module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500135MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700136
Steve Wisecfdda9d2010-04-21 15:30:06 -0700137static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138
139static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
141static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
142static void ep_timeout(unsigned long arg);
143static void connect_reply_upcall(struct c4iw_ep *ep, int status);
144
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700145static LIST_HEAD(timeout_list);
146static spinlock_t timeout_lock;
147
Vipul Pandya325abea2013-01-07 13:11:53 +0000148static void deref_qp(struct c4iw_ep *ep)
149{
150 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
151 clear_bit(QP_REFERENCED, &ep->com.flags);
152}
153
154static void ref_qp(struct c4iw_ep *ep)
155{
156 set_bit(QP_REFERENCED, &ep->com.flags);
157 c4iw_qp_add_ref(&ep->com.qp->ibqp);
158}
159
Steve Wisecfdda9d2010-04-21 15:30:06 -0700160static void start_ep_timer(struct c4iw_ep *ep)
161{
162 PDBG("%s ep %p\n", __func__, ep);
163 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000164 pr_err("%s timer already started! ep %p\n",
165 __func__, ep);
166 return;
167 }
168 clear_bit(TIMEOUT, &ep->com.flags);
169 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700170 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
171 ep->timer.data = (unsigned long)ep;
172 ep->timer.function = ep_timeout;
173 add_timer(&ep->timer);
174}
175
176static void stop_ep_timer(struct c4iw_ep *ep)
177{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000178 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700179 del_timer_sync(&ep->timer);
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000180 if (!test_and_set_bit(TIMEOUT, &ep->com.flags))
181 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700182}
183
184static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
185 struct l2t_entry *l2e)
186{
187 int error = 0;
188
189 if (c4iw_fatal_error(rdev)) {
190 kfree_skb(skb);
191 PDBG("%s - device in error state - dropping\n", __func__);
192 return -EIO;
193 }
194 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
195 if (error < 0)
196 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500197 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700198}
199
200int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
201{
202 int error = 0;
203
204 if (c4iw_fatal_error(rdev)) {
205 kfree_skb(skb);
206 PDBG("%s - device in error state - dropping\n", __func__);
207 return -EIO;
208 }
209 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
210 if (error < 0)
211 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500212 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700213}
214
215static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
216{
217 struct cpl_tid_release *req;
218
219 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
220 if (!skb)
221 return;
222 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
223 INIT_TP_WR(req, hwtid);
224 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
225 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
226 c4iw_ofld_send(rdev, skb);
227 return;
228}
229
230static void set_emss(struct c4iw_ep *ep, u16 opt)
231{
232 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
233 ep->mss = ep->emss;
234 if (GET_TCPOPT_TSTAMP(opt))
235 ep->emss -= 12;
236 if (ep->emss < 128)
237 ep->emss = 128;
238 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
239 ep->mss, ep->emss);
240}
241
242static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
243{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700244 enum c4iw_ep_state state;
245
Steve Wise2f5b48c2010-09-10 11:15:36 -0500246 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500248 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700249 return state;
250}
251
252static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
253{
254 epc->state = new;
255}
256
257static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
258{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500259 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700260 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
261 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500262 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 return;
264}
265
266static void *alloc_ep(int size, gfp_t gfp)
267{
268 struct c4iw_ep_common *epc;
269
270 epc = kzalloc(size, gfp);
271 if (epc) {
272 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500273 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500274 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 }
276 PDBG("%s alloc ep %p\n", __func__, epc);
277 return epc;
278}
279
280void _c4iw_free_ep(struct kref *kref)
281{
282 struct c4iw_ep *ep;
283
284 ep = container_of(kref, struct c4iw_ep, com.kref);
285 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000286 if (test_bit(QP_REFERENCED, &ep->com.flags))
287 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700288 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000289 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700290 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
291 dst_release(ep->dst);
292 cxgb4_l2t_release(ep->l2t);
293 }
294 kfree(ep);
295}
296
297static void release_ep_resources(struct c4iw_ep *ep)
298{
299 set_bit(RELEASE_RESOURCES, &ep->com.flags);
300 c4iw_put_ep(&ep->com);
301}
302
Steve Wisecfdda9d2010-04-21 15:30:06 -0700303static int status2errno(int status)
304{
305 switch (status) {
306 case CPL_ERR_NONE:
307 return 0;
308 case CPL_ERR_CONN_RESET:
309 return -ECONNRESET;
310 case CPL_ERR_ARP_MISS:
311 return -EHOSTUNREACH;
312 case CPL_ERR_CONN_TIMEDOUT:
313 return -ETIMEDOUT;
314 case CPL_ERR_TCAM_FULL:
315 return -ENOMEM;
316 case CPL_ERR_CONN_EXIST:
317 return -EADDRINUSE;
318 default:
319 return -EIO;
320 }
321}
322
323/*
324 * Try and reuse skbs already allocated...
325 */
326static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
327{
328 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
329 skb_trim(skb, 0);
330 skb_get(skb);
331 skb_reset_transport_header(skb);
332 } else {
333 skb = alloc_skb(len, gfp);
334 }
335 return skb;
336}
337
Vipul Pandya830662f2013-07-04 16:10:47 +0530338static struct net_device *get_real_dev(struct net_device *egress_dev)
339{
340 struct net_device *phys_dev = egress_dev;
341 if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
342 phys_dev = vlan_dev_real_dev(egress_dev);
343 return phys_dev;
344}
345
346static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
347{
348 int i;
349
350 egress_dev = get_real_dev(egress_dev);
351 for (i = 0; i < dev->rdev.lldi.nports; i++)
352 if (dev->rdev.lldi.ports[i] == egress_dev)
353 return 1;
354 return 0;
355}
356
357static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
358 __u8 *peer_ip, __be16 local_port,
359 __be16 peer_port, u8 tos,
360 __u32 sin6_scope_id)
361{
362 struct dst_entry *dst = NULL;
363
364 if (IS_ENABLED(CONFIG_IPV6)) {
365 struct flowi6 fl6;
366
367 memset(&fl6, 0, sizeof(fl6));
368 memcpy(&fl6.daddr, peer_ip, 16);
369 memcpy(&fl6.saddr, local_ip, 16);
370 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
371 fl6.flowi6_oif = sin6_scope_id;
372 dst = ip6_route_output(&init_net, NULL, &fl6);
373 if (!dst)
374 goto out;
375 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
376 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
377 dst_release(dst);
378 dst = NULL;
379 }
380 }
381
382out:
383 return dst;
384}
385
386static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700387 __be32 peer_ip, __be16 local_port,
388 __be16 peer_port, u8 tos)
389{
390 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700391 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530392 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700393
David S. Miller31e4543d2011-05-03 20:25:42 -0700394 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500395 peer_port, local_port, IPPROTO_TCP,
396 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800397 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700398 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530399 n = dst_neigh_lookup(&rt->dst, &peer_ip);
400 if (!n)
401 return NULL;
402 if (!our_interface(dev, n->dev)) {
403 dst_release(&rt->dst);
404 return NULL;
405 }
406 neigh_release(n);
407 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700408}
409
410static void arp_failure_discard(void *handle, struct sk_buff *skb)
411{
412 PDBG("%s c4iw_dev %p\n", __func__, handle);
413 kfree_skb(skb);
414}
415
416/*
417 * Handle an ARP failure for an active open.
418 */
419static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
420{
421 printk(KERN_ERR MOD "ARP failure duing connect\n");
422 kfree_skb(skb);
423}
424
425/*
426 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
427 * and send it along.
428 */
429static void abort_arp_failure(void *handle, struct sk_buff *skb)
430{
431 struct c4iw_rdev *rdev = handle;
432 struct cpl_abort_req *req = cplhdr(skb);
433
434 PDBG("%s rdev %p\n", __func__, rdev);
435 req->cmd = CPL_ABORT_NO_RST;
436 c4iw_ofld_send(rdev, skb);
437}
438
439static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
440{
441 unsigned int flowclen = 80;
442 struct fw_flowc_wr *flowc;
443 int i;
444
445 skb = get_skb(skb, flowclen, GFP_KERNEL);
446 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
447
448 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
449 FW_FLOWC_WR_NPARAMS(8));
450 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
451 16)) | FW_WR_FLOWID(ep->hwtid));
452
453 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000454 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700455 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
456 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
457 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
458 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
459 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
460 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
461 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
462 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
463 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
464 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
465 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
466 flowc->mnemval[6].val = cpu_to_be32(snd_win);
467 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
468 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
469 /* Pad WR to 16 byte boundary */
470 flowc->mnemval[8].mnemonic = 0;
471 flowc->mnemval[8].val = 0;
472 for (i = 0; i < 9; i++) {
473 flowc->mnemval[i].r4[0] = 0;
474 flowc->mnemval[i].r4[1] = 0;
475 flowc->mnemval[i].r4[2] = 0;
476 }
477
478 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
479 c4iw_ofld_send(&ep->com.dev->rdev, skb);
480}
481
482static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
483{
484 struct cpl_close_con_req *req;
485 struct sk_buff *skb;
486 int wrlen = roundup(sizeof *req, 16);
487
488 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
489 skb = get_skb(NULL, wrlen, gfp);
490 if (!skb) {
491 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
492 return -ENOMEM;
493 }
494 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
495 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
496 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
497 memset(req, 0, wrlen);
498 INIT_TP_WR(req, ep->hwtid);
499 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
500 ep->hwtid));
501 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
502}
503
504static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
505{
506 struct cpl_abort_req *req;
507 int wrlen = roundup(sizeof *req, 16);
508
509 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
510 skb = get_skb(skb, wrlen, gfp);
511 if (!skb) {
512 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
513 __func__);
514 return -ENOMEM;
515 }
516 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
517 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
518 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
519 memset(req, 0, wrlen);
520 INIT_TP_WR(req, ep->hwtid);
521 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
522 req->cmd = CPL_ABORT_SEND_RST;
523 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
524}
525
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000526#define VLAN_NONE 0xfff
527#define FILTER_SEL_VLAN_NONE 0xffff
528#define FILTER_SEL_WIDTH_P_FC (3+1) /* port uses 3 bits, FCoE one bit */
529#define FILTER_SEL_WIDTH_VIN_P_FC \
530 (6 + 7 + FILTER_SEL_WIDTH_P_FC) /* 6 bits are unused, VF uses 7 bits*/
531#define FILTER_SEL_WIDTH_TAG_P_FC \
532 (3 + FILTER_SEL_WIDTH_VIN_P_FC) /* PF uses 3 bits */
533#define FILTER_SEL_WIDTH_VLD_TAG_P_FC (1 + FILTER_SEL_WIDTH_TAG_P_FC)
534
535static unsigned int select_ntuple(struct c4iw_dev *dev, struct dst_entry *dst,
536 struct l2t_entry *l2t)
537{
538 unsigned int ntuple = 0;
539 u32 viid;
540
541 switch (dev->rdev.lldi.filt_mode) {
542
543 /* default filter mode */
544 case HW_TPL_FR_MT_PR_IV_P_FC:
545 if (l2t->vlan == VLAN_NONE)
546 ntuple |= FILTER_SEL_VLAN_NONE << FILTER_SEL_WIDTH_P_FC;
547 else {
548 ntuple |= l2t->vlan << FILTER_SEL_WIDTH_P_FC;
Steve Wise68074bb2013-08-06 21:04:33 +0530549 ntuple |= 1 << FILTER_SEL_WIDTH_TAG_P_FC;
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000550 }
551 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
552 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
553 break;
554 case HW_TPL_FR_MT_PR_OV_P_FC: {
555 viid = cxgb4_port_viid(l2t->neigh->dev);
556
557 ntuple |= FW_VIID_VIN_GET(viid) << FILTER_SEL_WIDTH_P_FC;
558 ntuple |= FW_VIID_PFN_GET(viid) << FILTER_SEL_WIDTH_VIN_P_FC;
559 ntuple |= FW_VIID_VIVLD_GET(viid) << FILTER_SEL_WIDTH_TAG_P_FC;
560 ntuple |= l2t->lport << S_PORT | IPPROTO_TCP <<
561 FILTER_SEL_WIDTH_VLD_TAG_P_FC;
562 break;
563 }
564 default:
565 break;
566 }
567 return ntuple;
568}
569
Steve Wisecfdda9d2010-04-21 15:30:06 -0700570static int send_connect(struct c4iw_ep *ep)
571{
572 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000573 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530574 struct cpl_act_open_req6 *req6;
575 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700576 struct sk_buff *skb;
577 u64 opt0;
578 u32 opt2;
579 unsigned int mtu_idx;
580 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530581 int wrlen;
582 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
583 sizeof(struct cpl_act_open_req) :
584 sizeof(struct cpl_t5_act_open_req);
585 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
586 sizeof(struct cpl_act_open_req6) :
587 sizeof(struct cpl_t5_act_open_req6);
588 struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
589 struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
590 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
591 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
592
593 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
594 roundup(sizev4, 16) :
595 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596
597 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
598
599 skb = get_skb(NULL, wrlen, GFP_KERNEL);
600 if (!skb) {
601 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
602 __func__);
603 return -ENOMEM;
604 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000605 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606
607 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
608 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000609 opt0 = (nocong ? NO_CONG(1) : 0) |
610 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000611 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700612 WND_SCALE(wscale) |
613 MSS_IDX(mtu_idx) |
614 L2T_IDX(ep->l2t->idx) |
615 TX_CHAN(ep->tx_chan) |
616 SMAC_SEL(ep->smac_idx) |
617 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000618 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700619 RCV_BUFSIZ(rcv_win>>10);
620 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000621 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700622 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
623 if (enable_tcp_timestamps)
624 opt2 |= TSTAMPS_EN(1);
625 if (enable_tcp_sack)
626 opt2 |= SACK_EN(1);
627 if (wscale && enable_tcp_window_scaling)
628 opt2 |= WND_SCALE_EN(1);
629 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
630
Vipul Pandyaf079af72013-03-14 05:08:58 +0000631 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530632 if (ep->com.remote_addr.ss_family == AF_INET) {
633 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
634 INIT_TP_WR(req, 0);
635 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000636 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
637 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530638 req->local_port = la->sin_port;
639 req->peer_port = ra->sin_port;
640 req->local_ip = la->sin_addr.s_addr;
641 req->peer_ip = ra->sin_addr.s_addr;
642 req->opt0 = cpu_to_be64(opt0);
643 req->params = cpu_to_be32(select_ntuple(ep->com.dev,
644 ep->dst, ep->l2t));
645 req->opt2 = cpu_to_be32(opt2);
646 } else {
647 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
648
649 INIT_TP_WR(req6, 0);
650 OPCODE_TID(req6) = cpu_to_be32(
651 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
652 ((ep->rss_qid<<14)|ep->atid)));
653 req6->local_port = la6->sin6_port;
654 req6->peer_port = ra6->sin6_port;
655 req6->local_ip_hi = *((__be64 *)
656 (la6->sin6_addr.s6_addr));
657 req6->local_ip_lo = *((__be64 *)
658 (la6->sin6_addr.s6_addr + 8));
659 req6->peer_ip_hi = *((__be64 *)
660 (ra6->sin6_addr.s6_addr));
661 req6->peer_ip_lo = *((__be64 *)
662 (ra6->sin6_addr.s6_addr + 8));
663 req6->opt0 = cpu_to_be64(opt0);
664 req6->params = cpu_to_be32(
665 select_ntuple(ep->com.dev, ep->dst,
666 ep->l2t));
667 req6->opt2 = cpu_to_be32(opt2);
668 }
669 } else {
670 if (ep->com.remote_addr.ss_family == AF_INET) {
671 t5_req = (struct cpl_t5_act_open_req *)
672 skb_put(skb, wrlen);
673 INIT_TP_WR(t5_req, 0);
674 OPCODE_TID(t5_req) = cpu_to_be32(
675 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
676 ((ep->rss_qid << 14) | ep->atid)));
677 t5_req->local_port = la->sin_port;
678 t5_req->peer_port = ra->sin_port;
679 t5_req->local_ip = la->sin_addr.s_addr;
680 t5_req->peer_ip = ra->sin_addr.s_addr;
681 t5_req->opt0 = cpu_to_be64(opt0);
682 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
683 select_ntuple(ep->com.dev,
684 ep->dst, ep->l2t)));
685 t5_req->opt2 = cpu_to_be32(opt2);
686 } else {
687 t5_req6 = (struct cpl_t5_act_open_req6 *)
688 skb_put(skb, wrlen);
689 INIT_TP_WR(t5_req6, 0);
690 OPCODE_TID(t5_req6) = cpu_to_be32(
691 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
692 ((ep->rss_qid<<14)|ep->atid)));
693 t5_req6->local_port = la6->sin6_port;
694 t5_req6->peer_port = ra6->sin6_port;
695 t5_req6->local_ip_hi = *((__be64 *)
696 (la6->sin6_addr.s6_addr));
697 t5_req6->local_ip_lo = *((__be64 *)
698 (la6->sin6_addr.s6_addr + 8));
699 t5_req6->peer_ip_hi = *((__be64 *)
700 (ra6->sin6_addr.s6_addr));
701 t5_req6->peer_ip_lo = *((__be64 *)
702 (ra6->sin6_addr.s6_addr + 8));
703 t5_req6->opt0 = cpu_to_be64(opt0);
704 t5_req6->params = (__force __be64)cpu_to_be32(
705 select_ntuple(ep->com.dev, ep->dst, ep->l2t));
706 t5_req6->opt2 = cpu_to_be32(opt2);
707 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000708 }
709
Vipul Pandya793dad92012-12-10 09:30:56 +0000710 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700711 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
712}
713
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530714static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
715 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716{
717 int mpalen, wrlen;
718 struct fw_ofld_tx_data_wr *req;
719 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530720 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700721
722 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
723
724 BUG_ON(skb_cloned(skb));
725
726 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530727 if (mpa_rev_to_use == 2)
728 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700729 wrlen = roundup(mpalen + sizeof *req, 16);
730 skb = get_skb(skb, wrlen, GFP_KERNEL);
731 if (!skb) {
732 connect_reply_upcall(ep, -ENOMEM);
733 return;
734 }
735 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
736
737 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
738 memset(req, 0, wrlen);
739 req->op_to_immdlen = cpu_to_be32(
740 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
741 FW_WR_COMPL(1) |
742 FW_WR_IMMDLEN(mpalen));
743 req->flowid_len16 = cpu_to_be32(
744 FW_WR_FLOWID(ep->hwtid) |
745 FW_WR_LEN16(wrlen >> 4));
746 req->plen = cpu_to_be32(mpalen);
747 req->tunnel_to_proxy = cpu_to_be32(
748 FW_OFLD_TX_DATA_WR_FLUSH(1) |
749 FW_OFLD_TX_DATA_WR_SHOVE(1));
750
751 mpa = (struct mpa_message *)(req + 1);
752 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
753 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530754 (markers_enabled ? MPA_MARKERS : 0) |
755 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530757 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530758 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530759 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530760 ep->retry_with_mpa_v1 = 0;
761 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700762
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530763 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700764 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
765 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530766 mpa_v2_params.ird = htons((u16)ep->ird);
767 mpa_v2_params.ord = htons((u16)ep->ord);
768
769 if (peer2peer) {
770 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
771 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
772 mpa_v2_params.ord |=
773 htons(MPA_V2_RDMA_WRITE_RTR);
774 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
775 mpa_v2_params.ord |=
776 htons(MPA_V2_RDMA_READ_RTR);
777 }
778 memcpy(mpa->private_data, &mpa_v2_params,
779 sizeof(struct mpa_v2_conn_params));
780
781 if (ep->plen)
782 memcpy(mpa->private_data +
783 sizeof(struct mpa_v2_conn_params),
784 ep->mpa_pkt + sizeof(*mpa), ep->plen);
785 } else
786 if (ep->plen)
787 memcpy(mpa->private_data,
788 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700789
790 /*
791 * Reference the mpa skb. This ensures the data area
792 * will remain in memory until the hw acks the tx.
793 * Function fw4_ack() will deref it.
794 */
795 skb_get(skb);
796 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
797 BUG_ON(ep->mpa_skb);
798 ep->mpa_skb = skb;
799 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
800 start_ep_timer(ep);
801 state_set(&ep->com, MPA_REQ_SENT);
802 ep->mpa_attr.initiator = 1;
803 return;
804}
805
806static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
807{
808 int mpalen, wrlen;
809 struct fw_ofld_tx_data_wr *req;
810 struct mpa_message *mpa;
811 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530812 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700813
814 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
815
816 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530817 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
818 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700819 wrlen = roundup(mpalen + sizeof *req, 16);
820
821 skb = get_skb(NULL, wrlen, GFP_KERNEL);
822 if (!skb) {
823 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
824 return -ENOMEM;
825 }
826 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
827
828 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
829 memset(req, 0, wrlen);
830 req->op_to_immdlen = cpu_to_be32(
831 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
832 FW_WR_COMPL(1) |
833 FW_WR_IMMDLEN(mpalen));
834 req->flowid_len16 = cpu_to_be32(
835 FW_WR_FLOWID(ep->hwtid) |
836 FW_WR_LEN16(wrlen >> 4));
837 req->plen = cpu_to_be32(mpalen);
838 req->tunnel_to_proxy = cpu_to_be32(
839 FW_OFLD_TX_DATA_WR_FLUSH(1) |
840 FW_OFLD_TX_DATA_WR_SHOVE(1));
841
842 mpa = (struct mpa_message *)(req + 1);
843 memset(mpa, 0, sizeof(*mpa));
844 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
845 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000846 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700847 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530848
849 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
850 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700851 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
852 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530853 mpa_v2_params.ird = htons(((u16)ep->ird) |
854 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
855 0));
856 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
857 (p2p_type ==
858 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
859 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
860 FW_RI_INIT_P2PTYPE_READ_REQ ?
861 MPA_V2_RDMA_READ_RTR : 0) : 0));
862 memcpy(mpa->private_data, &mpa_v2_params,
863 sizeof(struct mpa_v2_conn_params));
864
865 if (ep->plen)
866 memcpy(mpa->private_data +
867 sizeof(struct mpa_v2_conn_params), pdata, plen);
868 } else
869 if (plen)
870 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700871
872 /*
873 * Reference the mpa skb again. This ensures the data area
874 * will remain in memory until the hw acks the tx.
875 * Function fw4_ack() will deref it.
876 */
877 skb_get(skb);
878 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
879 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
880 BUG_ON(ep->mpa_skb);
881 ep->mpa_skb = skb;
882 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
883}
884
885static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
886{
887 int mpalen, wrlen;
888 struct fw_ofld_tx_data_wr *req;
889 struct mpa_message *mpa;
890 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530891 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700892
893 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
894
895 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530896 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
897 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700898 wrlen = roundup(mpalen + sizeof *req, 16);
899
900 skb = get_skb(NULL, wrlen, GFP_KERNEL);
901 if (!skb) {
902 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
903 return -ENOMEM;
904 }
905 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
906
907 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
908 memset(req, 0, wrlen);
909 req->op_to_immdlen = cpu_to_be32(
910 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
911 FW_WR_COMPL(1) |
912 FW_WR_IMMDLEN(mpalen));
913 req->flowid_len16 = cpu_to_be32(
914 FW_WR_FLOWID(ep->hwtid) |
915 FW_WR_LEN16(wrlen >> 4));
916 req->plen = cpu_to_be32(mpalen);
917 req->tunnel_to_proxy = cpu_to_be32(
918 FW_OFLD_TX_DATA_WR_FLUSH(1) |
919 FW_OFLD_TX_DATA_WR_SHOVE(1));
920
921 mpa = (struct mpa_message *)(req + 1);
922 memset(mpa, 0, sizeof(*mpa));
923 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
924 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
925 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530926 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700927 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530928
929 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
930 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700931 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
932 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530933 mpa_v2_params.ird = htons((u16)ep->ird);
934 mpa_v2_params.ord = htons((u16)ep->ord);
935 if (peer2peer && (ep->mpa_attr.p2p_type !=
936 FW_RI_INIT_P2PTYPE_DISABLED)) {
937 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
938
939 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
940 mpa_v2_params.ord |=
941 htons(MPA_V2_RDMA_WRITE_RTR);
942 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
943 mpa_v2_params.ord |=
944 htons(MPA_V2_RDMA_READ_RTR);
945 }
946
947 memcpy(mpa->private_data, &mpa_v2_params,
948 sizeof(struct mpa_v2_conn_params));
949
950 if (ep->plen)
951 memcpy(mpa->private_data +
952 sizeof(struct mpa_v2_conn_params), pdata, plen);
953 } else
954 if (plen)
955 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700956
957 /*
958 * Reference the mpa skb. This ensures the data area
959 * will remain in memory until the hw acks the tx.
960 * Function fw4_ack() will deref it.
961 */
962 skb_get(skb);
963 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
964 ep->mpa_skb = skb;
965 state_set(&ep->com, MPA_REP_SENT);
966 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
967}
968
969static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
970{
971 struct c4iw_ep *ep;
972 struct cpl_act_establish *req = cplhdr(skb);
973 unsigned int tid = GET_TID(req);
974 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
975 struct tid_info *t = dev->rdev.lldi.tids;
976
977 ep = lookup_atid(t, atid);
978
979 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
980 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
981
982 dst_confirm(ep->dst);
983
984 /* setup the hwtid for this connection */
985 ep->hwtid = tid;
986 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000987 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700988
989 ep->snd_seq = be32_to_cpu(req->snd_isn);
990 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
991
992 set_emss(ep, ntohs(req->tcp_opt));
993
994 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000995 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000997 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700998
999 /* start MPA negotiation */
1000 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301001 if (ep->retry_with_mpa_v1)
1002 send_mpa_req(ep, skb, 1);
1003 else
1004 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001005
1006 return 0;
1007}
1008
1009static void close_complete_upcall(struct c4iw_ep *ep)
1010{
1011 struct iw_cm_event event;
1012
1013 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1014 memset(&event, 0, sizeof(event));
1015 event.event = IW_CM_EVENT_CLOSE;
1016 if (ep->com.cm_id) {
1017 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1018 ep, ep->com.cm_id, ep->hwtid);
1019 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1020 ep->com.cm_id->rem_ref(ep->com.cm_id);
1021 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001022 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001023 }
1024}
1025
1026static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
1027{
1028 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1029 close_complete_upcall(ep);
1030 state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001031 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001032 return send_abort(ep, skb, gfp);
1033}
1034
1035static void peer_close_upcall(struct c4iw_ep *ep)
1036{
1037 struct iw_cm_event event;
1038
1039 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1040 memset(&event, 0, sizeof(event));
1041 event.event = IW_CM_EVENT_DISCONNECT;
1042 if (ep->com.cm_id) {
1043 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1044 ep, ep->com.cm_id, ep->hwtid);
1045 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001046 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001047 }
1048}
1049
1050static void peer_abort_upcall(struct c4iw_ep *ep)
1051{
1052 struct iw_cm_event event;
1053
1054 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1055 memset(&event, 0, sizeof(event));
1056 event.event = IW_CM_EVENT_CLOSE;
1057 event.status = -ECONNRESET;
1058 if (ep->com.cm_id) {
1059 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1060 ep->com.cm_id, ep->hwtid);
1061 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1062 ep->com.cm_id->rem_ref(ep->com.cm_id);
1063 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001064 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001065 }
1066}
1067
1068static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1069{
1070 struct iw_cm_event event;
1071
1072 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1073 memset(&event, 0, sizeof(event));
1074 event.event = IW_CM_EVENT_CONNECT_REPLY;
1075 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301076 memcpy(&event.local_addr, &ep->com.local_addr,
1077 sizeof(ep->com.local_addr));
1078 memcpy(&event.remote_addr, &ep->com.remote_addr,
1079 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080
1081 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301082 if (!ep->tried_with_mpa_v1) {
1083 /* this means MPA_v2 is used */
1084 event.private_data_len = ep->plen -
1085 sizeof(struct mpa_v2_conn_params);
1086 event.private_data = ep->mpa_pkt +
1087 sizeof(struct mpa_message) +
1088 sizeof(struct mpa_v2_conn_params);
1089 } else {
1090 /* this means MPA_v1 is used */
1091 event.private_data_len = ep->plen;
1092 event.private_data = ep->mpa_pkt +
1093 sizeof(struct mpa_message);
1094 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001095 }
Roland Dreier85963e42010-07-19 13:13:09 -07001096
1097 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1098 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001099 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001100 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1101
Steve Wisecfdda9d2010-04-21 15:30:06 -07001102 if (status < 0) {
1103 ep->com.cm_id->rem_ref(ep->com.cm_id);
1104 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001105 }
1106}
1107
1108static void connect_request_upcall(struct c4iw_ep *ep)
1109{
1110 struct iw_cm_event event;
1111
1112 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1113 memset(&event, 0, sizeof(event));
1114 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301115 memcpy(&event.local_addr, &ep->com.local_addr,
1116 sizeof(ep->com.local_addr));
1117 memcpy(&event.remote_addr, &ep->com.remote_addr,
1118 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001119 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301120 if (!ep->tried_with_mpa_v1) {
1121 /* this means MPA_v2 is used */
1122 event.ord = ep->ord;
1123 event.ird = ep->ird;
1124 event.private_data_len = ep->plen -
1125 sizeof(struct mpa_v2_conn_params);
1126 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1127 sizeof(struct mpa_v2_conn_params);
1128 } else {
1129 /* this means MPA_v1 is used. Send max supported */
1130 event.ord = c4iw_max_read_depth;
1131 event.ird = c4iw_max_read_depth;
1132 event.private_data_len = ep->plen;
1133 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1134 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001135 if (state_read(&ep->parent_ep->com) != DEAD) {
1136 c4iw_get_ep(&ep->com);
1137 ep->parent_ep->com.cm_id->event_handler(
1138 ep->parent_ep->com.cm_id,
1139 &event);
1140 }
Vipul Pandya793dad92012-12-10 09:30:56 +00001141 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001142 c4iw_put_ep(&ep->parent_ep->com);
1143 ep->parent_ep = NULL;
1144}
1145
1146static void established_upcall(struct c4iw_ep *ep)
1147{
1148 struct iw_cm_event event;
1149
1150 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1151 memset(&event, 0, sizeof(event));
1152 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301153 event.ird = ep->ird;
1154 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155 if (ep->com.cm_id) {
1156 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1157 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001158 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001159 }
1160}
1161
1162static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1163{
1164 struct cpl_rx_data_ack *req;
1165 struct sk_buff *skb;
1166 int wrlen = roundup(sizeof *req, 16);
1167
1168 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1169 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1170 if (!skb) {
1171 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1172 return 0;
1173 }
1174
1175 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1176 memset(req, 0, wrlen);
1177 INIT_TP_WR(req, ep->hwtid);
1178 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1179 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001180 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1181 F_RX_DACK_CHANGE |
1182 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001183 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001184 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1185 return credits;
1186}
1187
1188static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1189{
1190 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301191 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001192 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301193 u16 resp_ird, resp_ord;
1194 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001195 struct c4iw_qp_attributes attrs;
1196 enum c4iw_qp_attr_mask mask;
1197 int err;
1198
1199 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1200
1201 /*
1202 * Stop mpa timer. If it expired, then the state has
1203 * changed and we bail since ep_timeout already aborted
1204 * the connection.
1205 */
1206 stop_ep_timer(ep);
1207 if (state_read(&ep->com) != MPA_REQ_SENT)
1208 return;
1209
1210 /*
1211 * If we get more than the supported amount of private data
1212 * then we must fail this connection.
1213 */
1214 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1215 err = -EINVAL;
1216 goto err;
1217 }
1218
1219 /*
1220 * copy the new data into our accumulation buffer.
1221 */
1222 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1223 skb->len);
1224 ep->mpa_pkt_len += skb->len;
1225
1226 /*
1227 * if we don't even have the mpa message, then bail.
1228 */
1229 if (ep->mpa_pkt_len < sizeof(*mpa))
1230 return;
1231 mpa = (struct mpa_message *) ep->mpa_pkt;
1232
1233 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301234 if (mpa->revision > mpa_rev) {
1235 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1236 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237 err = -EPROTO;
1238 goto err;
1239 }
1240 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1241 err = -EPROTO;
1242 goto err;
1243 }
1244
1245 plen = ntohs(mpa->private_data_size);
1246
1247 /*
1248 * Fail if there's too much private data.
1249 */
1250 if (plen > MPA_MAX_PRIVATE_DATA) {
1251 err = -EPROTO;
1252 goto err;
1253 }
1254
1255 /*
1256 * If plen does not account for pkt size
1257 */
1258 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1259 err = -EPROTO;
1260 goto err;
1261 }
1262
1263 ep->plen = (u8) plen;
1264
1265 /*
1266 * If we don't have all the pdata yet, then bail.
1267 * We'll continue process when more data arrives.
1268 */
1269 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1270 return;
1271
1272 if (mpa->flags & MPA_REJECT) {
1273 err = -ECONNREFUSED;
1274 goto err;
1275 }
1276
1277 /*
1278 * If we get here we have accumulated the entire mpa
1279 * start reply message including private data. And
1280 * the MPA header is valid.
1281 */
1282 state_set(&ep->com, FPDU_MODE);
1283 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1284 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1285 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301286 ep->mpa_attr.version = mpa->revision;
1287 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1288
1289 if (mpa->revision == 2) {
1290 ep->mpa_attr.enhanced_rdma_conn =
1291 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1292 if (ep->mpa_attr.enhanced_rdma_conn) {
1293 mpa_v2_params = (struct mpa_v2_conn_params *)
1294 (ep->mpa_pkt + sizeof(*mpa));
1295 resp_ird = ntohs(mpa_v2_params->ird) &
1296 MPA_V2_IRD_ORD_MASK;
1297 resp_ord = ntohs(mpa_v2_params->ord) &
1298 MPA_V2_IRD_ORD_MASK;
1299
1300 /*
1301 * This is a double-check. Ideally, below checks are
1302 * not required since ird/ord stuff has been taken
1303 * care of in c4iw_accept_cr
1304 */
1305 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1306 err = -ENOMEM;
1307 ep->ird = resp_ord;
1308 ep->ord = resp_ird;
1309 insuff_ird = 1;
1310 }
1311
1312 if (ntohs(mpa_v2_params->ird) &
1313 MPA_V2_PEER2PEER_MODEL) {
1314 if (ntohs(mpa_v2_params->ord) &
1315 MPA_V2_RDMA_WRITE_RTR)
1316 ep->mpa_attr.p2p_type =
1317 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1318 else if (ntohs(mpa_v2_params->ord) &
1319 MPA_V2_RDMA_READ_RTR)
1320 ep->mpa_attr.p2p_type =
1321 FW_RI_INIT_P2PTYPE_READ_REQ;
1322 }
1323 }
1324 } else if (mpa->revision == 1)
1325 if (peer2peer)
1326 ep->mpa_attr.p2p_type = p2p_type;
1327
Steve Wisecfdda9d2010-04-21 15:30:06 -07001328 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301329 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1330 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1331 ep->mpa_attr.recv_marker_enabled,
1332 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1333 ep->mpa_attr.p2p_type, p2p_type);
1334
1335 /*
1336 * If responder's RTR does not match with that of initiator, assign
1337 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1338 * generated when moving QP to RTS state.
1339 * A TERM message will be sent after QP has moved to RTS state
1340 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001341 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301342 (ep->mpa_attr.p2p_type != p2p_type)) {
1343 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1344 rtr_mismatch = 1;
1345 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001346
1347 attrs.mpa_attr = ep->mpa_attr;
1348 attrs.max_ird = ep->ird;
1349 attrs.max_ord = ep->ord;
1350 attrs.llp_stream_handle = ep;
1351 attrs.next_state = C4IW_QP_STATE_RTS;
1352
1353 mask = C4IW_QP_ATTR_NEXT_STATE |
1354 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1355 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1356
1357 /* bind QP and TID with INIT_WR */
1358 err = c4iw_modify_qp(ep->com.qp->rhp,
1359 ep->com.qp, mask, &attrs, 1);
1360 if (err)
1361 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301362
1363 /*
1364 * If responder's RTR requirement did not match with what initiator
1365 * supports, generate TERM message
1366 */
1367 if (rtr_mismatch) {
1368 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1369 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1370 attrs.ecode = MPA_NOMATCH_RTR;
1371 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1372 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1373 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1374 err = -ENOMEM;
1375 goto out;
1376 }
1377
1378 /*
1379 * Generate TERM if initiator IRD is not sufficient for responder
1380 * provided ORD. Currently, we do the same behaviour even when
1381 * responder provided IRD is also not sufficient as regards to
1382 * initiator ORD.
1383 */
1384 if (insuff_ird) {
1385 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1386 __func__);
1387 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1388 attrs.ecode = MPA_INSUFF_IRD;
1389 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1390 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1391 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1392 err = -ENOMEM;
1393 goto out;
1394 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001395 goto out;
1396err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001397 state_set(&ep->com, ABORTING);
1398 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001399out:
1400 connect_reply_upcall(ep, err);
1401 return;
1402}
1403
1404static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1405{
1406 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301407 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001408 u16 plen;
1409
1410 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1411
1412 if (state_read(&ep->com) != MPA_REQ_WAIT)
1413 return;
1414
1415 /*
1416 * If we get more than the supported amount of private data
1417 * then we must fail this connection.
1418 */
1419 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1420 stop_ep_timer(ep);
1421 abort_connection(ep, skb, GFP_KERNEL);
1422 return;
1423 }
1424
1425 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1426
1427 /*
1428 * Copy the new data into our accumulation buffer.
1429 */
1430 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1431 skb->len);
1432 ep->mpa_pkt_len += skb->len;
1433
1434 /*
1435 * If we don't even have the mpa message, then bail.
1436 * We'll continue process when more data arrives.
1437 */
1438 if (ep->mpa_pkt_len < sizeof(*mpa))
1439 return;
1440
1441 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1442 stop_ep_timer(ep);
1443 mpa = (struct mpa_message *) ep->mpa_pkt;
1444
1445 /*
1446 * Validate MPA Header.
1447 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301448 if (mpa->revision > mpa_rev) {
1449 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1450 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001451 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001452 abort_connection(ep, skb, GFP_KERNEL);
1453 return;
1454 }
1455
1456 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001457 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001458 abort_connection(ep, skb, GFP_KERNEL);
1459 return;
1460 }
1461
1462 plen = ntohs(mpa->private_data_size);
1463
1464 /*
1465 * Fail if there's too much private data.
1466 */
1467 if (plen > MPA_MAX_PRIVATE_DATA) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001468 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469 abort_connection(ep, skb, GFP_KERNEL);
1470 return;
1471 }
1472
1473 /*
1474 * If plen does not account for pkt size
1475 */
1476 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001477 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001478 abort_connection(ep, skb, GFP_KERNEL);
1479 return;
1480 }
1481 ep->plen = (u8) plen;
1482
1483 /*
1484 * If we don't have all the pdata yet, then bail.
1485 */
1486 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1487 return;
1488
1489 /*
1490 * If we get here we have accumulated the entire mpa
1491 * start reply message including private data.
1492 */
1493 ep->mpa_attr.initiator = 0;
1494 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1495 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1496 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301497 ep->mpa_attr.version = mpa->revision;
1498 if (mpa->revision == 1)
1499 ep->tried_with_mpa_v1 = 1;
1500 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1501
1502 if (mpa->revision == 2) {
1503 ep->mpa_attr.enhanced_rdma_conn =
1504 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1505 if (ep->mpa_attr.enhanced_rdma_conn) {
1506 mpa_v2_params = (struct mpa_v2_conn_params *)
1507 (ep->mpa_pkt + sizeof(*mpa));
1508 ep->ird = ntohs(mpa_v2_params->ird) &
1509 MPA_V2_IRD_ORD_MASK;
1510 ep->ord = ntohs(mpa_v2_params->ord) &
1511 MPA_V2_IRD_ORD_MASK;
1512 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1513 if (peer2peer) {
1514 if (ntohs(mpa_v2_params->ord) &
1515 MPA_V2_RDMA_WRITE_RTR)
1516 ep->mpa_attr.p2p_type =
1517 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1518 else if (ntohs(mpa_v2_params->ord) &
1519 MPA_V2_RDMA_READ_RTR)
1520 ep->mpa_attr.p2p_type =
1521 FW_RI_INIT_P2PTYPE_READ_REQ;
1522 }
1523 }
1524 } else if (mpa->revision == 1)
1525 if (peer2peer)
1526 ep->mpa_attr.p2p_type = p2p_type;
1527
Steve Wisecfdda9d2010-04-21 15:30:06 -07001528 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1529 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1530 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1531 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1532 ep->mpa_attr.p2p_type);
1533
1534 state_set(&ep->com, MPA_REQ_RCVD);
1535
1536 /* drive upcall */
1537 connect_request_upcall(ep);
1538 return;
1539}
1540
1541static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1542{
1543 struct c4iw_ep *ep;
1544 struct cpl_rx_data *hdr = cplhdr(skb);
1545 unsigned int dlen = ntohs(hdr->len);
1546 unsigned int tid = GET_TID(hdr);
1547 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001548 __u8 status = hdr->status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001549
1550 ep = lookup_tid(t, tid);
1551 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1552 skb_pull(skb, sizeof(*hdr));
1553 skb_trim(skb, dlen);
1554
Steve Wisecfdda9d2010-04-21 15:30:06 -07001555 /* update RX credits */
1556 update_rx_credits(ep, dlen);
1557
1558 switch (state_read(&ep->com)) {
1559 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001560 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001561 process_mpa_reply(ep, skb);
1562 break;
1563 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001564 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001565 process_mpa_request(ep, skb);
1566 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001567 case FPDU_MODE: {
1568 struct c4iw_qp_attributes attrs;
1569 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001570 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001571 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001572 " qpid %u ep %p state %d tid %u status %d\n",
1573 __func__, ep->com.qp->wq.sq.qid, ep,
1574 state_read(&ep->com), ep->hwtid, status);
Vipul Pandya15579672013-01-07 13:11:52 +00001575 attrs.next_state = C4IW_QP_STATE_ERROR;
1576 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1577 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001578 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001579 break;
1580 }
Vipul Pandya15579672013-01-07 13:11:52 +00001581 default:
1582 break;
1583 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001584 return 0;
1585}
1586
1587static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1588{
1589 struct c4iw_ep *ep;
1590 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001591 int release = 0;
1592 unsigned int tid = GET_TID(rpl);
1593 struct tid_info *t = dev->rdev.lldi.tids;
1594
1595 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301596 if (!ep) {
1597 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1598 return 0;
1599 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001600 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001601 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602 switch (ep->com.state) {
1603 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001604 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001605 __state_set(&ep->com, DEAD);
1606 release = 1;
1607 break;
1608 default:
1609 printk(KERN_ERR "%s ep %p state %d\n",
1610 __func__, ep, ep->com.state);
1611 break;
1612 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001613 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001614
1615 if (release)
1616 release_ep_resources(ep);
1617 return 0;
1618}
1619
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001620static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1621{
1622 struct sk_buff *skb;
1623 struct fw_ofld_connection_wr *req;
1624 unsigned int mtu_idx;
1625 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301626 struct sockaddr_in *sin;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001627
1628 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1629 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1630 memset(req, 0, sizeof(*req));
1631 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1632 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
1633 req->le.filter = cpu_to_be32(select_ntuple(ep->com.dev, ep->dst,
1634 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +05301635 sin = (struct sockaddr_in *)&ep->com.local_addr;
1636 req->le.lport = sin->sin_port;
1637 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1638 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1639 req->le.pport = sin->sin_port;
1640 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001641 req->tcb.t_state_to_astid =
1642 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1643 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1644 req->tcb.cplrxdataack_cplpassacceptrpl =
1645 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001646 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001647 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001648 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1649 wscale = compute_wscale(rcv_win);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001650 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001651 (nocong ? NO_CONG(1) : 0) |
1652 KEEP_ALIVE(1) |
1653 DELACK(1) |
1654 WND_SCALE(wscale) |
1655 MSS_IDX(mtu_idx) |
1656 L2T_IDX(ep->l2t->idx) |
1657 TX_CHAN(ep->tx_chan) |
1658 SMAC_SEL(ep->smac_idx) |
1659 DSCP(ep->tos) |
1660 ULP_MODE(ULP_MODE_TCPDDP) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001661 RCV_BUFSIZ(rcv_win >> 10));
1662 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001663 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1664 RX_CHANNEL(0) |
1665 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001666 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001667 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001668 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001669 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001670 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001671 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001672 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1673 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1674 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001675 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1676 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001677 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1678}
1679
Steve Wisecfdda9d2010-04-21 15:30:06 -07001680/*
1681 * Return whether a failed active open has allocated a TID
1682 */
1683static inline int act_open_has_tid(int status)
1684{
1685 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1686 status != CPL_ERR_ARP_MISS;
1687}
1688
Vipul Pandya793dad92012-12-10 09:30:56 +00001689#define ACT_OPEN_RETRY_COUNT 2
1690
Vipul Pandya830662f2013-07-04 16:10:47 +05301691static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1692 struct dst_entry *dst, struct c4iw_dev *cdev,
1693 bool clear_mpa_v1)
1694{
1695 struct neighbour *n;
1696 int err, step;
1697 struct net_device *pdev;
1698
1699 n = dst_neigh_lookup(dst, peer_ip);
1700 if (!n)
1701 return -ENODEV;
1702
1703 rcu_read_lock();
1704 err = -ENOMEM;
1705 if (n->dev->flags & IFF_LOOPBACK) {
1706 if (iptype == 4)
1707 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1708 else if (IS_ENABLED(CONFIG_IPV6))
1709 for_each_netdev(&init_net, pdev) {
1710 if (ipv6_chk_addr(&init_net,
1711 (struct in6_addr *)peer_ip,
1712 pdev, 1))
1713 break;
1714 }
1715 else
1716 pdev = NULL;
1717
1718 if (!pdev) {
1719 err = -ENODEV;
1720 goto out;
1721 }
1722 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1723 n, pdev, 0);
1724 if (!ep->l2t)
1725 goto out;
1726 ep->mtu = pdev->mtu;
1727 ep->tx_chan = cxgb4_port_chan(pdev);
1728 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1729 step = cdev->rdev.lldi.ntxq /
1730 cdev->rdev.lldi.nchan;
1731 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1732 step = cdev->rdev.lldi.nrxq /
1733 cdev->rdev.lldi.nchan;
1734 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1735 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1736 cxgb4_port_idx(pdev) * step];
1737 dev_put(pdev);
1738 } else {
1739 pdev = get_real_dev(n->dev);
1740 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1741 n, pdev, 0);
1742 if (!ep->l2t)
1743 goto out;
1744 ep->mtu = dst_mtu(dst);
1745 ep->tx_chan = cxgb4_port_chan(n->dev);
1746 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1747 step = cdev->rdev.lldi.ntxq /
1748 cdev->rdev.lldi.nchan;
1749 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1750 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1751 step = cdev->rdev.lldi.nrxq /
1752 cdev->rdev.lldi.nchan;
1753 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1754 cxgb4_port_idx(n->dev) * step];
1755
1756 if (clear_mpa_v1) {
1757 ep->retry_with_mpa_v1 = 0;
1758 ep->tried_with_mpa_v1 = 0;
1759 }
1760 }
1761 err = 0;
1762out:
1763 rcu_read_unlock();
1764
1765 neigh_release(n);
1766
1767 return err;
1768}
1769
Vipul Pandya793dad92012-12-10 09:30:56 +00001770static int c4iw_reconnect(struct c4iw_ep *ep)
1771{
1772 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301773 struct sockaddr_in *laddr = (struct sockaddr_in *)
1774 &ep->com.cm_id->local_addr;
1775 struct sockaddr_in *raddr = (struct sockaddr_in *)
1776 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301777 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1778 &ep->com.cm_id->local_addr;
1779 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1780 &ep->com.cm_id->remote_addr;
1781 int iptype;
1782 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001783
1784 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1785 init_timer(&ep->timer);
1786
1787 /*
1788 * Allocate an active TID to initiate a TCP connection.
1789 */
1790 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1791 if (ep->atid == -1) {
1792 pr_err("%s - cannot alloc atid.\n", __func__);
1793 err = -ENOMEM;
1794 goto fail2;
1795 }
1796 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1797
1798 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301799 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1800 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1801 raddr->sin_addr.s_addr, laddr->sin_port,
1802 raddr->sin_port, 0);
1803 iptype = 4;
1804 ra = (__u8 *)&raddr->sin_addr;
1805 } else {
1806 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1807 raddr6->sin6_addr.s6_addr,
1808 laddr6->sin6_port, raddr6->sin6_port, 0,
1809 raddr6->sin6_scope_id);
1810 iptype = 6;
1811 ra = (__u8 *)&raddr6->sin6_addr;
1812 }
1813 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001814 pr_err("%s - cannot find route.\n", __func__);
1815 err = -EHOSTUNREACH;
1816 goto fail3;
1817 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301818 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1819 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001820 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001821 goto fail4;
1822 }
1823
1824 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1825 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1826 ep->l2t->idx);
1827
1828 state_set(&ep->com, CONNECTING);
1829 ep->tos = 0;
1830
1831 /* send connect request to rnic */
1832 err = send_connect(ep);
1833 if (!err)
1834 goto out;
1835
1836 cxgb4_l2t_release(ep->l2t);
1837fail4:
1838 dst_release(ep->dst);
1839fail3:
1840 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1841 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1842fail2:
1843 /*
1844 * remember to send notification to upper layer.
1845 * We are in here so the upper layer is not aware that this is
1846 * re-connect attempt and so, upper layer is still waiting for
1847 * response of 1st connect request.
1848 */
1849 connect_reply_upcall(ep, -ECONNRESET);
1850 c4iw_put_ep(&ep->com);
1851out:
1852 return err;
1853}
1854
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1856{
1857 struct c4iw_ep *ep;
1858 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1859 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1860 ntohl(rpl->atid_status)));
1861 struct tid_info *t = dev->rdev.lldi.tids;
1862 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301863 struct sockaddr_in *la;
1864 struct sockaddr_in *ra;
1865 struct sockaddr_in6 *la6;
1866 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001867
1868 ep = lookup_atid(t, atid);
Vipul Pandya830662f2013-07-04 16:10:47 +05301869 la = (struct sockaddr_in *)&ep->com.local_addr;
1870 ra = (struct sockaddr_in *)&ep->com.remote_addr;
1871 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
1872 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873
1874 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1875 status, status2errno(status));
1876
1877 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1878 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1879 atid);
1880 return 0;
1881 }
1882
Vipul Pandya793dad92012-12-10 09:30:56 +00001883 set_bit(ACT_OPEN_RPL, &ep->com.history);
1884
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301885 /*
1886 * Log interesting failures.
1887 */
1888 switch (status) {
1889 case CPL_ERR_CONN_RESET:
1890 case CPL_ERR_CONN_TIMEDOUT:
1891 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001892 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05301893 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00001894 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05301895 mutex_unlock(&dev->rdev.stats.lock);
1896 if (ep->com.local_addr.ss_family == AF_INET &&
1897 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001898 send_fw_act_open_req(ep,
1899 GET_TID_TID(GET_AOPEN_ATID(
1900 ntohl(rpl->atid_status))));
1901 return 0;
1902 }
1903 break;
1904 case CPL_ERR_CONN_EXIST:
1905 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1906 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1907 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1908 atid);
1909 cxgb4_free_atid(t, atid);
1910 dst_release(ep->dst);
1911 cxgb4_l2t_release(ep->l2t);
1912 c4iw_reconnect(ep);
1913 return 0;
1914 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301916 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05301917 if (ep->com.local_addr.ss_family == AF_INET) {
1918 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1919 atid, status, status2errno(status),
1920 &la->sin_addr.s_addr, ntohs(la->sin_port),
1921 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1922 } else {
1923 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1924 atid, status, status2errno(status),
1925 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1926 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1927 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301928 break;
1929 }
1930
Steve Wisecfdda9d2010-04-21 15:30:06 -07001931 connect_reply_upcall(ep, status2errno(status));
1932 state_set(&ep->com, DEAD);
1933
1934 if (status && act_open_has_tid(status))
1935 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1936
Vipul Pandya793dad92012-12-10 09:30:56 +00001937 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001938 cxgb4_free_atid(t, atid);
1939 dst_release(ep->dst);
1940 cxgb4_l2t_release(ep->l2t);
1941 c4iw_put_ep(&ep->com);
1942
1943 return 0;
1944}
1945
1946static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1947{
1948 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1949 struct tid_info *t = dev->rdev.lldi.tids;
1950 unsigned int stid = GET_TID(rpl);
1951 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1952
1953 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001954 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1955 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001956 }
1957 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1958 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001959 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001960
Vipul Pandya1cab7752012-12-10 09:30:55 +00001961out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962 return 0;
1963}
1964
Steve Wisecfdda9d2010-04-21 15:30:06 -07001965static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1966{
1967 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1968 struct tid_info *t = dev->rdev.lldi.tids;
1969 unsigned int stid = GET_TID(rpl);
1970 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1971
1972 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001973 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001974 return 0;
1975}
1976
Vipul Pandya830662f2013-07-04 16:10:47 +05301977static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07001978 struct cpl_pass_accept_req *req)
1979{
1980 struct cpl_pass_accept_rpl *rpl;
1981 unsigned int mtu_idx;
1982 u64 opt0;
1983 u32 opt2;
1984 int wscale;
1985
1986 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1987 BUG_ON(skb_cloned(skb));
1988 skb_trim(skb, sizeof(*rpl));
1989 skb_get(skb);
1990 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1991 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001992 opt0 = (nocong ? NO_CONG(1) : 0) |
1993 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001994 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001995 WND_SCALE(wscale) |
1996 MSS_IDX(mtu_idx) |
1997 L2T_IDX(ep->l2t->idx) |
1998 TX_CHAN(ep->tx_chan) |
1999 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002000 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002001 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002002 RCV_BUFSIZ(rcv_win>>10);
2003 opt2 = RX_CHANNEL(0) |
2004 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2005
2006 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2007 opt2 |= TSTAMPS_EN(1);
2008 if (enable_tcp_sack && req->tcpopt.sack)
2009 opt2 |= SACK_EN(1);
2010 if (wscale && enable_tcp_window_scaling)
2011 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002012 if (enable_ecn) {
2013 const struct tcphdr *tcph;
2014 u32 hlen = ntohl(req->hdr_len);
2015
2016 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2017 G_IP_HDR_LEN(hlen);
2018 if (tcph->ece && tcph->cwr)
2019 opt2 |= CCTRL_ECN(1);
2020 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002021
2022 rpl = cplhdr(skb);
2023 INIT_TP_WR(rpl, ep->hwtid);
2024 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2025 ep->hwtid));
2026 rpl->opt0 = cpu_to_be64(opt0);
2027 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002028 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002029 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2030
2031 return;
2032}
2033
Vipul Pandya830662f2013-07-04 16:10:47 +05302034static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002035{
Vipul Pandya830662f2013-07-04 16:10:47 +05302036 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002037 BUG_ON(skb_cloned(skb));
2038 skb_trim(skb, sizeof(struct cpl_tid_release));
2039 skb_get(skb);
2040 release_tid(&dev->rdev, hwtid, skb);
2041 return;
2042}
2043
Vipul Pandya830662f2013-07-04 16:10:47 +05302044static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2045 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002046 __be16 *local_port, __be16 *peer_port)
2047{
2048 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2049 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2050 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302051 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002052 struct tcphdr *tcp = (struct tcphdr *)
2053 ((u8 *)(req + 1) + eth_len + ip_len);
2054
Vipul Pandya830662f2013-07-04 16:10:47 +05302055 if (ip->version == 4) {
2056 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2057 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2058 ntohs(tcp->dest));
2059 *iptype = 4;
2060 memcpy(peer_ip, &ip->saddr, 4);
2061 memcpy(local_ip, &ip->daddr, 4);
2062 } else {
2063 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2064 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2065 ntohs(tcp->dest));
2066 *iptype = 6;
2067 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2068 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2069 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002070 *peer_port = tcp->source;
2071 *local_port = tcp->dest;
2072
2073 return;
2074}
2075
2076static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2077{
Vipul Pandya793dad92012-12-10 09:30:56 +00002078 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002079 struct cpl_pass_accept_req *req = cplhdr(skb);
2080 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2081 struct tid_info *t = dev->rdev.lldi.tids;
2082 unsigned int hwtid = GET_TID(req);
2083 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002085 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002086 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002087 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002089
2090 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002091 if (!parent_ep) {
2092 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2093 goto reject;
2094 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002095
Steve Wisecfdda9d2010-04-21 15:30:06 -07002096 if (state_read(&parent_ep->com) != LISTEN) {
2097 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2098 __func__);
2099 goto reject;
2100 }
2101
Vipul Pandya830662f2013-07-04 16:10:47 +05302102 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2103
Steve Wisecfdda9d2010-04-21 15:30:06 -07002104 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302105 if (iptype == 4) {
2106 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2107 , __func__, parent_ep, hwtid,
2108 local_ip, peer_ip, ntohs(local_port),
2109 ntohs(peer_port), peer_mss);
2110 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2111 local_port, peer_port,
2112 GET_POPEN_TOS(ntohl(req->tos_stid)));
2113 } else {
2114 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2115 , __func__, parent_ep, hwtid,
2116 local_ip, peer_ip, ntohs(local_port),
2117 ntohs(peer_port), peer_mss);
2118 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2119 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2120 ((struct sockaddr_in6 *)
2121 &parent_ep->com.local_addr)->sin6_scope_id);
2122 }
2123 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002124 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2125 __func__);
2126 goto reject;
2127 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002128
2129 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2130 if (!child_ep) {
2131 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2132 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002133 dst_release(dst);
2134 goto reject;
2135 }
David Miller3786cf12011-12-02 16:52:31 +00002136
Vipul Pandya830662f2013-07-04 16:10:47 +05302137 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002138 if (err) {
2139 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2140 __func__);
2141 dst_release(dst);
2142 kfree(child_ep);
2143 goto reject;
2144 }
2145
Vipul Pandya1cab7752012-12-10 09:30:55 +00002146 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2147 child_ep->mtu = peer_mss + 40;
2148
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149 state_set(&child_ep->com, CONNECTING);
2150 child_ep->com.dev = dev;
2151 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302152 if (iptype == 4) {
2153 struct sockaddr_in *sin = (struct sockaddr_in *)
2154 &child_ep->com.local_addr;
2155 sin->sin_family = PF_INET;
2156 sin->sin_port = local_port;
2157 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2158 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2159 sin->sin_family = PF_INET;
2160 sin->sin_port = peer_port;
2161 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2162 } else {
2163 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2164 &child_ep->com.local_addr;
2165 sin6->sin6_family = PF_INET6;
2166 sin6->sin6_port = local_port;
2167 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2168 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2169 sin6->sin6_family = PF_INET6;
2170 sin6->sin6_port = peer_port;
2171 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2172 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002173 c4iw_get_ep(&parent_ep->com);
2174 child_ep->parent_ep = parent_ep;
2175 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002176 child_ep->dst = dst;
2177 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002178
2179 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002180 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002181
2182 init_timer(&child_ep->timer);
2183 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002184 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302185 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002186 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002187 goto out;
2188reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302189 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190out:
2191 return 0;
2192}
2193
2194static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2195{
2196 struct c4iw_ep *ep;
2197 struct cpl_pass_establish *req = cplhdr(skb);
2198 struct tid_info *t = dev->rdev.lldi.tids;
2199 unsigned int tid = GET_TID(req);
2200
2201 ep = lookup_tid(t, tid);
2202 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2203 ep->snd_seq = be32_to_cpu(req->snd_isn);
2204 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2205
Vipul Pandya1cab7752012-12-10 09:30:55 +00002206 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2207 ntohs(req->tcp_opt));
2208
Steve Wisecfdda9d2010-04-21 15:30:06 -07002209 set_emss(ep, ntohs(req->tcp_opt));
2210
2211 dst_confirm(ep->dst);
2212 state_set(&ep->com, MPA_REQ_WAIT);
2213 start_ep_timer(ep);
2214 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002215 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002216
2217 return 0;
2218}
2219
2220static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2221{
2222 struct cpl_peer_close *hdr = cplhdr(skb);
2223 struct c4iw_ep *ep;
2224 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225 int disconnect = 1;
2226 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002227 struct tid_info *t = dev->rdev.lldi.tids;
2228 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002229 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002230
2231 ep = lookup_tid(t, tid);
2232 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2233 dst_confirm(ep->dst);
2234
Vipul Pandya793dad92012-12-10 09:30:56 +00002235 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002236 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002237 switch (ep->com.state) {
2238 case MPA_REQ_WAIT:
2239 __state_set(&ep->com, CLOSING);
2240 break;
2241 case MPA_REQ_SENT:
2242 __state_set(&ep->com, CLOSING);
2243 connect_reply_upcall(ep, -ECONNRESET);
2244 break;
2245 case MPA_REQ_RCVD:
2246
2247 /*
2248 * We're gonna mark this puppy DEAD, but keep
2249 * the reference on it until the ULP accepts or
2250 * rejects the CR. Also wake up anyone waiting
2251 * in rdma connection migration (see c4iw_accept_cr()).
2252 */
2253 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002255 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002256 break;
2257 case MPA_REP_SENT:
2258 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002259 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002260 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002261 break;
2262 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002263 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002264 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002265 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002266 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002267 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002268 if (ret != -ECONNRESET) {
2269 peer_close_upcall(ep);
2270 disconnect = 1;
2271 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 break;
2273 case ABORTING:
2274 disconnect = 0;
2275 break;
2276 case CLOSING:
2277 __state_set(&ep->com, MORIBUND);
2278 disconnect = 0;
2279 break;
2280 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002281 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 if (ep->com.cm_id && ep->com.qp) {
2283 attrs.next_state = C4IW_QP_STATE_IDLE;
2284 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2285 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2286 }
2287 close_complete_upcall(ep);
2288 __state_set(&ep->com, DEAD);
2289 release = 1;
2290 disconnect = 0;
2291 break;
2292 case DEAD:
2293 disconnect = 0;
2294 break;
2295 default:
2296 BUG_ON(1);
2297 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002298 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299 if (disconnect)
2300 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2301 if (release)
2302 release_ep_resources(ep);
2303 return 0;
2304}
2305
2306/*
2307 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2308 */
2309static int is_neg_adv_abort(unsigned int status)
2310{
2311 return status == CPL_ERR_RTX_NEG_ADVICE ||
2312 status == CPL_ERR_PERSIST_NEG_ADVICE;
2313}
2314
2315static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2316{
2317 struct cpl_abort_req_rss *req = cplhdr(skb);
2318 struct c4iw_ep *ep;
2319 struct cpl_abort_rpl *rpl;
2320 struct sk_buff *rpl_skb;
2321 struct c4iw_qp_attributes attrs;
2322 int ret;
2323 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324 struct tid_info *t = dev->rdev.lldi.tids;
2325 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002326
2327 ep = lookup_tid(t, tid);
2328 if (is_neg_adv_abort(req->status)) {
2329 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2330 ep->hwtid);
2331 return 0;
2332 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2334 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002335 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002336
2337 /*
2338 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302339 * However, this is not needed if com state is just
2340 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002341 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302342 if (ep->com.state != MPA_REQ_SENT)
2343 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002344
2345 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346 switch (ep->com.state) {
2347 case CONNECTING:
2348 break;
2349 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002350 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 break;
2352 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002353 stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002354 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302355 connect_reply_upcall(ep, -ECONNRESET);
2356 else {
2357 /*
2358 * we just don't send notification upwards because we
2359 * want to retry with mpa_v1 without upper layers even
2360 * knowing it.
2361 *
2362 * do some housekeeping so as to re-initiate the
2363 * connection
2364 */
2365 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2366 mpa_rev);
2367 ep->retry_with_mpa_v1 = 1;
2368 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369 break;
2370 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002371 break;
2372 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373 break;
2374 case MORIBUND:
2375 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002376 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002377 /*FALLTHROUGH*/
2378 case FPDU_MODE:
2379 if (ep->com.cm_id && ep->com.qp) {
2380 attrs.next_state = C4IW_QP_STATE_ERROR;
2381 ret = c4iw_modify_qp(ep->com.qp->rhp,
2382 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2383 &attrs, 1);
2384 if (ret)
2385 printk(KERN_ERR MOD
2386 "%s - qp <- error failed!\n",
2387 __func__);
2388 }
2389 peer_abort_upcall(ep);
2390 break;
2391 case ABORTING:
2392 break;
2393 case DEAD:
2394 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002395 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 return 0;
2397 default:
2398 BUG_ON(1);
2399 break;
2400 }
2401 dst_confirm(ep->dst);
2402 if (ep->com.state != ABORTING) {
2403 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302404 /* we don't release if we want to retry with mpa_v1 */
2405 if (!ep->retry_with_mpa_v1)
2406 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002408 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409
2410 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2411 if (!rpl_skb) {
2412 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2413 __func__);
2414 release = 1;
2415 goto out;
2416 }
2417 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2418 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2419 INIT_TP_WR(rpl, ep->hwtid);
2420 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2421 rpl->cmd = CPL_ABORT_NO_RST;
2422 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2423out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002424 if (release)
2425 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002426 else if (ep->retry_with_mpa_v1) {
2427 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302428 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2429 dst_release(ep->dst);
2430 cxgb4_l2t_release(ep->l2t);
2431 c4iw_reconnect(ep);
2432 }
2433
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 return 0;
2435}
2436
2437static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2438{
2439 struct c4iw_ep *ep;
2440 struct c4iw_qp_attributes attrs;
2441 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002442 int release = 0;
2443 struct tid_info *t = dev->rdev.lldi.tids;
2444 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445
2446 ep = lookup_tid(t, tid);
2447
2448 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2449 BUG_ON(!ep);
2450
2451 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002452 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 switch (ep->com.state) {
2454 case CLOSING:
2455 __state_set(&ep->com, MORIBUND);
2456 break;
2457 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002458 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 if ((ep->com.cm_id) && (ep->com.qp)) {
2460 attrs.next_state = C4IW_QP_STATE_IDLE;
2461 c4iw_modify_qp(ep->com.qp->rhp,
2462 ep->com.qp,
2463 C4IW_QP_ATTR_NEXT_STATE,
2464 &attrs, 1);
2465 }
2466 close_complete_upcall(ep);
2467 __state_set(&ep->com, DEAD);
2468 release = 1;
2469 break;
2470 case ABORTING:
2471 case DEAD:
2472 break;
2473 default:
2474 BUG_ON(1);
2475 break;
2476 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002477 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478 if (release)
2479 release_ep_resources(ep);
2480 return 0;
2481}
2482
2483static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2484{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002485 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002487 unsigned int tid = GET_TID(rpl);
2488 struct c4iw_ep *ep;
2489 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490
2491 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002492 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002493
Steve Wise30c95c22011-05-09 22:06:22 -07002494 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002495 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2496 ep->com.qp->wq.sq.qid);
2497 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2498 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2499 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2500 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002501 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002502
Steve Wisecfdda9d2010-04-21 15:30:06 -07002503 return 0;
2504}
2505
2506/*
2507 * Upcall from the adapter indicating data has been transmitted.
2508 * For us its just the single MPA request or reply. We can now free
2509 * the skb holding the mpa message.
2510 */
2511static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2512{
2513 struct c4iw_ep *ep;
2514 struct cpl_fw4_ack *hdr = cplhdr(skb);
2515 u8 credits = hdr->credits;
2516 unsigned int tid = GET_TID(hdr);
2517 struct tid_info *t = dev->rdev.lldi.tids;
2518
2519
2520 ep = lookup_tid(t, tid);
2521 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2522 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002523 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2524 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 return 0;
2526 }
2527
2528 dst_confirm(ep->dst);
2529 if (ep->mpa_skb) {
2530 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2531 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2532 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2533 kfree_skb(ep->mpa_skb);
2534 ep->mpa_skb = NULL;
2535 }
2536 return 0;
2537}
2538
Steve Wisecfdda9d2010-04-21 15:30:06 -07002539int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2540{
2541 int err;
2542 struct c4iw_ep *ep = to_ep(cm_id);
2543 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2544
2545 if (state_read(&ep->com) == DEAD) {
2546 c4iw_put_ep(&ep->com);
2547 return -ECONNRESET;
2548 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002549 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2551 if (mpa_rev == 0)
2552 abort_connection(ep, NULL, GFP_KERNEL);
2553 else {
2554 err = send_mpa_reject(ep, pdata, pdata_len);
2555 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2556 }
2557 c4iw_put_ep(&ep->com);
2558 return 0;
2559}
2560
2561int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2562{
2563 int err;
2564 struct c4iw_qp_attributes attrs;
2565 enum c4iw_qp_attr_mask mask;
2566 struct c4iw_ep *ep = to_ep(cm_id);
2567 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2568 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2569
2570 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2571 if (state_read(&ep->com) == DEAD) {
2572 err = -ECONNRESET;
2573 goto err;
2574 }
2575
2576 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2577 BUG_ON(!qp);
2578
Vipul Pandya793dad92012-12-10 09:30:56 +00002579 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002580 if ((conn_param->ord > c4iw_max_read_depth) ||
2581 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582 abort_connection(ep, NULL, GFP_KERNEL);
2583 err = -EINVAL;
2584 goto err;
2585 }
2586
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302587 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2588 if (conn_param->ord > ep->ird) {
2589 ep->ird = conn_param->ird;
2590 ep->ord = conn_param->ord;
2591 send_mpa_reject(ep, conn_param->private_data,
2592 conn_param->private_data_len);
2593 abort_connection(ep, NULL, GFP_KERNEL);
2594 err = -ENOMEM;
2595 goto err;
2596 }
2597 if (conn_param->ird > ep->ord) {
2598 if (!ep->ord)
2599 conn_param->ird = 1;
2600 else {
2601 abort_connection(ep, NULL, GFP_KERNEL);
2602 err = -ENOMEM;
2603 goto err;
2604 }
2605 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002606
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302607 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608 ep->ird = conn_param->ird;
2609 ep->ord = conn_param->ord;
2610
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302611 if (ep->mpa_attr.version != 2)
2612 if (peer2peer && ep->ird == 0)
2613 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614
2615 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2616
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302617 cm_id->add_ref(cm_id);
2618 ep->com.cm_id = cm_id;
2619 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002620 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302621
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 /* bind QP to EP and move to RTS */
2623 attrs.mpa_attr = ep->mpa_attr;
2624 attrs.max_ird = ep->ird;
2625 attrs.max_ord = ep->ord;
2626 attrs.llp_stream_handle = ep;
2627 attrs.next_state = C4IW_QP_STATE_RTS;
2628
2629 /* bind QP and TID with INIT_WR */
2630 mask = C4IW_QP_ATTR_NEXT_STATE |
2631 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2632 C4IW_QP_ATTR_MPA_ATTR |
2633 C4IW_QP_ATTR_MAX_IRD |
2634 C4IW_QP_ATTR_MAX_ORD;
2635
2636 err = c4iw_modify_qp(ep->com.qp->rhp,
2637 ep->com.qp, mask, &attrs, 1);
2638 if (err)
2639 goto err1;
2640 err = send_mpa_reply(ep, conn_param->private_data,
2641 conn_param->private_data_len);
2642 if (err)
2643 goto err1;
2644
2645 state_set(&ep->com, FPDU_MODE);
2646 established_upcall(ep);
2647 c4iw_put_ep(&ep->com);
2648 return 0;
2649err1:
2650 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651 cm_id->rem_ref(cm_id);
2652err:
2653 c4iw_put_ep(&ep->com);
2654 return err;
2655}
2656
Vipul Pandya830662f2013-07-04 16:10:47 +05302657static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2658{
2659 struct in_device *ind;
2660 int found = 0;
2661 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2662 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2663
2664 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2665 if (!ind)
2666 return -EADDRNOTAVAIL;
2667 for_primary_ifa(ind) {
2668 laddr->sin_addr.s_addr = ifa->ifa_address;
2669 raddr->sin_addr.s_addr = ifa->ifa_address;
2670 found = 1;
2671 break;
2672 }
2673 endfor_ifa(ind);
2674 in_dev_put(ind);
2675 return found ? 0 : -EADDRNOTAVAIL;
2676}
2677
2678static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2679 unsigned char banned_flags)
2680{
2681 struct inet6_dev *idev;
2682 int err = -EADDRNOTAVAIL;
2683
2684 rcu_read_lock();
2685 idev = __in6_dev_get(dev);
2686 if (idev != NULL) {
2687 struct inet6_ifaddr *ifp;
2688
2689 read_lock_bh(&idev->lock);
2690 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2691 if (ifp->scope == IFA_LINK &&
2692 !(ifp->flags & banned_flags)) {
2693 memcpy(addr, &ifp->addr, 16);
2694 err = 0;
2695 break;
2696 }
2697 }
2698 read_unlock_bh(&idev->lock);
2699 }
2700 rcu_read_unlock();
2701 return err;
2702}
2703
2704static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2705{
2706 struct in6_addr uninitialized_var(addr);
2707 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2708 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2709
2710 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2711 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2712 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2713 return 0;
2714 }
2715 return -EADDRNOTAVAIL;
2716}
2717
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2719{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2721 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002722 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302723 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2724 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302725 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2726 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2727 &cm_id->remote_addr;
2728 __u8 *ra;
2729 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002731 if ((conn_param->ord > c4iw_max_read_depth) ||
2732 (conn_param->ird > c4iw_max_read_depth)) {
2733 err = -EINVAL;
2734 goto out;
2735 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2737 if (!ep) {
2738 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2739 err = -ENOMEM;
2740 goto out;
2741 }
2742 init_timer(&ep->timer);
2743 ep->plen = conn_param->private_data_len;
2744 if (ep->plen)
2745 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2746 conn_param->private_data, ep->plen);
2747 ep->ird = conn_param->ird;
2748 ep->ord = conn_param->ord;
2749
2750 if (peer2peer && ep->ord == 0)
2751 ep->ord = 1;
2752
2753 cm_id->add_ref(cm_id);
2754 ep->com.dev = dev;
2755 ep->com.cm_id = cm_id;
2756 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302757 if (!ep->com.qp) {
2758 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2759 err = -EINVAL;
2760 goto fail2;
2761 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002762 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2764 ep->com.qp, cm_id);
2765
2766 /*
2767 * Allocate an active TID to initiate a TCP connection.
2768 */
2769 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2770 if (ep->atid == -1) {
2771 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2772 err = -ENOMEM;
2773 goto fail2;
2774 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002775 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002776
Vipul Pandya830662f2013-07-04 16:10:47 +05302777 if (cm_id->remote_addr.ss_family == AF_INET) {
2778 iptype = 4;
2779 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780
Vipul Pandya830662f2013-07-04 16:10:47 +05302781 /*
2782 * Handle loopback requests to INADDR_ANY.
2783 */
2784 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2785 err = pick_local_ipaddrs(dev, cm_id);
2786 if (err)
2787 goto fail2;
2788 }
2789
2790 /* find a route */
2791 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2792 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2793 ra, ntohs(raddr->sin_port));
2794 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2795 raddr->sin_addr.s_addr, laddr->sin_port,
2796 raddr->sin_port, 0);
2797 } else {
2798 iptype = 6;
2799 ra = (__u8 *)&raddr6->sin6_addr;
2800
2801 /*
2802 * Handle loopback requests to INADDR_ANY.
2803 */
2804 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2805 err = pick_local_ip6addrs(dev, cm_id);
2806 if (err)
2807 goto fail2;
2808 }
2809
2810 /* find a route */
2811 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2812 __func__, laddr6->sin6_addr.s6_addr,
2813 ntohs(laddr6->sin6_port),
2814 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2815 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2816 raddr6->sin6_addr.s6_addr,
2817 laddr6->sin6_port, raddr6->sin6_port, 0,
2818 raddr6->sin6_scope_id);
2819 }
2820 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002821 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2822 err = -EHOSTUNREACH;
2823 goto fail3;
2824 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002825
Vipul Pandya830662f2013-07-04 16:10:47 +05302826 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00002827 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002828 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 goto fail4;
2830 }
2831
2832 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2833 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2834 ep->l2t->idx);
2835
2836 state_set(&ep->com, CONNECTING);
2837 ep->tos = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302838 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2839 sizeof(ep->com.local_addr));
2840 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2841 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002842
2843 /* send connect request to rnic */
2844 err = send_connect(ep);
2845 if (!err)
2846 goto out;
2847
2848 cxgb4_l2t_release(ep->l2t);
2849fail4:
2850 dst_release(ep->dst);
2851fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002852 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002853 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2854fail2:
2855 cm_id->rem_ref(cm_id);
2856 c4iw_put_ep(&ep->com);
2857out:
2858 return err;
2859}
2860
Vipul Pandya830662f2013-07-04 16:10:47 +05302861static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2862{
2863 int err;
2864 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2865
2866 c4iw_init_wr_wait(&ep->com.wr_wait);
2867 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2868 ep->stid, &sin6->sin6_addr,
2869 sin6->sin6_port,
2870 ep->com.dev->rdev.lldi.rxq_ids[0]);
2871 if (!err)
2872 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2873 &ep->com.wr_wait,
2874 0, 0, __func__);
2875 if (err)
2876 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2877 err, ep->stid,
2878 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2879 return err;
2880}
2881
2882static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2883{
2884 int err;
2885 struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
2886
2887 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2888 do {
2889 err = cxgb4_create_server_filter(
2890 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2891 sin->sin_addr.s_addr, sin->sin_port, 0,
2892 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2893 if (err == -EBUSY) {
2894 set_current_state(TASK_UNINTERRUPTIBLE);
2895 schedule_timeout(usecs_to_jiffies(100));
2896 }
2897 } while (err == -EBUSY);
2898 } else {
2899 c4iw_init_wr_wait(&ep->com.wr_wait);
2900 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2901 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2902 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2903 if (!err)
2904 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2905 &ep->com.wr_wait,
2906 0, 0, __func__);
2907 }
2908 if (err)
2909 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
2910 , err, ep->stid,
2911 &sin->sin_addr, ntohs(sin->sin_port));
2912 return err;
2913}
2914
Steve Wisecfdda9d2010-04-21 15:30:06 -07002915int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2916{
2917 int err = 0;
2918 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2919 struct c4iw_listen_ep *ep;
2920
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 might_sleep();
2922
2923 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2924 if (!ep) {
2925 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2926 err = -ENOMEM;
2927 goto fail1;
2928 }
2929 PDBG("%s ep %p\n", __func__, ep);
2930 cm_id->add_ref(cm_id);
2931 ep->com.cm_id = cm_id;
2932 ep->com.dev = dev;
2933 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05302934 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2935 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936
2937 /*
2938 * Allocate a server TID.
2939 */
Vipul Pandya1cab7752012-12-10 09:30:55 +00002940 if (dev->rdev.lldi.enable_fw_ofld_conn)
Vipul Pandya830662f2013-07-04 16:10:47 +05302941 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
2942 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002943 else
Vipul Pandya830662f2013-07-04 16:10:47 +05302944 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
2945 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002946
Steve Wisecfdda9d2010-04-21 15:30:06 -07002947 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002948 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 err = -ENOMEM;
2950 goto fail2;
2951 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002952 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05302954 if (ep->com.local_addr.ss_family == AF_INET)
2955 err = create_server4(dev, ep);
2956 else
2957 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002958 if (!err) {
2959 cm_id->provider_data = ep;
2960 goto out;
2961 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302962 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2963 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002964fail2:
2965 cm_id->rem_ref(cm_id);
2966 c4iw_put_ep(&ep->com);
2967fail1:
2968out:
2969 return err;
2970}
2971
2972int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2973{
2974 int err;
2975 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2976
2977 PDBG("%s ep %p\n", __func__, ep);
2978
2979 might_sleep();
2980 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05302981 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
2982 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002983 err = cxgb4_remove_server_filter(
2984 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2985 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2986 } else {
2987 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05302988 err = cxgb4_remove_server(
2989 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2990 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002991 if (err)
2992 goto done;
2993 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2994 0, 0, __func__);
2995 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002996 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302997 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2998 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003000 cm_id->rem_ref(cm_id);
3001 c4iw_put_ep(&ep->com);
3002 return err;
3003}
3004
3005int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3006{
3007 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003008 int close = 0;
3009 int fatal = 0;
3010 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011
Steve Wise2f5b48c2010-09-10 11:15:36 -05003012 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003013
3014 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3015 states[ep->com.state], abrupt);
3016
3017 rdev = &ep->com.dev->rdev;
3018 if (c4iw_fatal_error(rdev)) {
3019 fatal = 1;
3020 close_complete_upcall(ep);
3021 ep->com.state = DEAD;
3022 }
3023 switch (ep->com.state) {
3024 case MPA_REQ_WAIT:
3025 case MPA_REQ_SENT:
3026 case MPA_REQ_RCVD:
3027 case MPA_REP_SENT:
3028 case FPDU_MODE:
3029 close = 1;
3030 if (abrupt)
3031 ep->com.state = ABORTING;
3032 else {
3033 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003034 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003035 }
3036 set_bit(CLOSE_SENT, &ep->com.flags);
3037 break;
3038 case CLOSING:
3039 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3040 close = 1;
3041 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00003042 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 ep->com.state = ABORTING;
3044 } else
3045 ep->com.state = MORIBUND;
3046 }
3047 break;
3048 case MORIBUND:
3049 case ABORTING:
3050 case DEAD:
3051 PDBG("%s ignoring disconnect ep %p state %u\n",
3052 __func__, ep, ep->com.state);
3053 break;
3054 default:
3055 BUG();
3056 break;
3057 }
3058
Steve Wisecfdda9d2010-04-21 15:30:06 -07003059 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003060 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003061 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003062 close_complete_upcall(ep);
3063 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003064 } else {
3065 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003066 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003067 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 if (ret)
3069 fatal = 1;
3070 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003071 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003072 if (fatal)
3073 release_ep_resources(ep);
3074 return ret;
3075}
3076
Vipul Pandya1cab7752012-12-10 09:30:55 +00003077static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3078 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3079{
3080 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003081 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003082
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003083 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3084 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003085 if (!ep)
3086 return;
3087
3088 switch (req->retval) {
3089 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003090 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3091 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3092 send_fw_act_open_req(ep, atid);
3093 return;
3094 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003095 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003096 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3097 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3098 send_fw_act_open_req(ep, atid);
3099 return;
3100 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003101 break;
3102 default:
3103 pr_info("%s unexpected ofld conn wr retval %d\n",
3104 __func__, req->retval);
3105 break;
3106 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003107 pr_err("active ofld_connect_wr failure %d atid %d\n",
3108 req->retval, atid);
3109 mutex_lock(&dev->rdev.stats.lock);
3110 dev->rdev.stats.act_ofld_conn_fails++;
3111 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003112 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003113 state_set(&ep->com, DEAD);
3114 remove_handle(dev, &dev->atid_idr, atid);
3115 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3116 dst_release(ep->dst);
3117 cxgb4_l2t_release(ep->l2t);
3118 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003119}
3120
3121static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3122 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3123{
3124 struct sk_buff *rpl_skb;
3125 struct cpl_pass_accept_req *cpl;
3126 int ret;
3127
Paul Bolle710a3112013-02-05 20:51:30 +00003128 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003129 BUG_ON(!rpl_skb);
3130 if (req->retval) {
3131 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003132 mutex_lock(&dev->rdev.stats.lock);
3133 dev->rdev.stats.pas_ofld_conn_fails++;
3134 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003135 kfree_skb(rpl_skb);
3136 } else {
3137 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3138 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003139 (__force u32) htonl(
3140 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003141 ret = pass_accept_req(dev, rpl_skb);
3142 if (!ret)
3143 kfree_skb(rpl_skb);
3144 }
3145 return;
3146}
3147
3148static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003149{
3150 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003151 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3152
3153 switch (rpl->type) {
3154 case FW6_TYPE_CQE:
3155 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3156 break;
3157 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3158 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3159 switch (req->t_state) {
3160 case TCP_SYN_SENT:
3161 active_ofld_conn_reply(dev, skb, req);
3162 break;
3163 case TCP_SYN_RECV:
3164 passive_ofld_conn_reply(dev, skb, req);
3165 break;
3166 default:
3167 pr_err("%s unexpected ofld conn wr state %d\n",
3168 __func__, req->t_state);
3169 break;
3170 }
3171 break;
3172 }
3173 return 0;
3174}
3175
3176static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3177{
3178 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003179 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003180 u8 intf;
3181 struct cpl_rx_pkt *cpl = cplhdr(skb);
3182 struct cpl_pass_accept_req *req;
3183 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003184 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003185
Vipul Pandyaf079af72013-03-14 05:08:58 +00003186 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003187 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003188 vlantag = (__force u16) cpl->vlan;
3189 len = (__force u16) cpl->len;
3190 l2info = (__force u32) cpl->l2info;
3191 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003192 intf = cpl->iff;
3193
3194 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3195
3196 /*
3197 * We need to parse the TCP options from SYN packet.
3198 * to generate cpl_pass_accept_req.
3199 */
3200 memset(&tmp_opt, 0, sizeof(tmp_opt));
3201 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003202 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003203
3204 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3205 memset(req, 0, sizeof(*req));
3206 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003207 V_SYN_MAC_IDX(G_RX_MACIDX(
3208 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003209 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003210 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3211 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3212 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003213 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3214 (__force int) htonl(l2info))) |
3215 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3216 (__force int) htons(hdr_len))) |
3217 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3218 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003219 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003220 req->vlan = (__force __be16) vlantag;
3221 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003222 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3223 PASS_OPEN_TOS(tos));
3224 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3225 if (tmp_opt.wscale_ok)
3226 req->tcpopt.wsf = tmp_opt.snd_wscale;
3227 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3228 if (tmp_opt.sack_ok)
3229 req->tcpopt.sack = 1;
3230 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3231 return;
3232}
3233
3234static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3235 __be32 laddr, __be16 lport,
3236 __be32 raddr, __be16 rport,
3237 u32 rcv_isn, u32 filter, u16 window,
3238 u32 rss_qid, u8 port_id)
3239{
3240 struct sk_buff *req_skb;
3241 struct fw_ofld_connection_wr *req;
3242 struct cpl_pass_accept_req *cpl = cplhdr(skb);
3243
3244 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3245 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3246 memset(req, 0, sizeof(*req));
3247 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3248 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3249 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003250 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003251 req->le.lport = lport;
3252 req->le.pport = rport;
3253 req->le.u.ipv4.lip = laddr;
3254 req->le.u.ipv4.pip = raddr;
3255 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3256 req->tcb.rcv_adv = htons(window);
3257 req->tcb.t_state_to_astid =
3258 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3259 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3260 V_FW_OFLD_CONNECTION_WR_ASTID(
3261 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3262
3263 /*
3264 * We store the qid in opt2 which will be used by the firmware
3265 * to send us the wr response.
3266 */
3267 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3268
3269 /*
3270 * We initialize the MSS index in TCB to 0xF.
3271 * So that when driver sends cpl_pass_accept_rpl
3272 * TCB picks up the correct value. If this was 0
3273 * TP will ignore any value > 0 for MSS index.
3274 */
3275 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003276 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003277
3278 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
3279 cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3280}
3281
3282/*
3283 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3284 * messages when a filter is being used instead of server to
3285 * redirect a syn packet. When packets hit filter they are redirected
3286 * to the offload queue and driver tries to establish the connection
3287 * using firmware work request.
3288 */
3289static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3290{
3291 int stid;
3292 unsigned int filter;
3293 struct ethhdr *eh = NULL;
3294 struct vlan_ethhdr *vlan_eh = NULL;
3295 struct iphdr *iph;
3296 struct tcphdr *tcph;
3297 struct rss_header *rss = (void *)skb->data;
3298 struct cpl_rx_pkt *cpl = (void *)skb->data;
3299 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3300 struct l2t_entry *e;
3301 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003302 struct c4iw_ep *lep;
3303 u16 window;
3304 struct port_info *pi;
3305 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003306 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003307 int step;
3308 u32 tx_chan;
3309 struct neighbour *neigh;
3310
3311 /* Drop all non-SYN packets */
3312 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3313 goto reject;
3314
3315 /*
3316 * Drop all packets which did not hit the filter.
3317 * Unlikely to happen.
3318 */
3319 if (!(rss->filter_hit && rss->filter_tid))
3320 goto reject;
3321
3322 /*
3323 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3324 */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003325 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val)
3326 - dev->rdev.lldi.tids->sftid_base
Vipul Pandya1cab7752012-12-10 09:30:55 +00003327 + dev->rdev.lldi.tids->nstids;
3328
3329 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3330 if (!lep) {
3331 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3332 goto reject;
3333 }
3334
Vipul Pandyaf079af72013-03-14 05:08:58 +00003335 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3336 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3337 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3338 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003339 eh = (struct ethhdr *)(req + 1);
3340 iph = (struct iphdr *)(eh + 1);
3341 } else {
3342 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3343 iph = (struct iphdr *)(vlan_eh + 1);
3344 skb->vlan_tci = ntohs(cpl->vlan);
3345 }
3346
3347 if (iph->version != 0x4)
3348 goto reject;
3349
3350 tcph = (struct tcphdr *)(iph + 1);
3351 skb_set_network_header(skb, (void *)iph - (void *)rss);
3352 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3353 skb_get(skb);
3354
3355 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3356 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3357 ntohs(tcph->source), iph->tos);
3358
Vipul Pandya830662f2013-07-04 16:10:47 +05303359 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3360 iph->tos);
3361 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003362 pr_err("%s - failed to find dst entry!\n",
3363 __func__);
3364 goto reject;
3365 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003366 neigh = dst_neigh_lookup_skb(dst, skb);
3367
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003368 if (!neigh) {
3369 pr_err("%s - failed to allocate neigh!\n",
3370 __func__);
3371 goto free_dst;
3372 }
3373
Vipul Pandya1cab7752012-12-10 09:30:55 +00003374 if (neigh->dev->flags & IFF_LOOPBACK) {
3375 pdev = ip_dev_find(&init_net, iph->daddr);
3376 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3377 pdev, 0);
3378 pi = (struct port_info *)netdev_priv(pdev);
3379 tx_chan = cxgb4_port_chan(pdev);
3380 dev_put(pdev);
3381 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303382 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003383 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303384 pdev, 0);
3385 pi = (struct port_info *)netdev_priv(pdev);
3386 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003387 }
3388 if (!e) {
3389 pr_err("%s - failed to allocate l2t entry!\n",
3390 __func__);
3391 goto free_dst;
3392 }
3393
3394 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3395 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003396 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003397
3398 /* Calcuate filter portion for LE region. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003399 filter = (__force unsigned int) cpu_to_be32(select_ntuple(dev, dst, e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003400
3401 /*
3402 * Synthesize the cpl_pass_accept_req. We have everything except the
3403 * TID. Once firmware sends a reply with TID we update the TID field
3404 * in cpl and pass it through the regular cpl_pass_accept_req path.
3405 */
3406 build_cpl_pass_accept_req(skb, stid, iph->tos);
3407 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3408 tcph->source, ntohl(tcph->seq), filter, window,
3409 rss_qid, pi->port_id);
3410 cxgb4_l2t_release(e);
3411free_dst:
3412 dst_release(dst);
3413reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003414 return 0;
3415}
3416
Steve Wisecfdda9d2010-04-21 15:30:06 -07003417/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003418 * These are the real handlers that are called from a
3419 * work queue.
3420 */
3421static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3422 [CPL_ACT_ESTABLISH] = act_establish,
3423 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3424 [CPL_RX_DATA] = rx_data,
3425 [CPL_ABORT_RPL_RSS] = abort_rpl,
3426 [CPL_ABORT_RPL] = abort_rpl,
3427 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3428 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3429 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3430 [CPL_PASS_ESTABLISH] = pass_establish,
3431 [CPL_PEER_CLOSE] = peer_close,
3432 [CPL_ABORT_REQ_RSS] = peer_abort,
3433 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3434 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003435 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003436 [CPL_FW6_MSG] = deferred_fw6_msg,
3437 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003438};
3439
3440static void process_timeout(struct c4iw_ep *ep)
3441{
3442 struct c4iw_qp_attributes attrs;
3443 int abort = 1;
3444
Steve Wise2f5b48c2010-09-10 11:15:36 -05003445 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003446 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3447 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003448 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003449 switch (ep->com.state) {
3450 case MPA_REQ_SENT:
3451 __state_set(&ep->com, ABORTING);
3452 connect_reply_upcall(ep, -ETIMEDOUT);
3453 break;
3454 case MPA_REQ_WAIT:
3455 __state_set(&ep->com, ABORTING);
3456 break;
3457 case CLOSING:
3458 case MORIBUND:
3459 if (ep->com.cm_id && ep->com.qp) {
3460 attrs.next_state = C4IW_QP_STATE_ERROR;
3461 c4iw_modify_qp(ep->com.qp->rhp,
3462 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3463 &attrs, 1);
3464 }
3465 __state_set(&ep->com, ABORTING);
3466 break;
3467 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003468 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003469 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003470 abort = 0;
3471 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003472 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003473 if (abort)
3474 abort_connection(ep, NULL, GFP_KERNEL);
3475 c4iw_put_ep(&ep->com);
3476}
3477
3478static void process_timedout_eps(void)
3479{
3480 struct c4iw_ep *ep;
3481
3482 spin_lock_irq(&timeout_lock);
3483 while (!list_empty(&timeout_list)) {
3484 struct list_head *tmp;
3485
3486 tmp = timeout_list.next;
3487 list_del(tmp);
3488 spin_unlock_irq(&timeout_lock);
3489 ep = list_entry(tmp, struct c4iw_ep, entry);
3490 process_timeout(ep);
3491 spin_lock_irq(&timeout_lock);
3492 }
3493 spin_unlock_irq(&timeout_lock);
3494}
3495
3496static void process_work(struct work_struct *work)
3497{
3498 struct sk_buff *skb = NULL;
3499 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003500 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003501 unsigned int opcode;
3502 int ret;
3503
3504 while ((skb = skb_dequeue(&rxq))) {
3505 rpl = cplhdr(skb);
3506 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3507 opcode = rpl->ot.opcode;
3508
3509 BUG_ON(!work_handlers[opcode]);
3510 ret = work_handlers[opcode](dev, skb);
3511 if (!ret)
3512 kfree_skb(skb);
3513 }
3514 process_timedout_eps();
3515}
3516
3517static DECLARE_WORK(skb_work, process_work);
3518
3519static void ep_timeout(unsigned long arg)
3520{
3521 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003522 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003523
3524 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003525 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3526 list_add_tail(&ep->entry, &timeout_list);
3527 kickit = 1;
3528 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003529 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003530 if (kickit)
3531 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003532}
3533
3534/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535 * All the CM events are handled on a work queue to have a safe context.
3536 */
3537static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3538{
3539
3540 /*
3541 * Save dev in the skb->cb area.
3542 */
3543 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3544
3545 /*
3546 * Queue the skb and schedule the worker thread.
3547 */
3548 skb_queue_tail(&rxq, skb);
3549 queue_work(workq, &skb_work);
3550 return 0;
3551}
3552
3553static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3554{
3555 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3556
3557 if (rpl->status != CPL_ERR_NONE) {
3558 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3559 "for tid %u\n", rpl->status, GET_TID(rpl));
3560 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003561 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003562 return 0;
3563}
3564
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003565static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3566{
3567 struct cpl_fw6_msg *rpl = cplhdr(skb);
3568 struct c4iw_wr_wait *wr_waitp;
3569 int ret;
3570
3571 PDBG("%s type %u\n", __func__, rpl->type);
3572
3573 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003574 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003575 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003576 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003577 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003578 if (wr_waitp)
3579 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003580 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003581 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003582 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003583 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003584 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003585 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003586 default:
3587 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3588 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003589 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003590 break;
3591 }
3592 return 0;
3593}
3594
Steve Wise8da7e7a2011-06-14 20:59:27 +00003595static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3596{
3597 struct cpl_abort_req_rss *req = cplhdr(skb);
3598 struct c4iw_ep *ep;
3599 struct tid_info *t = dev->rdev.lldi.tids;
3600 unsigned int tid = GET_TID(req);
3601
3602 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003603 if (!ep) {
3604 printk(KERN_WARNING MOD
3605 "Abort on non-existent endpoint, tid %d\n", tid);
3606 kfree_skb(skb);
3607 return 0;
3608 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003609 if (is_neg_adv_abort(req->status)) {
3610 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3611 ep->hwtid);
3612 kfree_skb(skb);
3613 return 0;
3614 }
3615 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3616 ep->com.state);
3617
3618 /*
3619 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003620 * However, if we are on MPAv2 and want to retry with MPAv1
3621 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003622 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003623 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3624 if (ep->com.state != MPA_REQ_SENT)
3625 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3626 } else
3627 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003628 sched(dev, skb);
3629 return 0;
3630}
3631
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003632/*
3633 * Most upcalls from the T4 Core go to sched() to
3634 * schedule the processing on a work queue.
3635 */
3636c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3637 [CPL_ACT_ESTABLISH] = sched,
3638 [CPL_ACT_OPEN_RPL] = sched,
3639 [CPL_RX_DATA] = sched,
3640 [CPL_ABORT_RPL_RSS] = sched,
3641 [CPL_ABORT_RPL] = sched,
3642 [CPL_PASS_OPEN_RPL] = sched,
3643 [CPL_CLOSE_LISTSRV_RPL] = sched,
3644 [CPL_PASS_ACCEPT_REQ] = sched,
3645 [CPL_PASS_ESTABLISH] = sched,
3646 [CPL_PEER_CLOSE] = sched,
3647 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003648 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003649 [CPL_RDMA_TERMINATE] = sched,
3650 [CPL_FW4_ACK] = sched,
3651 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003652 [CPL_FW6_MSG] = fw6_msg,
3653 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003654};
3655
Steve Wisecfdda9d2010-04-21 15:30:06 -07003656int __init c4iw_cm_init(void)
3657{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003658 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003659 skb_queue_head_init(&rxq);
3660
3661 workq = create_singlethread_workqueue("iw_cxgb4");
3662 if (!workq)
3663 return -ENOMEM;
3664
Steve Wisecfdda9d2010-04-21 15:30:06 -07003665 return 0;
3666}
3667
3668void __exit c4iw_cm_term(void)
3669{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003670 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003671 flush_workqueue(workq);
3672 destroy_workqueue(workq);
3673}