blob: a1bc41d04620d900e57e5166fb7ac821437cd914 [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
Steve Wisedf2d5132014-03-19 17:44:44 +0530101static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700102module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530103MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700104
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 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530335 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700336 return skb;
337}
338
Vipul Pandya830662f2013-07-04 16:10:47 +0530339static struct net_device *get_real_dev(struct net_device *egress_dev)
340{
341 struct net_device *phys_dev = egress_dev;
342 if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
343 phys_dev = vlan_dev_real_dev(egress_dev);
344 return phys_dev;
345}
346
347static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
348{
349 int i;
350
351 egress_dev = get_real_dev(egress_dev);
352 for (i = 0; i < dev->rdev.lldi.nports; i++)
353 if (dev->rdev.lldi.ports[i] == egress_dev)
354 return 1;
355 return 0;
356}
357
358static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
359 __u8 *peer_ip, __be16 local_port,
360 __be16 peer_port, u8 tos,
361 __u32 sin6_scope_id)
362{
363 struct dst_entry *dst = NULL;
364
365 if (IS_ENABLED(CONFIG_IPV6)) {
366 struct flowi6 fl6;
367
368 memset(&fl6, 0, sizeof(fl6));
369 memcpy(&fl6.daddr, peer_ip, 16);
370 memcpy(&fl6.saddr, local_ip, 16);
371 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
372 fl6.flowi6_oif = sin6_scope_id;
373 dst = ip6_route_output(&init_net, NULL, &fl6);
374 if (!dst)
375 goto out;
376 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
377 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
378 dst_release(dst);
379 dst = NULL;
380 }
381 }
382
383out:
384 return dst;
385}
386
387static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700388 __be32 peer_ip, __be16 local_port,
389 __be16 peer_port, u8 tos)
390{
391 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700392 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530393 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700394
David S. Miller31e4543d2011-05-03 20:25:42 -0700395 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500396 peer_port, local_port, IPPROTO_TCP,
397 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800398 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700399 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530400 n = dst_neigh_lookup(&rt->dst, &peer_ip);
401 if (!n)
402 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530403 if (!our_interface(dev, n->dev) &&
404 !(n->dev->flags & IFF_LOOPBACK)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530405 dst_release(&rt->dst);
406 return NULL;
407 }
408 neigh_release(n);
409 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700410}
411
412static void arp_failure_discard(void *handle, struct sk_buff *skb)
413{
414 PDBG("%s c4iw_dev %p\n", __func__, handle);
415 kfree_skb(skb);
416}
417
418/*
419 * Handle an ARP failure for an active open.
420 */
421static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
422{
423 printk(KERN_ERR MOD "ARP failure duing connect\n");
424 kfree_skb(skb);
425}
426
427/*
428 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
429 * and send it along.
430 */
431static void abort_arp_failure(void *handle, struct sk_buff *skb)
432{
433 struct c4iw_rdev *rdev = handle;
434 struct cpl_abort_req *req = cplhdr(skb);
435
436 PDBG("%s rdev %p\n", __func__, rdev);
437 req->cmd = CPL_ABORT_NO_RST;
438 c4iw_ofld_send(rdev, skb);
439}
440
441static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
442{
443 unsigned int flowclen = 80;
444 struct fw_flowc_wr *flowc;
445 int i;
446
447 skb = get_skb(skb, flowclen, GFP_KERNEL);
448 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
449
450 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
451 FW_FLOWC_WR_NPARAMS(8));
452 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
453 16)) | FW_WR_FLOWID(ep->hwtid));
454
455 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000456 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700457 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
458 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
459 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
460 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
461 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
462 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
463 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
464 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
465 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
466 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
467 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
468 flowc->mnemval[6].val = cpu_to_be32(snd_win);
469 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
470 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
471 /* Pad WR to 16 byte boundary */
472 flowc->mnemval[8].mnemonic = 0;
473 flowc->mnemval[8].val = 0;
474 for (i = 0; i < 9; i++) {
475 flowc->mnemval[i].r4[0] = 0;
476 flowc->mnemval[i].r4[1] = 0;
477 flowc->mnemval[i].r4[2] = 0;
478 }
479
480 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
481 c4iw_ofld_send(&ep->com.dev->rdev, skb);
482}
483
484static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
485{
486 struct cpl_close_con_req *req;
487 struct sk_buff *skb;
488 int wrlen = roundup(sizeof *req, 16);
489
490 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
491 skb = get_skb(NULL, wrlen, gfp);
492 if (!skb) {
493 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
494 return -ENOMEM;
495 }
496 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
497 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
498 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
499 memset(req, 0, wrlen);
500 INIT_TP_WR(req, ep->hwtid);
501 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
502 ep->hwtid));
503 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
504}
505
506static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
507{
508 struct cpl_abort_req *req;
509 int wrlen = roundup(sizeof *req, 16);
510
511 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
512 skb = get_skb(skb, wrlen, gfp);
513 if (!skb) {
514 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
515 __func__);
516 return -ENOMEM;
517 }
518 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
519 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
520 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
521 memset(req, 0, wrlen);
522 INIT_TP_WR(req, ep->hwtid);
523 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
524 req->cmd = CPL_ABORT_SEND_RST;
525 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
526}
527
528static int send_connect(struct c4iw_ep *ep)
529{
530 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000531 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530532 struct cpl_act_open_req6 *req6;
533 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700534 struct sk_buff *skb;
535 u64 opt0;
536 u32 opt2;
537 unsigned int mtu_idx;
538 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530539 int wrlen;
540 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
541 sizeof(struct cpl_act_open_req) :
542 sizeof(struct cpl_t5_act_open_req);
543 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
544 sizeof(struct cpl_act_open_req6) :
545 sizeof(struct cpl_t5_act_open_req6);
546 struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
547 struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
548 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
549 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
550
551 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
552 roundup(sizev4, 16) :
553 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700554
555 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
556
557 skb = get_skb(NULL, wrlen, GFP_KERNEL);
558 if (!skb) {
559 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
560 __func__);
561 return -ENOMEM;
562 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000563 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700564
565 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
566 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000567 opt0 = (nocong ? NO_CONG(1) : 0) |
568 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000569 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700570 WND_SCALE(wscale) |
571 MSS_IDX(mtu_idx) |
572 L2T_IDX(ep->l2t->idx) |
573 TX_CHAN(ep->tx_chan) |
574 SMAC_SEL(ep->smac_idx) |
575 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000576 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577 RCV_BUFSIZ(rcv_win>>10);
578 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000579 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700580 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
581 if (enable_tcp_timestamps)
582 opt2 |= TSTAMPS_EN(1);
583 if (enable_tcp_sack)
584 opt2 |= SACK_EN(1);
585 if (wscale && enable_tcp_window_scaling)
586 opt2 |= WND_SCALE_EN(1);
587 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
588
Vipul Pandyaf079af72013-03-14 05:08:58 +0000589 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530590 if (ep->com.remote_addr.ss_family == AF_INET) {
591 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
592 INIT_TP_WR(req, 0);
593 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000594 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
595 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530596 req->local_port = la->sin_port;
597 req->peer_port = ra->sin_port;
598 req->local_ip = la->sin_addr.s_addr;
599 req->peer_ip = ra->sin_addr.s_addr;
600 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530601 req->params = cpu_to_be32(cxgb4_select_ntuple(
602 ep->com.dev->rdev.lldi.ports[0],
603 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530604 req->opt2 = cpu_to_be32(opt2);
605 } else {
606 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
607
608 INIT_TP_WR(req6, 0);
609 OPCODE_TID(req6) = cpu_to_be32(
610 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
611 ((ep->rss_qid<<14)|ep->atid)));
612 req6->local_port = la6->sin6_port;
613 req6->peer_port = ra6->sin6_port;
614 req6->local_ip_hi = *((__be64 *)
615 (la6->sin6_addr.s6_addr));
616 req6->local_ip_lo = *((__be64 *)
617 (la6->sin6_addr.s6_addr + 8));
618 req6->peer_ip_hi = *((__be64 *)
619 (ra6->sin6_addr.s6_addr));
620 req6->peer_ip_lo = *((__be64 *)
621 (ra6->sin6_addr.s6_addr + 8));
622 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530623 req6->params = cpu_to_be32(cxgb4_select_ntuple(
624 ep->com.dev->rdev.lldi.ports[0],
625 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530626 req6->opt2 = cpu_to_be32(opt2);
627 }
628 } else {
629 if (ep->com.remote_addr.ss_family == AF_INET) {
630 t5_req = (struct cpl_t5_act_open_req *)
631 skb_put(skb, wrlen);
632 INIT_TP_WR(t5_req, 0);
633 OPCODE_TID(t5_req) = cpu_to_be32(
634 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
635 ((ep->rss_qid << 14) | ep->atid)));
636 t5_req->local_port = la->sin_port;
637 t5_req->peer_port = ra->sin_port;
638 t5_req->local_ip = la->sin_addr.s_addr;
639 t5_req->peer_ip = ra->sin_addr.s_addr;
640 t5_req->opt0 = cpu_to_be64(opt0);
641 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530642 cxgb4_select_ntuple(
643 ep->com.dev->rdev.lldi.ports[0],
644 ep->l2t)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530645 t5_req->opt2 = cpu_to_be32(opt2);
646 } else {
647 t5_req6 = (struct cpl_t5_act_open_req6 *)
648 skb_put(skb, wrlen);
649 INIT_TP_WR(t5_req6, 0);
650 OPCODE_TID(t5_req6) = cpu_to_be32(
651 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
652 ((ep->rss_qid<<14)|ep->atid)));
653 t5_req6->local_port = la6->sin6_port;
654 t5_req6->peer_port = ra6->sin6_port;
655 t5_req6->local_ip_hi = *((__be64 *)
656 (la6->sin6_addr.s6_addr));
657 t5_req6->local_ip_lo = *((__be64 *)
658 (la6->sin6_addr.s6_addr + 8));
659 t5_req6->peer_ip_hi = *((__be64 *)
660 (ra6->sin6_addr.s6_addr));
661 t5_req6->peer_ip_lo = *((__be64 *)
662 (ra6->sin6_addr.s6_addr + 8));
663 t5_req6->opt0 = cpu_to_be64(opt0);
664 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530665 cxgb4_select_ntuple(
666 ep->com.dev->rdev.lldi.ports[0],
667 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530668 t5_req6->opt2 = cpu_to_be32(opt2);
669 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000670 }
671
Vipul Pandya793dad92012-12-10 09:30:56 +0000672 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700673 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
674}
675
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530676static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
677 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700678{
679 int mpalen, wrlen;
680 struct fw_ofld_tx_data_wr *req;
681 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530682 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700683
684 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
685
686 BUG_ON(skb_cloned(skb));
687
688 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530689 if (mpa_rev_to_use == 2)
690 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700691 wrlen = roundup(mpalen + sizeof *req, 16);
692 skb = get_skb(skb, wrlen, GFP_KERNEL);
693 if (!skb) {
694 connect_reply_upcall(ep, -ENOMEM);
695 return;
696 }
697 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
698
699 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
700 memset(req, 0, wrlen);
701 req->op_to_immdlen = cpu_to_be32(
702 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
703 FW_WR_COMPL(1) |
704 FW_WR_IMMDLEN(mpalen));
705 req->flowid_len16 = cpu_to_be32(
706 FW_WR_FLOWID(ep->hwtid) |
707 FW_WR_LEN16(wrlen >> 4));
708 req->plen = cpu_to_be32(mpalen);
709 req->tunnel_to_proxy = cpu_to_be32(
710 FW_OFLD_TX_DATA_WR_FLUSH(1) |
711 FW_OFLD_TX_DATA_WR_SHOVE(1));
712
713 mpa = (struct mpa_message *)(req + 1);
714 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
715 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530716 (markers_enabled ? MPA_MARKERS : 0) |
717 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700718 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530719 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530720 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530721 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530722 ep->retry_with_mpa_v1 = 0;
723 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700724
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530725 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700726 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
727 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530728 mpa_v2_params.ird = htons((u16)ep->ird);
729 mpa_v2_params.ord = htons((u16)ep->ord);
730
731 if (peer2peer) {
732 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
733 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
734 mpa_v2_params.ord |=
735 htons(MPA_V2_RDMA_WRITE_RTR);
736 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
737 mpa_v2_params.ord |=
738 htons(MPA_V2_RDMA_READ_RTR);
739 }
740 memcpy(mpa->private_data, &mpa_v2_params,
741 sizeof(struct mpa_v2_conn_params));
742
743 if (ep->plen)
744 memcpy(mpa->private_data +
745 sizeof(struct mpa_v2_conn_params),
746 ep->mpa_pkt + sizeof(*mpa), ep->plen);
747 } else
748 if (ep->plen)
749 memcpy(mpa->private_data,
750 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700751
752 /*
753 * Reference the mpa skb. This ensures the data area
754 * will remain in memory until the hw acks the tx.
755 * Function fw4_ack() will deref it.
756 */
757 skb_get(skb);
758 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
759 BUG_ON(ep->mpa_skb);
760 ep->mpa_skb = skb;
761 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
762 start_ep_timer(ep);
763 state_set(&ep->com, MPA_REQ_SENT);
764 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530765 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700766 return;
767}
768
769static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
770{
771 int mpalen, wrlen;
772 struct fw_ofld_tx_data_wr *req;
773 struct mpa_message *mpa;
774 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530775 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700776
777 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
778
779 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530780 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
781 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700782 wrlen = roundup(mpalen + sizeof *req, 16);
783
784 skb = get_skb(NULL, wrlen, GFP_KERNEL);
785 if (!skb) {
786 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
787 return -ENOMEM;
788 }
789 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
790
791 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
792 memset(req, 0, wrlen);
793 req->op_to_immdlen = cpu_to_be32(
794 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
795 FW_WR_COMPL(1) |
796 FW_WR_IMMDLEN(mpalen));
797 req->flowid_len16 = cpu_to_be32(
798 FW_WR_FLOWID(ep->hwtid) |
799 FW_WR_LEN16(wrlen >> 4));
800 req->plen = cpu_to_be32(mpalen);
801 req->tunnel_to_proxy = cpu_to_be32(
802 FW_OFLD_TX_DATA_WR_FLUSH(1) |
803 FW_OFLD_TX_DATA_WR_SHOVE(1));
804
805 mpa = (struct mpa_message *)(req + 1);
806 memset(mpa, 0, sizeof(*mpa));
807 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
808 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000809 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700810 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530811
812 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
813 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700814 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
815 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530816 mpa_v2_params.ird = htons(((u16)ep->ird) |
817 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
818 0));
819 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
820 (p2p_type ==
821 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
822 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
823 FW_RI_INIT_P2PTYPE_READ_REQ ?
824 MPA_V2_RDMA_READ_RTR : 0) : 0));
825 memcpy(mpa->private_data, &mpa_v2_params,
826 sizeof(struct mpa_v2_conn_params));
827
828 if (ep->plen)
829 memcpy(mpa->private_data +
830 sizeof(struct mpa_v2_conn_params), pdata, plen);
831 } else
832 if (plen)
833 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700834
835 /*
836 * Reference the mpa skb again. This ensures the data area
837 * will remain in memory until the hw acks the tx.
838 * Function fw4_ack() will deref it.
839 */
840 skb_get(skb);
841 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
842 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
843 BUG_ON(ep->mpa_skb);
844 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530845 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700846 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
847}
848
849static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
850{
851 int mpalen, wrlen;
852 struct fw_ofld_tx_data_wr *req;
853 struct mpa_message *mpa;
854 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530855 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700856
857 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
858
859 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530860 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
861 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700862 wrlen = roundup(mpalen + sizeof *req, 16);
863
864 skb = get_skb(NULL, wrlen, GFP_KERNEL);
865 if (!skb) {
866 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
867 return -ENOMEM;
868 }
869 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
870
871 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
872 memset(req, 0, wrlen);
873 req->op_to_immdlen = cpu_to_be32(
874 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
875 FW_WR_COMPL(1) |
876 FW_WR_IMMDLEN(mpalen));
877 req->flowid_len16 = cpu_to_be32(
878 FW_WR_FLOWID(ep->hwtid) |
879 FW_WR_LEN16(wrlen >> 4));
880 req->plen = cpu_to_be32(mpalen);
881 req->tunnel_to_proxy = cpu_to_be32(
882 FW_OFLD_TX_DATA_WR_FLUSH(1) |
883 FW_OFLD_TX_DATA_WR_SHOVE(1));
884
885 mpa = (struct mpa_message *)(req + 1);
886 memset(mpa, 0, sizeof(*mpa));
887 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
888 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
889 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530890 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530892
893 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
894 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700895 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
896 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530897 mpa_v2_params.ird = htons((u16)ep->ird);
898 mpa_v2_params.ord = htons((u16)ep->ord);
899 if (peer2peer && (ep->mpa_attr.p2p_type !=
900 FW_RI_INIT_P2PTYPE_DISABLED)) {
901 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
902
903 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
904 mpa_v2_params.ord |=
905 htons(MPA_V2_RDMA_WRITE_RTR);
906 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
907 mpa_v2_params.ord |=
908 htons(MPA_V2_RDMA_READ_RTR);
909 }
910
911 memcpy(mpa->private_data, &mpa_v2_params,
912 sizeof(struct mpa_v2_conn_params));
913
914 if (ep->plen)
915 memcpy(mpa->private_data +
916 sizeof(struct mpa_v2_conn_params), pdata, plen);
917 } else
918 if (plen)
919 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700920
921 /*
922 * Reference the mpa skb. This ensures the data area
923 * will remain in memory until the hw acks the tx.
924 * Function fw4_ack() will deref it.
925 */
926 skb_get(skb);
927 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
928 ep->mpa_skb = skb;
929 state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +0530930 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700931 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
932}
933
934static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
935{
936 struct c4iw_ep *ep;
937 struct cpl_act_establish *req = cplhdr(skb);
938 unsigned int tid = GET_TID(req);
939 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
940 struct tid_info *t = dev->rdev.lldi.tids;
941
942 ep = lookup_atid(t, atid);
943
944 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
945 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
946
947 dst_confirm(ep->dst);
948
949 /* setup the hwtid for this connection */
950 ep->hwtid = tid;
951 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000952 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700953
954 ep->snd_seq = be32_to_cpu(req->snd_isn);
955 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
956
957 set_emss(ep, ntohs(req->tcp_opt));
958
959 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000960 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700961 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000962 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700963
964 /* start MPA negotiation */
965 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530966 if (ep->retry_with_mpa_v1)
967 send_mpa_req(ep, skb, 1);
968 else
969 send_mpa_req(ep, skb, mpa_rev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700970
971 return 0;
972}
973
Steve Wisebe13b2d2014-03-21 20:40:33 +0530974static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700975{
976 struct iw_cm_event event;
977
978 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
979 memset(&event, 0, sizeof(event));
980 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +0530981 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982 if (ep->com.cm_id) {
983 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
984 ep, ep->com.cm_id, ep->hwtid);
985 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
986 ep->com.cm_id->rem_ref(ep->com.cm_id);
987 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000988 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700989 }
990}
991
992static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
993{
994 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700995 state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +0000996 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700997 return send_abort(ep, skb, gfp);
998}
999
1000static void peer_close_upcall(struct c4iw_ep *ep)
1001{
1002 struct iw_cm_event event;
1003
1004 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1005 memset(&event, 0, sizeof(event));
1006 event.event = IW_CM_EVENT_DISCONNECT;
1007 if (ep->com.cm_id) {
1008 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1009 ep, ep->com.cm_id, ep->hwtid);
1010 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001011 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001012 }
1013}
1014
1015static void peer_abort_upcall(struct c4iw_ep *ep)
1016{
1017 struct iw_cm_event event;
1018
1019 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1020 memset(&event, 0, sizeof(event));
1021 event.event = IW_CM_EVENT_CLOSE;
1022 event.status = -ECONNRESET;
1023 if (ep->com.cm_id) {
1024 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1025 ep->com.cm_id, ep->hwtid);
1026 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1027 ep->com.cm_id->rem_ref(ep->com.cm_id);
1028 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001029 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001030 }
1031}
1032
1033static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1034{
1035 struct iw_cm_event event;
1036
1037 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1038 memset(&event, 0, sizeof(event));
1039 event.event = IW_CM_EVENT_CONNECT_REPLY;
1040 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301041 memcpy(&event.local_addr, &ep->com.local_addr,
1042 sizeof(ep->com.local_addr));
1043 memcpy(&event.remote_addr, &ep->com.remote_addr,
1044 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001045
1046 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301047 if (!ep->tried_with_mpa_v1) {
1048 /* this means MPA_v2 is used */
1049 event.private_data_len = ep->plen -
1050 sizeof(struct mpa_v2_conn_params);
1051 event.private_data = ep->mpa_pkt +
1052 sizeof(struct mpa_message) +
1053 sizeof(struct mpa_v2_conn_params);
1054 } else {
1055 /* this means MPA_v1 is used */
1056 event.private_data_len = ep->plen;
1057 event.private_data = ep->mpa_pkt +
1058 sizeof(struct mpa_message);
1059 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060 }
Roland Dreier85963e42010-07-19 13:13:09 -07001061
1062 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1063 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001064 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001065 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1066
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067 if (status < 0) {
1068 ep->com.cm_id->rem_ref(ep->com.cm_id);
1069 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 }
1071}
1072
Steve Wisebe13b2d2014-03-21 20:40:33 +05301073static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001074{
1075 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301076 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001077
1078 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1079 memset(&event, 0, sizeof(event));
1080 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301081 memcpy(&event.local_addr, &ep->com.local_addr,
1082 sizeof(ep->com.local_addr));
1083 memcpy(&event.remote_addr, &ep->com.remote_addr,
1084 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001085 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301086 if (!ep->tried_with_mpa_v1) {
1087 /* this means MPA_v2 is used */
1088 event.ord = ep->ord;
1089 event.ird = ep->ird;
1090 event.private_data_len = ep->plen -
1091 sizeof(struct mpa_v2_conn_params);
1092 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1093 sizeof(struct mpa_v2_conn_params);
1094 } else {
1095 /* this means MPA_v1 is used. Send max supported */
1096 event.ord = c4iw_max_read_depth;
1097 event.ird = c4iw_max_read_depth;
1098 event.private_data_len = ep->plen;
1099 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1100 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301101 c4iw_get_ep(&ep->com);
1102 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1103 &event);
1104 if (ret)
1105 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001106 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001107 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301108 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001109}
1110
1111static void established_upcall(struct c4iw_ep *ep)
1112{
1113 struct iw_cm_event event;
1114
1115 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1116 memset(&event, 0, sizeof(event));
1117 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301118 event.ird = ep->ird;
1119 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001120 if (ep->com.cm_id) {
1121 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1122 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001123 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001124 }
1125}
1126
1127static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1128{
1129 struct cpl_rx_data_ack *req;
1130 struct sk_buff *skb;
1131 int wrlen = roundup(sizeof *req, 16);
1132
1133 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1134 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1135 if (!skb) {
1136 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1137 return 0;
1138 }
1139
1140 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1141 memset(req, 0, wrlen);
1142 INIT_TP_WR(req, ep->hwtid);
1143 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1144 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001145 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1146 F_RX_DACK_CHANGE |
1147 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001148 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001149 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1150 return credits;
1151}
1152
1153static void process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
1154{
1155 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301156 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301158 u16 resp_ird, resp_ord;
1159 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001160 struct c4iw_qp_attributes attrs;
1161 enum c4iw_qp_attr_mask mask;
1162 int err;
1163
1164 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1165
1166 /*
1167 * Stop mpa timer. If it expired, then the state has
1168 * changed and we bail since ep_timeout already aborted
1169 * the connection.
1170 */
1171 stop_ep_timer(ep);
1172 if (state_read(&ep->com) != MPA_REQ_SENT)
1173 return;
1174
1175 /*
1176 * If we get more than the supported amount of private data
1177 * then we must fail this connection.
1178 */
1179 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1180 err = -EINVAL;
1181 goto err;
1182 }
1183
1184 /*
1185 * copy the new data into our accumulation buffer.
1186 */
1187 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1188 skb->len);
1189 ep->mpa_pkt_len += skb->len;
1190
1191 /*
1192 * if we don't even have the mpa message, then bail.
1193 */
1194 if (ep->mpa_pkt_len < sizeof(*mpa))
1195 return;
1196 mpa = (struct mpa_message *) ep->mpa_pkt;
1197
1198 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301199 if (mpa->revision > mpa_rev) {
1200 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1201 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202 err = -EPROTO;
1203 goto err;
1204 }
1205 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1206 err = -EPROTO;
1207 goto err;
1208 }
1209
1210 plen = ntohs(mpa->private_data_size);
1211
1212 /*
1213 * Fail if there's too much private data.
1214 */
1215 if (plen > MPA_MAX_PRIVATE_DATA) {
1216 err = -EPROTO;
1217 goto err;
1218 }
1219
1220 /*
1221 * If plen does not account for pkt size
1222 */
1223 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1224 err = -EPROTO;
1225 goto err;
1226 }
1227
1228 ep->plen = (u8) plen;
1229
1230 /*
1231 * If we don't have all the pdata yet, then bail.
1232 * We'll continue process when more data arrives.
1233 */
1234 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1235 return;
1236
1237 if (mpa->flags & MPA_REJECT) {
1238 err = -ECONNREFUSED;
1239 goto err;
1240 }
1241
1242 /*
1243 * If we get here we have accumulated the entire mpa
1244 * start reply message including private data. And
1245 * the MPA header is valid.
1246 */
1247 state_set(&ep->com, FPDU_MODE);
1248 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1249 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1250 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301251 ep->mpa_attr.version = mpa->revision;
1252 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1253
1254 if (mpa->revision == 2) {
1255 ep->mpa_attr.enhanced_rdma_conn =
1256 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1257 if (ep->mpa_attr.enhanced_rdma_conn) {
1258 mpa_v2_params = (struct mpa_v2_conn_params *)
1259 (ep->mpa_pkt + sizeof(*mpa));
1260 resp_ird = ntohs(mpa_v2_params->ird) &
1261 MPA_V2_IRD_ORD_MASK;
1262 resp_ord = ntohs(mpa_v2_params->ord) &
1263 MPA_V2_IRD_ORD_MASK;
1264
1265 /*
1266 * This is a double-check. Ideally, below checks are
1267 * not required since ird/ord stuff has been taken
1268 * care of in c4iw_accept_cr
1269 */
1270 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1271 err = -ENOMEM;
1272 ep->ird = resp_ord;
1273 ep->ord = resp_ird;
1274 insuff_ird = 1;
1275 }
1276
1277 if (ntohs(mpa_v2_params->ird) &
1278 MPA_V2_PEER2PEER_MODEL) {
1279 if (ntohs(mpa_v2_params->ord) &
1280 MPA_V2_RDMA_WRITE_RTR)
1281 ep->mpa_attr.p2p_type =
1282 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1283 else if (ntohs(mpa_v2_params->ord) &
1284 MPA_V2_RDMA_READ_RTR)
1285 ep->mpa_attr.p2p_type =
1286 FW_RI_INIT_P2PTYPE_READ_REQ;
1287 }
1288 }
1289 } else if (mpa->revision == 1)
1290 if (peer2peer)
1291 ep->mpa_attr.p2p_type = p2p_type;
1292
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301294 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1295 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1296 ep->mpa_attr.recv_marker_enabled,
1297 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1298 ep->mpa_attr.p2p_type, p2p_type);
1299
1300 /*
1301 * If responder's RTR does not match with that of initiator, assign
1302 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1303 * generated when moving QP to RTS state.
1304 * A TERM message will be sent after QP has moved to RTS state
1305 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001306 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301307 (ep->mpa_attr.p2p_type != p2p_type)) {
1308 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1309 rtr_mismatch = 1;
1310 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001311
1312 attrs.mpa_attr = ep->mpa_attr;
1313 attrs.max_ird = ep->ird;
1314 attrs.max_ord = ep->ord;
1315 attrs.llp_stream_handle = ep;
1316 attrs.next_state = C4IW_QP_STATE_RTS;
1317
1318 mask = C4IW_QP_ATTR_NEXT_STATE |
1319 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1320 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1321
1322 /* bind QP and TID with INIT_WR */
1323 err = c4iw_modify_qp(ep->com.qp->rhp,
1324 ep->com.qp, mask, &attrs, 1);
1325 if (err)
1326 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301327
1328 /*
1329 * If responder's RTR requirement did not match with what initiator
1330 * supports, generate TERM message
1331 */
1332 if (rtr_mismatch) {
1333 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1334 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1335 attrs.ecode = MPA_NOMATCH_RTR;
1336 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1337 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1338 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1339 err = -ENOMEM;
1340 goto out;
1341 }
1342
1343 /*
1344 * Generate TERM if initiator IRD is not sufficient for responder
1345 * provided ORD. Currently, we do the same behaviour even when
1346 * responder provided IRD is also not sufficient as regards to
1347 * initiator ORD.
1348 */
1349 if (insuff_ird) {
1350 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1351 __func__);
1352 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1353 attrs.ecode = MPA_INSUFF_IRD;
1354 attrs.next_state = C4IW_QP_STATE_TERMINATE;
1355 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
1356 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
1357 err = -ENOMEM;
1358 goto out;
1359 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360 goto out;
1361err:
Steve Wiseb21ef162010-06-10 19:02:55 +00001362 state_set(&ep->com, ABORTING);
1363 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001364out:
1365 connect_reply_upcall(ep, err);
1366 return;
1367}
1368
1369static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1370{
1371 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301372 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001373 u16 plen;
1374
1375 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1376
1377 if (state_read(&ep->com) != MPA_REQ_WAIT)
1378 return;
1379
1380 /*
1381 * If we get more than the supported amount of private data
1382 * then we must fail this connection.
1383 */
1384 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1385 stop_ep_timer(ep);
1386 abort_connection(ep, skb, GFP_KERNEL);
1387 return;
1388 }
1389
1390 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1391
1392 /*
1393 * Copy the new data into our accumulation buffer.
1394 */
1395 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1396 skb->len);
1397 ep->mpa_pkt_len += skb->len;
1398
1399 /*
1400 * If we don't even have the mpa message, then bail.
1401 * We'll continue process when more data arrives.
1402 */
1403 if (ep->mpa_pkt_len < sizeof(*mpa))
1404 return;
1405
1406 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001407 mpa = (struct mpa_message *) ep->mpa_pkt;
1408
1409 /*
1410 * Validate MPA Header.
1411 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301412 if (mpa->revision > mpa_rev) {
1413 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1414 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001415 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001416 abort_connection(ep, skb, GFP_KERNEL);
1417 return;
1418 }
1419
1420 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001421 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001422 abort_connection(ep, skb, GFP_KERNEL);
1423 return;
1424 }
1425
1426 plen = ntohs(mpa->private_data_size);
1427
1428 /*
1429 * Fail if there's too much private data.
1430 */
1431 if (plen > MPA_MAX_PRIVATE_DATA) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001432 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001433 abort_connection(ep, skb, GFP_KERNEL);
1434 return;
1435 }
1436
1437 /*
1438 * If plen does not account for pkt size
1439 */
1440 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00001441 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001442 abort_connection(ep, skb, GFP_KERNEL);
1443 return;
1444 }
1445 ep->plen = (u8) plen;
1446
1447 /*
1448 * If we don't have all the pdata yet, then bail.
1449 */
1450 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1451 return;
1452
1453 /*
1454 * If we get here we have accumulated the entire mpa
1455 * start reply message including private data.
1456 */
1457 ep->mpa_attr.initiator = 0;
1458 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1459 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1460 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301461 ep->mpa_attr.version = mpa->revision;
1462 if (mpa->revision == 1)
1463 ep->tried_with_mpa_v1 = 1;
1464 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1465
1466 if (mpa->revision == 2) {
1467 ep->mpa_attr.enhanced_rdma_conn =
1468 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1469 if (ep->mpa_attr.enhanced_rdma_conn) {
1470 mpa_v2_params = (struct mpa_v2_conn_params *)
1471 (ep->mpa_pkt + sizeof(*mpa));
1472 ep->ird = ntohs(mpa_v2_params->ird) &
1473 MPA_V2_IRD_ORD_MASK;
1474 ep->ord = ntohs(mpa_v2_params->ord) &
1475 MPA_V2_IRD_ORD_MASK;
1476 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1477 if (peer2peer) {
1478 if (ntohs(mpa_v2_params->ord) &
1479 MPA_V2_RDMA_WRITE_RTR)
1480 ep->mpa_attr.p2p_type =
1481 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1482 else if (ntohs(mpa_v2_params->ord) &
1483 MPA_V2_RDMA_READ_RTR)
1484 ep->mpa_attr.p2p_type =
1485 FW_RI_INIT_P2PTYPE_READ_REQ;
1486 }
1487 }
1488 } else if (mpa->revision == 1)
1489 if (peer2peer)
1490 ep->mpa_attr.p2p_type = p2p_type;
1491
Steve Wisecfdda9d2010-04-21 15:30:06 -07001492 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1493 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1494 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1495 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1496 ep->mpa_attr.p2p_type);
1497
1498 state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301499 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001500
1501 /* drive upcall */
Steve Wisebe13b2d2014-03-21 20:40:33 +05301502 mutex_lock(&ep->parent_ep->com.mutex);
1503 if (ep->parent_ep->com.state != DEAD) {
1504 if (connect_request_upcall(ep))
1505 abort_connection(ep, skb, GFP_KERNEL);
1506 } else {
1507 abort_connection(ep, skb, GFP_KERNEL);
1508 }
1509 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510 return;
1511}
1512
1513static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1514{
1515 struct c4iw_ep *ep;
1516 struct cpl_rx_data *hdr = cplhdr(skb);
1517 unsigned int dlen = ntohs(hdr->len);
1518 unsigned int tid = GET_TID(hdr);
1519 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001520 __u8 status = hdr->status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001521
1522 ep = lookup_tid(t, tid);
1523 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1524 skb_pull(skb, sizeof(*hdr));
1525 skb_trim(skb, dlen);
1526
Steve Wisecfdda9d2010-04-21 15:30:06 -07001527 /* update RX credits */
1528 update_rx_credits(ep, dlen);
1529
1530 switch (state_read(&ep->com)) {
1531 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001532 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001533 process_mpa_reply(ep, skb);
1534 break;
1535 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001536 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001537 process_mpa_request(ep, skb);
1538 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001539 case FPDU_MODE: {
1540 struct c4iw_qp_attributes attrs;
1541 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001542 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001543 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001544 " qpid %u ep %p state %d tid %u status %d\n",
1545 __func__, ep->com.qp->wq.sq.qid, ep,
1546 state_read(&ep->com), ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301547 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001548 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise97d7ec02013-08-06 21:04:34 +05301549 C4IW_QP_ATTR_NEXT_STATE, &attrs, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001550 break;
1551 }
Vipul Pandya15579672013-01-07 13:11:52 +00001552 default:
1553 break;
1554 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001555 return 0;
1556}
1557
1558static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1559{
1560 struct c4iw_ep *ep;
1561 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001562 int release = 0;
1563 unsigned int tid = GET_TID(rpl);
1564 struct tid_info *t = dev->rdev.lldi.tids;
1565
1566 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301567 if (!ep) {
1568 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1569 return 0;
1570 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001571 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001572 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001573 switch (ep->com.state) {
1574 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001575 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001576 __state_set(&ep->com, DEAD);
1577 release = 1;
1578 break;
1579 default:
1580 printk(KERN_ERR "%s ep %p state %d\n",
1581 __func__, ep, ep->com.state);
1582 break;
1583 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001584 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001585
1586 if (release)
1587 release_ep_resources(ep);
1588 return 0;
1589}
1590
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001591static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1592{
1593 struct sk_buff *skb;
1594 struct fw_ofld_connection_wr *req;
1595 unsigned int mtu_idx;
1596 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301597 struct sockaddr_in *sin;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001598
1599 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1600 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1601 memset(req, 0, sizeof(*req));
1602 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1603 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301604 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1605 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001606 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +05301607 sin = (struct sockaddr_in *)&ep->com.local_addr;
1608 req->le.lport = sin->sin_port;
1609 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1610 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1611 req->le.pport = sin->sin_port;
1612 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001613 req->tcb.t_state_to_astid =
1614 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1615 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1616 req->tcb.cplrxdataack_cplpassacceptrpl =
1617 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001618 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001619 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001620 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1621 wscale = compute_wscale(rcv_win);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001622 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001623 (nocong ? NO_CONG(1) : 0) |
1624 KEEP_ALIVE(1) |
1625 DELACK(1) |
1626 WND_SCALE(wscale) |
1627 MSS_IDX(mtu_idx) |
1628 L2T_IDX(ep->l2t->idx) |
1629 TX_CHAN(ep->tx_chan) |
1630 SMAC_SEL(ep->smac_idx) |
1631 DSCP(ep->tos) |
1632 ULP_MODE(ULP_MODE_TCPDDP) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001633 RCV_BUFSIZ(rcv_win >> 10));
1634 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001635 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1636 RX_CHANNEL(0) |
1637 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001638 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001639 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001640 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001641 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001642 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001643 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001644 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1645 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1646 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001647 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1648 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001649 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1650}
1651
Steve Wisecfdda9d2010-04-21 15:30:06 -07001652/*
1653 * Return whether a failed active open has allocated a TID
1654 */
1655static inline int act_open_has_tid(int status)
1656{
1657 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1658 status != CPL_ERR_ARP_MISS;
1659}
1660
Vipul Pandya793dad92012-12-10 09:30:56 +00001661#define ACT_OPEN_RETRY_COUNT 2
1662
Vipul Pandya830662f2013-07-04 16:10:47 +05301663static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1664 struct dst_entry *dst, struct c4iw_dev *cdev,
1665 bool clear_mpa_v1)
1666{
1667 struct neighbour *n;
1668 int err, step;
1669 struct net_device *pdev;
1670
1671 n = dst_neigh_lookup(dst, peer_ip);
1672 if (!n)
1673 return -ENODEV;
1674
1675 rcu_read_lock();
1676 err = -ENOMEM;
1677 if (n->dev->flags & IFF_LOOPBACK) {
1678 if (iptype == 4)
1679 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1680 else if (IS_ENABLED(CONFIG_IPV6))
1681 for_each_netdev(&init_net, pdev) {
1682 if (ipv6_chk_addr(&init_net,
1683 (struct in6_addr *)peer_ip,
1684 pdev, 1))
1685 break;
1686 }
1687 else
1688 pdev = NULL;
1689
1690 if (!pdev) {
1691 err = -ENODEV;
1692 goto out;
1693 }
1694 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1695 n, pdev, 0);
1696 if (!ep->l2t)
1697 goto out;
1698 ep->mtu = pdev->mtu;
1699 ep->tx_chan = cxgb4_port_chan(pdev);
1700 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1701 step = cdev->rdev.lldi.ntxq /
1702 cdev->rdev.lldi.nchan;
1703 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1704 step = cdev->rdev.lldi.nrxq /
1705 cdev->rdev.lldi.nchan;
1706 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1707 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1708 cxgb4_port_idx(pdev) * step];
1709 dev_put(pdev);
1710 } else {
1711 pdev = get_real_dev(n->dev);
1712 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1713 n, pdev, 0);
1714 if (!ep->l2t)
1715 goto out;
1716 ep->mtu = dst_mtu(dst);
1717 ep->tx_chan = cxgb4_port_chan(n->dev);
1718 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1719 step = cdev->rdev.lldi.ntxq /
1720 cdev->rdev.lldi.nchan;
1721 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1722 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1723 step = cdev->rdev.lldi.nrxq /
1724 cdev->rdev.lldi.nchan;
1725 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1726 cxgb4_port_idx(n->dev) * step];
1727
1728 if (clear_mpa_v1) {
1729 ep->retry_with_mpa_v1 = 0;
1730 ep->tried_with_mpa_v1 = 0;
1731 }
1732 }
1733 err = 0;
1734out:
1735 rcu_read_unlock();
1736
1737 neigh_release(n);
1738
1739 return err;
1740}
1741
Vipul Pandya793dad92012-12-10 09:30:56 +00001742static int c4iw_reconnect(struct c4iw_ep *ep)
1743{
1744 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301745 struct sockaddr_in *laddr = (struct sockaddr_in *)
1746 &ep->com.cm_id->local_addr;
1747 struct sockaddr_in *raddr = (struct sockaddr_in *)
1748 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301749 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1750 &ep->com.cm_id->local_addr;
1751 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1752 &ep->com.cm_id->remote_addr;
1753 int iptype;
1754 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001755
1756 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1757 init_timer(&ep->timer);
1758
1759 /*
1760 * Allocate an active TID to initiate a TCP connection.
1761 */
1762 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1763 if (ep->atid == -1) {
1764 pr_err("%s - cannot alloc atid.\n", __func__);
1765 err = -ENOMEM;
1766 goto fail2;
1767 }
1768 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1769
1770 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301771 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1772 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1773 raddr->sin_addr.s_addr, laddr->sin_port,
1774 raddr->sin_port, 0);
1775 iptype = 4;
1776 ra = (__u8 *)&raddr->sin_addr;
1777 } else {
1778 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1779 raddr6->sin6_addr.s6_addr,
1780 laddr6->sin6_port, raddr6->sin6_port, 0,
1781 raddr6->sin6_scope_id);
1782 iptype = 6;
1783 ra = (__u8 *)&raddr6->sin6_addr;
1784 }
1785 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001786 pr_err("%s - cannot find route.\n", __func__);
1787 err = -EHOSTUNREACH;
1788 goto fail3;
1789 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301790 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1791 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001792 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001793 goto fail4;
1794 }
1795
1796 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1797 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1798 ep->l2t->idx);
1799
1800 state_set(&ep->com, CONNECTING);
1801 ep->tos = 0;
1802
1803 /* send connect request to rnic */
1804 err = send_connect(ep);
1805 if (!err)
1806 goto out;
1807
1808 cxgb4_l2t_release(ep->l2t);
1809fail4:
1810 dst_release(ep->dst);
1811fail3:
1812 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1813 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1814fail2:
1815 /*
1816 * remember to send notification to upper layer.
1817 * We are in here so the upper layer is not aware that this is
1818 * re-connect attempt and so, upper layer is still waiting for
1819 * response of 1st connect request.
1820 */
1821 connect_reply_upcall(ep, -ECONNRESET);
1822 c4iw_put_ep(&ep->com);
1823out:
1824 return err;
1825}
1826
Steve Wisecfdda9d2010-04-21 15:30:06 -07001827static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1828{
1829 struct c4iw_ep *ep;
1830 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1831 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1832 ntohl(rpl->atid_status)));
1833 struct tid_info *t = dev->rdev.lldi.tids;
1834 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301835 struct sockaddr_in *la;
1836 struct sockaddr_in *ra;
1837 struct sockaddr_in6 *la6;
1838 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001839
1840 ep = lookup_atid(t, atid);
Vipul Pandya830662f2013-07-04 16:10:47 +05301841 la = (struct sockaddr_in *)&ep->com.local_addr;
1842 ra = (struct sockaddr_in *)&ep->com.remote_addr;
1843 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
1844 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845
1846 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1847 status, status2errno(status));
1848
1849 if (status == CPL_ERR_RTX_NEG_ADVICE) {
1850 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1851 atid);
1852 return 0;
1853 }
1854
Vipul Pandya793dad92012-12-10 09:30:56 +00001855 set_bit(ACT_OPEN_RPL, &ep->com.history);
1856
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301857 /*
1858 * Log interesting failures.
1859 */
1860 switch (status) {
1861 case CPL_ERR_CONN_RESET:
1862 case CPL_ERR_CONN_TIMEDOUT:
1863 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001864 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05301865 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00001866 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05301867 mutex_unlock(&dev->rdev.stats.lock);
1868 if (ep->com.local_addr.ss_family == AF_INET &&
1869 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001870 send_fw_act_open_req(ep,
1871 GET_TID_TID(GET_AOPEN_ATID(
1872 ntohl(rpl->atid_status))));
1873 return 0;
1874 }
1875 break;
1876 case CPL_ERR_CONN_EXIST:
1877 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1878 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1879 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1880 atid);
1881 cxgb4_free_atid(t, atid);
1882 dst_release(ep->dst);
1883 cxgb4_l2t_release(ep->l2t);
1884 c4iw_reconnect(ep);
1885 return 0;
1886 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001887 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301888 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05301889 if (ep->com.local_addr.ss_family == AF_INET) {
1890 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1891 atid, status, status2errno(status),
1892 &la->sin_addr.s_addr, ntohs(la->sin_port),
1893 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1894 } else {
1895 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1896 atid, status, status2errno(status),
1897 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1898 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1899 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301900 break;
1901 }
1902
Steve Wisecfdda9d2010-04-21 15:30:06 -07001903 connect_reply_upcall(ep, status2errno(status));
1904 state_set(&ep->com, DEAD);
1905
1906 if (status && act_open_has_tid(status))
1907 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1908
Vipul Pandya793dad92012-12-10 09:30:56 +00001909 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001910 cxgb4_free_atid(t, atid);
1911 dst_release(ep->dst);
1912 cxgb4_l2t_release(ep->l2t);
1913 c4iw_put_ep(&ep->com);
1914
1915 return 0;
1916}
1917
1918static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1919{
1920 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1921 struct tid_info *t = dev->rdev.lldi.tids;
1922 unsigned int stid = GET_TID(rpl);
1923 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1924
1925 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001926 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1927 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001928 }
1929 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1930 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001931 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001932
Vipul Pandya1cab7752012-12-10 09:30:55 +00001933out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001934 return 0;
1935}
1936
Steve Wisecfdda9d2010-04-21 15:30:06 -07001937static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1938{
1939 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1940 struct tid_info *t = dev->rdev.lldi.tids;
1941 unsigned int stid = GET_TID(rpl);
1942 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1943
1944 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001945 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001946 return 0;
1947}
1948
Vipul Pandya830662f2013-07-04 16:10:47 +05301949static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07001950 struct cpl_pass_accept_req *req)
1951{
1952 struct cpl_pass_accept_rpl *rpl;
1953 unsigned int mtu_idx;
1954 u64 opt0;
1955 u32 opt2;
1956 int wscale;
1957
1958 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1959 BUG_ON(skb_cloned(skb));
1960 skb_trim(skb, sizeof(*rpl));
1961 skb_get(skb);
1962 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1963 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001964 opt0 = (nocong ? NO_CONG(1) : 0) |
1965 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001966 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001967 WND_SCALE(wscale) |
1968 MSS_IDX(mtu_idx) |
1969 L2T_IDX(ep->l2t->idx) |
1970 TX_CHAN(ep->tx_chan) |
1971 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001972 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00001973 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001974 RCV_BUFSIZ(rcv_win>>10);
1975 opt2 = RX_CHANNEL(0) |
1976 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
1977
1978 if (enable_tcp_timestamps && req->tcpopt.tstamp)
1979 opt2 |= TSTAMPS_EN(1);
1980 if (enable_tcp_sack && req->tcpopt.sack)
1981 opt2 |= SACK_EN(1);
1982 if (wscale && enable_tcp_window_scaling)
1983 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001984 if (enable_ecn) {
1985 const struct tcphdr *tcph;
1986 u32 hlen = ntohl(req->hdr_len);
1987
1988 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
1989 G_IP_HDR_LEN(hlen);
1990 if (tcph->ece && tcph->cwr)
1991 opt2 |= CCTRL_ECN(1);
1992 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001993
1994 rpl = cplhdr(skb);
1995 INIT_TP_WR(rpl, ep->hwtid);
1996 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
1997 ep->hwtid));
1998 rpl->opt0 = cpu_to_be64(opt0);
1999 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002000 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302001 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002002 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2003
2004 return;
2005}
2006
Vipul Pandya830662f2013-07-04 16:10:47 +05302007static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002008{
Vipul Pandya830662f2013-07-04 16:10:47 +05302009 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002010 BUG_ON(skb_cloned(skb));
2011 skb_trim(skb, sizeof(struct cpl_tid_release));
2012 skb_get(skb);
2013 release_tid(&dev->rdev, hwtid, skb);
2014 return;
2015}
2016
Vipul Pandya830662f2013-07-04 16:10:47 +05302017static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2018 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002019 __be16 *local_port, __be16 *peer_port)
2020{
2021 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2022 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2023 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302024 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002025 struct tcphdr *tcp = (struct tcphdr *)
2026 ((u8 *)(req + 1) + eth_len + ip_len);
2027
Vipul Pandya830662f2013-07-04 16:10:47 +05302028 if (ip->version == 4) {
2029 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2030 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2031 ntohs(tcp->dest));
2032 *iptype = 4;
2033 memcpy(peer_ip, &ip->saddr, 4);
2034 memcpy(local_ip, &ip->daddr, 4);
2035 } else {
2036 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2037 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2038 ntohs(tcp->dest));
2039 *iptype = 6;
2040 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2041 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2042 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002043 *peer_port = tcp->source;
2044 *local_port = tcp->dest;
2045
2046 return;
2047}
2048
2049static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2050{
Vipul Pandya793dad92012-12-10 09:30:56 +00002051 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002052 struct cpl_pass_accept_req *req = cplhdr(skb);
2053 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2054 struct tid_info *t = dev->rdev.lldi.tids;
2055 unsigned int hwtid = GET_TID(req);
2056 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302057 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002058 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002059 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002060 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302061 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002062
2063 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002064 if (!parent_ep) {
2065 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2066 goto reject;
2067 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002068
Steve Wisecfdda9d2010-04-21 15:30:06 -07002069 if (state_read(&parent_ep->com) != LISTEN) {
2070 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2071 __func__);
2072 goto reject;
2073 }
2074
Vipul Pandya830662f2013-07-04 16:10:47 +05302075 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2076
Steve Wisecfdda9d2010-04-21 15:30:06 -07002077 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302078 if (iptype == 4) {
2079 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2080 , __func__, parent_ep, hwtid,
2081 local_ip, peer_ip, ntohs(local_port),
2082 ntohs(peer_port), peer_mss);
2083 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2084 local_port, peer_port,
2085 GET_POPEN_TOS(ntohl(req->tos_stid)));
2086 } else {
2087 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2088 , __func__, parent_ep, hwtid,
2089 local_ip, peer_ip, ntohs(local_port),
2090 ntohs(peer_port), peer_mss);
2091 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2092 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2093 ((struct sockaddr_in6 *)
2094 &parent_ep->com.local_addr)->sin6_scope_id);
2095 }
2096 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002097 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2098 __func__);
2099 goto reject;
2100 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002101
2102 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2103 if (!child_ep) {
2104 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2105 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002106 dst_release(dst);
2107 goto reject;
2108 }
David Miller3786cf12011-12-02 16:52:31 +00002109
Vipul Pandya830662f2013-07-04 16:10:47 +05302110 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002111 if (err) {
2112 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2113 __func__);
2114 dst_release(dst);
2115 kfree(child_ep);
2116 goto reject;
2117 }
2118
Vipul Pandya1cab7752012-12-10 09:30:55 +00002119 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2120 child_ep->mtu = peer_mss + 40;
2121
Steve Wisecfdda9d2010-04-21 15:30:06 -07002122 state_set(&child_ep->com, CONNECTING);
2123 child_ep->com.dev = dev;
2124 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302125 if (iptype == 4) {
2126 struct sockaddr_in *sin = (struct sockaddr_in *)
2127 &child_ep->com.local_addr;
2128 sin->sin_family = PF_INET;
2129 sin->sin_port = local_port;
2130 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2131 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2132 sin->sin_family = PF_INET;
2133 sin->sin_port = peer_port;
2134 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2135 } else {
2136 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2137 &child_ep->com.local_addr;
2138 sin6->sin6_family = PF_INET6;
2139 sin6->sin6_port = local_port;
2140 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2141 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2142 sin6->sin6_family = PF_INET6;
2143 sin6->sin6_port = peer_port;
2144 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2145 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002146 c4iw_get_ep(&parent_ep->com);
2147 child_ep->parent_ep = parent_ep;
2148 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149 child_ep->dst = dst;
2150 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002151
2152 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002153 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002154
2155 init_timer(&child_ep->timer);
2156 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002157 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302158 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002159 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002160 goto out;
2161reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302162 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002163out:
2164 return 0;
2165}
2166
2167static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2168{
2169 struct c4iw_ep *ep;
2170 struct cpl_pass_establish *req = cplhdr(skb);
2171 struct tid_info *t = dev->rdev.lldi.tids;
2172 unsigned int tid = GET_TID(req);
2173
2174 ep = lookup_tid(t, tid);
2175 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2176 ep->snd_seq = be32_to_cpu(req->snd_isn);
2177 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2178
Vipul Pandya1cab7752012-12-10 09:30:55 +00002179 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2180 ntohs(req->tcp_opt));
2181
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182 set_emss(ep, ntohs(req->tcp_opt));
2183
2184 dst_confirm(ep->dst);
2185 state_set(&ep->com, MPA_REQ_WAIT);
2186 start_ep_timer(ep);
2187 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002188 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002189
2190 return 0;
2191}
2192
2193static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2194{
2195 struct cpl_peer_close *hdr = cplhdr(skb);
2196 struct c4iw_ep *ep;
2197 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198 int disconnect = 1;
2199 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002200 struct tid_info *t = dev->rdev.lldi.tids;
2201 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002202 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203
2204 ep = lookup_tid(t, tid);
2205 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2206 dst_confirm(ep->dst);
2207
Vipul Pandya793dad92012-12-10 09:30:56 +00002208 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002209 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002210 switch (ep->com.state) {
2211 case MPA_REQ_WAIT:
2212 __state_set(&ep->com, CLOSING);
2213 break;
2214 case MPA_REQ_SENT:
2215 __state_set(&ep->com, CLOSING);
2216 connect_reply_upcall(ep, -ECONNRESET);
2217 break;
2218 case MPA_REQ_RCVD:
2219
2220 /*
2221 * We're gonna mark this puppy DEAD, but keep
2222 * the reference on it until the ULP accepts or
2223 * rejects the CR. Also wake up anyone waiting
2224 * in rdma connection migration (see c4iw_accept_cr()).
2225 */
2226 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002227 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002228 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229 break;
2230 case MPA_REP_SENT:
2231 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002232 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002233 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234 break;
2235 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002236 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002237 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002238 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002239 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002240 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002241 if (ret != -ECONNRESET) {
2242 peer_close_upcall(ep);
2243 disconnect = 1;
2244 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245 break;
2246 case ABORTING:
2247 disconnect = 0;
2248 break;
2249 case CLOSING:
2250 __state_set(&ep->com, MORIBUND);
2251 disconnect = 0;
2252 break;
2253 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002254 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002255 if (ep->com.cm_id && ep->com.qp) {
2256 attrs.next_state = C4IW_QP_STATE_IDLE;
2257 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2258 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2259 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302260 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002261 __state_set(&ep->com, DEAD);
2262 release = 1;
2263 disconnect = 0;
2264 break;
2265 case DEAD:
2266 disconnect = 0;
2267 break;
2268 default:
2269 BUG_ON(1);
2270 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002271 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 if (disconnect)
2273 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2274 if (release)
2275 release_ep_resources(ep);
2276 return 0;
2277}
2278
2279/*
2280 * Returns whether an ABORT_REQ_RSS message is a negative advice.
2281 */
2282static int is_neg_adv_abort(unsigned int status)
2283{
2284 return status == CPL_ERR_RTX_NEG_ADVICE ||
2285 status == CPL_ERR_PERSIST_NEG_ADVICE;
2286}
2287
2288static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2289{
2290 struct cpl_abort_req_rss *req = cplhdr(skb);
2291 struct c4iw_ep *ep;
2292 struct cpl_abort_rpl *rpl;
2293 struct sk_buff *rpl_skb;
2294 struct c4iw_qp_attributes attrs;
2295 int ret;
2296 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 struct tid_info *t = dev->rdev.lldi.tids;
2298 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299
2300 ep = lookup_tid(t, tid);
2301 if (is_neg_adv_abort(req->status)) {
2302 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2303 ep->hwtid);
2304 return 0;
2305 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002306 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2307 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002308 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002309
2310 /*
2311 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302312 * However, this is not needed if com state is just
2313 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002314 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302315 if (ep->com.state != MPA_REQ_SENT)
2316 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002317
2318 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319 switch (ep->com.state) {
2320 case CONNECTING:
2321 break;
2322 case MPA_REQ_WAIT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002323 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324 break;
2325 case MPA_REQ_SENT:
Steve Wiseca5a2202010-07-23 19:12:37 +00002326 stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002327 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302328 connect_reply_upcall(ep, -ECONNRESET);
2329 else {
2330 /*
2331 * we just don't send notification upwards because we
2332 * want to retry with mpa_v1 without upper layers even
2333 * knowing it.
2334 *
2335 * do some housekeeping so as to re-initiate the
2336 * connection
2337 */
2338 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2339 mpa_rev);
2340 ep->retry_with_mpa_v1 = 1;
2341 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 break;
2343 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 break;
2345 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346 break;
2347 case MORIBUND:
2348 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002349 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 /*FALLTHROUGH*/
2351 case FPDU_MODE:
2352 if (ep->com.cm_id && ep->com.qp) {
2353 attrs.next_state = C4IW_QP_STATE_ERROR;
2354 ret = c4iw_modify_qp(ep->com.qp->rhp,
2355 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2356 &attrs, 1);
2357 if (ret)
2358 printk(KERN_ERR MOD
2359 "%s - qp <- error failed!\n",
2360 __func__);
2361 }
2362 peer_abort_upcall(ep);
2363 break;
2364 case ABORTING:
2365 break;
2366 case DEAD:
2367 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002368 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369 return 0;
2370 default:
2371 BUG_ON(1);
2372 break;
2373 }
2374 dst_confirm(ep->dst);
2375 if (ep->com.state != ABORTING) {
2376 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302377 /* we don't release if we want to retry with mpa_v1 */
2378 if (!ep->retry_with_mpa_v1)
2379 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002381 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002382
2383 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2384 if (!rpl_skb) {
2385 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2386 __func__);
2387 release = 1;
2388 goto out;
2389 }
2390 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2391 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2392 INIT_TP_WR(rpl, ep->hwtid);
2393 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2394 rpl->cmd = CPL_ABORT_NO_RST;
2395 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2396out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002397 if (release)
2398 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002399 else if (ep->retry_with_mpa_v1) {
2400 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302401 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2402 dst_release(ep->dst);
2403 cxgb4_l2t_release(ep->l2t);
2404 c4iw_reconnect(ep);
2405 }
2406
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407 return 0;
2408}
2409
2410static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2411{
2412 struct c4iw_ep *ep;
2413 struct c4iw_qp_attributes attrs;
2414 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415 int release = 0;
2416 struct tid_info *t = dev->rdev.lldi.tids;
2417 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
2419 ep = lookup_tid(t, tid);
2420
2421 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2422 BUG_ON(!ep);
2423
2424 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002425 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 switch (ep->com.state) {
2427 case CLOSING:
2428 __state_set(&ep->com, MORIBUND);
2429 break;
2430 case MORIBUND:
Steve Wiseca5a2202010-07-23 19:12:37 +00002431 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 if ((ep->com.cm_id) && (ep->com.qp)) {
2433 attrs.next_state = C4IW_QP_STATE_IDLE;
2434 c4iw_modify_qp(ep->com.qp->rhp,
2435 ep->com.qp,
2436 C4IW_QP_ATTR_NEXT_STATE,
2437 &attrs, 1);
2438 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302439 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 __state_set(&ep->com, DEAD);
2441 release = 1;
2442 break;
2443 case ABORTING:
2444 case DEAD:
2445 break;
2446 default:
2447 BUG_ON(1);
2448 break;
2449 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002450 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 if (release)
2452 release_ep_resources(ep);
2453 return 0;
2454}
2455
2456static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2457{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002458 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002460 unsigned int tid = GET_TID(rpl);
2461 struct c4iw_ep *ep;
2462 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002463
2464 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002465 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466
Steve Wise30c95c22011-05-09 22:06:22 -07002467 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002468 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2469 ep->com.qp->wq.sq.qid);
2470 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2471 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2472 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2473 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002474 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475
Steve Wisecfdda9d2010-04-21 15:30:06 -07002476 return 0;
2477}
2478
2479/*
2480 * Upcall from the adapter indicating data has been transmitted.
2481 * For us its just the single MPA request or reply. We can now free
2482 * the skb holding the mpa message.
2483 */
2484static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2485{
2486 struct c4iw_ep *ep;
2487 struct cpl_fw4_ack *hdr = cplhdr(skb);
2488 u8 credits = hdr->credits;
2489 unsigned int tid = GET_TID(hdr);
2490 struct tid_info *t = dev->rdev.lldi.tids;
2491
2492
2493 ep = lookup_tid(t, tid);
2494 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2495 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002496 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2497 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002498 return 0;
2499 }
2500
2501 dst_confirm(ep->dst);
2502 if (ep->mpa_skb) {
2503 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2504 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2505 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2506 kfree_skb(ep->mpa_skb);
2507 ep->mpa_skb = NULL;
2508 }
2509 return 0;
2510}
2511
Steve Wisecfdda9d2010-04-21 15:30:06 -07002512int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2513{
2514 int err;
2515 struct c4iw_ep *ep = to_ep(cm_id);
2516 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2517
2518 if (state_read(&ep->com) == DEAD) {
2519 c4iw_put_ep(&ep->com);
2520 return -ECONNRESET;
2521 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002522 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2524 if (mpa_rev == 0)
2525 abort_connection(ep, NULL, GFP_KERNEL);
2526 else {
2527 err = send_mpa_reject(ep, pdata, pdata_len);
2528 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2529 }
2530 c4iw_put_ep(&ep->com);
2531 return 0;
2532}
2533
2534int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2535{
2536 int err;
2537 struct c4iw_qp_attributes attrs;
2538 enum c4iw_qp_attr_mask mask;
2539 struct c4iw_ep *ep = to_ep(cm_id);
2540 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2541 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2542
2543 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2544 if (state_read(&ep->com) == DEAD) {
2545 err = -ECONNRESET;
2546 goto err;
2547 }
2548
2549 BUG_ON(state_read(&ep->com) != MPA_REQ_RCVD);
2550 BUG_ON(!qp);
2551
Vipul Pandya793dad92012-12-10 09:30:56 +00002552 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002553 if ((conn_param->ord > c4iw_max_read_depth) ||
2554 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 abort_connection(ep, NULL, GFP_KERNEL);
2556 err = -EINVAL;
2557 goto err;
2558 }
2559
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302560 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2561 if (conn_param->ord > ep->ird) {
2562 ep->ird = conn_param->ird;
2563 ep->ord = conn_param->ord;
2564 send_mpa_reject(ep, conn_param->private_data,
2565 conn_param->private_data_len);
2566 abort_connection(ep, NULL, GFP_KERNEL);
2567 err = -ENOMEM;
2568 goto err;
2569 }
2570 if (conn_param->ird > ep->ord) {
2571 if (!ep->ord)
2572 conn_param->ird = 1;
2573 else {
2574 abort_connection(ep, NULL, GFP_KERNEL);
2575 err = -ENOMEM;
2576 goto err;
2577 }
2578 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002579
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302580 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581 ep->ird = conn_param->ird;
2582 ep->ord = conn_param->ord;
2583
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302584 if (ep->mpa_attr.version != 2)
2585 if (peer2peer && ep->ird == 0)
2586 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002587
2588 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2589
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302590 cm_id->add_ref(cm_id);
2591 ep->com.cm_id = cm_id;
2592 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002593 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302594
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 /* bind QP to EP and move to RTS */
2596 attrs.mpa_attr = ep->mpa_attr;
2597 attrs.max_ird = ep->ird;
2598 attrs.max_ord = ep->ord;
2599 attrs.llp_stream_handle = ep;
2600 attrs.next_state = C4IW_QP_STATE_RTS;
2601
2602 /* bind QP and TID with INIT_WR */
2603 mask = C4IW_QP_ATTR_NEXT_STATE |
2604 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2605 C4IW_QP_ATTR_MPA_ATTR |
2606 C4IW_QP_ATTR_MAX_IRD |
2607 C4IW_QP_ATTR_MAX_ORD;
2608
2609 err = c4iw_modify_qp(ep->com.qp->rhp,
2610 ep->com.qp, mask, &attrs, 1);
2611 if (err)
2612 goto err1;
2613 err = send_mpa_reply(ep, conn_param->private_data,
2614 conn_param->private_data_len);
2615 if (err)
2616 goto err1;
2617
2618 state_set(&ep->com, FPDU_MODE);
2619 established_upcall(ep);
2620 c4iw_put_ep(&ep->com);
2621 return 0;
2622err1:
2623 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 cm_id->rem_ref(cm_id);
2625err:
2626 c4iw_put_ep(&ep->com);
2627 return err;
2628}
2629
Vipul Pandya830662f2013-07-04 16:10:47 +05302630static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2631{
2632 struct in_device *ind;
2633 int found = 0;
2634 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2635 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2636
2637 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2638 if (!ind)
2639 return -EADDRNOTAVAIL;
2640 for_primary_ifa(ind) {
2641 laddr->sin_addr.s_addr = ifa->ifa_address;
2642 raddr->sin_addr.s_addr = ifa->ifa_address;
2643 found = 1;
2644 break;
2645 }
2646 endfor_ifa(ind);
2647 in_dev_put(ind);
2648 return found ? 0 : -EADDRNOTAVAIL;
2649}
2650
2651static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2652 unsigned char banned_flags)
2653{
2654 struct inet6_dev *idev;
2655 int err = -EADDRNOTAVAIL;
2656
2657 rcu_read_lock();
2658 idev = __in6_dev_get(dev);
2659 if (idev != NULL) {
2660 struct inet6_ifaddr *ifp;
2661
2662 read_lock_bh(&idev->lock);
2663 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2664 if (ifp->scope == IFA_LINK &&
2665 !(ifp->flags & banned_flags)) {
2666 memcpy(addr, &ifp->addr, 16);
2667 err = 0;
2668 break;
2669 }
2670 }
2671 read_unlock_bh(&idev->lock);
2672 }
2673 rcu_read_unlock();
2674 return err;
2675}
2676
2677static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2678{
2679 struct in6_addr uninitialized_var(addr);
2680 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2681 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2682
2683 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2684 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2685 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2686 return 0;
2687 }
2688 return -EADDRNOTAVAIL;
2689}
2690
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2692{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2694 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002695 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302696 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2697 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302698 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2699 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2700 &cm_id->remote_addr;
2701 __u8 *ra;
2702 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002704 if ((conn_param->ord > c4iw_max_read_depth) ||
2705 (conn_param->ird > c4iw_max_read_depth)) {
2706 err = -EINVAL;
2707 goto out;
2708 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2710 if (!ep) {
2711 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2712 err = -ENOMEM;
2713 goto out;
2714 }
2715 init_timer(&ep->timer);
2716 ep->plen = conn_param->private_data_len;
2717 if (ep->plen)
2718 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2719 conn_param->private_data, ep->plen);
2720 ep->ird = conn_param->ird;
2721 ep->ord = conn_param->ord;
2722
2723 if (peer2peer && ep->ord == 0)
2724 ep->ord = 1;
2725
2726 cm_id->add_ref(cm_id);
2727 ep->com.dev = dev;
2728 ep->com.cm_id = cm_id;
2729 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302730 if (!ep->com.qp) {
2731 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2732 err = -EINVAL;
2733 goto fail2;
2734 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002735 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2737 ep->com.qp, cm_id);
2738
2739 /*
2740 * Allocate an active TID to initiate a TCP connection.
2741 */
2742 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2743 if (ep->atid == -1) {
2744 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2745 err = -ENOMEM;
2746 goto fail2;
2747 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002748 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002749
Vipul Pandya830662f2013-07-04 16:10:47 +05302750 if (cm_id->remote_addr.ss_family == AF_INET) {
2751 iptype = 4;
2752 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753
Vipul Pandya830662f2013-07-04 16:10:47 +05302754 /*
2755 * Handle loopback requests to INADDR_ANY.
2756 */
2757 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2758 err = pick_local_ipaddrs(dev, cm_id);
2759 if (err)
2760 goto fail2;
2761 }
2762
2763 /* find a route */
2764 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2765 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2766 ra, ntohs(raddr->sin_port));
2767 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2768 raddr->sin_addr.s_addr, laddr->sin_port,
2769 raddr->sin_port, 0);
2770 } else {
2771 iptype = 6;
2772 ra = (__u8 *)&raddr6->sin6_addr;
2773
2774 /*
2775 * Handle loopback requests to INADDR_ANY.
2776 */
2777 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2778 err = pick_local_ip6addrs(dev, cm_id);
2779 if (err)
2780 goto fail2;
2781 }
2782
2783 /* find a route */
2784 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2785 __func__, laddr6->sin6_addr.s6_addr,
2786 ntohs(laddr6->sin6_port),
2787 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2788 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2789 raddr6->sin6_addr.s6_addr,
2790 laddr6->sin6_port, raddr6->sin6_port, 0,
2791 raddr6->sin6_scope_id);
2792 }
2793 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2795 err = -EHOSTUNREACH;
2796 goto fail3;
2797 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798
Vipul Pandya830662f2013-07-04 16:10:47 +05302799 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00002800 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002801 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002802 goto fail4;
2803 }
2804
2805 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2806 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2807 ep->l2t->idx);
2808
2809 state_set(&ep->com, CONNECTING);
2810 ep->tos = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302811 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2812 sizeof(ep->com.local_addr));
2813 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2814 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002815
2816 /* send connect request to rnic */
2817 err = send_connect(ep);
2818 if (!err)
2819 goto out;
2820
2821 cxgb4_l2t_release(ep->l2t);
2822fail4:
2823 dst_release(ep->dst);
2824fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002825 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2827fail2:
2828 cm_id->rem_ref(cm_id);
2829 c4iw_put_ep(&ep->com);
2830out:
2831 return err;
2832}
2833
Vipul Pandya830662f2013-07-04 16:10:47 +05302834static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2835{
2836 int err;
2837 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2838
2839 c4iw_init_wr_wait(&ep->com.wr_wait);
2840 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2841 ep->stid, &sin6->sin6_addr,
2842 sin6->sin6_port,
2843 ep->com.dev->rdev.lldi.rxq_ids[0]);
2844 if (!err)
2845 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2846 &ep->com.wr_wait,
2847 0, 0, __func__);
2848 if (err)
2849 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2850 err, ep->stid,
2851 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2852 return err;
2853}
2854
2855static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2856{
2857 int err;
2858 struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
2859
2860 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2861 do {
2862 err = cxgb4_create_server_filter(
2863 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2864 sin->sin_addr.s_addr, sin->sin_port, 0,
2865 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2866 if (err == -EBUSY) {
2867 set_current_state(TASK_UNINTERRUPTIBLE);
2868 schedule_timeout(usecs_to_jiffies(100));
2869 }
2870 } while (err == -EBUSY);
2871 } else {
2872 c4iw_init_wr_wait(&ep->com.wr_wait);
2873 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2874 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2875 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2876 if (!err)
2877 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2878 &ep->com.wr_wait,
2879 0, 0, __func__);
2880 }
2881 if (err)
2882 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
2883 , err, ep->stid,
2884 &sin->sin_addr, ntohs(sin->sin_port));
2885 return err;
2886}
2887
Steve Wisecfdda9d2010-04-21 15:30:06 -07002888int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2889{
2890 int err = 0;
2891 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2892 struct c4iw_listen_ep *ep;
2893
Steve Wisecfdda9d2010-04-21 15:30:06 -07002894 might_sleep();
2895
2896 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2897 if (!ep) {
2898 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2899 err = -ENOMEM;
2900 goto fail1;
2901 }
2902 PDBG("%s ep %p\n", __func__, ep);
2903 cm_id->add_ref(cm_id);
2904 ep->com.cm_id = cm_id;
2905 ep->com.dev = dev;
2906 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05302907 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2908 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909
2910 /*
2911 * Allocate a server TID.
2912 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05302913 if (dev->rdev.lldi.enable_fw_ofld_conn &&
2914 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05302915 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
2916 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002917 else
Vipul Pandya830662f2013-07-04 16:10:47 +05302918 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
2919 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002920
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002922 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 err = -ENOMEM;
2924 goto fail2;
2925 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002926 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002927 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05302928 if (ep->com.local_addr.ss_family == AF_INET)
2929 err = create_server4(dev, ep);
2930 else
2931 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002932 if (!err) {
2933 cm_id->provider_data = ep;
2934 goto out;
2935 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302936 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2937 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938fail2:
2939 cm_id->rem_ref(cm_id);
2940 c4iw_put_ep(&ep->com);
2941fail1:
2942out:
2943 return err;
2944}
2945
2946int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2947{
2948 int err;
2949 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2950
2951 PDBG("%s ep %p\n", __func__, ep);
2952
2953 might_sleep();
2954 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05302955 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
2956 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002957 err = cxgb4_remove_server_filter(
2958 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2959 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2960 } else {
2961 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05302962 err = cxgb4_remove_server(
2963 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2964 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002965 if (err)
2966 goto done;
2967 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2968 0, 0, __func__);
2969 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002970 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302971 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2972 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974 cm_id->rem_ref(cm_id);
2975 c4iw_put_ep(&ep->com);
2976 return err;
2977}
2978
2979int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
2980{
2981 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002982 int close = 0;
2983 int fatal = 0;
2984 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985
Steve Wise2f5b48c2010-09-10 11:15:36 -05002986 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002987
2988 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
2989 states[ep->com.state], abrupt);
2990
2991 rdev = &ep->com.dev->rdev;
2992 if (c4iw_fatal_error(rdev)) {
2993 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05302994 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002995 ep->com.state = DEAD;
2996 }
2997 switch (ep->com.state) {
2998 case MPA_REQ_WAIT:
2999 case MPA_REQ_SENT:
3000 case MPA_REQ_RCVD:
3001 case MPA_REP_SENT:
3002 case FPDU_MODE:
3003 close = 1;
3004 if (abrupt)
3005 ep->com.state = ABORTING;
3006 else {
3007 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003008 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 }
3010 set_bit(CLOSE_SENT, &ep->com.flags);
3011 break;
3012 case CLOSING:
3013 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3014 close = 1;
3015 if (abrupt) {
Steve Wiseca5a2202010-07-23 19:12:37 +00003016 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003017 ep->com.state = ABORTING;
3018 } else
3019 ep->com.state = MORIBUND;
3020 }
3021 break;
3022 case MORIBUND:
3023 case ABORTING:
3024 case DEAD:
3025 PDBG("%s ignoring disconnect ep %p state %u\n",
3026 __func__, ep, ep->com.state);
3027 break;
3028 default:
3029 BUG();
3030 break;
3031 }
3032
Steve Wisecfdda9d2010-04-21 15:30:06 -07003033 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003034 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003035 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303036 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003037 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003038 } else {
3039 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003040 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003041 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042 if (ret)
3043 fatal = 1;
3044 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003045 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003046 if (fatal)
3047 release_ep_resources(ep);
3048 return ret;
3049}
3050
Vipul Pandya1cab7752012-12-10 09:30:55 +00003051static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3052 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3053{
3054 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003055 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003056
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003057 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3058 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003059 if (!ep)
3060 return;
3061
3062 switch (req->retval) {
3063 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003064 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3065 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3066 send_fw_act_open_req(ep, atid);
3067 return;
3068 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003069 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003070 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3071 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3072 send_fw_act_open_req(ep, atid);
3073 return;
3074 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003075 break;
3076 default:
3077 pr_info("%s unexpected ofld conn wr retval %d\n",
3078 __func__, req->retval);
3079 break;
3080 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003081 pr_err("active ofld_connect_wr failure %d atid %d\n",
3082 req->retval, atid);
3083 mutex_lock(&dev->rdev.stats.lock);
3084 dev->rdev.stats.act_ofld_conn_fails++;
3085 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003086 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003087 state_set(&ep->com, DEAD);
3088 remove_handle(dev, &dev->atid_idr, atid);
3089 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3090 dst_release(ep->dst);
3091 cxgb4_l2t_release(ep->l2t);
3092 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003093}
3094
3095static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3096 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3097{
3098 struct sk_buff *rpl_skb;
3099 struct cpl_pass_accept_req *cpl;
3100 int ret;
3101
Paul Bolle710a3112013-02-05 20:51:30 +00003102 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003103 BUG_ON(!rpl_skb);
3104 if (req->retval) {
3105 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003106 mutex_lock(&dev->rdev.stats.lock);
3107 dev->rdev.stats.pas_ofld_conn_fails++;
3108 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003109 kfree_skb(rpl_skb);
3110 } else {
3111 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3112 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003113 (__force u32) htonl(
3114 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003115 ret = pass_accept_req(dev, rpl_skb);
3116 if (!ret)
3117 kfree_skb(rpl_skb);
3118 }
3119 return;
3120}
3121
3122static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003123{
3124 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003125 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3126
3127 switch (rpl->type) {
3128 case FW6_TYPE_CQE:
3129 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3130 break;
3131 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3132 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3133 switch (req->t_state) {
3134 case TCP_SYN_SENT:
3135 active_ofld_conn_reply(dev, skb, req);
3136 break;
3137 case TCP_SYN_RECV:
3138 passive_ofld_conn_reply(dev, skb, req);
3139 break;
3140 default:
3141 pr_err("%s unexpected ofld conn wr state %d\n",
3142 __func__, req->t_state);
3143 break;
3144 }
3145 break;
3146 }
3147 return 0;
3148}
3149
3150static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3151{
3152 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003153 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003154 u8 intf;
3155 struct cpl_rx_pkt *cpl = cplhdr(skb);
3156 struct cpl_pass_accept_req *req;
3157 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003158 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003159
Vipul Pandyaf079af72013-03-14 05:08:58 +00003160 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003161 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003162 vlantag = (__force u16) cpl->vlan;
3163 len = (__force u16) cpl->len;
3164 l2info = (__force u32) cpl->l2info;
3165 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003166 intf = cpl->iff;
3167
3168 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3169
3170 /*
3171 * We need to parse the TCP options from SYN packet.
3172 * to generate cpl_pass_accept_req.
3173 */
3174 memset(&tmp_opt, 0, sizeof(tmp_opt));
3175 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003176 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003177
3178 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3179 memset(req, 0, sizeof(*req));
3180 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003181 V_SYN_MAC_IDX(G_RX_MACIDX(
3182 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003183 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003184 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3185 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3186 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003187 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3188 (__force int) htonl(l2info))) |
3189 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3190 (__force int) htons(hdr_len))) |
3191 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3192 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003193 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003194 req->vlan = (__force __be16) vlantag;
3195 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003196 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3197 PASS_OPEN_TOS(tos));
3198 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3199 if (tmp_opt.wscale_ok)
3200 req->tcpopt.wsf = tmp_opt.snd_wscale;
3201 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3202 if (tmp_opt.sack_ok)
3203 req->tcpopt.sack = 1;
3204 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3205 return;
3206}
3207
3208static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3209 __be32 laddr, __be16 lport,
3210 __be32 raddr, __be16 rport,
3211 u32 rcv_isn, u32 filter, u16 window,
3212 u32 rss_qid, u8 port_id)
3213{
3214 struct sk_buff *req_skb;
3215 struct fw_ofld_connection_wr *req;
3216 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303217 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003218
3219 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3220 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3221 memset(req, 0, sizeof(*req));
3222 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3223 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3224 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003225 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003226 req->le.lport = lport;
3227 req->le.pport = rport;
3228 req->le.u.ipv4.lip = laddr;
3229 req->le.u.ipv4.pip = raddr;
3230 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3231 req->tcb.rcv_adv = htons(window);
3232 req->tcb.t_state_to_astid =
3233 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3234 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3235 V_FW_OFLD_CONNECTION_WR_ASTID(
3236 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3237
3238 /*
3239 * We store the qid in opt2 which will be used by the firmware
3240 * to send us the wr response.
3241 */
3242 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3243
3244 /*
3245 * We initialize the MSS index in TCB to 0xF.
3246 * So that when driver sends cpl_pass_accept_rpl
3247 * TCB picks up the correct value. If this was 0
3248 * TP will ignore any value > 0 for MSS index.
3249 */
3250 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003251 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003252
3253 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303254 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3255 if (ret < 0) {
3256 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3257 ret);
3258 kfree_skb(skb);
3259 kfree_skb(req_skb);
3260 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003261}
3262
3263/*
3264 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3265 * messages when a filter is being used instead of server to
3266 * redirect a syn packet. When packets hit filter they are redirected
3267 * to the offload queue and driver tries to establish the connection
3268 * using firmware work request.
3269 */
3270static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3271{
3272 int stid;
3273 unsigned int filter;
3274 struct ethhdr *eh = NULL;
3275 struct vlan_ethhdr *vlan_eh = NULL;
3276 struct iphdr *iph;
3277 struct tcphdr *tcph;
3278 struct rss_header *rss = (void *)skb->data;
3279 struct cpl_rx_pkt *cpl = (void *)skb->data;
3280 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3281 struct l2t_entry *e;
3282 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003283 struct c4iw_ep *lep;
3284 u16 window;
3285 struct port_info *pi;
3286 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003287 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003288 int step;
3289 u32 tx_chan;
3290 struct neighbour *neigh;
3291
3292 /* Drop all non-SYN packets */
3293 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3294 goto reject;
3295
3296 /*
3297 * Drop all packets which did not hit the filter.
3298 * Unlikely to happen.
3299 */
3300 if (!(rss->filter_hit && rss->filter_tid))
3301 goto reject;
3302
3303 /*
3304 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3305 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303306 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003307
3308 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3309 if (!lep) {
3310 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3311 goto reject;
3312 }
3313
Vipul Pandyaf079af72013-03-14 05:08:58 +00003314 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3315 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3316 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3317 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003318 eh = (struct ethhdr *)(req + 1);
3319 iph = (struct iphdr *)(eh + 1);
3320 } else {
3321 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3322 iph = (struct iphdr *)(vlan_eh + 1);
3323 skb->vlan_tci = ntohs(cpl->vlan);
3324 }
3325
3326 if (iph->version != 0x4)
3327 goto reject;
3328
3329 tcph = (struct tcphdr *)(iph + 1);
3330 skb_set_network_header(skb, (void *)iph - (void *)rss);
3331 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3332 skb_get(skb);
3333
3334 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3335 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3336 ntohs(tcph->source), iph->tos);
3337
Vipul Pandya830662f2013-07-04 16:10:47 +05303338 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3339 iph->tos);
3340 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003341 pr_err("%s - failed to find dst entry!\n",
3342 __func__);
3343 goto reject;
3344 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003345 neigh = dst_neigh_lookup_skb(dst, skb);
3346
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003347 if (!neigh) {
3348 pr_err("%s - failed to allocate neigh!\n",
3349 __func__);
3350 goto free_dst;
3351 }
3352
Vipul Pandya1cab7752012-12-10 09:30:55 +00003353 if (neigh->dev->flags & IFF_LOOPBACK) {
3354 pdev = ip_dev_find(&init_net, iph->daddr);
3355 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3356 pdev, 0);
3357 pi = (struct port_info *)netdev_priv(pdev);
3358 tx_chan = cxgb4_port_chan(pdev);
3359 dev_put(pdev);
3360 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303361 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003362 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303363 pdev, 0);
3364 pi = (struct port_info *)netdev_priv(pdev);
3365 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003366 }
Steve Wiseebf00062014-03-19 17:44:40 +05303367 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003368 if (!e) {
3369 pr_err("%s - failed to allocate l2t entry!\n",
3370 __func__);
3371 goto free_dst;
3372 }
3373
3374 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3375 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003376 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003377
3378 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303379 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3380 dev->rdev.lldi.ports[0],
3381 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003382
3383 /*
3384 * Synthesize the cpl_pass_accept_req. We have everything except the
3385 * TID. Once firmware sends a reply with TID we update the TID field
3386 * in cpl and pass it through the regular cpl_pass_accept_req path.
3387 */
3388 build_cpl_pass_accept_req(skb, stid, iph->tos);
3389 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3390 tcph->source, ntohl(tcph->seq), filter, window,
3391 rss_qid, pi->port_id);
3392 cxgb4_l2t_release(e);
3393free_dst:
3394 dst_release(dst);
3395reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003396 return 0;
3397}
3398
Steve Wisecfdda9d2010-04-21 15:30:06 -07003399/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003400 * These are the real handlers that are called from a
3401 * work queue.
3402 */
3403static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3404 [CPL_ACT_ESTABLISH] = act_establish,
3405 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3406 [CPL_RX_DATA] = rx_data,
3407 [CPL_ABORT_RPL_RSS] = abort_rpl,
3408 [CPL_ABORT_RPL] = abort_rpl,
3409 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3410 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3411 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3412 [CPL_PASS_ESTABLISH] = pass_establish,
3413 [CPL_PEER_CLOSE] = peer_close,
3414 [CPL_ABORT_REQ_RSS] = peer_abort,
3415 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3416 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003417 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003418 [CPL_FW6_MSG] = deferred_fw6_msg,
3419 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003420};
3421
3422static void process_timeout(struct c4iw_ep *ep)
3423{
3424 struct c4iw_qp_attributes attrs;
3425 int abort = 1;
3426
Steve Wise2f5b48c2010-09-10 11:15:36 -05003427 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003428 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3429 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003430 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003431 switch (ep->com.state) {
3432 case MPA_REQ_SENT:
3433 __state_set(&ep->com, ABORTING);
3434 connect_reply_upcall(ep, -ETIMEDOUT);
3435 break;
3436 case MPA_REQ_WAIT:
3437 __state_set(&ep->com, ABORTING);
3438 break;
3439 case CLOSING:
3440 case MORIBUND:
3441 if (ep->com.cm_id && ep->com.qp) {
3442 attrs.next_state = C4IW_QP_STATE_ERROR;
3443 c4iw_modify_qp(ep->com.qp->rhp,
3444 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3445 &attrs, 1);
3446 }
3447 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303448 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003449 break;
3450 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003451 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003452 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003453 abort = 0;
3454 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003455 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003456 if (abort)
3457 abort_connection(ep, NULL, GFP_KERNEL);
3458 c4iw_put_ep(&ep->com);
3459}
3460
3461static void process_timedout_eps(void)
3462{
3463 struct c4iw_ep *ep;
3464
3465 spin_lock_irq(&timeout_lock);
3466 while (!list_empty(&timeout_list)) {
3467 struct list_head *tmp;
3468
3469 tmp = timeout_list.next;
3470 list_del(tmp);
3471 spin_unlock_irq(&timeout_lock);
3472 ep = list_entry(tmp, struct c4iw_ep, entry);
3473 process_timeout(ep);
3474 spin_lock_irq(&timeout_lock);
3475 }
3476 spin_unlock_irq(&timeout_lock);
3477}
3478
3479static void process_work(struct work_struct *work)
3480{
3481 struct sk_buff *skb = NULL;
3482 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003483 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003484 unsigned int opcode;
3485 int ret;
3486
3487 while ((skb = skb_dequeue(&rxq))) {
3488 rpl = cplhdr(skb);
3489 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3490 opcode = rpl->ot.opcode;
3491
3492 BUG_ON(!work_handlers[opcode]);
3493 ret = work_handlers[opcode](dev, skb);
3494 if (!ret)
3495 kfree_skb(skb);
3496 }
3497 process_timedout_eps();
3498}
3499
3500static DECLARE_WORK(skb_work, process_work);
3501
3502static void ep_timeout(unsigned long arg)
3503{
3504 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003505 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003506
3507 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003508 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
3509 list_add_tail(&ep->entry, &timeout_list);
3510 kickit = 1;
3511 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003512 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003513 if (kickit)
3514 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003515}
3516
3517/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 * All the CM events are handled on a work queue to have a safe context.
3519 */
3520static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3521{
3522
3523 /*
3524 * Save dev in the skb->cb area.
3525 */
3526 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3527
3528 /*
3529 * Queue the skb and schedule the worker thread.
3530 */
3531 skb_queue_tail(&rxq, skb);
3532 queue_work(workq, &skb_work);
3533 return 0;
3534}
3535
3536static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3537{
3538 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3539
3540 if (rpl->status != CPL_ERR_NONE) {
3541 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3542 "for tid %u\n", rpl->status, GET_TID(rpl));
3543 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003544 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003545 return 0;
3546}
3547
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003548static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3549{
3550 struct cpl_fw6_msg *rpl = cplhdr(skb);
3551 struct c4iw_wr_wait *wr_waitp;
3552 int ret;
3553
3554 PDBG("%s type %u\n", __func__, rpl->type);
3555
3556 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003557 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003558 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003559 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003560 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003561 if (wr_waitp)
3562 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003563 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003564 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003565 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003566 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003567 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003568 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003569 default:
3570 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3571 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003572 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003573 break;
3574 }
3575 return 0;
3576}
3577
Steve Wise8da7e7a2011-06-14 20:59:27 +00003578static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3579{
3580 struct cpl_abort_req_rss *req = cplhdr(skb);
3581 struct c4iw_ep *ep;
3582 struct tid_info *t = dev->rdev.lldi.tids;
3583 unsigned int tid = GET_TID(req);
3584
3585 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003586 if (!ep) {
3587 printk(KERN_WARNING MOD
3588 "Abort on non-existent endpoint, tid %d\n", tid);
3589 kfree_skb(skb);
3590 return 0;
3591 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003592 if (is_neg_adv_abort(req->status)) {
3593 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3594 ep->hwtid);
3595 kfree_skb(skb);
3596 return 0;
3597 }
3598 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3599 ep->com.state);
3600
3601 /*
3602 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003603 * However, if we are on MPAv2 and want to retry with MPAv1
3604 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003605 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003606 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3607 if (ep->com.state != MPA_REQ_SENT)
3608 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3609 } else
3610 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003611 sched(dev, skb);
3612 return 0;
3613}
3614
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003615/*
3616 * Most upcalls from the T4 Core go to sched() to
3617 * schedule the processing on a work queue.
3618 */
3619c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3620 [CPL_ACT_ESTABLISH] = sched,
3621 [CPL_ACT_OPEN_RPL] = sched,
3622 [CPL_RX_DATA] = sched,
3623 [CPL_ABORT_RPL_RSS] = sched,
3624 [CPL_ABORT_RPL] = sched,
3625 [CPL_PASS_OPEN_RPL] = sched,
3626 [CPL_CLOSE_LISTSRV_RPL] = sched,
3627 [CPL_PASS_ACCEPT_REQ] = sched,
3628 [CPL_PASS_ESTABLISH] = sched,
3629 [CPL_PEER_CLOSE] = sched,
3630 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003631 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003632 [CPL_RDMA_TERMINATE] = sched,
3633 [CPL_FW4_ACK] = sched,
3634 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003635 [CPL_FW6_MSG] = fw6_msg,
3636 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003637};
3638
Steve Wisecfdda9d2010-04-21 15:30:06 -07003639int __init c4iw_cm_init(void)
3640{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003641 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003642 skb_queue_head_init(&rxq);
3643
3644 workq = create_singlethread_workqueue("iw_cxgb4");
3645 if (!workq)
3646 return -ENOMEM;
3647
Steve Wisecfdda9d2010-04-21 15:30:06 -07003648 return 0;
3649}
3650
3651void __exit c4iw_cm_term(void)
3652{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003653 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003654 flush_workqueue(workq);
3655 destroy_workqueue(workq);
3656}