blob: f9b04bc7e6026a850a1b4b6257407884e8e0674c [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
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500176static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700177{
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);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500180 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000181 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500182 return 0;
183 }
184 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700185}
186
187static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
188 struct l2t_entry *l2e)
189{
190 int error = 0;
191
192 if (c4iw_fatal_error(rdev)) {
193 kfree_skb(skb);
194 PDBG("%s - device in error state - dropping\n", __func__);
195 return -EIO;
196 }
197 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
198 if (error < 0)
199 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500200 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700201}
202
203int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
204{
205 int error = 0;
206
207 if (c4iw_fatal_error(rdev)) {
208 kfree_skb(skb);
209 PDBG("%s - device in error state - dropping\n", __func__);
210 return -EIO;
211 }
212 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
213 if (error < 0)
214 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500215 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700216}
217
218static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
219{
220 struct cpl_tid_release *req;
221
222 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
223 if (!skb)
224 return;
225 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
226 INIT_TP_WR(req, hwtid);
227 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
228 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
229 c4iw_ofld_send(rdev, skb);
230 return;
231}
232
233static void set_emss(struct c4iw_ep *ep, u16 opt)
234{
235 ep->emss = ep->com.dev->rdev.lldi.mtus[GET_TCPOPT_MSS(opt)] - 40;
236 ep->mss = ep->emss;
237 if (GET_TCPOPT_TSTAMP(opt))
238 ep->emss -= 12;
239 if (ep->emss < 128)
240 ep->emss = 128;
241 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, GET_TCPOPT_MSS(opt),
242 ep->mss, ep->emss);
243}
244
245static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
246{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700247 enum c4iw_ep_state state;
248
Steve Wise2f5b48c2010-09-10 11:15:36 -0500249 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700250 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500251 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700252 return state;
253}
254
255static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
256{
257 epc->state = new;
258}
259
260static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
261{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500262 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
264 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500265 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700266 return;
267}
268
269static void *alloc_ep(int size, gfp_t gfp)
270{
271 struct c4iw_ep_common *epc;
272
273 epc = kzalloc(size, gfp);
274 if (epc) {
275 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500276 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500277 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 }
279 PDBG("%s alloc ep %p\n", __func__, epc);
280 return epc;
281}
282
283void _c4iw_free_ep(struct kref *kref)
284{
285 struct c4iw_ep *ep;
286
287 ep = container_of(kref, struct c4iw_ep, com.kref);
288 PDBG("%s ep %p state %s\n", __func__, ep, states[state_read(&ep->com)]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000289 if (test_bit(QP_REFERENCED, &ep->com.flags))
290 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000292 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700293 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
294 dst_release(ep->dst);
295 cxgb4_l2t_release(ep->l2t);
296 }
297 kfree(ep);
298}
299
300static void release_ep_resources(struct c4iw_ep *ep)
301{
302 set_bit(RELEASE_RESOURCES, &ep->com.flags);
303 c4iw_put_ep(&ep->com);
304}
305
Steve Wisecfdda9d2010-04-21 15:30:06 -0700306static int status2errno(int status)
307{
308 switch (status) {
309 case CPL_ERR_NONE:
310 return 0;
311 case CPL_ERR_CONN_RESET:
312 return -ECONNRESET;
313 case CPL_ERR_ARP_MISS:
314 return -EHOSTUNREACH;
315 case CPL_ERR_CONN_TIMEDOUT:
316 return -ETIMEDOUT;
317 case CPL_ERR_TCAM_FULL:
318 return -ENOMEM;
319 case CPL_ERR_CONN_EXIST:
320 return -EADDRINUSE;
321 default:
322 return -EIO;
323 }
324}
325
326/*
327 * Try and reuse skbs already allocated...
328 */
329static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
330{
331 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
332 skb_trim(skb, 0);
333 skb_get(skb);
334 skb_reset_transport_header(skb);
335 } else {
336 skb = alloc_skb(len, gfp);
337 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530338 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700339 return skb;
340}
341
Vipul Pandya830662f2013-07-04 16:10:47 +0530342static struct net_device *get_real_dev(struct net_device *egress_dev)
343{
344 struct net_device *phys_dev = egress_dev;
345 if (egress_dev->priv_flags & IFF_802_1Q_VLAN)
346 phys_dev = vlan_dev_real_dev(egress_dev);
347 return phys_dev;
348}
349
350static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
351{
352 int i;
353
354 egress_dev = get_real_dev(egress_dev);
355 for (i = 0; i < dev->rdev.lldi.nports; i++)
356 if (dev->rdev.lldi.ports[i] == egress_dev)
357 return 1;
358 return 0;
359}
360
361static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
362 __u8 *peer_ip, __be16 local_port,
363 __be16 peer_port, u8 tos,
364 __u32 sin6_scope_id)
365{
366 struct dst_entry *dst = NULL;
367
368 if (IS_ENABLED(CONFIG_IPV6)) {
369 struct flowi6 fl6;
370
371 memset(&fl6, 0, sizeof(fl6));
372 memcpy(&fl6.daddr, peer_ip, 16);
373 memcpy(&fl6.saddr, local_ip, 16);
374 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
375 fl6.flowi6_oif = sin6_scope_id;
376 dst = ip6_route_output(&init_net, NULL, &fl6);
377 if (!dst)
378 goto out;
379 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
380 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
381 dst_release(dst);
382 dst = NULL;
383 }
384 }
385
386out:
387 return dst;
388}
389
390static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700391 __be32 peer_ip, __be16 local_port,
392 __be16 peer_port, u8 tos)
393{
394 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700395 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530396 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700397
David S. Miller31e4543d2011-05-03 20:25:42 -0700398 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500399 peer_port, local_port, IPPROTO_TCP,
400 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800401 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700402 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530403 n = dst_neigh_lookup(&rt->dst, &peer_ip);
404 if (!n)
405 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530406 if (!our_interface(dev, n->dev) &&
407 !(n->dev->flags & IFF_LOOPBACK)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530408 dst_release(&rt->dst);
409 return NULL;
410 }
411 neigh_release(n);
412 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700413}
414
415static void arp_failure_discard(void *handle, struct sk_buff *skb)
416{
417 PDBG("%s c4iw_dev %p\n", __func__, handle);
418 kfree_skb(skb);
419}
420
421/*
422 * Handle an ARP failure for an active open.
423 */
424static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
425{
426 printk(KERN_ERR MOD "ARP failure duing connect\n");
427 kfree_skb(skb);
428}
429
430/*
431 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
432 * and send it along.
433 */
434static void abort_arp_failure(void *handle, struct sk_buff *skb)
435{
436 struct c4iw_rdev *rdev = handle;
437 struct cpl_abort_req *req = cplhdr(skb);
438
439 PDBG("%s rdev %p\n", __func__, rdev);
440 req->cmd = CPL_ABORT_NO_RST;
441 c4iw_ofld_send(rdev, skb);
442}
443
444static void send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
445{
446 unsigned int flowclen = 80;
447 struct fw_flowc_wr *flowc;
448 int i;
449
450 skb = get_skb(skb, flowclen, GFP_KERNEL);
451 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
452
453 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP(FW_FLOWC_WR) |
454 FW_FLOWC_WR_NPARAMS(8));
455 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16(DIV_ROUND_UP(flowclen,
456 16)) | FW_WR_FLOWID(ep->hwtid));
457
458 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Steve Wise94788652011-01-21 17:00:34 +0000459 flowc->mnemval[0].val = cpu_to_be32(PCI_FUNC(ep->com.dev->rdev.lldi.pdev->devfn) << 8);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700460 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
461 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
462 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
463 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
464 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
465 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
466 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
467 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
468 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
469 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
470 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
471 flowc->mnemval[6].val = cpu_to_be32(snd_win);
472 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
473 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
474 /* Pad WR to 16 byte boundary */
475 flowc->mnemval[8].mnemonic = 0;
476 flowc->mnemval[8].val = 0;
477 for (i = 0; i < 9; i++) {
478 flowc->mnemval[i].r4[0] = 0;
479 flowc->mnemval[i].r4[1] = 0;
480 flowc->mnemval[i].r4[2] = 0;
481 }
482
483 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
484 c4iw_ofld_send(&ep->com.dev->rdev, skb);
485}
486
487static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
488{
489 struct cpl_close_con_req *req;
490 struct sk_buff *skb;
491 int wrlen = roundup(sizeof *req, 16);
492
493 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
494 skb = get_skb(NULL, wrlen, gfp);
495 if (!skb) {
496 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
497 return -ENOMEM;
498 }
499 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
500 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
501 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
502 memset(req, 0, wrlen);
503 INIT_TP_WR(req, ep->hwtid);
504 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
505 ep->hwtid));
506 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
507}
508
509static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
510{
511 struct cpl_abort_req *req;
512 int wrlen = roundup(sizeof *req, 16);
513
514 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
515 skb = get_skb(skb, wrlen, gfp);
516 if (!skb) {
517 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
518 __func__);
519 return -ENOMEM;
520 }
521 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
522 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
523 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
524 memset(req, 0, wrlen);
525 INIT_TP_WR(req, ep->hwtid);
526 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
527 req->cmd = CPL_ABORT_SEND_RST;
528 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
529}
530
531static int send_connect(struct c4iw_ep *ep)
532{
533 struct cpl_act_open_req *req;
Vipul Pandyaf079af72013-03-14 05:08:58 +0000534 struct cpl_t5_act_open_req *t5_req;
Vipul Pandya830662f2013-07-04 16:10:47 +0530535 struct cpl_act_open_req6 *req6;
536 struct cpl_t5_act_open_req6 *t5_req6;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700537 struct sk_buff *skb;
538 u64 opt0;
539 u32 opt2;
540 unsigned int mtu_idx;
541 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +0530542 int wrlen;
543 int sizev4 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
544 sizeof(struct cpl_act_open_req) :
545 sizeof(struct cpl_t5_act_open_req);
546 int sizev6 = is_t4(ep->com.dev->rdev.lldi.adapter_type) ?
547 sizeof(struct cpl_act_open_req6) :
548 sizeof(struct cpl_t5_act_open_req6);
549 struct sockaddr_in *la = (struct sockaddr_in *)&ep->com.local_addr;
550 struct sockaddr_in *ra = (struct sockaddr_in *)&ep->com.remote_addr;
551 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
552 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
553
554 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
555 roundup(sizev4, 16) :
556 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557
558 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
559
560 skb = get_skb(NULL, wrlen, GFP_KERNEL);
561 if (!skb) {
562 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
563 __func__);
564 return -ENOMEM;
565 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000566 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700567
568 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
569 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000570 opt0 = (nocong ? NO_CONG(1) : 0) |
571 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +0000572 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700573 WND_SCALE(wscale) |
574 MSS_IDX(mtu_idx) |
575 L2T_IDX(ep->l2t->idx) |
576 TX_CHAN(ep->tx_chan) |
577 SMAC_SEL(ep->smac_idx) |
578 DSCP(ep->tos) |
Steve Wiseb48f3b92011-03-11 22:30:21 +0000579 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700580 RCV_BUFSIZ(rcv_win>>10);
581 opt2 = RX_CHANNEL(0) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +0000582 CCTRL_ECN(enable_ecn) |
Steve Wisecfdda9d2010-04-21 15:30:06 -0700583 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
584 if (enable_tcp_timestamps)
585 opt2 |= TSTAMPS_EN(1);
586 if (enable_tcp_sack)
587 opt2 |= SACK_EN(1);
588 if (wscale && enable_tcp_window_scaling)
589 opt2 |= WND_SCALE_EN(1);
590 t4_set_arp_err_handler(skb, NULL, act_open_req_arp_failure);
591
Vipul Pandyaf079af72013-03-14 05:08:58 +0000592 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Vipul Pandya830662f2013-07-04 16:10:47 +0530593 if (ep->com.remote_addr.ss_family == AF_INET) {
594 req = (struct cpl_act_open_req *) skb_put(skb, wrlen);
595 INIT_TP_WR(req, 0);
596 OPCODE_TID(req) = cpu_to_be32(
Vipul Pandyaf079af72013-03-14 05:08:58 +0000597 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
598 ((ep->rss_qid << 14) | ep->atid)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530599 req->local_port = la->sin_port;
600 req->peer_port = ra->sin_port;
601 req->local_ip = la->sin_addr.s_addr;
602 req->peer_ip = ra->sin_addr.s_addr;
603 req->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530604 req->params = cpu_to_be32(cxgb4_select_ntuple(
605 ep->com.dev->rdev.lldi.ports[0],
606 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530607 req->opt2 = cpu_to_be32(opt2);
608 } else {
609 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
610
611 INIT_TP_WR(req6, 0);
612 OPCODE_TID(req6) = cpu_to_be32(
613 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
614 ((ep->rss_qid<<14)|ep->atid)));
615 req6->local_port = la6->sin6_port;
616 req6->peer_port = ra6->sin6_port;
617 req6->local_ip_hi = *((__be64 *)
618 (la6->sin6_addr.s6_addr));
619 req6->local_ip_lo = *((__be64 *)
620 (la6->sin6_addr.s6_addr + 8));
621 req6->peer_ip_hi = *((__be64 *)
622 (ra6->sin6_addr.s6_addr));
623 req6->peer_ip_lo = *((__be64 *)
624 (ra6->sin6_addr.s6_addr + 8));
625 req6->opt0 = cpu_to_be64(opt0);
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530626 req6->params = cpu_to_be32(cxgb4_select_ntuple(
627 ep->com.dev->rdev.lldi.ports[0],
628 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530629 req6->opt2 = cpu_to_be32(opt2);
630 }
631 } else {
632 if (ep->com.remote_addr.ss_family == AF_INET) {
633 t5_req = (struct cpl_t5_act_open_req *)
634 skb_put(skb, wrlen);
635 INIT_TP_WR(t5_req, 0);
636 OPCODE_TID(t5_req) = cpu_to_be32(
637 MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
638 ((ep->rss_qid << 14) | ep->atid)));
639 t5_req->local_port = la->sin_port;
640 t5_req->peer_port = ra->sin_port;
641 t5_req->local_ip = la->sin_addr.s_addr;
642 t5_req->peer_ip = ra->sin_addr.s_addr;
643 t5_req->opt0 = cpu_to_be64(opt0);
644 t5_req->params = cpu_to_be64(V_FILTER_TUPLE(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530645 cxgb4_select_ntuple(
646 ep->com.dev->rdev.lldi.ports[0],
647 ep->l2t)));
Vipul Pandya830662f2013-07-04 16:10:47 +0530648 t5_req->opt2 = cpu_to_be32(opt2);
649 } else {
650 t5_req6 = (struct cpl_t5_act_open_req6 *)
651 skb_put(skb, wrlen);
652 INIT_TP_WR(t5_req6, 0);
653 OPCODE_TID(t5_req6) = cpu_to_be32(
654 MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
655 ((ep->rss_qid<<14)|ep->atid)));
656 t5_req6->local_port = la6->sin6_port;
657 t5_req6->peer_port = ra6->sin6_port;
658 t5_req6->local_ip_hi = *((__be64 *)
659 (la6->sin6_addr.s6_addr));
660 t5_req6->local_ip_lo = *((__be64 *)
661 (la6->sin6_addr.s6_addr + 8));
662 t5_req6->peer_ip_hi = *((__be64 *)
663 (ra6->sin6_addr.s6_addr));
664 t5_req6->peer_ip_lo = *((__be64 *)
665 (ra6->sin6_addr.s6_addr + 8));
666 t5_req6->opt0 = cpu_to_be64(opt0);
667 t5_req6->params = (__force __be64)cpu_to_be32(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530668 cxgb4_select_ntuple(
669 ep->com.dev->rdev.lldi.ports[0],
670 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530671 t5_req6->opt2 = cpu_to_be32(opt2);
672 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000673 }
674
Vipul Pandya793dad92012-12-10 09:30:56 +0000675 set_bit(ACT_OPEN_REQ, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700676 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
677}
678
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530679static void send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
680 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700681{
682 int mpalen, wrlen;
683 struct fw_ofld_tx_data_wr *req;
684 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530685 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700686
687 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
688
689 BUG_ON(skb_cloned(skb));
690
691 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530692 if (mpa_rev_to_use == 2)
693 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700694 wrlen = roundup(mpalen + sizeof *req, 16);
695 skb = get_skb(skb, wrlen, GFP_KERNEL);
696 if (!skb) {
697 connect_reply_upcall(ep, -ENOMEM);
698 return;
699 }
700 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
701
702 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
703 memset(req, 0, wrlen);
704 req->op_to_immdlen = cpu_to_be32(
705 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
706 FW_WR_COMPL(1) |
707 FW_WR_IMMDLEN(mpalen));
708 req->flowid_len16 = cpu_to_be32(
709 FW_WR_FLOWID(ep->hwtid) |
710 FW_WR_LEN16(wrlen >> 4));
711 req->plen = cpu_to_be32(mpalen);
712 req->tunnel_to_proxy = cpu_to_be32(
713 FW_OFLD_TX_DATA_WR_FLUSH(1) |
714 FW_OFLD_TX_DATA_WR_SHOVE(1));
715
716 mpa = (struct mpa_message *)(req + 1);
717 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
718 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530719 (markers_enabled ? MPA_MARKERS : 0) |
720 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700721 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530722 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530723 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530724 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530725 ep->retry_with_mpa_v1 = 0;
726 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700727
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530728 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700729 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
730 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530731 mpa_v2_params.ird = htons((u16)ep->ird);
732 mpa_v2_params.ord = htons((u16)ep->ord);
733
734 if (peer2peer) {
735 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
736 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
737 mpa_v2_params.ord |=
738 htons(MPA_V2_RDMA_WRITE_RTR);
739 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
740 mpa_v2_params.ord |=
741 htons(MPA_V2_RDMA_READ_RTR);
742 }
743 memcpy(mpa->private_data, &mpa_v2_params,
744 sizeof(struct mpa_v2_conn_params));
745
746 if (ep->plen)
747 memcpy(mpa->private_data +
748 sizeof(struct mpa_v2_conn_params),
749 ep->mpa_pkt + sizeof(*mpa), ep->plen);
750 } else
751 if (ep->plen)
752 memcpy(mpa->private_data,
753 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754
755 /*
756 * Reference the mpa skb. This ensures the data area
757 * will remain in memory until the hw acks the tx.
758 * Function fw4_ack() will deref it.
759 */
760 skb_get(skb);
761 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
762 BUG_ON(ep->mpa_skb);
763 ep->mpa_skb = skb;
764 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
765 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530766 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700767 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530768 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700769 return;
770}
771
772static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
773{
774 int mpalen, wrlen;
775 struct fw_ofld_tx_data_wr *req;
776 struct mpa_message *mpa;
777 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530778 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700779
780 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
781
782 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530783 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
784 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700785 wrlen = roundup(mpalen + sizeof *req, 16);
786
787 skb = get_skb(NULL, wrlen, GFP_KERNEL);
788 if (!skb) {
789 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
790 return -ENOMEM;
791 }
792 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
793
794 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
795 memset(req, 0, wrlen);
796 req->op_to_immdlen = cpu_to_be32(
797 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
798 FW_WR_COMPL(1) |
799 FW_WR_IMMDLEN(mpalen));
800 req->flowid_len16 = cpu_to_be32(
801 FW_WR_FLOWID(ep->hwtid) |
802 FW_WR_LEN16(wrlen >> 4));
803 req->plen = cpu_to_be32(mpalen);
804 req->tunnel_to_proxy = cpu_to_be32(
805 FW_OFLD_TX_DATA_WR_FLUSH(1) |
806 FW_OFLD_TX_DATA_WR_SHOVE(1));
807
808 mpa = (struct mpa_message *)(req + 1);
809 memset(mpa, 0, sizeof(*mpa));
810 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
811 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000812 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700813 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530814
815 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
816 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700817 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
818 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530819 mpa_v2_params.ird = htons(((u16)ep->ird) |
820 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
821 0));
822 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
823 (p2p_type ==
824 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
825 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
826 FW_RI_INIT_P2PTYPE_READ_REQ ?
827 MPA_V2_RDMA_READ_RTR : 0) : 0));
828 memcpy(mpa->private_data, &mpa_v2_params,
829 sizeof(struct mpa_v2_conn_params));
830
831 if (ep->plen)
832 memcpy(mpa->private_data +
833 sizeof(struct mpa_v2_conn_params), pdata, plen);
834 } else
835 if (plen)
836 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700837
838 /*
839 * Reference the mpa skb again. This ensures the data area
840 * will remain in memory until the hw acks the tx.
841 * Function fw4_ack() will deref it.
842 */
843 skb_get(skb);
844 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
845 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
846 BUG_ON(ep->mpa_skb);
847 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +0530848 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700849 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
850}
851
852static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
853{
854 int mpalen, wrlen;
855 struct fw_ofld_tx_data_wr *req;
856 struct mpa_message *mpa;
857 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530858 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700859
860 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
861
862 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530863 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
864 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700865 wrlen = roundup(mpalen + sizeof *req, 16);
866
867 skb = get_skb(NULL, wrlen, GFP_KERNEL);
868 if (!skb) {
869 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
870 return -ENOMEM;
871 }
872 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
873
874 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
875 memset(req, 0, wrlen);
876 req->op_to_immdlen = cpu_to_be32(
877 FW_WR_OP(FW_OFLD_TX_DATA_WR) |
878 FW_WR_COMPL(1) |
879 FW_WR_IMMDLEN(mpalen));
880 req->flowid_len16 = cpu_to_be32(
881 FW_WR_FLOWID(ep->hwtid) |
882 FW_WR_LEN16(wrlen >> 4));
883 req->plen = cpu_to_be32(mpalen);
884 req->tunnel_to_proxy = cpu_to_be32(
885 FW_OFLD_TX_DATA_WR_FLUSH(1) |
886 FW_OFLD_TX_DATA_WR_SHOVE(1));
887
888 mpa = (struct mpa_message *)(req + 1);
889 memset(mpa, 0, sizeof(*mpa));
890 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
891 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
892 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530893 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700894 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530895
896 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
897 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -0700898 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
899 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530900 mpa_v2_params.ird = htons((u16)ep->ird);
901 mpa_v2_params.ord = htons((u16)ep->ord);
902 if (peer2peer && (ep->mpa_attr.p2p_type !=
903 FW_RI_INIT_P2PTYPE_DISABLED)) {
904 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
905
906 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
907 mpa_v2_params.ord |=
908 htons(MPA_V2_RDMA_WRITE_RTR);
909 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
910 mpa_v2_params.ord |=
911 htons(MPA_V2_RDMA_READ_RTR);
912 }
913
914 memcpy(mpa->private_data, &mpa_v2_params,
915 sizeof(struct mpa_v2_conn_params));
916
917 if (ep->plen)
918 memcpy(mpa->private_data +
919 sizeof(struct mpa_v2_conn_params), pdata, plen);
920 } else
921 if (plen)
922 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700923
924 /*
925 * Reference the mpa skb. This ensures the data area
926 * will remain in memory until the hw acks the tx.
927 * Function fw4_ack() will deref it.
928 */
929 skb_get(skb);
930 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
931 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +0530932 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +0530933 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700934 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
935}
936
937static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
938{
939 struct c4iw_ep *ep;
940 struct cpl_act_establish *req = cplhdr(skb);
941 unsigned int tid = GET_TID(req);
942 unsigned int atid = GET_TID_TID(ntohl(req->tos_atid));
943 struct tid_info *t = dev->rdev.lldi.tids;
944
945 ep = lookup_atid(t, atid);
946
947 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
948 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
949
Steve Wisea7db89e2014-03-21 20:40:35 +0530950 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700951 dst_confirm(ep->dst);
952
953 /* setup the hwtid for this connection */
954 ep->hwtid = tid;
955 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000956 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700957
958 ep->snd_seq = be32_to_cpu(req->snd_isn);
959 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
960
961 set_emss(ep, ntohs(req->tcp_opt));
962
963 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +0000964 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700965 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +0000966 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700967
968 /* start MPA negotiation */
969 send_flowc(ep, NULL);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530970 if (ep->retry_with_mpa_v1)
971 send_mpa_req(ep, skb, 1);
972 else
973 send_mpa_req(ep, skb, mpa_rev);
Steve Wisea7db89e2014-03-21 20:40:35 +0530974 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700975 return 0;
976}
977
Steve Wisebe13b2d2014-03-21 20:40:33 +0530978static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979{
980 struct iw_cm_event event;
981
982 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
983 memset(&event, 0, sizeof(event));
984 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +0530985 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700986 if (ep->com.cm_id) {
987 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
988 ep, ep->com.cm_id, ep->hwtid);
989 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
990 ep->com.cm_id->rem_ref(ep->com.cm_id);
991 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +0000992 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700993 }
994}
995
996static int abort_connection(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
997{
998 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecc18b932014-04-24 14:31:53 -0500999 __state_set(&ep->com, ABORTING);
Vipul Pandya793dad92012-12-10 09:30:56 +00001000 set_bit(ABORT_CONN, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001001 return send_abort(ep, skb, gfp);
1002}
1003
1004static void peer_close_upcall(struct c4iw_ep *ep)
1005{
1006 struct iw_cm_event event;
1007
1008 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1009 memset(&event, 0, sizeof(event));
1010 event.event = IW_CM_EVENT_DISCONNECT;
1011 if (ep->com.cm_id) {
1012 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1013 ep, ep->com.cm_id, ep->hwtid);
1014 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001015 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001016 }
1017}
1018
1019static void peer_abort_upcall(struct c4iw_ep *ep)
1020{
1021 struct iw_cm_event event;
1022
1023 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1024 memset(&event, 0, sizeof(event));
1025 event.event = IW_CM_EVENT_CLOSE;
1026 event.status = -ECONNRESET;
1027 if (ep->com.cm_id) {
1028 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1029 ep->com.cm_id, ep->hwtid);
1030 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1031 ep->com.cm_id->rem_ref(ep->com.cm_id);
1032 ep->com.cm_id = NULL;
Vipul Pandya793dad92012-12-10 09:30:56 +00001033 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001034 }
1035}
1036
1037static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1038{
1039 struct iw_cm_event event;
1040
1041 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1042 memset(&event, 0, sizeof(event));
1043 event.event = IW_CM_EVENT_CONNECT_REPLY;
1044 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301045 memcpy(&event.local_addr, &ep->com.local_addr,
1046 sizeof(ep->com.local_addr));
1047 memcpy(&event.remote_addr, &ep->com.remote_addr,
1048 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001049
1050 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301051 if (!ep->tried_with_mpa_v1) {
1052 /* this means MPA_v2 is used */
1053 event.private_data_len = ep->plen -
1054 sizeof(struct mpa_v2_conn_params);
1055 event.private_data = ep->mpa_pkt +
1056 sizeof(struct mpa_message) +
1057 sizeof(struct mpa_v2_conn_params);
1058 } else {
1059 /* this means MPA_v1 is used */
1060 event.private_data_len = ep->plen;
1061 event.private_data = ep->mpa_pkt +
1062 sizeof(struct mpa_message);
1063 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001064 }
Roland Dreier85963e42010-07-19 13:13:09 -07001065
1066 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1067 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001068 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001069 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1070
Steve Wisecfdda9d2010-04-21 15:30:06 -07001071 if (status < 0) {
1072 ep->com.cm_id->rem_ref(ep->com.cm_id);
1073 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001074 }
1075}
1076
Steve Wisebe13b2d2014-03-21 20:40:33 +05301077static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001078{
1079 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301080 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081
1082 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1083 memset(&event, 0, sizeof(event));
1084 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301085 memcpy(&event.local_addr, &ep->com.local_addr,
1086 sizeof(ep->com.local_addr));
1087 memcpy(&event.remote_addr, &ep->com.remote_addr,
1088 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301090 if (!ep->tried_with_mpa_v1) {
1091 /* this means MPA_v2 is used */
1092 event.ord = ep->ord;
1093 event.ird = ep->ird;
1094 event.private_data_len = ep->plen -
1095 sizeof(struct mpa_v2_conn_params);
1096 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1097 sizeof(struct mpa_v2_conn_params);
1098 } else {
1099 /* this means MPA_v1 is used. Send max supported */
1100 event.ord = c4iw_max_read_depth;
1101 event.ird = c4iw_max_read_depth;
1102 event.private_data_len = ep->plen;
1103 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1104 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301105 c4iw_get_ep(&ep->com);
1106 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1107 &event);
1108 if (ret)
1109 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001110 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001111 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301112 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001113}
1114
1115static void established_upcall(struct c4iw_ep *ep)
1116{
1117 struct iw_cm_event event;
1118
1119 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1120 memset(&event, 0, sizeof(event));
1121 event.event = IW_CM_EVENT_ESTABLISHED;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301122 event.ird = ep->ird;
1123 event.ord = ep->ord;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001124 if (ep->com.cm_id) {
1125 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1126 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001127 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001128 }
1129}
1130
1131static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1132{
1133 struct cpl_rx_data_ack *req;
1134 struct sk_buff *skb;
1135 int wrlen = roundup(sizeof *req, 16);
1136
1137 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1138 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1139 if (!skb) {
1140 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1141 return 0;
1142 }
1143
1144 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1145 memset(req, 0, wrlen);
1146 INIT_TP_WR(req, ep->hwtid);
1147 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1148 ep->hwtid));
Steve Wiseba6d3922010-06-23 15:46:49 +00001149 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK(1) |
1150 F_RX_DACK_CHANGE |
1151 V_RX_DACK_MODE(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001152 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001153 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1154 return credits;
1155}
1156
Steve Wisecc18b932014-04-24 14:31:53 -05001157static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158{
1159 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301160 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301162 u16 resp_ird, resp_ord;
1163 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001164 struct c4iw_qp_attributes attrs;
1165 enum c4iw_qp_attr_mask mask;
1166 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001167 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001168
1169 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1170
1171 /*
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001172 * Stop mpa timer. If it expired, then
1173 * we ignore the MPA reply. process_timeout()
1174 * will abort the connection.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175 */
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001176 if (stop_ep_timer(ep))
Steve Wisecc18b932014-04-24 14:31:53 -05001177 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001178
1179 /*
1180 * If we get more than the supported amount of private data
1181 * then we must fail this connection.
1182 */
1183 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1184 err = -EINVAL;
1185 goto err;
1186 }
1187
1188 /*
1189 * copy the new data into our accumulation buffer.
1190 */
1191 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1192 skb->len);
1193 ep->mpa_pkt_len += skb->len;
1194
1195 /*
1196 * if we don't even have the mpa message, then bail.
1197 */
1198 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001199 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200 mpa = (struct mpa_message *) ep->mpa_pkt;
1201
1202 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301203 if (mpa->revision > mpa_rev) {
1204 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1205 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206 err = -EPROTO;
1207 goto err;
1208 }
1209 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1210 err = -EPROTO;
1211 goto err;
1212 }
1213
1214 plen = ntohs(mpa->private_data_size);
1215
1216 /*
1217 * Fail if there's too much private data.
1218 */
1219 if (plen > MPA_MAX_PRIVATE_DATA) {
1220 err = -EPROTO;
1221 goto err;
1222 }
1223
1224 /*
1225 * If plen does not account for pkt size
1226 */
1227 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1228 err = -EPROTO;
1229 goto err;
1230 }
1231
1232 ep->plen = (u8) plen;
1233
1234 /*
1235 * If we don't have all the pdata yet, then bail.
1236 * We'll continue process when more data arrives.
1237 */
1238 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001239 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240
1241 if (mpa->flags & MPA_REJECT) {
1242 err = -ECONNREFUSED;
1243 goto err;
1244 }
1245
1246 /*
1247 * If we get here we have accumulated the entire mpa
1248 * start reply message including private data. And
1249 * the MPA header is valid.
1250 */
Steve Wisec529fb52014-03-21 20:40:37 +05301251 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001252 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1253 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1254 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301255 ep->mpa_attr.version = mpa->revision;
1256 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1257
1258 if (mpa->revision == 2) {
1259 ep->mpa_attr.enhanced_rdma_conn =
1260 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1261 if (ep->mpa_attr.enhanced_rdma_conn) {
1262 mpa_v2_params = (struct mpa_v2_conn_params *)
1263 (ep->mpa_pkt + sizeof(*mpa));
1264 resp_ird = ntohs(mpa_v2_params->ird) &
1265 MPA_V2_IRD_ORD_MASK;
1266 resp_ord = ntohs(mpa_v2_params->ord) &
1267 MPA_V2_IRD_ORD_MASK;
1268
1269 /*
1270 * This is a double-check. Ideally, below checks are
1271 * not required since ird/ord stuff has been taken
1272 * care of in c4iw_accept_cr
1273 */
1274 if ((ep->ird < resp_ord) || (ep->ord > resp_ird)) {
1275 err = -ENOMEM;
1276 ep->ird = resp_ord;
1277 ep->ord = resp_ird;
1278 insuff_ird = 1;
1279 }
1280
1281 if (ntohs(mpa_v2_params->ird) &
1282 MPA_V2_PEER2PEER_MODEL) {
1283 if (ntohs(mpa_v2_params->ord) &
1284 MPA_V2_RDMA_WRITE_RTR)
1285 ep->mpa_attr.p2p_type =
1286 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1287 else if (ntohs(mpa_v2_params->ord) &
1288 MPA_V2_RDMA_READ_RTR)
1289 ep->mpa_attr.p2p_type =
1290 FW_RI_INIT_P2PTYPE_READ_REQ;
1291 }
1292 }
1293 } else if (mpa->revision == 1)
1294 if (peer2peer)
1295 ep->mpa_attr.p2p_type = p2p_type;
1296
Steve Wisecfdda9d2010-04-21 15:30:06 -07001297 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301298 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1299 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1300 ep->mpa_attr.recv_marker_enabled,
1301 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1302 ep->mpa_attr.p2p_type, p2p_type);
1303
1304 /*
1305 * If responder's RTR does not match with that of initiator, assign
1306 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1307 * generated when moving QP to RTS state.
1308 * A TERM message will be sent after QP has moved to RTS state
1309 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001310 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301311 (ep->mpa_attr.p2p_type != p2p_type)) {
1312 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1313 rtr_mismatch = 1;
1314 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315
1316 attrs.mpa_attr = ep->mpa_attr;
1317 attrs.max_ird = ep->ird;
1318 attrs.max_ord = ep->ord;
1319 attrs.llp_stream_handle = ep;
1320 attrs.next_state = C4IW_QP_STATE_RTS;
1321
1322 mask = C4IW_QP_ATTR_NEXT_STATE |
1323 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1324 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1325
1326 /* bind QP and TID with INIT_WR */
1327 err = c4iw_modify_qp(ep->com.qp->rhp,
1328 ep->com.qp, mask, &attrs, 1);
1329 if (err)
1330 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301331
1332 /*
1333 * If responder's RTR requirement did not match with what initiator
1334 * supports, generate TERM message
1335 */
1336 if (rtr_mismatch) {
1337 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1338 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1339 attrs.ecode = MPA_NOMATCH_RTR;
1340 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001341 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301342 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001343 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301344 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001345 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301346 goto out;
1347 }
1348
1349 /*
1350 * Generate TERM if initiator IRD is not sufficient for responder
1351 * provided ORD. Currently, we do the same behaviour even when
1352 * responder provided IRD is also not sufficient as regards to
1353 * initiator ORD.
1354 */
1355 if (insuff_ird) {
1356 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1357 __func__);
1358 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1359 attrs.ecode = MPA_INSUFF_IRD;
1360 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001361 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301362 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001363 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301364 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001365 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301366 goto out;
1367 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001368 goto out;
1369err:
Steve Wisec529fb52014-03-21 20:40:37 +05301370 __state_set(&ep->com, ABORTING);
Steve Wiseb21ef162010-06-10 19:02:55 +00001371 send_abort(ep, skb, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001372out:
1373 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001374 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001375}
1376
1377static void process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
1378{
1379 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301380 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001381 u16 plen;
1382
1383 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1384
Steve Wisecfdda9d2010-04-21 15:30:06 -07001385 /*
1386 * If we get more than the supported amount of private data
1387 * then we must fail this connection.
1388 */
1389 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001390 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001391 abort_connection(ep, skb, GFP_KERNEL);
1392 return;
1393 }
1394
1395 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1396
1397 /*
1398 * Copy the new data into our accumulation buffer.
1399 */
1400 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1401 skb->len);
1402 ep->mpa_pkt_len += skb->len;
1403
1404 /*
1405 * If we don't even have the mpa message, then bail.
1406 * We'll continue process when more data arrives.
1407 */
1408 if (ep->mpa_pkt_len < sizeof(*mpa))
1409 return;
1410
1411 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001412 mpa = (struct mpa_message *) ep->mpa_pkt;
1413
1414 /*
1415 * Validate MPA Header.
1416 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301417 if (mpa->revision > mpa_rev) {
1418 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1419 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001420 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001421 abort_connection(ep, skb, GFP_KERNEL);
1422 return;
1423 }
1424
1425 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key))) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001426 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427 abort_connection(ep, skb, GFP_KERNEL);
1428 return;
1429 }
1430
1431 plen = ntohs(mpa->private_data_size);
1432
1433 /*
1434 * Fail if there's too much private data.
1435 */
1436 if (plen > MPA_MAX_PRIVATE_DATA) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001437 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001438 abort_connection(ep, skb, GFP_KERNEL);
1439 return;
1440 }
1441
1442 /*
1443 * If plen does not account for pkt size
1444 */
1445 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001446 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001447 abort_connection(ep, skb, GFP_KERNEL);
1448 return;
1449 }
1450 ep->plen = (u8) plen;
1451
1452 /*
1453 * If we don't have all the pdata yet, then bail.
1454 */
1455 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
1456 return;
1457
1458 /*
1459 * If we get here we have accumulated the entire mpa
1460 * start reply message including private data.
1461 */
1462 ep->mpa_attr.initiator = 0;
1463 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1464 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1465 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301466 ep->mpa_attr.version = mpa->revision;
1467 if (mpa->revision == 1)
1468 ep->tried_with_mpa_v1 = 1;
1469 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1470
1471 if (mpa->revision == 2) {
1472 ep->mpa_attr.enhanced_rdma_conn =
1473 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1474 if (ep->mpa_attr.enhanced_rdma_conn) {
1475 mpa_v2_params = (struct mpa_v2_conn_params *)
1476 (ep->mpa_pkt + sizeof(*mpa));
1477 ep->ird = ntohs(mpa_v2_params->ird) &
1478 MPA_V2_IRD_ORD_MASK;
1479 ep->ord = ntohs(mpa_v2_params->ord) &
1480 MPA_V2_IRD_ORD_MASK;
1481 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1482 if (peer2peer) {
1483 if (ntohs(mpa_v2_params->ord) &
1484 MPA_V2_RDMA_WRITE_RTR)
1485 ep->mpa_attr.p2p_type =
1486 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1487 else if (ntohs(mpa_v2_params->ord) &
1488 MPA_V2_RDMA_READ_RTR)
1489 ep->mpa_attr.p2p_type =
1490 FW_RI_INIT_P2PTYPE_READ_REQ;
1491 }
1492 }
1493 } else if (mpa->revision == 1)
1494 if (peer2peer)
1495 ep->mpa_attr.p2p_type = p2p_type;
1496
Steve Wisecfdda9d2010-04-21 15:30:06 -07001497 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1498 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1499 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1500 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1501 ep->mpa_attr.p2p_type);
1502
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001503 /*
1504 * If the endpoint timer already expired, then we ignore
1505 * the start request. process_timeout() will abort
1506 * the connection.
1507 */
1508 if (!stop_ep_timer(ep)) {
1509 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001511 /* drive upcall */
1512 mutex_lock(&ep->parent_ep->com.mutex);
1513 if (ep->parent_ep->com.state != DEAD) {
1514 if (connect_request_upcall(ep))
1515 abort_connection(ep, skb, GFP_KERNEL);
1516 } else {
Steve Wisebe13b2d2014-03-21 20:40:33 +05301517 abort_connection(ep, skb, GFP_KERNEL);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05001518 }
1519 mutex_unlock(&ep->parent_ep->com.mutex);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301520 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001521 return;
1522}
1523
1524static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1525{
1526 struct c4iw_ep *ep;
1527 struct cpl_rx_data *hdr = cplhdr(skb);
1528 unsigned int dlen = ntohs(hdr->len);
1529 unsigned int tid = GET_TID(hdr);
1530 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001531 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001532 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001533
1534 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301535 if (!ep)
1536 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001537 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1538 skb_pull(skb, sizeof(*hdr));
1539 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301540 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001541
Steve Wisecfdda9d2010-04-21 15:30:06 -07001542 /* update RX credits */
1543 update_rx_credits(ep, dlen);
1544
Steve Wisec529fb52014-03-21 20:40:37 +05301545 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001546 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001547 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001548 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001549 break;
1550 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001551 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552 process_mpa_request(ep, skb);
1553 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001554 case FPDU_MODE: {
1555 struct c4iw_qp_attributes attrs;
1556 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001557 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001558 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001559 " qpid %u ep %p state %d tid %u status %d\n",
1560 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301561 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301562 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001563 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001564 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1565 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001566 break;
1567 }
Vipul Pandya15579672013-01-07 13:11:52 +00001568 default:
1569 break;
1570 }
Steve Wisec529fb52014-03-21 20:40:37 +05301571 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001572 if (disconnect)
1573 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001574 return 0;
1575}
1576
1577static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1578{
1579 struct c4iw_ep *ep;
1580 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001581 int release = 0;
1582 unsigned int tid = GET_TID(rpl);
1583 struct tid_info *t = dev->rdev.lldi.tids;
1584
1585 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301586 if (!ep) {
1587 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1588 return 0;
1589 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001590 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001591 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001592 switch (ep->com.state) {
1593 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001594 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001595 __state_set(&ep->com, DEAD);
1596 release = 1;
1597 break;
1598 default:
1599 printk(KERN_ERR "%s ep %p state %d\n",
1600 __func__, ep, ep->com.state);
1601 break;
1602 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001603 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001604
1605 if (release)
1606 release_ep_resources(ep);
1607 return 0;
1608}
1609
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001610static void send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
1611{
1612 struct sk_buff *skb;
1613 struct fw_ofld_connection_wr *req;
1614 unsigned int mtu_idx;
1615 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301616 struct sockaddr_in *sin;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001617
1618 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1619 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1620 memset(req, 0, sizeof(*req));
1621 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR));
1622 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301623 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1624 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001625 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +05301626 sin = (struct sockaddr_in *)&ep->com.local_addr;
1627 req->le.lport = sin->sin_port;
1628 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
1629 sin = (struct sockaddr_in *)&ep->com.remote_addr;
1630 req->le.pport = sin->sin_port;
1631 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001632 req->tcb.t_state_to_astid =
1633 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_SENT) |
1634 V_FW_OFLD_CONNECTION_WR_ASTID(atid));
1635 req->tcb.cplrxdataack_cplpassacceptrpl =
1636 htons(F_FW_OFLD_CONNECTION_WR_CPLRXDATAACK);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001637 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001638 req->tcb.rcv_adv = htons(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001639 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1640 wscale = compute_wscale(rcv_win);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001641 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001642 (nocong ? NO_CONG(1) : 0) |
1643 KEEP_ALIVE(1) |
1644 DELACK(1) |
1645 WND_SCALE(wscale) |
1646 MSS_IDX(mtu_idx) |
1647 L2T_IDX(ep->l2t->idx) |
1648 TX_CHAN(ep->tx_chan) |
1649 SMAC_SEL(ep->smac_idx) |
1650 DSCP(ep->tos) |
1651 ULP_MODE(ULP_MODE_TCPDDP) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001652 RCV_BUFSIZ(rcv_win >> 10));
1653 req->tcb.opt2 = (__force __be32) (PACE(1) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001654 TX_QUEUE(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
1655 RX_CHANNEL(0) |
1656 CCTRL_ECN(enable_ecn) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001657 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001658 if (enable_tcp_timestamps)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001659 req->tcb.opt2 |= (__force __be32) TSTAMPS_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001660 if (enable_tcp_sack)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001661 req->tcb.opt2 |= (__force __be32) SACK_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001662 if (wscale && enable_tcp_window_scaling)
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001663 req->tcb.opt2 |= (__force __be32) WND_SCALE_EN(1);
1664 req->tcb.opt0 = cpu_to_be64((__force u64) req->tcb.opt0);
1665 req->tcb.opt2 = cpu_to_be32((__force u32) req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001666 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1667 set_bit(ACT_OFLD_CONN, &ep->com.history);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001668 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1669}
1670
Steve Wisecfdda9d2010-04-21 15:30:06 -07001671/*
1672 * Return whether a failed active open has allocated a TID
1673 */
1674static inline int act_open_has_tid(int status)
1675{
1676 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1677 status != CPL_ERR_ARP_MISS;
1678}
1679
Steve Wise7a2cea22014-03-14 21:52:07 +05301680/* Returns whether a CPL status conveys negative advice.
1681 */
1682static int is_neg_adv(unsigned int status)
1683{
1684 return status == CPL_ERR_RTX_NEG_ADVICE ||
1685 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1686 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1687}
1688
Vipul Pandya793dad92012-12-10 09:30:56 +00001689#define ACT_OPEN_RETRY_COUNT 2
1690
Vipul Pandya830662f2013-07-04 16:10:47 +05301691static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1692 struct dst_entry *dst, struct c4iw_dev *cdev,
1693 bool clear_mpa_v1)
1694{
1695 struct neighbour *n;
1696 int err, step;
1697 struct net_device *pdev;
1698
1699 n = dst_neigh_lookup(dst, peer_ip);
1700 if (!n)
1701 return -ENODEV;
1702
1703 rcu_read_lock();
1704 err = -ENOMEM;
1705 if (n->dev->flags & IFF_LOOPBACK) {
1706 if (iptype == 4)
1707 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1708 else if (IS_ENABLED(CONFIG_IPV6))
1709 for_each_netdev(&init_net, pdev) {
1710 if (ipv6_chk_addr(&init_net,
1711 (struct in6_addr *)peer_ip,
1712 pdev, 1))
1713 break;
1714 }
1715 else
1716 pdev = NULL;
1717
1718 if (!pdev) {
1719 err = -ENODEV;
1720 goto out;
1721 }
1722 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1723 n, pdev, 0);
1724 if (!ep->l2t)
1725 goto out;
1726 ep->mtu = pdev->mtu;
1727 ep->tx_chan = cxgb4_port_chan(pdev);
1728 ep->smac_idx = (cxgb4_port_viid(pdev) & 0x7F) << 1;
1729 step = cdev->rdev.lldi.ntxq /
1730 cdev->rdev.lldi.nchan;
1731 ep->txq_idx = cxgb4_port_idx(pdev) * step;
1732 step = cdev->rdev.lldi.nrxq /
1733 cdev->rdev.lldi.nchan;
1734 ep->ctrlq_idx = cxgb4_port_idx(pdev);
1735 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1736 cxgb4_port_idx(pdev) * step];
1737 dev_put(pdev);
1738 } else {
1739 pdev = get_real_dev(n->dev);
1740 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
1741 n, pdev, 0);
1742 if (!ep->l2t)
1743 goto out;
1744 ep->mtu = dst_mtu(dst);
1745 ep->tx_chan = cxgb4_port_chan(n->dev);
1746 ep->smac_idx = (cxgb4_port_viid(n->dev) & 0x7F) << 1;
1747 step = cdev->rdev.lldi.ntxq /
1748 cdev->rdev.lldi.nchan;
1749 ep->txq_idx = cxgb4_port_idx(n->dev) * step;
1750 ep->ctrlq_idx = cxgb4_port_idx(n->dev);
1751 step = cdev->rdev.lldi.nrxq /
1752 cdev->rdev.lldi.nchan;
1753 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
1754 cxgb4_port_idx(n->dev) * step];
1755
1756 if (clear_mpa_v1) {
1757 ep->retry_with_mpa_v1 = 0;
1758 ep->tried_with_mpa_v1 = 0;
1759 }
1760 }
1761 err = 0;
1762out:
1763 rcu_read_unlock();
1764
1765 neigh_release(n);
1766
1767 return err;
1768}
1769
Vipul Pandya793dad92012-12-10 09:30:56 +00001770static int c4iw_reconnect(struct c4iw_ep *ep)
1771{
1772 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05301773 struct sockaddr_in *laddr = (struct sockaddr_in *)
1774 &ep->com.cm_id->local_addr;
1775 struct sockaddr_in *raddr = (struct sockaddr_in *)
1776 &ep->com.cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301777 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
1778 &ep->com.cm_id->local_addr;
1779 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
1780 &ep->com.cm_id->remote_addr;
1781 int iptype;
1782 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00001783
1784 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
1785 init_timer(&ep->timer);
1786
1787 /*
1788 * Allocate an active TID to initiate a TCP connection.
1789 */
1790 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
1791 if (ep->atid == -1) {
1792 pr_err("%s - cannot alloc atid.\n", __func__);
1793 err = -ENOMEM;
1794 goto fail2;
1795 }
1796 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
1797
1798 /* find a route */
Vipul Pandya830662f2013-07-04 16:10:47 +05301799 if (ep->com.cm_id->local_addr.ss_family == AF_INET) {
1800 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
1801 raddr->sin_addr.s_addr, laddr->sin_port,
1802 raddr->sin_port, 0);
1803 iptype = 4;
1804 ra = (__u8 *)&raddr->sin_addr;
1805 } else {
1806 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
1807 raddr6->sin6_addr.s6_addr,
1808 laddr6->sin6_port, raddr6->sin6_port, 0,
1809 raddr6->sin6_scope_id);
1810 iptype = 6;
1811 ra = (__u8 *)&raddr6->sin6_addr;
1812 }
1813 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001814 pr_err("%s - cannot find route.\n", __func__);
1815 err = -EHOSTUNREACH;
1816 goto fail3;
1817 }
Vipul Pandya830662f2013-07-04 16:10:47 +05301818 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false);
1819 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001820 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00001821 goto fail4;
1822 }
1823
1824 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
1825 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
1826 ep->l2t->idx);
1827
1828 state_set(&ep->com, CONNECTING);
1829 ep->tos = 0;
1830
1831 /* send connect request to rnic */
1832 err = send_connect(ep);
1833 if (!err)
1834 goto out;
1835
1836 cxgb4_l2t_release(ep->l2t);
1837fail4:
1838 dst_release(ep->dst);
1839fail3:
1840 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
1841 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
1842fail2:
1843 /*
1844 * remember to send notification to upper layer.
1845 * We are in here so the upper layer is not aware that this is
1846 * re-connect attempt and so, upper layer is still waiting for
1847 * response of 1st connect request.
1848 */
1849 connect_reply_upcall(ep, -ECONNRESET);
1850 c4iw_put_ep(&ep->com);
1851out:
1852 return err;
1853}
1854
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1856{
1857 struct c4iw_ep *ep;
1858 struct cpl_act_open_rpl *rpl = cplhdr(skb);
1859 unsigned int atid = GET_TID_TID(GET_AOPEN_ATID(
1860 ntohl(rpl->atid_status)));
1861 struct tid_info *t = dev->rdev.lldi.tids;
1862 int status = GET_AOPEN_STATUS(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05301863 struct sockaddr_in *la;
1864 struct sockaddr_in *ra;
1865 struct sockaddr_in6 *la6;
1866 struct sockaddr_in6 *ra6;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001867
1868 ep = lookup_atid(t, atid);
Vipul Pandya830662f2013-07-04 16:10:47 +05301869 la = (struct sockaddr_in *)&ep->com.local_addr;
1870 ra = (struct sockaddr_in *)&ep->com.remote_addr;
1871 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
1872 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873
1874 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
1875 status, status2errno(status));
1876
Steve Wise7a2cea22014-03-14 21:52:07 +05301877 if (is_neg_adv(status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001878 printk(KERN_WARNING MOD "Connection problems for atid %u\n",
1879 atid);
1880 return 0;
1881 }
1882
Vipul Pandya793dad92012-12-10 09:30:56 +00001883 set_bit(ACT_OPEN_RPL, &ep->com.history);
1884
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301885 /*
1886 * Log interesting failures.
1887 */
1888 switch (status) {
1889 case CPL_ERR_CONN_RESET:
1890 case CPL_ERR_CONN_TIMEDOUT:
1891 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001892 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05301893 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00001894 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05301895 mutex_unlock(&dev->rdev.stats.lock);
1896 if (ep->com.local_addr.ss_family == AF_INET &&
1897 dev->rdev.lldi.enable_fw_ofld_conn) {
Vipul Pandya793dad92012-12-10 09:30:56 +00001898 send_fw_act_open_req(ep,
1899 GET_TID_TID(GET_AOPEN_ATID(
1900 ntohl(rpl->atid_status))));
1901 return 0;
1902 }
1903 break;
1904 case CPL_ERR_CONN_EXIST:
1905 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
1906 set_bit(ACT_RETRY_INUSE, &ep->com.history);
1907 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
1908 atid);
1909 cxgb4_free_atid(t, atid);
1910 dst_release(ep->dst);
1911 cxgb4_l2t_release(ep->l2t);
1912 c4iw_reconnect(ep);
1913 return 0;
1914 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301916 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05301917 if (ep->com.local_addr.ss_family == AF_INET) {
1918 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
1919 atid, status, status2errno(status),
1920 &la->sin_addr.s_addr, ntohs(la->sin_port),
1921 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
1922 } else {
1923 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
1924 atid, status, status2errno(status),
1925 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
1926 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
1927 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05301928 break;
1929 }
1930
Steve Wisecfdda9d2010-04-21 15:30:06 -07001931 connect_reply_upcall(ep, status2errno(status));
1932 state_set(&ep->com, DEAD);
1933
1934 if (status && act_open_has_tid(status))
1935 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
1936
Vipul Pandya793dad92012-12-10 09:30:56 +00001937 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001938 cxgb4_free_atid(t, atid);
1939 dst_release(ep->dst);
1940 cxgb4_l2t_release(ep->l2t);
1941 c4iw_put_ep(&ep->com);
1942
1943 return 0;
1944}
1945
1946static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1947{
1948 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
1949 struct tid_info *t = dev->rdev.lldi.tids;
1950 unsigned int stid = GET_TID(rpl);
1951 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1952
1953 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00001954 PDBG("%s stid %d lookup failure!\n", __func__, stid);
1955 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001956 }
1957 PDBG("%s ep %p status %d error %d\n", __func__, ep,
1958 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07001959 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001960
Vipul Pandya1cab7752012-12-10 09:30:55 +00001961out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962 return 0;
1963}
1964
Steve Wisecfdda9d2010-04-21 15:30:06 -07001965static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1966{
1967 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
1968 struct tid_info *t = dev->rdev.lldi.tids;
1969 unsigned int stid = GET_TID(rpl);
1970 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
1971
1972 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07001973 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001974 return 0;
1975}
1976
Vipul Pandya830662f2013-07-04 16:10:47 +05301977static void accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
Steve Wisecfdda9d2010-04-21 15:30:06 -07001978 struct cpl_pass_accept_req *req)
1979{
1980 struct cpl_pass_accept_rpl *rpl;
1981 unsigned int mtu_idx;
1982 u64 opt0;
1983 u32 opt2;
1984 int wscale;
1985
1986 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1987 BUG_ON(skb_cloned(skb));
1988 skb_trim(skb, sizeof(*rpl));
1989 skb_get(skb);
1990 cxgb4_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx);
1991 wscale = compute_wscale(rcv_win);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001992 opt0 = (nocong ? NO_CONG(1) : 0) |
1993 KEEP_ALIVE(1) |
Steve Wiseba6d3922010-06-23 15:46:49 +00001994 DELACK(1) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07001995 WND_SCALE(wscale) |
1996 MSS_IDX(mtu_idx) |
1997 L2T_IDX(ep->l2t->idx) |
1998 TX_CHAN(ep->tx_chan) |
1999 SMAC_SEL(ep->smac_idx) |
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002000 DSCP(ep->tos >> 2) |
Steve Wiseb48f3b92011-03-11 22:30:21 +00002001 ULP_MODE(ULP_MODE_TCPDDP) |
Steve Wisecfdda9d2010-04-21 15:30:06 -07002002 RCV_BUFSIZ(rcv_win>>10);
2003 opt2 = RX_CHANNEL(0) |
2004 RSS_QUEUE_VALID | RSS_QUEUE(ep->rss_qid);
2005
2006 if (enable_tcp_timestamps && req->tcpopt.tstamp)
2007 opt2 |= TSTAMPS_EN(1);
2008 if (enable_tcp_sack && req->tcpopt.sack)
2009 opt2 |= SACK_EN(1);
2010 if (wscale && enable_tcp_window_scaling)
2011 opt2 |= WND_SCALE_EN(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002012 if (enable_ecn) {
2013 const struct tcphdr *tcph;
2014 u32 hlen = ntohl(req->hdr_len);
2015
2016 tcph = (const void *)(req + 1) + G_ETH_HDR_LEN(hlen) +
2017 G_IP_HDR_LEN(hlen);
2018 if (tcph->ece && tcph->cwr)
2019 opt2 |= CCTRL_ECN(1);
2020 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002021
2022 rpl = cplhdr(skb);
2023 INIT_TP_WR(rpl, ep->hwtid);
2024 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2025 ep->hwtid));
2026 rpl->opt0 = cpu_to_be64(opt0);
2027 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002028 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wiseb38a0ad2013-08-06 21:04:37 +05302029 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002030 c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
2031
2032 return;
2033}
2034
Vipul Pandya830662f2013-07-04 16:10:47 +05302035static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002036{
Vipul Pandya830662f2013-07-04 16:10:47 +05302037 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002038 BUG_ON(skb_cloned(skb));
2039 skb_trim(skb, sizeof(struct cpl_tid_release));
2040 skb_get(skb);
2041 release_tid(&dev->rdev, hwtid, skb);
2042 return;
2043}
2044
Vipul Pandya830662f2013-07-04 16:10:47 +05302045static void get_4tuple(struct cpl_pass_accept_req *req, int *iptype,
2046 __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002047 __be16 *local_port, __be16 *peer_port)
2048{
2049 int eth_len = G_ETH_HDR_LEN(be32_to_cpu(req->hdr_len));
2050 int ip_len = G_IP_HDR_LEN(be32_to_cpu(req->hdr_len));
2051 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302052 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002053 struct tcphdr *tcp = (struct tcphdr *)
2054 ((u8 *)(req + 1) + eth_len + ip_len);
2055
Vipul Pandya830662f2013-07-04 16:10:47 +05302056 if (ip->version == 4) {
2057 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2058 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2059 ntohs(tcp->dest));
2060 *iptype = 4;
2061 memcpy(peer_ip, &ip->saddr, 4);
2062 memcpy(local_ip, &ip->daddr, 4);
2063 } else {
2064 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2065 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2066 ntohs(tcp->dest));
2067 *iptype = 6;
2068 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2069 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2070 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002071 *peer_port = tcp->source;
2072 *local_port = tcp->dest;
2073
2074 return;
2075}
2076
2077static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2078{
Vipul Pandya793dad92012-12-10 09:30:56 +00002079 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002080 struct cpl_pass_accept_req *req = cplhdr(skb);
2081 unsigned int stid = GET_POPEN_TID(ntohl(req->tos_stid));
2082 struct tid_info *t = dev->rdev.lldi.tids;
2083 unsigned int hwtid = GET_TID(req);
2084 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302085 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002086 __be16 local_port, peer_port;
David Miller3786cf12011-12-02 16:52:31 +00002087 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002088 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302089 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002090
2091 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002092 if (!parent_ep) {
2093 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2094 goto reject;
2095 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002096
Steve Wisecfdda9d2010-04-21 15:30:06 -07002097 if (state_read(&parent_ep->com) != LISTEN) {
2098 printk(KERN_ERR "%s - listening ep not in LISTEN\n",
2099 __func__);
2100 goto reject;
2101 }
2102
Vipul Pandya830662f2013-07-04 16:10:47 +05302103 get_4tuple(req, &iptype, local_ip, peer_ip, &local_port, &peer_port);
2104
Steve Wisecfdda9d2010-04-21 15:30:06 -07002105 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302106 if (iptype == 4) {
2107 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2108 , __func__, parent_ep, hwtid,
2109 local_ip, peer_ip, ntohs(local_port),
2110 ntohs(peer_port), peer_mss);
2111 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2112 local_port, peer_port,
2113 GET_POPEN_TOS(ntohl(req->tos_stid)));
2114 } else {
2115 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2116 , __func__, parent_ep, hwtid,
2117 local_ip, peer_ip, ntohs(local_port),
2118 ntohs(peer_port), peer_mss);
2119 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
2120 PASS_OPEN_TOS(ntohl(req->tos_stid)),
2121 ((struct sockaddr_in6 *)
2122 &parent_ep->com.local_addr)->sin6_scope_id);
2123 }
2124 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002125 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2126 __func__);
2127 goto reject;
2128 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002129
2130 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2131 if (!child_ep) {
2132 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2133 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002134 dst_release(dst);
2135 goto reject;
2136 }
David Miller3786cf12011-12-02 16:52:31 +00002137
Vipul Pandya830662f2013-07-04 16:10:47 +05302138 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false);
David Miller3786cf12011-12-02 16:52:31 +00002139 if (err) {
2140 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2141 __func__);
2142 dst_release(dst);
2143 kfree(child_ep);
2144 goto reject;
2145 }
2146
Vipul Pandya1cab7752012-12-10 09:30:55 +00002147 if (peer_mss && child_ep->mtu > (peer_mss + 40))
2148 child_ep->mtu = peer_mss + 40;
2149
Steve Wisecfdda9d2010-04-21 15:30:06 -07002150 state_set(&child_ep->com, CONNECTING);
2151 child_ep->com.dev = dev;
2152 child_ep->com.cm_id = NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +05302153 if (iptype == 4) {
2154 struct sockaddr_in *sin = (struct sockaddr_in *)
2155 &child_ep->com.local_addr;
2156 sin->sin_family = PF_INET;
2157 sin->sin_port = local_port;
2158 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2159 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
2160 sin->sin_family = PF_INET;
2161 sin->sin_port = peer_port;
2162 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2163 } else {
2164 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
2165 &child_ep->com.local_addr;
2166 sin6->sin6_family = PF_INET6;
2167 sin6->sin6_port = local_port;
2168 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2169 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
2170 sin6->sin6_family = PF_INET6;
2171 sin6->sin6_port = peer_port;
2172 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2173 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002174 c4iw_get_ep(&parent_ep->com);
2175 child_ep->parent_ep = parent_ep;
2176 child_ep->tos = GET_POPEN_TOS(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002177 child_ep->dst = dst;
2178 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002179
2180 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002181 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182
2183 init_timer(&child_ep->timer);
2184 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002185 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Vipul Pandya830662f2013-07-04 16:10:47 +05302186 accept_cr(child_ep, skb, req);
Vipul Pandya793dad92012-12-10 09:30:56 +00002187 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002188 goto out;
2189reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302190 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191out:
2192 return 0;
2193}
2194
2195static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2196{
2197 struct c4iw_ep *ep;
2198 struct cpl_pass_establish *req = cplhdr(skb);
2199 struct tid_info *t = dev->rdev.lldi.tids;
2200 unsigned int tid = GET_TID(req);
2201
2202 ep = lookup_tid(t, tid);
2203 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2204 ep->snd_seq = be32_to_cpu(req->snd_isn);
2205 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2206
Vipul Pandya1cab7752012-12-10 09:30:55 +00002207 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2208 ntohs(req->tcp_opt));
2209
Steve Wisecfdda9d2010-04-21 15:30:06 -07002210 set_emss(ep, ntohs(req->tcp_opt));
2211
2212 dst_confirm(ep->dst);
2213 state_set(&ep->com, MPA_REQ_WAIT);
2214 start_ep_timer(ep);
2215 send_flowc(ep, skb);
Vipul Pandya793dad92012-12-10 09:30:56 +00002216 set_bit(PASS_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002217
2218 return 0;
2219}
2220
2221static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2222{
2223 struct cpl_peer_close *hdr = cplhdr(skb);
2224 struct c4iw_ep *ep;
2225 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002226 int disconnect = 1;
2227 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002228 struct tid_info *t = dev->rdev.lldi.tids;
2229 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002230 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002231
2232 ep = lookup_tid(t, tid);
2233 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2234 dst_confirm(ep->dst);
2235
Vipul Pandya793dad92012-12-10 09:30:56 +00002236 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002237 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002238 switch (ep->com.state) {
2239 case MPA_REQ_WAIT:
2240 __state_set(&ep->com, CLOSING);
2241 break;
2242 case MPA_REQ_SENT:
2243 __state_set(&ep->com, CLOSING);
2244 connect_reply_upcall(ep, -ECONNRESET);
2245 break;
2246 case MPA_REQ_RCVD:
2247
2248 /*
2249 * We're gonna mark this puppy DEAD, but keep
2250 * the reference on it until the ULP accepts or
2251 * rejects the CR. Also wake up anyone waiting
2252 * in rdma connection migration (see c4iw_accept_cr()).
2253 */
2254 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002255 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002256 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002257 break;
2258 case MPA_REP_SENT:
2259 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002260 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002261 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002262 break;
2263 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002264 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002266 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002267 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002268 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002269 if (ret != -ECONNRESET) {
2270 peer_close_upcall(ep);
2271 disconnect = 1;
2272 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002273 break;
2274 case ABORTING:
2275 disconnect = 0;
2276 break;
2277 case CLOSING:
2278 __state_set(&ep->com, MORIBUND);
2279 disconnect = 0;
2280 break;
2281 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002282 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002283 if (ep->com.cm_id && ep->com.qp) {
2284 attrs.next_state = C4IW_QP_STATE_IDLE;
2285 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2286 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2287 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302288 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289 __state_set(&ep->com, DEAD);
2290 release = 1;
2291 disconnect = 0;
2292 break;
2293 case DEAD:
2294 disconnect = 0;
2295 break;
2296 default:
2297 BUG_ON(1);
2298 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002299 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002300 if (disconnect)
2301 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2302 if (release)
2303 release_ep_resources(ep);
2304 return 0;
2305}
2306
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2308{
2309 struct cpl_abort_req_rss *req = cplhdr(skb);
2310 struct c4iw_ep *ep;
2311 struct cpl_abort_rpl *rpl;
2312 struct sk_buff *rpl_skb;
2313 struct c4iw_qp_attributes attrs;
2314 int ret;
2315 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316 struct tid_info *t = dev->rdev.lldi.tids;
2317 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318
2319 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302320 if (is_neg_adv(req->status)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
2322 ep->hwtid);
2323 return 0;
2324 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2326 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002327 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002328
2329 /*
2330 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302331 * However, this is not needed if com state is just
2332 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002333 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302334 if (ep->com.state != MPA_REQ_SENT)
2335 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002336
2337 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002338 switch (ep->com.state) {
2339 case CONNECTING:
2340 break;
2341 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002342 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 break;
2344 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002345 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002346 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302347 connect_reply_upcall(ep, -ECONNRESET);
2348 else {
2349 /*
2350 * we just don't send notification upwards because we
2351 * want to retry with mpa_v1 without upper layers even
2352 * knowing it.
2353 *
2354 * do some housekeeping so as to re-initiate the
2355 * connection
2356 */
2357 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2358 mpa_rev);
2359 ep->retry_with_mpa_v1 = 1;
2360 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 break;
2362 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002363 break;
2364 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002365 break;
2366 case MORIBUND:
2367 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002368 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369 /*FALLTHROUGH*/
2370 case FPDU_MODE:
2371 if (ep->com.cm_id && ep->com.qp) {
2372 attrs.next_state = C4IW_QP_STATE_ERROR;
2373 ret = c4iw_modify_qp(ep->com.qp->rhp,
2374 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2375 &attrs, 1);
2376 if (ret)
2377 printk(KERN_ERR MOD
2378 "%s - qp <- error failed!\n",
2379 __func__);
2380 }
2381 peer_abort_upcall(ep);
2382 break;
2383 case ABORTING:
2384 break;
2385 case DEAD:
2386 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002387 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388 return 0;
2389 default:
2390 BUG_ON(1);
2391 break;
2392 }
2393 dst_confirm(ep->dst);
2394 if (ep->com.state != ABORTING) {
2395 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302396 /* we don't release if we want to retry with mpa_v1 */
2397 if (!ep->retry_with_mpa_v1)
2398 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002399 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002400 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401
2402 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2403 if (!rpl_skb) {
2404 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2405 __func__);
2406 release = 1;
2407 goto out;
2408 }
2409 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2410 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2411 INIT_TP_WR(rpl, ep->hwtid);
2412 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2413 rpl->cmd = CPL_ABORT_NO_RST;
2414 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2415out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 if (release)
2417 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002418 else if (ep->retry_with_mpa_v1) {
2419 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302420 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2421 dst_release(ep->dst);
2422 cxgb4_l2t_release(ep->l2t);
2423 c4iw_reconnect(ep);
2424 }
2425
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 return 0;
2427}
2428
2429static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2430{
2431 struct c4iw_ep *ep;
2432 struct c4iw_qp_attributes attrs;
2433 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 int release = 0;
2435 struct tid_info *t = dev->rdev.lldi.tids;
2436 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437
2438 ep = lookup_tid(t, tid);
2439
2440 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2441 BUG_ON(!ep);
2442
2443 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002444 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445 switch (ep->com.state) {
2446 case CLOSING:
2447 __state_set(&ep->com, MORIBUND);
2448 break;
2449 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002450 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 if ((ep->com.cm_id) && (ep->com.qp)) {
2452 attrs.next_state = C4IW_QP_STATE_IDLE;
2453 c4iw_modify_qp(ep->com.qp->rhp,
2454 ep->com.qp,
2455 C4IW_QP_ATTR_NEXT_STATE,
2456 &attrs, 1);
2457 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302458 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 __state_set(&ep->com, DEAD);
2460 release = 1;
2461 break;
2462 case ABORTING:
2463 case DEAD:
2464 break;
2465 default:
2466 BUG_ON(1);
2467 break;
2468 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002469 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 if (release)
2471 release_ep_resources(ep);
2472 return 0;
2473}
2474
2475static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2476{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002477 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002479 unsigned int tid = GET_TID(rpl);
2480 struct c4iw_ep *ep;
2481 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002482
2483 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002484 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485
Steve Wise30c95c22011-05-09 22:06:22 -07002486 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002487 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2488 ep->com.qp->wq.sq.qid);
2489 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2490 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2491 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2492 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002493 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002494
Steve Wisecfdda9d2010-04-21 15:30:06 -07002495 return 0;
2496}
2497
2498/*
2499 * Upcall from the adapter indicating data has been transmitted.
2500 * For us its just the single MPA request or reply. We can now free
2501 * the skb holding the mpa message.
2502 */
2503static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2504{
2505 struct c4iw_ep *ep;
2506 struct cpl_fw4_ack *hdr = cplhdr(skb);
2507 u8 credits = hdr->credits;
2508 unsigned int tid = GET_TID(hdr);
2509 struct tid_info *t = dev->rdev.lldi.tids;
2510
2511
2512 ep = lookup_tid(t, tid);
2513 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2514 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002515 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2516 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 return 0;
2518 }
2519
2520 dst_confirm(ep->dst);
2521 if (ep->mpa_skb) {
2522 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2523 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2524 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2525 kfree_skb(ep->mpa_skb);
2526 ep->mpa_skb = NULL;
2527 }
2528 return 0;
2529}
2530
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2532{
Steve Wisea7db89e2014-03-21 20:40:35 +05302533 int err = 0;
2534 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002535 struct c4iw_ep *ep = to_ep(cm_id);
2536 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2537
Steve Wisea7db89e2014-03-21 20:40:35 +05302538 mutex_lock(&ep->com.mutex);
2539 if (ep->com.state == DEAD) {
2540 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002541 c4iw_put_ep(&ep->com);
2542 return -ECONNRESET;
2543 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002544 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302545 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002546 if (mpa_rev == 0)
2547 abort_connection(ep, NULL, GFP_KERNEL);
2548 else {
2549 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302550 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002551 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302552 mutex_unlock(&ep->com.mutex);
2553 if (disconnect)
2554 err = c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 c4iw_put_ep(&ep->com);
2556 return 0;
2557}
2558
2559int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2560{
2561 int err;
2562 struct c4iw_qp_attributes attrs;
2563 enum c4iw_qp_attr_mask mask;
2564 struct c4iw_ep *ep = to_ep(cm_id);
2565 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2566 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
2567
2568 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302569
2570 mutex_lock(&ep->com.mutex);
2571 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002572 err = -ECONNRESET;
2573 goto err;
2574 }
2575
Steve Wisea7db89e2014-03-21 20:40:35 +05302576 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577 BUG_ON(!qp);
2578
Vipul Pandya793dad92012-12-10 09:30:56 +00002579 set_bit(ULP_ACCEPT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002580 if ((conn_param->ord > c4iw_max_read_depth) ||
2581 (conn_param->ird > c4iw_max_read_depth)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582 abort_connection(ep, NULL, GFP_KERNEL);
2583 err = -EINVAL;
2584 goto err;
2585 }
2586
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302587 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2588 if (conn_param->ord > ep->ird) {
2589 ep->ird = conn_param->ird;
2590 ep->ord = conn_param->ord;
2591 send_mpa_reject(ep, conn_param->private_data,
2592 conn_param->private_data_len);
2593 abort_connection(ep, NULL, GFP_KERNEL);
2594 err = -ENOMEM;
2595 goto err;
2596 }
2597 if (conn_param->ird > ep->ord) {
2598 if (!ep->ord)
2599 conn_param->ird = 1;
2600 else {
2601 abort_connection(ep, NULL, GFP_KERNEL);
2602 err = -ENOMEM;
2603 goto err;
2604 }
2605 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002606
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302607 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608 ep->ird = conn_param->ird;
2609 ep->ord = conn_param->ord;
2610
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302611 if (ep->mpa_attr.version != 2)
2612 if (peer2peer && ep->ird == 0)
2613 ep->ird = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614
2615 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
2616
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302617 cm_id->add_ref(cm_id);
2618 ep->com.cm_id = cm_id;
2619 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00002620 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302621
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 /* bind QP to EP and move to RTS */
2623 attrs.mpa_attr = ep->mpa_attr;
2624 attrs.max_ird = ep->ird;
2625 attrs.max_ord = ep->ord;
2626 attrs.llp_stream_handle = ep;
2627 attrs.next_state = C4IW_QP_STATE_RTS;
2628
2629 /* bind QP and TID with INIT_WR */
2630 mask = C4IW_QP_ATTR_NEXT_STATE |
2631 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
2632 C4IW_QP_ATTR_MPA_ATTR |
2633 C4IW_QP_ATTR_MAX_IRD |
2634 C4IW_QP_ATTR_MAX_ORD;
2635
2636 err = c4iw_modify_qp(ep->com.qp->rhp,
2637 ep->com.qp, mask, &attrs, 1);
2638 if (err)
2639 goto err1;
2640 err = send_mpa_reply(ep, conn_param->private_data,
2641 conn_param->private_data_len);
2642 if (err)
2643 goto err1;
2644
Steve Wisea7db89e2014-03-21 20:40:35 +05302645 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05302647 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 c4iw_put_ep(&ep->com);
2649 return 0;
2650err1:
2651 ep->com.cm_id = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652 cm_id->rem_ref(cm_id);
2653err:
Steve Wisea7db89e2014-03-21 20:40:35 +05302654 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 c4iw_put_ep(&ep->com);
2656 return err;
2657}
2658
Vipul Pandya830662f2013-07-04 16:10:47 +05302659static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2660{
2661 struct in_device *ind;
2662 int found = 0;
2663 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2664 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
2665
2666 ind = in_dev_get(dev->rdev.lldi.ports[0]);
2667 if (!ind)
2668 return -EADDRNOTAVAIL;
2669 for_primary_ifa(ind) {
2670 laddr->sin_addr.s_addr = ifa->ifa_address;
2671 raddr->sin_addr.s_addr = ifa->ifa_address;
2672 found = 1;
2673 break;
2674 }
2675 endfor_ifa(ind);
2676 in_dev_put(ind);
2677 return found ? 0 : -EADDRNOTAVAIL;
2678}
2679
2680static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
2681 unsigned char banned_flags)
2682{
2683 struct inet6_dev *idev;
2684 int err = -EADDRNOTAVAIL;
2685
2686 rcu_read_lock();
2687 idev = __in6_dev_get(dev);
2688 if (idev != NULL) {
2689 struct inet6_ifaddr *ifp;
2690
2691 read_lock_bh(&idev->lock);
2692 list_for_each_entry(ifp, &idev->addr_list, if_list) {
2693 if (ifp->scope == IFA_LINK &&
2694 !(ifp->flags & banned_flags)) {
2695 memcpy(addr, &ifp->addr, 16);
2696 err = 0;
2697 break;
2698 }
2699 }
2700 read_unlock_bh(&idev->lock);
2701 }
2702 rcu_read_unlock();
2703 return err;
2704}
2705
2706static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
2707{
2708 struct in6_addr uninitialized_var(addr);
2709 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2710 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->remote_addr;
2711
2712 if (get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
2713 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
2714 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
2715 return 0;
2716 }
2717 return -EADDRNOTAVAIL;
2718}
2719
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2721{
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2723 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00002724 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302725 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->local_addr;
2726 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302727 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)&cm_id->local_addr;
2728 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
2729 &cm_id->remote_addr;
2730 __u8 *ra;
2731 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002733 if ((conn_param->ord > c4iw_max_read_depth) ||
2734 (conn_param->ird > c4iw_max_read_depth)) {
2735 err = -EINVAL;
2736 goto out;
2737 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2739 if (!ep) {
2740 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2741 err = -ENOMEM;
2742 goto out;
2743 }
2744 init_timer(&ep->timer);
2745 ep->plen = conn_param->private_data_len;
2746 if (ep->plen)
2747 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
2748 conn_param->private_data, ep->plen);
2749 ep->ird = conn_param->ird;
2750 ep->ord = conn_param->ord;
2751
2752 if (peer2peer && ep->ord == 0)
2753 ep->ord = 1;
2754
2755 cm_id->add_ref(cm_id);
2756 ep->com.dev = dev;
2757 ep->com.cm_id = cm_id;
2758 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05302759 if (!ep->com.qp) {
2760 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
2761 err = -EINVAL;
2762 goto fail2;
2763 }
Vipul Pandya325abea2013-01-07 13:11:53 +00002764 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002765 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
2766 ep->com.qp, cm_id);
2767
2768 /*
2769 * Allocate an active TID to initiate a TCP connection.
2770 */
2771 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
2772 if (ep->atid == -1) {
2773 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
2774 err = -ENOMEM;
2775 goto fail2;
2776 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002777 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778
Vipul Pandya830662f2013-07-04 16:10:47 +05302779 if (cm_id->remote_addr.ss_family == AF_INET) {
2780 iptype = 4;
2781 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002782
Vipul Pandya830662f2013-07-04 16:10:47 +05302783 /*
2784 * Handle loopback requests to INADDR_ANY.
2785 */
2786 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
2787 err = pick_local_ipaddrs(dev, cm_id);
2788 if (err)
2789 goto fail2;
2790 }
2791
2792 /* find a route */
2793 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
2794 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
2795 ra, ntohs(raddr->sin_port));
2796 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
2797 raddr->sin_addr.s_addr, laddr->sin_port,
2798 raddr->sin_port, 0);
2799 } else {
2800 iptype = 6;
2801 ra = (__u8 *)&raddr6->sin6_addr;
2802
2803 /*
2804 * Handle loopback requests to INADDR_ANY.
2805 */
2806 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
2807 err = pick_local_ip6addrs(dev, cm_id);
2808 if (err)
2809 goto fail2;
2810 }
2811
2812 /* find a route */
2813 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
2814 __func__, laddr6->sin6_addr.s6_addr,
2815 ntohs(laddr6->sin6_port),
2816 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
2817 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
2818 raddr6->sin6_addr.s6_addr,
2819 laddr6->sin6_port, raddr6->sin6_port, 0,
2820 raddr6->sin6_scope_id);
2821 }
2822 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002823 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
2824 err = -EHOSTUNREACH;
2825 goto fail3;
2826 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827
Vipul Pandya830662f2013-07-04 16:10:47 +05302828 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true);
David Miller3786cf12011-12-02 16:52:31 +00002829 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002830 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002831 goto fail4;
2832 }
2833
2834 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2835 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2836 ep->l2t->idx);
2837
2838 state_set(&ep->com, CONNECTING);
2839 ep->tos = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302840 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2841 sizeof(ep->com.local_addr));
2842 memcpy(&ep->com.remote_addr, &cm_id->remote_addr,
2843 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002844
2845 /* send connect request to rnic */
2846 err = send_connect(ep);
2847 if (!err)
2848 goto out;
2849
2850 cxgb4_l2t_release(ep->l2t);
2851fail4:
2852 dst_release(ep->dst);
2853fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00002854 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002855 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2856fail2:
2857 cm_id->rem_ref(cm_id);
2858 c4iw_put_ep(&ep->com);
2859out:
2860 return err;
2861}
2862
Vipul Pandya830662f2013-07-04 16:10:47 +05302863static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2864{
2865 int err;
2866 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2867
2868 c4iw_init_wr_wait(&ep->com.wr_wait);
2869 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
2870 ep->stid, &sin6->sin6_addr,
2871 sin6->sin6_port,
2872 ep->com.dev->rdev.lldi.rxq_ids[0]);
2873 if (!err)
2874 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2875 &ep->com.wr_wait,
2876 0, 0, __func__);
2877 if (err)
2878 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
2879 err, ep->stid,
2880 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
2881 return err;
2882}
2883
2884static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
2885{
2886 int err;
2887 struct sockaddr_in *sin = (struct sockaddr_in *)&ep->com.local_addr;
2888
2889 if (dev->rdev.lldi.enable_fw_ofld_conn) {
2890 do {
2891 err = cxgb4_create_server_filter(
2892 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2893 sin->sin_addr.s_addr, sin->sin_port, 0,
2894 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
2895 if (err == -EBUSY) {
2896 set_current_state(TASK_UNINTERRUPTIBLE);
2897 schedule_timeout(usecs_to_jiffies(100));
2898 }
2899 } while (err == -EBUSY);
2900 } else {
2901 c4iw_init_wr_wait(&ep->com.wr_wait);
2902 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
2903 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
2904 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
2905 if (!err)
2906 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
2907 &ep->com.wr_wait,
2908 0, 0, __func__);
2909 }
2910 if (err)
2911 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
2912 , err, ep->stid,
2913 &sin->sin_addr, ntohs(sin->sin_port));
2914 return err;
2915}
2916
Steve Wisecfdda9d2010-04-21 15:30:06 -07002917int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
2918{
2919 int err = 0;
2920 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
2921 struct c4iw_listen_ep *ep;
2922
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 might_sleep();
2924
2925 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
2926 if (!ep) {
2927 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
2928 err = -ENOMEM;
2929 goto fail1;
2930 }
2931 PDBG("%s ep %p\n", __func__, ep);
2932 cm_id->add_ref(cm_id);
2933 ep->com.cm_id = cm_id;
2934 ep->com.dev = dev;
2935 ep->backlog = backlog;
Steve Wise24d44a32013-07-04 16:10:44 +05302936 memcpy(&ep->com.local_addr, &cm_id->local_addr,
2937 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938
2939 /*
2940 * Allocate a server TID.
2941 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05302942 if (dev->rdev.lldi.enable_fw_ofld_conn &&
2943 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05302944 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
2945 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002946 else
Vipul Pandya830662f2013-07-04 16:10:47 +05302947 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
2948 cm_id->local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002949
Steve Wisecfdda9d2010-04-21 15:30:06 -07002950 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07002951 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002952 err = -ENOMEM;
2953 goto fail2;
2954 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002955 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05302957 if (ep->com.local_addr.ss_family == AF_INET)
2958 err = create_server4(dev, ep);
2959 else
2960 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961 if (!err) {
2962 cm_id->provider_data = ep;
2963 goto out;
2964 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302965 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
2966 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967fail2:
2968 cm_id->rem_ref(cm_id);
2969 c4iw_put_ep(&ep->com);
2970fail1:
2971out:
2972 return err;
2973}
2974
2975int c4iw_destroy_listen(struct iw_cm_id *cm_id)
2976{
2977 int err;
2978 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
2979
2980 PDBG("%s ep %p\n", __func__, ep);
2981
2982 might_sleep();
2983 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05302984 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
2985 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002986 err = cxgb4_remove_server_filter(
2987 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2988 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
2989 } else {
2990 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05302991 err = cxgb4_remove_server(
2992 ep->com.dev->rdev.lldi.ports[0], ep->stid,
2993 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002994 if (err)
2995 goto done;
2996 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
2997 0, 0, __func__);
2998 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002999 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303000 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3001 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002done:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003003 cm_id->rem_ref(cm_id);
3004 c4iw_put_ep(&ep->com);
3005 return err;
3006}
3007
3008int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3009{
3010 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 int close = 0;
3012 int fatal = 0;
3013 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014
Steve Wise2f5b48c2010-09-10 11:15:36 -05003015 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003016
3017 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3018 states[ep->com.state], abrupt);
3019
3020 rdev = &ep->com.dev->rdev;
3021 if (c4iw_fatal_error(rdev)) {
3022 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303023 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003024 ep->com.state = DEAD;
3025 }
3026 switch (ep->com.state) {
3027 case MPA_REQ_WAIT:
3028 case MPA_REQ_SENT:
3029 case MPA_REQ_RCVD:
3030 case MPA_REP_SENT:
3031 case FPDU_MODE:
3032 close = 1;
3033 if (abrupt)
3034 ep->com.state = ABORTING;
3035 else {
3036 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003037 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038 }
3039 set_bit(CLOSE_SENT, &ep->com.flags);
3040 break;
3041 case CLOSING:
3042 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3043 close = 1;
3044 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003045 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003046 ep->com.state = ABORTING;
3047 } else
3048 ep->com.state = MORIBUND;
3049 }
3050 break;
3051 case MORIBUND:
3052 case ABORTING:
3053 case DEAD:
3054 PDBG("%s ignoring disconnect ep %p state %u\n",
3055 __func__, ep, ep->com.state);
3056 break;
3057 default:
3058 BUG();
3059 break;
3060 }
3061
Steve Wisecfdda9d2010-04-21 15:30:06 -07003062 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003063 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003064 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303065 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003066 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003067 } else {
3068 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003069 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003070 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003071 if (ret)
3072 fatal = 1;
3073 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003074 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003075 if (fatal)
3076 release_ep_resources(ep);
3077 return ret;
3078}
3079
Vipul Pandya1cab7752012-12-10 09:30:55 +00003080static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3081 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3082{
3083 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003084 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003085
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003086 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3087 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003088 if (!ep)
3089 return;
3090
3091 switch (req->retval) {
3092 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003093 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3094 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3095 send_fw_act_open_req(ep, atid);
3096 return;
3097 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003098 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003099 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3100 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3101 send_fw_act_open_req(ep, atid);
3102 return;
3103 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003104 break;
3105 default:
3106 pr_info("%s unexpected ofld conn wr retval %d\n",
3107 __func__, req->retval);
3108 break;
3109 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003110 pr_err("active ofld_connect_wr failure %d atid %d\n",
3111 req->retval, atid);
3112 mutex_lock(&dev->rdev.stats.lock);
3113 dev->rdev.stats.act_ofld_conn_fails++;
3114 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003115 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003116 state_set(&ep->com, DEAD);
3117 remove_handle(dev, &dev->atid_idr, atid);
3118 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3119 dst_release(ep->dst);
3120 cxgb4_l2t_release(ep->l2t);
3121 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003122}
3123
3124static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3125 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3126{
3127 struct sk_buff *rpl_skb;
3128 struct cpl_pass_accept_req *cpl;
3129 int ret;
3130
Paul Bolle710a3112013-02-05 20:51:30 +00003131 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003132 BUG_ON(!rpl_skb);
3133 if (req->retval) {
3134 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003135 mutex_lock(&dev->rdev.stats.lock);
3136 dev->rdev.stats.pas_ofld_conn_fails++;
3137 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003138 kfree_skb(rpl_skb);
3139 } else {
3140 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3141 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003142 (__force u32) htonl(
3143 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003144 ret = pass_accept_req(dev, rpl_skb);
3145 if (!ret)
3146 kfree_skb(rpl_skb);
3147 }
3148 return;
3149}
3150
3151static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003152{
3153 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003154 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3155
3156 switch (rpl->type) {
3157 case FW6_TYPE_CQE:
3158 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3159 break;
3160 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3161 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3162 switch (req->t_state) {
3163 case TCP_SYN_SENT:
3164 active_ofld_conn_reply(dev, skb, req);
3165 break;
3166 case TCP_SYN_RECV:
3167 passive_ofld_conn_reply(dev, skb, req);
3168 break;
3169 default:
3170 pr_err("%s unexpected ofld conn wr state %d\n",
3171 __func__, req->t_state);
3172 break;
3173 }
3174 break;
3175 }
3176 return 0;
3177}
3178
3179static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3180{
3181 u32 l2info;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003182 u16 vlantag, len, hdr_len, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003183 u8 intf;
3184 struct cpl_rx_pkt *cpl = cplhdr(skb);
3185 struct cpl_pass_accept_req *req;
3186 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003187 struct c4iw_dev *dev;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003188
Vipul Pandyaf079af72013-03-14 05:08:58 +00003189 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003190 /* Store values from cpl_rx_pkt in temporary location. */
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003191 vlantag = (__force u16) cpl->vlan;
3192 len = (__force u16) cpl->len;
3193 l2info = (__force u32) cpl->l2info;
3194 hdr_len = (__force u16) cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003195 intf = cpl->iff;
3196
3197 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3198
3199 /*
3200 * We need to parse the TCP options from SYN packet.
3201 * to generate cpl_pass_accept_req.
3202 */
3203 memset(&tmp_opt, 0, sizeof(tmp_opt));
3204 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003205 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003206
3207 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3208 memset(req, 0, sizeof(*req));
3209 req->l2info = cpu_to_be16(V_SYN_INTF(intf) |
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003210 V_SYN_MAC_IDX(G_RX_MACIDX(
3211 (__force int) htonl(l2info))) |
Vipul Pandya1cab7752012-12-10 09:30:55 +00003212 F_SYN_XACT_MATCH);
Vipul Pandyaf079af72013-03-14 05:08:58 +00003213 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3214 G_RX_ETHHDR_LEN((__force int) htonl(l2info)) :
3215 G_RX_T5_ETHHDR_LEN((__force int) htonl(l2info));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003216 req->hdr_len = cpu_to_be32(V_SYN_RX_CHAN(G_RX_CHAN(
3217 (__force int) htonl(l2info))) |
3218 V_TCP_HDR_LEN(G_RX_TCPHDR_LEN(
3219 (__force int) htons(hdr_len))) |
3220 V_IP_HDR_LEN(G_RX_IPHDR_LEN(
3221 (__force int) htons(hdr_len))) |
Vipul Pandyaf079af72013-03-14 05:08:58 +00003222 V_ETH_HDR_LEN(G_RX_ETHHDR_LEN(eth_hdr_len)));
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003223 req->vlan = (__force __be16) vlantag;
3224 req->len = (__force __be16) len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003225 req->tos_stid = cpu_to_be32(PASS_OPEN_TID(stid) |
3226 PASS_OPEN_TOS(tos));
3227 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3228 if (tmp_opt.wscale_ok)
3229 req->tcpopt.wsf = tmp_opt.snd_wscale;
3230 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3231 if (tmp_opt.sack_ok)
3232 req->tcpopt.sack = 1;
3233 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3234 return;
3235}
3236
3237static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3238 __be32 laddr, __be16 lport,
3239 __be32 raddr, __be16 rport,
3240 u32 rcv_isn, u32 filter, u16 window,
3241 u32 rss_qid, u8 port_id)
3242{
3243 struct sk_buff *req_skb;
3244 struct fw_ofld_connection_wr *req;
3245 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303246 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003247
3248 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3249 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3250 memset(req, 0, sizeof(*req));
3251 req->op_compl = htonl(V_WR_OP(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL(1));
3252 req->len16_pkd = htonl(FW_WR_LEN16(DIV_ROUND_UP(sizeof(*req), 16)));
3253 req->le.version_cpl = htonl(F_FW_OFLD_CONNECTION_WR_CPL);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003254 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003255 req->le.lport = lport;
3256 req->le.pport = rport;
3257 req->le.u.ipv4.lip = laddr;
3258 req->le.u.ipv4.pip = raddr;
3259 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3260 req->tcb.rcv_adv = htons(window);
3261 req->tcb.t_state_to_astid =
3262 htonl(V_FW_OFLD_CONNECTION_WR_T_STATE(TCP_SYN_RECV) |
3263 V_FW_OFLD_CONNECTION_WR_RCV_SCALE(cpl->tcpopt.wsf) |
3264 V_FW_OFLD_CONNECTION_WR_ASTID(
3265 GET_PASS_OPEN_TID(ntohl(cpl->tos_stid))));
3266
3267 /*
3268 * We store the qid in opt2 which will be used by the firmware
3269 * to send us the wr response.
3270 */
3271 req->tcb.opt2 = htonl(V_RSS_QUEUE(rss_qid));
3272
3273 /*
3274 * We initialize the MSS index in TCB to 0xF.
3275 * So that when driver sends cpl_pass_accept_rpl
3276 * TCB picks up the correct value. If this was 0
3277 * TP will ignore any value > 0 for MSS index.
3278 */
3279 req->tcb.opt0 = cpu_to_be64(V_MSS_IDX(0xF));
Paul Bolle710a3112013-02-05 20:51:30 +00003280 req->cookie = (unsigned long)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003281
3282 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303283 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3284 if (ret < 0) {
3285 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3286 ret);
3287 kfree_skb(skb);
3288 kfree_skb(req_skb);
3289 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003290}
3291
3292/*
3293 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3294 * messages when a filter is being used instead of server to
3295 * redirect a syn packet. When packets hit filter they are redirected
3296 * to the offload queue and driver tries to establish the connection
3297 * using firmware work request.
3298 */
3299static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3300{
3301 int stid;
3302 unsigned int filter;
3303 struct ethhdr *eh = NULL;
3304 struct vlan_ethhdr *vlan_eh = NULL;
3305 struct iphdr *iph;
3306 struct tcphdr *tcph;
3307 struct rss_header *rss = (void *)skb->data;
3308 struct cpl_rx_pkt *cpl = (void *)skb->data;
3309 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3310 struct l2t_entry *e;
3311 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003312 struct c4iw_ep *lep;
3313 u16 window;
3314 struct port_info *pi;
3315 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003316 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003317 int step;
3318 u32 tx_chan;
3319 struct neighbour *neigh;
3320
3321 /* Drop all non-SYN packets */
3322 if (!(cpl->l2info & cpu_to_be32(F_RXF_SYN)))
3323 goto reject;
3324
3325 /*
3326 * Drop all packets which did not hit the filter.
3327 * Unlikely to happen.
3328 */
3329 if (!(rss->filter_hit && rss->filter_tid))
3330 goto reject;
3331
3332 /*
3333 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3334 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303335 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003336
3337 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3338 if (!lep) {
3339 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3340 goto reject;
3341 }
3342
Vipul Pandyaf079af72013-03-14 05:08:58 +00003343 eth_hdr_len = is_t4(dev->rdev.lldi.adapter_type) ?
3344 G_RX_ETHHDR_LEN(htonl(cpl->l2info)) :
3345 G_RX_T5_ETHHDR_LEN(htonl(cpl->l2info));
3346 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003347 eh = (struct ethhdr *)(req + 1);
3348 iph = (struct iphdr *)(eh + 1);
3349 } else {
3350 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3351 iph = (struct iphdr *)(vlan_eh + 1);
3352 skb->vlan_tci = ntohs(cpl->vlan);
3353 }
3354
3355 if (iph->version != 0x4)
3356 goto reject;
3357
3358 tcph = (struct tcphdr *)(iph + 1);
3359 skb_set_network_header(skb, (void *)iph - (void *)rss);
3360 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3361 skb_get(skb);
3362
3363 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3364 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3365 ntohs(tcph->source), iph->tos);
3366
Vipul Pandya830662f2013-07-04 16:10:47 +05303367 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3368 iph->tos);
3369 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003370 pr_err("%s - failed to find dst entry!\n",
3371 __func__);
3372 goto reject;
3373 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003374 neigh = dst_neigh_lookup_skb(dst, skb);
3375
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003376 if (!neigh) {
3377 pr_err("%s - failed to allocate neigh!\n",
3378 __func__);
3379 goto free_dst;
3380 }
3381
Vipul Pandya1cab7752012-12-10 09:30:55 +00003382 if (neigh->dev->flags & IFF_LOOPBACK) {
3383 pdev = ip_dev_find(&init_net, iph->daddr);
3384 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3385 pdev, 0);
3386 pi = (struct port_info *)netdev_priv(pdev);
3387 tx_chan = cxgb4_port_chan(pdev);
3388 dev_put(pdev);
3389 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303390 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003391 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303392 pdev, 0);
3393 pi = (struct port_info *)netdev_priv(pdev);
3394 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003395 }
Steve Wiseebf00062014-03-19 17:44:40 +05303396 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003397 if (!e) {
3398 pr_err("%s - failed to allocate l2t entry!\n",
3399 __func__);
3400 goto free_dst;
3401 }
3402
3403 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3404 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003405 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003406
3407 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303408 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3409 dev->rdev.lldi.ports[0],
3410 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003411
3412 /*
3413 * Synthesize the cpl_pass_accept_req. We have everything except the
3414 * TID. Once firmware sends a reply with TID we update the TID field
3415 * in cpl and pass it through the regular cpl_pass_accept_req path.
3416 */
3417 build_cpl_pass_accept_req(skb, stid, iph->tos);
3418 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3419 tcph->source, ntohl(tcph->seq), filter, window,
3420 rss_qid, pi->port_id);
3421 cxgb4_l2t_release(e);
3422free_dst:
3423 dst_release(dst);
3424reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003425 return 0;
3426}
3427
Steve Wisecfdda9d2010-04-21 15:30:06 -07003428/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003429 * These are the real handlers that are called from a
3430 * work queue.
3431 */
3432static c4iw_handler_func work_handlers[NUM_CPL_CMDS] = {
3433 [CPL_ACT_ESTABLISH] = act_establish,
3434 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3435 [CPL_RX_DATA] = rx_data,
3436 [CPL_ABORT_RPL_RSS] = abort_rpl,
3437 [CPL_ABORT_RPL] = abort_rpl,
3438 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3439 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3440 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3441 [CPL_PASS_ESTABLISH] = pass_establish,
3442 [CPL_PEER_CLOSE] = peer_close,
3443 [CPL_ABORT_REQ_RSS] = peer_abort,
3444 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3445 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003446 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003447 [CPL_FW6_MSG] = deferred_fw6_msg,
3448 [CPL_RX_PKT] = rx_pkt
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003449};
3450
3451static void process_timeout(struct c4iw_ep *ep)
3452{
3453 struct c4iw_qp_attributes attrs;
3454 int abort = 1;
3455
Steve Wise2f5b48c2010-09-10 11:15:36 -05003456 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003457 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3458 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003459 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003460 switch (ep->com.state) {
3461 case MPA_REQ_SENT:
3462 __state_set(&ep->com, ABORTING);
3463 connect_reply_upcall(ep, -ETIMEDOUT);
3464 break;
3465 case MPA_REQ_WAIT:
3466 __state_set(&ep->com, ABORTING);
3467 break;
3468 case CLOSING:
3469 case MORIBUND:
3470 if (ep->com.cm_id && ep->com.qp) {
3471 attrs.next_state = C4IW_QP_STATE_ERROR;
3472 c4iw_modify_qp(ep->com.qp->rhp,
3473 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3474 &attrs, 1);
3475 }
3476 __state_set(&ep->com, ABORTING);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303477 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003478 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003479 case ABORTING:
3480 case DEAD:
3481
3482 /*
3483 * These states are expected if the ep timed out at the same
3484 * time as another thread was calling stop_ep_timer().
3485 * So we silently do nothing for these states.
3486 */
3487 abort = 0;
3488 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003489 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00003490 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003491 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003492 abort = 0;
3493 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003494 if (abort)
3495 abort_connection(ep, NULL, GFP_KERNEL);
Steve Wisecc18b932014-04-24 14:31:53 -05003496 mutex_unlock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003497 c4iw_put_ep(&ep->com);
3498}
3499
3500static void process_timedout_eps(void)
3501{
3502 struct c4iw_ep *ep;
3503
3504 spin_lock_irq(&timeout_lock);
3505 while (!list_empty(&timeout_list)) {
3506 struct list_head *tmp;
3507
3508 tmp = timeout_list.next;
3509 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003510 tmp->next = NULL;
3511 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003512 spin_unlock_irq(&timeout_lock);
3513 ep = list_entry(tmp, struct c4iw_ep, entry);
3514 process_timeout(ep);
3515 spin_lock_irq(&timeout_lock);
3516 }
3517 spin_unlock_irq(&timeout_lock);
3518}
3519
3520static void process_work(struct work_struct *work)
3521{
3522 struct sk_buff *skb = NULL;
3523 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00003524 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003525 unsigned int opcode;
3526 int ret;
3527
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003528 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003529 while ((skb = skb_dequeue(&rxq))) {
3530 rpl = cplhdr(skb);
3531 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
3532 opcode = rpl->ot.opcode;
3533
3534 BUG_ON(!work_handlers[opcode]);
3535 ret = work_handlers[opcode](dev, skb);
3536 if (!ret)
3537 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003538 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003539 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003540}
3541
3542static DECLARE_WORK(skb_work, process_work);
3543
3544static void ep_timeout(unsigned long arg)
3545{
3546 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003547 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003548
3549 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003550 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003551 /*
3552 * Only insert if it is not already on the list.
3553 */
3554 if (!ep->entry.next) {
3555 list_add_tail(&ep->entry, &timeout_list);
3556 kickit = 1;
3557 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003558 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003559 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00003560 if (kickit)
3561 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003562}
3563
3564/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07003565 * All the CM events are handled on a work queue to have a safe context.
3566 */
3567static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
3568{
3569
3570 /*
3571 * Save dev in the skb->cb area.
3572 */
3573 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
3574
3575 /*
3576 * Queue the skb and schedule the worker thread.
3577 */
3578 skb_queue_tail(&rxq, skb);
3579 queue_work(workq, &skb_work);
3580 return 0;
3581}
3582
3583static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
3584{
3585 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
3586
3587 if (rpl->status != CPL_ERR_NONE) {
3588 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
3589 "for tid %u\n", rpl->status, GET_TID(rpl));
3590 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003591 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003592 return 0;
3593}
3594
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003595static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
3596{
3597 struct cpl_fw6_msg *rpl = cplhdr(skb);
3598 struct c4iw_wr_wait *wr_waitp;
3599 int ret;
3600
3601 PDBG("%s type %u\n", __func__, rpl->type);
3602
3603 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003604 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003605 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07003606 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003607 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07003608 if (wr_waitp)
3609 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003610 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003611 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003612 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003613 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00003614 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00003615 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003616 default:
3617 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
3618 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003619 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003620 break;
3621 }
3622 return 0;
3623}
3624
Steve Wise8da7e7a2011-06-14 20:59:27 +00003625static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
3626{
3627 struct cpl_abort_req_rss *req = cplhdr(skb);
3628 struct c4iw_ep *ep;
3629 struct tid_info *t = dev->rdev.lldi.tids;
3630 unsigned int tid = GET_TID(req);
3631
3632 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05003633 if (!ep) {
3634 printk(KERN_WARNING MOD
3635 "Abort on non-existent endpoint, tid %d\n", tid);
3636 kfree_skb(skb);
3637 return 0;
3638 }
Steve Wise7a2cea22014-03-14 21:52:07 +05303639 if (is_neg_adv(req->status)) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003640 PDBG("%s neg_adv_abort ep %p tid %u\n", __func__, ep,
3641 ep->hwtid);
3642 kfree_skb(skb);
3643 return 0;
3644 }
3645 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
3646 ep->com.state);
3647
3648 /*
3649 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003650 * However, if we are on MPAv2 and want to retry with MPAv1
3651 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00003652 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00003653 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
3654 if (ep->com.state != MPA_REQ_SENT)
3655 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
3656 } else
3657 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003658 sched(dev, skb);
3659 return 0;
3660}
3661
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003662/*
3663 * Most upcalls from the T4 Core go to sched() to
3664 * schedule the processing on a work queue.
3665 */
3666c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
3667 [CPL_ACT_ESTABLISH] = sched,
3668 [CPL_ACT_OPEN_RPL] = sched,
3669 [CPL_RX_DATA] = sched,
3670 [CPL_ABORT_RPL_RSS] = sched,
3671 [CPL_ABORT_RPL] = sched,
3672 [CPL_PASS_OPEN_RPL] = sched,
3673 [CPL_CLOSE_LISTSRV_RPL] = sched,
3674 [CPL_PASS_ACCEPT_REQ] = sched,
3675 [CPL_PASS_ESTABLISH] = sched,
3676 [CPL_PEER_CLOSE] = sched,
3677 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00003678 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003679 [CPL_RDMA_TERMINATE] = sched,
3680 [CPL_FW4_ACK] = sched,
3681 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003682 [CPL_FW6_MSG] = fw6_msg,
3683 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003684};
3685
Steve Wisecfdda9d2010-04-21 15:30:06 -07003686int __init c4iw_cm_init(void)
3687{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003688 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003689 skb_queue_head_init(&rxq);
3690
3691 workq = create_singlethread_workqueue("iw_cxgb4");
3692 if (!workq)
3693 return -ENOMEM;
3694
Steve Wisecfdda9d2010-04-21 15:30:06 -07003695 return 0;
3696}
3697
3698void __exit c4iw_cm_term(void)
3699{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003700 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003701 flush_workqueue(workq);
3702 destroy_workqueue(workq);
3703}