blob: e8edfeea84f9c871755e8debd894ecdd91264af8 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
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
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Steve Wisecfdda9d2010-04-21 15:30:06 -070052#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053053#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070054
55static char *states[] = {
56 "idle",
57 "listen",
58 "connecting",
59 "mpa_wait_req",
60 "mpa_req_sent",
61 "mpa_req_rcvd",
62 "mpa_rep_sent",
63 "fpdu_mode",
64 "aborting",
65 "closing",
66 "moribund",
67 "dead",
68 NULL,
69};
70
Vipul Pandya5be78ee2012-12-10 09:30:54 +000071static int nocong;
72module_param(nocong, int, 0644);
73MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75static int enable_ecn;
76module_param(enable_ecn, int, 0644);
77MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
Steve Wiseb52fe092011-03-11 22:30:01 +000079static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000080module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000081MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000082
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053083uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070084module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053085MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070087
Steve Wisecfdda9d2010-04-21 15:30:06 -070088static int enable_tcp_timestamps;
89module_param(enable_tcp_timestamps, int, 0644);
90MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92static int enable_tcp_sack;
93module_param(enable_tcp_sack, int, 0644);
94MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96static int enable_tcp_window_scaling = 1;
97module_param(enable_tcp_window_scaling, int, 0644);
98MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101int c4iw_debug;
102module_param(c4iw_debug, int, 0644);
103MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
Steve Wisedf2d5132014-03-19 17:44:44 +0530105static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530107MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110module_param(p2p_type, int, 0644);
111MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114static int ep_timeout_secs = 60;
115module_param(ep_timeout_secs, int, 0644);
116MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530119static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120module_param(mpa_rev, int, 0644);
121MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530122 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530123 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
125static int markers_enabled;
126module_param(markers_enabled, int, 0644);
127MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129static int crc_enabled = 1;
130module_param(crc_enabled, int, 0644);
131MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133static int rcv_win = 256 * 1024;
134module_param(rcv_win, int, 0644);
135MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
Steve Wise98ae68b2010-09-10 11:15:41 -0500137static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500139MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700144
145static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146static void ep_timeout(unsigned long arg);
147static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530148static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700149
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700150static LIST_HEAD(timeout_list);
151static spinlock_t timeout_lock;
152
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530153static void deref_cm_id(struct c4iw_ep_common *epc)
154{
155 epc->cm_id->rem_ref(epc->cm_id);
156 epc->cm_id = NULL;
157 set_bit(CM_ID_DEREFED, &epc->history);
158}
159
160static void ref_cm_id(struct c4iw_ep_common *epc)
161{
162 set_bit(CM_ID_REFED, &epc->history);
163 epc->cm_id->add_ref(epc->cm_id);
164}
165
Vipul Pandya325abea2013-01-07 13:11:53 +0000166static void deref_qp(struct c4iw_ep *ep)
167{
168 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
169 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530170 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000171}
172
173static void ref_qp(struct c4iw_ep *ep)
174{
175 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530176 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000177 c4iw_qp_add_ref(&ep->com.qp->ibqp);
178}
179
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180static void start_ep_timer(struct c4iw_ep *ep)
181{
182 PDBG("%s ep %p\n", __func__, ep);
183 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000184 pr_err("%s timer already started! ep %p\n",
185 __func__, ep);
186 return;
187 }
188 clear_bit(TIMEOUT, &ep->com.flags);
189 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700190 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
191 ep->timer.data = (unsigned long)ep;
192 ep->timer.function = ep_timeout;
193 add_timer(&ep->timer);
194}
195
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500196static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700197{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000198 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700199 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500200 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000201 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500202 return 0;
203 }
204 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
208 struct l2t_entry *l2e)
209{
210 int error = 0;
211
212 if (c4iw_fatal_error(rdev)) {
213 kfree_skb(skb);
214 PDBG("%s - device in error state - dropping\n", __func__);
215 return -EIO;
216 }
217 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
218 if (error < 0)
219 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530220 else if (error == NET_XMIT_DROP)
221 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500222 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700223}
224
225int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
226{
227 int error = 0;
228
229 if (c4iw_fatal_error(rdev)) {
230 kfree_skb(skb);
231 PDBG("%s - device in error state - dropping\n", __func__);
232 return -EIO;
233 }
234 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
235 if (error < 0)
236 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500237 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700238}
239
240static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
241{
242 struct cpl_tid_release *req;
243
244 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
245 if (!skb)
246 return;
247 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
248 INIT_TP_WR(req, hwtid);
249 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
250 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
251 c4iw_ofld_send(rdev, skb);
252 return;
253}
254
255static void set_emss(struct c4iw_ep *ep, u16 opt)
256{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800257 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530258 ((AF_INET == ep->com.remote_addr.ss_family) ?
259 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
260 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800262 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530263 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700264 if (ep->emss < 128)
265 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530266 if (ep->emss & 7)
267 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800268 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
269 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700270 ep->mss, ep->emss);
271}
272
273static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
274{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 enum c4iw_ep_state state;
276
Steve Wise2f5b48c2010-09-10 11:15:36 -0500277 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500279 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700280 return state;
281}
282
283static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
284{
285 epc->state = new;
286}
287
288static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
289{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500290 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
292 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500293 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700294 return;
295}
296
297static void *alloc_ep(int size, gfp_t gfp)
298{
299 struct c4iw_ep_common *epc;
300
301 epc = kzalloc(size, gfp);
302 if (epc) {
303 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500304 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500305 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700306 }
307 PDBG("%s alloc ep %p\n", __func__, epc);
308 return epc;
309}
310
Hariprasad S944661d2016-05-06 22:18:03 +0530311static void remove_ep_tid(struct c4iw_ep *ep)
312{
313 unsigned long flags;
314
315 spin_lock_irqsave(&ep->com.dev->lock, flags);
316 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
317 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
318}
319
320static void insert_ep_tid(struct c4iw_ep *ep)
321{
322 unsigned long flags;
323
324 spin_lock_irqsave(&ep->com.dev->lock, flags);
325 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
326 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
327}
328
329/*
330 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
331 */
332static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
333{
334 struct c4iw_ep *ep;
335 unsigned long flags;
336
337 spin_lock_irqsave(&dev->lock, flags);
338 ep = idr_find(&dev->hwtid_idr, tid);
339 if (ep)
340 c4iw_get_ep(&ep->com);
341 spin_unlock_irqrestore(&dev->lock, flags);
342 return ep;
343}
344
Steve Wisecfdda9d2010-04-21 15:30:06 -0700345void _c4iw_free_ep(struct kref *kref)
346{
347 struct c4iw_ep *ep;
348
349 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530350 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000351 if (test_bit(QP_REFERENCED, &ep->com.flags))
352 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700353 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530354 if (ep->com.remote_addr.ss_family == AF_INET6) {
355 struct sockaddr_in6 *sin6 =
356 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600357 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530358
359 cxgb4_clip_release(
360 ep->com.dev->rdev.lldi.ports[0],
361 (const u32 *)&sin6->sin6_addr.s6_addr,
362 1);
363 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700364 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
365 dst_release(ep->dst);
366 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530367 if (ep->mpa_skb)
368 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700369 }
370 kfree(ep);
371}
372
373static void release_ep_resources(struct c4iw_ep *ep)
374{
375 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530376
377 /*
378 * If we have a hwtid, then remove it from the idr table
379 * so lookups will no longer find this endpoint. Otherwise
380 * we have a race where one thread finds the ep ptr just
381 * before the other thread is freeing the ep memory.
382 */
383 if (ep->hwtid != -1)
384 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700385 c4iw_put_ep(&ep->com);
386}
387
Steve Wisecfdda9d2010-04-21 15:30:06 -0700388static int status2errno(int status)
389{
390 switch (status) {
391 case CPL_ERR_NONE:
392 return 0;
393 case CPL_ERR_CONN_RESET:
394 return -ECONNRESET;
395 case CPL_ERR_ARP_MISS:
396 return -EHOSTUNREACH;
397 case CPL_ERR_CONN_TIMEDOUT:
398 return -ETIMEDOUT;
399 case CPL_ERR_TCAM_FULL:
400 return -ENOMEM;
401 case CPL_ERR_CONN_EXIST:
402 return -EADDRINUSE;
403 default:
404 return -EIO;
405 }
406}
407
408/*
409 * Try and reuse skbs already allocated...
410 */
411static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
412{
413 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
414 skb_trim(skb, 0);
415 skb_get(skb);
416 skb_reset_transport_header(skb);
417 } else {
418 skb = alloc_skb(len, gfp);
419 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530420 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700421 return skb;
422}
423
Vipul Pandya830662f2013-07-04 16:10:47 +0530424static struct net_device *get_real_dev(struct net_device *egress_dev)
425{
Steve Wise11b8e222014-05-16 12:42:46 -0500426 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530427}
428
429static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
430{
431 int i;
432
433 egress_dev = get_real_dev(egress_dev);
434 for (i = 0; i < dev->rdev.lldi.nports; i++)
435 if (dev->rdev.lldi.ports[i] == egress_dev)
436 return 1;
437 return 0;
438}
439
440static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
441 __u8 *peer_ip, __be16 local_port,
442 __be16 peer_port, u8 tos,
443 __u32 sin6_scope_id)
444{
445 struct dst_entry *dst = NULL;
446
447 if (IS_ENABLED(CONFIG_IPV6)) {
448 struct flowi6 fl6;
449
450 memset(&fl6, 0, sizeof(fl6));
451 memcpy(&fl6.daddr, peer_ip, 16);
452 memcpy(&fl6.saddr, local_ip, 16);
453 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
454 fl6.flowi6_oif = sin6_scope_id;
455 dst = ip6_route_output(&init_net, NULL, &fl6);
456 if (!dst)
457 goto out;
458 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
459 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
460 dst_release(dst);
461 dst = NULL;
462 }
463 }
464
465out:
466 return dst;
467}
468
469static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700470 __be32 peer_ip, __be16 local_port,
471 __be16 peer_port, u8 tos)
472{
473 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700474 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530475 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700476
David S. Miller31e4543d2011-05-03 20:25:42 -0700477 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500478 peer_port, local_port, IPPROTO_TCP,
479 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800480 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700481 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530482 n = dst_neigh_lookup(&rt->dst, &peer_ip);
483 if (!n)
484 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530485 if (!our_interface(dev, n->dev) &&
486 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530487 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530488 dst_release(&rt->dst);
489 return NULL;
490 }
491 neigh_release(n);
492 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700493}
494
495static void arp_failure_discard(void *handle, struct sk_buff *skb)
496{
Hariprasad S9dec9002016-05-05 01:27:29 +0530497 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700498 kfree_skb(skb);
499}
500
Hariprasad S9dec9002016-05-05 01:27:29 +0530501enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530502 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530503 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530504 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530505};
506
507static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
508{
509 struct c4iw_ep *ep;
510
511 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
512 release_ep_resources(ep);
513 return 0;
514}
515
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530516static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
517{
518 struct c4iw_ep *ep;
519
520 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
521 c4iw_put_ep(&ep->parent_ep->com);
522 release_ep_resources(ep);
523 return 0;
524}
525
Hariprasad S9dec9002016-05-05 01:27:29 +0530526/*
527 * Fake up a special CPL opcode and call sched() so process_work() will call
528 * _put_ep_safe() in a safe context to free the ep resources. This is needed
529 * because ARP error handlers are called in an ATOMIC context, and
530 * _c4iw_free_ep() needs to block.
531 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530532static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
533 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530534{
535 struct cpl_act_establish *rpl = cplhdr(skb);
536
537 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530538 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530539
540 /*
541 * Save ep in the skb->cb area, after where sched() will save the dev
542 * ptr.
543 */
544 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
545 sched(ep->com.dev, skb);
546}
547
548/* Handle an ARP failure for an accept */
549static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
550{
551 struct c4iw_ep *ep = handle;
552
553 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
554 ep->hwtid);
555
556 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530557 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530558}
559
Steve Wisecfdda9d2010-04-21 15:30:06 -0700560/*
561 * Handle an ARP failure for an active open.
562 */
563static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
564{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530565 struct c4iw_ep *ep = handle;
566
Masanari Iidae3d132d2015-10-16 21:14:29 +0900567 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530568 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530569 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530570 if (ep->com.remote_addr.ss_family == AF_INET6) {
571 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600572 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530573 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
574 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
575 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530576 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
577 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530578 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700579}
580
581/*
582 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
583 * and send it along.
584 */
585static void abort_arp_failure(void *handle, struct sk_buff *skb)
586{
Hariprasad S761e19a2016-05-06 22:18:02 +0530587 int ret;
588 struct c4iw_ep *ep = handle;
589 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700590 struct cpl_abort_req *req = cplhdr(skb);
591
592 PDBG("%s rdev %p\n", __func__, rdev);
593 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530594 ret = c4iw_ofld_send(rdev, skb);
595 if (ret) {
596 __state_set(&ep->com, DEAD);
597 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
598 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700599}
600
Hariprasad Sfef44222016-05-05 01:27:33 +0530601static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700602{
603 unsigned int flowclen = 80;
604 struct fw_flowc_wr *flowc;
605 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530606 u16 vlan = ep->l2t->vlan;
607 int nparams;
608
609 if (vlan == CPL_L2T_VLAN_NONE)
610 nparams = 8;
611 else
612 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700613
614 skb = get_skb(skb, flowclen, GFP_KERNEL);
615 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
616
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530617 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530618 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530619 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
620 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700621
622 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530623 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530624 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700625 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
626 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
627 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
628 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
629 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
630 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
631 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
632 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
633 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
634 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
635 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530636 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700637 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
638 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530639 if (nparams == 9) {
640 u16 pri;
641
642 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
643 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
644 flowc->mnemval[8].val = cpu_to_be32(pri);
645 } else {
646 /* Pad WR to 16 byte boundary */
647 flowc->mnemval[8].mnemonic = 0;
648 flowc->mnemval[8].val = 0;
649 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 for (i = 0; i < 9; i++) {
651 flowc->mnemval[i].r4[0] = 0;
652 flowc->mnemval[i].r4[1] = 0;
653 flowc->mnemval[i].r4[2] = 0;
654 }
655
656 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530657 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700658}
659
660static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
661{
662 struct cpl_close_con_req *req;
663 struct sk_buff *skb;
664 int wrlen = roundup(sizeof *req, 16);
665
666 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
667 skb = get_skb(NULL, wrlen, gfp);
668 if (!skb) {
669 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
670 return -ENOMEM;
671 }
672 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
673 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
674 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
675 memset(req, 0, wrlen);
676 INIT_TP_WR(req, ep->hwtid);
677 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
678 ep->hwtid));
679 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
680}
681
682static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
683{
684 struct cpl_abort_req *req;
685 int wrlen = roundup(sizeof *req, 16);
686
687 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
688 skb = get_skb(skb, wrlen, gfp);
689 if (!skb) {
690 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
691 __func__);
692 return -ENOMEM;
693 }
694 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530695 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700696 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
697 memset(req, 0, wrlen);
698 INIT_TP_WR(req, ep->hwtid);
699 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
700 req->cmd = CPL_ABORT_SEND_RST;
701 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
702}
703
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530704static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530705 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530706{
Hariprasad S04524a42014-09-24 03:53:41 +0530707 unsigned short hdr_size = (ipv6 ?
708 sizeof(struct ipv6hdr) :
709 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530710 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530711 (use_ts ?
712 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530713 unsigned short data_size = mtu - hdr_size;
714
715 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
716}
717
Steve Wisecfdda9d2010-04-21 15:30:06 -0700718static int send_connect(struct c4iw_ep *ep)
719{
Hariprasad S963cab52015-09-23 17:19:27 +0530720 struct cpl_act_open_req *req = NULL;
721 struct cpl_t5_act_open_req *t5req = NULL;
722 struct cpl_t6_act_open_req *t6req = NULL;
723 struct cpl_act_open_req6 *req6 = NULL;
724 struct cpl_t5_act_open_req6 *t5req6 = NULL;
725 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726 struct sk_buff *skb;
727 u64 opt0;
728 u32 opt2;
729 unsigned int mtu_idx;
730 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530731 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500732 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600733 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500734 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600735 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500736 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600737 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500738 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600739 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530740 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530741 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
742 u32 isn = (prandom_u32() & ~7UL) - 1;
743
744 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
745 case CHELSIO_T4:
746 sizev4 = sizeof(struct cpl_act_open_req);
747 sizev6 = sizeof(struct cpl_act_open_req6);
748 break;
749 case CHELSIO_T5:
750 sizev4 = sizeof(struct cpl_t5_act_open_req);
751 sizev6 = sizeof(struct cpl_t5_act_open_req6);
752 break;
753 case CHELSIO_T6:
754 sizev4 = sizeof(struct cpl_t6_act_open_req);
755 sizev6 = sizeof(struct cpl_t6_act_open_req6);
756 break;
757 default:
758 pr_err("T%d Chip is not supported\n",
759 CHELSIO_CHIP_VERSION(adapter_type));
760 return -EINVAL;
761 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530762
763 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
764 roundup(sizev4, 16) :
765 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700766
767 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
768
769 skb = get_skb(NULL, wrlen, GFP_KERNEL);
770 if (!skb) {
771 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
772 __func__);
773 return -ENOMEM;
774 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000775 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700776
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530777 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530778 enable_tcp_timestamps,
779 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700780 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530781
782 /*
783 * Specify the largest window that will fit in opt0. The
784 * remainder will be specified in the rx_data_ack.
785 */
786 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800787 if (win > RCV_BUFSIZ_M)
788 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530789
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800790 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800791 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800792 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800793 WND_SCALE_V(wscale) |
794 MSS_IDX_V(mtu_idx) |
795 L2T_IDX_V(ep->l2t->idx) |
796 TX_CHAN_V(ep->tx_chan) |
797 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530798 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800799 ULP_MODE_V(ULP_MODE_TCPDDP) |
800 RCV_BUFSIZ_V(win);
801 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800802 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800803 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700804 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800805 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700806 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800807 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700808 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800809 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530810 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
811 if (peer2peer)
812 isn += 4;
813
Anish Bhattd7990b02014-11-12 17:15:57 -0800814 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530815 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530816 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500817 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530818
819 if (ep->com.remote_addr.ss_family == AF_INET6)
820 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
821 (const u32 *)&la6->sin6_addr.s6_addr, 1);
822
Hariprasad S5dab6d32014-06-23 19:12:36 +0530823 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700824
Hariprasad S963cab52015-09-23 17:19:27 +0530825 if (ep->com.remote_addr.ss_family == AF_INET) {
826 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
827 case CHELSIO_T4:
828 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530829 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530830 break;
831 case CHELSIO_T5:
832 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
833 wrlen);
834 INIT_TP_WR(t5req, 0);
835 req = (struct cpl_act_open_req *)t5req;
836 break;
837 case CHELSIO_T6:
838 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
839 wrlen);
840 INIT_TP_WR(t6req, 0);
841 req = (struct cpl_act_open_req *)t6req;
842 t5req = (struct cpl_t5_act_open_req *)t6req;
843 break;
844 default:
845 pr_err("T%d Chip is not supported\n",
846 CHELSIO_CHIP_VERSION(adapter_type));
847 ret = -EINVAL;
848 goto clip_release;
849 }
850
851 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
852 ((ep->rss_qid<<14) | ep->atid)));
853 req->local_port = la->sin_port;
854 req->peer_port = ra->sin_port;
855 req->local_ip = la->sin_addr.s_addr;
856 req->peer_ip = ra->sin_addr.s_addr;
857 req->opt0 = cpu_to_be64(opt0);
858
859 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530860 req->params = cpu_to_be32(cxgb4_select_ntuple(
861 ep->com.dev->rdev.lldi.ports[0],
862 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530863 req->opt2 = cpu_to_be32(opt2);
864 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530865 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
866 cxgb4_select_ntuple(
867 ep->com.dev->rdev.lldi.ports[0],
868 ep->l2t)));
869 t5req->rsvd = cpu_to_be32(isn);
870 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
871 t5req->opt2 = cpu_to_be32(opt2);
872 }
873 } else {
874 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
875 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530876 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530877 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530878 break;
879 case CHELSIO_T5:
880 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
881 wrlen);
882 INIT_TP_WR(t5req6, 0);
883 req6 = (struct cpl_act_open_req6 *)t5req6;
884 break;
885 case CHELSIO_T6:
886 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
887 wrlen);
888 INIT_TP_WR(t6req6, 0);
889 req6 = (struct cpl_act_open_req6 *)t6req6;
890 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
891 break;
892 default:
893 pr_err("T%d Chip is not supported\n",
894 CHELSIO_CHIP_VERSION(adapter_type));
895 ret = -EINVAL;
896 goto clip_release;
897 }
898
899 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
900 ((ep->rss_qid<<14)|ep->atid)));
901 req6->local_port = la6->sin6_port;
902 req6->peer_port = ra6->sin6_port;
903 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
904 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
905 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
906 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
907 req6->opt0 = cpu_to_be64(opt0);
908
909 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530910 req6->params = cpu_to_be32(cxgb4_select_ntuple(
911 ep->com.dev->rdev.lldi.ports[0],
912 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530913 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530914 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530915 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
916 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530917 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530918 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530919 t5req6->rsvd = cpu_to_be32(isn);
920 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
921 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530922 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000923 }
924
Vipul Pandya793dad92012-12-10 09:30:56 +0000925 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530926 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530927clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530928 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
929 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
930 (const u32 *)&la6->sin6_addr.s6_addr, 1);
931 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932}
933
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530934static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
935 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700936{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530937 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700938 struct fw_ofld_tx_data_wr *req;
939 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530940 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700941
942 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
943
944 BUG_ON(skb_cloned(skb));
945
946 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530947 if (mpa_rev_to_use == 2)
948 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700949 wrlen = roundup(mpalen + sizeof *req, 16);
950 skb = get_skb(skb, wrlen, GFP_KERNEL);
951 if (!skb) {
952 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530953 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954 }
955 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
956
957 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
958 memset(req, 0, wrlen);
959 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530960 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
961 FW_WR_COMPL_F |
962 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700963 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530964 FW_WR_FLOWID_V(ep->hwtid) |
965 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700966 req->plen = cpu_to_be32(mpalen);
967 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530968 FW_OFLD_TX_DATA_WR_FLUSH_F |
969 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700970
971 mpa = (struct mpa_message *)(req + 1);
972 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
973 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530974 (markers_enabled ? MPA_MARKERS : 0) |
975 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700976 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530977 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530978 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530979 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530980 ep->retry_with_mpa_v1 = 0;
981 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530983 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700984 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
985 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530986 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
987 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530988 mpa_v2_params.ird = htons((u16)ep->ird);
989 mpa_v2_params.ord = htons((u16)ep->ord);
990
991 if (peer2peer) {
992 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
993 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
994 mpa_v2_params.ord |=
995 htons(MPA_V2_RDMA_WRITE_RTR);
996 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
997 mpa_v2_params.ord |=
998 htons(MPA_V2_RDMA_READ_RTR);
999 }
1000 memcpy(mpa->private_data, &mpa_v2_params,
1001 sizeof(struct mpa_v2_conn_params));
1002
1003 if (ep->plen)
1004 memcpy(mpa->private_data +
1005 sizeof(struct mpa_v2_conn_params),
1006 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1007 } else
1008 if (ep->plen)
1009 memcpy(mpa->private_data,
1010 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011
1012 /*
1013 * Reference the mpa skb. This ensures the data area
1014 * will remain in memory until the hw acks the tx.
1015 * Function fw4_ack() will deref it.
1016 */
1017 skb_get(skb);
1018 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1019 BUG_ON(ep->mpa_skb);
1020 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301021 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1022 if (ret)
1023 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301025 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001026 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301027 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301028 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001029}
1030
1031static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1032{
1033 int mpalen, wrlen;
1034 struct fw_ofld_tx_data_wr *req;
1035 struct mpa_message *mpa;
1036 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301037 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001038
1039 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1040
1041 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301042 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1043 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001044 wrlen = roundup(mpalen + sizeof *req, 16);
1045
1046 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1047 if (!skb) {
1048 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1049 return -ENOMEM;
1050 }
1051 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1052
1053 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1054 memset(req, 0, wrlen);
1055 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301056 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1057 FW_WR_COMPL_F |
1058 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001059 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301060 FW_WR_FLOWID_V(ep->hwtid) |
1061 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001062 req->plen = cpu_to_be32(mpalen);
1063 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301064 FW_OFLD_TX_DATA_WR_FLUSH_F |
1065 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001066
1067 mpa = (struct mpa_message *)(req + 1);
1068 memset(mpa, 0, sizeof(*mpa));
1069 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1070 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001071 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001072 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301073
1074 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1075 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001076 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1077 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301078 mpa_v2_params.ird = htons(((u16)ep->ird) |
1079 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1080 0));
1081 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1082 (p2p_type ==
1083 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1084 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1085 FW_RI_INIT_P2PTYPE_READ_REQ ?
1086 MPA_V2_RDMA_READ_RTR : 0) : 0));
1087 memcpy(mpa->private_data, &mpa_v2_params,
1088 sizeof(struct mpa_v2_conn_params));
1089
1090 if (ep->plen)
1091 memcpy(mpa->private_data +
1092 sizeof(struct mpa_v2_conn_params), pdata, plen);
1093 } else
1094 if (plen)
1095 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001096
1097 /*
1098 * Reference the mpa skb again. This ensures the data area
1099 * will remain in memory until the hw acks the tx.
1100 * Function fw4_ack() will deref it.
1101 */
1102 skb_get(skb);
1103 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 BUG_ON(ep->mpa_skb);
1105 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301106 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001107 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1108}
1109
1110static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1111{
1112 int mpalen, wrlen;
1113 struct fw_ofld_tx_data_wr *req;
1114 struct mpa_message *mpa;
1115 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301116 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001117
1118 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1119
1120 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301121 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1122 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123 wrlen = roundup(mpalen + sizeof *req, 16);
1124
1125 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1126 if (!skb) {
1127 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1128 return -ENOMEM;
1129 }
1130 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1131
1132 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1133 memset(req, 0, wrlen);
1134 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301135 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1136 FW_WR_COMPL_F |
1137 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001138 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301139 FW_WR_FLOWID_V(ep->hwtid) |
1140 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001141 req->plen = cpu_to_be32(mpalen);
1142 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301143 FW_OFLD_TX_DATA_WR_FLUSH_F |
1144 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001145
1146 mpa = (struct mpa_message *)(req + 1);
1147 memset(mpa, 0, sizeof(*mpa));
1148 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1149 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1150 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301151 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001152 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301153
1154 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1155 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001156 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1157 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301158 mpa_v2_params.ird = htons((u16)ep->ird);
1159 mpa_v2_params.ord = htons((u16)ep->ord);
1160 if (peer2peer && (ep->mpa_attr.p2p_type !=
1161 FW_RI_INIT_P2PTYPE_DISABLED)) {
1162 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1163
1164 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1165 mpa_v2_params.ord |=
1166 htons(MPA_V2_RDMA_WRITE_RTR);
1167 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1168 mpa_v2_params.ord |=
1169 htons(MPA_V2_RDMA_READ_RTR);
1170 }
1171
1172 memcpy(mpa->private_data, &mpa_v2_params,
1173 sizeof(struct mpa_v2_conn_params));
1174
1175 if (ep->plen)
1176 memcpy(mpa->private_data +
1177 sizeof(struct mpa_v2_conn_params), pdata, plen);
1178 } else
1179 if (plen)
1180 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001181
1182 /*
1183 * Reference the mpa skb. This ensures the data area
1184 * will remain in memory until the hw acks the tx.
1185 * Function fw4_ack() will deref it.
1186 */
1187 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001188 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301189 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301190 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001191 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1192}
1193
1194static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1195{
1196 struct c4iw_ep *ep;
1197 struct cpl_act_establish *req = cplhdr(skb);
1198 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001199 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301201 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202
1203 ep = lookup_atid(t, atid);
1204
1205 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1206 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1207
Steve Wisea7db89e2014-03-21 20:40:35 +05301208 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001209 dst_confirm(ep->dst);
1210
1211 /* setup the hwtid for this connection */
1212 ep->hwtid = tid;
1213 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301214 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001215
1216 ep->snd_seq = be32_to_cpu(req->snd_isn);
1217 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1218
1219 set_emss(ep, ntohs(req->tcp_opt));
1220
1221 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001222 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001223 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001224 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001225
1226 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301227 ret = send_flowc(ep, NULL);
1228 if (ret)
1229 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301230 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301231 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301232 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301233 ret = send_mpa_req(ep, skb, mpa_rev);
1234 if (ret)
1235 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301236 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301238err:
1239 mutex_unlock(&ep->com.mutex);
1240 connect_reply_upcall(ep, -ENOMEM);
1241 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1242 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001243}
1244
Steve Wisebe13b2d2014-03-21 20:40:33 +05301245static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001246{
1247 struct iw_cm_event event;
1248
1249 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1250 memset(&event, 0, sizeof(event));
1251 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301252 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001253 if (ep->com.cm_id) {
1254 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1255 ep, ep->com.cm_id, ep->hwtid);
1256 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301257 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001258 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259 }
1260}
1261
Steve Wisecfdda9d2010-04-21 15:30:06 -07001262static void peer_close_upcall(struct c4iw_ep *ep)
1263{
1264 struct iw_cm_event event;
1265
1266 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1267 memset(&event, 0, sizeof(event));
1268 event.event = IW_CM_EVENT_DISCONNECT;
1269 if (ep->com.cm_id) {
1270 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1271 ep, ep->com.cm_id, ep->hwtid);
1272 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001273 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274 }
1275}
1276
1277static void peer_abort_upcall(struct c4iw_ep *ep)
1278{
1279 struct iw_cm_event event;
1280
1281 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1282 memset(&event, 0, sizeof(event));
1283 event.event = IW_CM_EVENT_CLOSE;
1284 event.status = -ECONNRESET;
1285 if (ep->com.cm_id) {
1286 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1287 ep->com.cm_id, ep->hwtid);
1288 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301289 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001290 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001291 }
1292}
1293
1294static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1295{
1296 struct iw_cm_event event;
1297
1298 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1299 memset(&event, 0, sizeof(event));
1300 event.event = IW_CM_EVENT_CONNECT_REPLY;
1301 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301302 memcpy(&event.local_addr, &ep->com.local_addr,
1303 sizeof(ep->com.local_addr));
1304 memcpy(&event.remote_addr, &ep->com.remote_addr,
1305 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001306
1307 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301308 if (!ep->tried_with_mpa_v1) {
1309 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301310 event.ord = ep->ird;
1311 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301312 event.private_data_len = ep->plen -
1313 sizeof(struct mpa_v2_conn_params);
1314 event.private_data = ep->mpa_pkt +
1315 sizeof(struct mpa_message) +
1316 sizeof(struct mpa_v2_conn_params);
1317 } else {
1318 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301319 event.ord = cur_max_read_depth(ep->com.dev);
1320 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301321 event.private_data_len = ep->plen;
1322 event.private_data = ep->mpa_pkt +
1323 sizeof(struct mpa_message);
1324 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001325 }
Roland Dreier85963e42010-07-19 13:13:09 -07001326
1327 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1328 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001329 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001330 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1331
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301332 if (status < 0)
1333 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001334}
1335
Steve Wisebe13b2d2014-03-21 20:40:33 +05301336static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337{
1338 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301339 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001340
1341 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1342 memset(&event, 0, sizeof(event));
1343 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301344 memcpy(&event.local_addr, &ep->com.local_addr,
1345 sizeof(ep->com.local_addr));
1346 memcpy(&event.remote_addr, &ep->com.remote_addr,
1347 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001348 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301349 if (!ep->tried_with_mpa_v1) {
1350 /* this means MPA_v2 is used */
1351 event.ord = ep->ord;
1352 event.ird = ep->ird;
1353 event.private_data_len = ep->plen -
1354 sizeof(struct mpa_v2_conn_params);
1355 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1356 sizeof(struct mpa_v2_conn_params);
1357 } else {
1358 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301359 event.ord = cur_max_read_depth(ep->com.dev);
1360 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301361 event.private_data_len = ep->plen;
1362 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1363 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301364 c4iw_get_ep(&ep->com);
1365 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1366 &event);
1367 if (ret)
1368 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001369 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301371 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001372}
1373
1374static void established_upcall(struct c4iw_ep *ep)
1375{
1376 struct iw_cm_event event;
1377
1378 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1379 memset(&event, 0, sizeof(event));
1380 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301381 event.ird = ep->ord;
1382 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001383 if (ep->com.cm_id) {
1384 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1385 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001386 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001387 }
1388}
1389
1390static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1391{
1392 struct cpl_rx_data_ack *req;
1393 struct sk_buff *skb;
1394 int wrlen = roundup(sizeof *req, 16);
1395
1396 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1397 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1398 if (!skb) {
1399 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1400 return 0;
1401 }
1402
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301403 /*
1404 * If we couldn't specify the entire rcv window at connection setup
1405 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1406 * then add the overage in to the credits returned.
1407 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001408 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1409 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301410
Steve Wisecfdda9d2010-04-21 15:30:06 -07001411 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1412 memset(req, 0, wrlen);
1413 INIT_TP_WR(req, ep->hwtid);
1414 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1415 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001416 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301417 RX_DACK_CHANGE_F |
1418 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001419 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001420 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1421 return credits;
1422}
1423
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301424#define RELAXED_IRD_NEGOTIATION 1
1425
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301426/*
1427 * process_mpa_reply - process streaming mode MPA reply
1428 *
1429 * Returns:
1430 *
1431 * 0 upon success indicating a connect request was delivered to the ULP
1432 * or the mpa request is incomplete but valid so far.
1433 *
1434 * 1 if a failure requires the caller to close the connection.
1435 *
1436 * 2 if a failure requires the caller to abort the connection.
1437 */
Steve Wisecc18b932014-04-24 14:31:53 -05001438static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439{
1440 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301441 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001442 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301443 u16 resp_ird, resp_ord;
1444 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001445 struct c4iw_qp_attributes attrs;
1446 enum c4iw_qp_attr_mask mask;
1447 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001448 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001449
1450 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1451
1452 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001453 * If we get more than the supported amount of private data
1454 * then we must fail this connection.
1455 */
1456 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1457 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301458 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459 }
1460
1461 /*
1462 * copy the new data into our accumulation buffer.
1463 */
1464 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1465 skb->len);
1466 ep->mpa_pkt_len += skb->len;
1467
1468 /*
1469 * if we don't even have the mpa message, then bail.
1470 */
1471 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001472 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 mpa = (struct mpa_message *) ep->mpa_pkt;
1474
1475 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301476 if (mpa->revision > mpa_rev) {
1477 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1478 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001479 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301480 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001481 }
1482 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1483 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301484 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001485 }
1486
1487 plen = ntohs(mpa->private_data_size);
1488
1489 /*
1490 * Fail if there's too much private data.
1491 */
1492 if (plen > MPA_MAX_PRIVATE_DATA) {
1493 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301494 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001495 }
1496
1497 /*
1498 * If plen does not account for pkt size
1499 */
1500 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1501 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301502 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001503 }
1504
1505 ep->plen = (u8) plen;
1506
1507 /*
1508 * If we don't have all the pdata yet, then bail.
1509 * We'll continue process when more data arrives.
1510 */
1511 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001512 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513
1514 if (mpa->flags & MPA_REJECT) {
1515 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301516 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001517 }
1518
1519 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301520 * Stop mpa timer. If it expired, then
1521 * we ignore the MPA reply. process_timeout()
1522 * will abort the connection.
1523 */
1524 if (stop_ep_timer(ep))
1525 return 0;
1526
1527 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001528 * If we get here we have accumulated the entire mpa
1529 * start reply message including private data. And
1530 * the MPA header is valid.
1531 */
Steve Wisec529fb52014-03-21 20:40:37 +05301532 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001533 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1534 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1535 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301536 ep->mpa_attr.version = mpa->revision;
1537 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1538
1539 if (mpa->revision == 2) {
1540 ep->mpa_attr.enhanced_rdma_conn =
1541 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1542 if (ep->mpa_attr.enhanced_rdma_conn) {
1543 mpa_v2_params = (struct mpa_v2_conn_params *)
1544 (ep->mpa_pkt + sizeof(*mpa));
1545 resp_ird = ntohs(mpa_v2_params->ird) &
1546 MPA_V2_IRD_ORD_MASK;
1547 resp_ord = ntohs(mpa_v2_params->ord) &
1548 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301549 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1550 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301551
1552 /*
1553 * This is a double-check. Ideally, below checks are
1554 * not required since ird/ord stuff has been taken
1555 * care of in c4iw_accept_cr
1556 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301557 if (ep->ird < resp_ord) {
1558 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1559 ep->com.dev->rdev.lldi.max_ordird_qp)
1560 ep->ird = resp_ord;
1561 else
1562 insuff_ird = 1;
1563 } else if (ep->ird > resp_ord) {
1564 ep->ird = resp_ord;
1565 }
1566 if (ep->ord > resp_ird) {
1567 if (RELAXED_IRD_NEGOTIATION)
1568 ep->ord = resp_ird;
1569 else
1570 insuff_ird = 1;
1571 }
1572 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301573 err = -ENOMEM;
1574 ep->ird = resp_ord;
1575 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301576 }
1577
1578 if (ntohs(mpa_v2_params->ird) &
1579 MPA_V2_PEER2PEER_MODEL) {
1580 if (ntohs(mpa_v2_params->ord) &
1581 MPA_V2_RDMA_WRITE_RTR)
1582 ep->mpa_attr.p2p_type =
1583 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1584 else if (ntohs(mpa_v2_params->ord) &
1585 MPA_V2_RDMA_READ_RTR)
1586 ep->mpa_attr.p2p_type =
1587 FW_RI_INIT_P2PTYPE_READ_REQ;
1588 }
1589 }
1590 } else if (mpa->revision == 1)
1591 if (peer2peer)
1592 ep->mpa_attr.p2p_type = p2p_type;
1593
Steve Wisecfdda9d2010-04-21 15:30:06 -07001594 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301595 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1596 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1597 ep->mpa_attr.recv_marker_enabled,
1598 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1599 ep->mpa_attr.p2p_type, p2p_type);
1600
1601 /*
1602 * If responder's RTR does not match with that of initiator, assign
1603 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1604 * generated when moving QP to RTS state.
1605 * A TERM message will be sent after QP has moved to RTS state
1606 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001607 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301608 (ep->mpa_attr.p2p_type != p2p_type)) {
1609 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1610 rtr_mismatch = 1;
1611 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001612
1613 attrs.mpa_attr = ep->mpa_attr;
1614 attrs.max_ird = ep->ird;
1615 attrs.max_ord = ep->ord;
1616 attrs.llp_stream_handle = ep;
1617 attrs.next_state = C4IW_QP_STATE_RTS;
1618
1619 mask = C4IW_QP_ATTR_NEXT_STATE |
1620 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1621 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1622
1623 /* bind QP and TID with INIT_WR */
1624 err = c4iw_modify_qp(ep->com.qp->rhp,
1625 ep->com.qp, mask, &attrs, 1);
1626 if (err)
1627 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301628
1629 /*
1630 * If responder's RTR requirement did not match with what initiator
1631 * supports, generate TERM message
1632 */
1633 if (rtr_mismatch) {
1634 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1635 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1636 attrs.ecode = MPA_NOMATCH_RTR;
1637 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001638 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301639 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001640 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301641 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001642 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301643 goto out;
1644 }
1645
1646 /*
1647 * Generate TERM if initiator IRD is not sufficient for responder
1648 * provided ORD. Currently, we do the same behaviour even when
1649 * responder provided IRD is also not sufficient as regards to
1650 * initiator ORD.
1651 */
1652 if (insuff_ird) {
1653 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1654 __func__);
1655 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1656 attrs.ecode = MPA_INSUFF_IRD;
1657 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001658 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301659 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001660 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301661 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001662 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301663 goto out;
1664 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301666err_stop_timer:
1667 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301669 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001670out:
1671 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001672 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001673}
1674
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301675/*
1676 * process_mpa_request - process streaming mode MPA request
1677 *
1678 * Returns:
1679 *
1680 * 0 upon success indicating a connect request was delivered to the ULP
1681 * or the mpa request is incomplete but valid so far.
1682 *
1683 * 1 if a failure requires the caller to close the connection.
1684 *
1685 * 2 if a failure requires the caller to abort the connection.
1686 */
1687static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001688{
1689 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301690 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691 u16 plen;
1692
1693 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1694
Steve Wisecfdda9d2010-04-21 15:30:06 -07001695 /*
1696 * If we get more than the supported amount of private data
1697 * then we must fail this connection.
1698 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301699 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1700 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001701
1702 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1703
1704 /*
1705 * Copy the new data into our accumulation buffer.
1706 */
1707 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1708 skb->len);
1709 ep->mpa_pkt_len += skb->len;
1710
1711 /*
1712 * If we don't even have the mpa message, then bail.
1713 * We'll continue process when more data arrives.
1714 */
1715 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301716 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001717
1718 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001719 mpa = (struct mpa_message *) ep->mpa_pkt;
1720
1721 /*
1722 * Validate MPA Header.
1723 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301724 if (mpa->revision > mpa_rev) {
1725 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1726 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301727 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001728 }
1729
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301730 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1731 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001732
1733 plen = ntohs(mpa->private_data_size);
1734
1735 /*
1736 * Fail if there's too much private data.
1737 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301738 if (plen > MPA_MAX_PRIVATE_DATA)
1739 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001740
1741 /*
1742 * If plen does not account for pkt size
1743 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301744 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1745 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001746 ep->plen = (u8) plen;
1747
1748 /*
1749 * If we don't have all the pdata yet, then bail.
1750 */
1751 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301752 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001753
1754 /*
1755 * If we get here we have accumulated the entire mpa
1756 * start reply message including private data.
1757 */
1758 ep->mpa_attr.initiator = 0;
1759 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1760 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1761 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301762 ep->mpa_attr.version = mpa->revision;
1763 if (mpa->revision == 1)
1764 ep->tried_with_mpa_v1 = 1;
1765 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1766
1767 if (mpa->revision == 2) {
1768 ep->mpa_attr.enhanced_rdma_conn =
1769 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1770 if (ep->mpa_attr.enhanced_rdma_conn) {
1771 mpa_v2_params = (struct mpa_v2_conn_params *)
1772 (ep->mpa_pkt + sizeof(*mpa));
1773 ep->ird = ntohs(mpa_v2_params->ird) &
1774 MPA_V2_IRD_ORD_MASK;
1775 ep->ord = ntohs(mpa_v2_params->ord) &
1776 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301777 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1778 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301779 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1780 if (peer2peer) {
1781 if (ntohs(mpa_v2_params->ord) &
1782 MPA_V2_RDMA_WRITE_RTR)
1783 ep->mpa_attr.p2p_type =
1784 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1785 else if (ntohs(mpa_v2_params->ord) &
1786 MPA_V2_RDMA_READ_RTR)
1787 ep->mpa_attr.p2p_type =
1788 FW_RI_INIT_P2PTYPE_READ_REQ;
1789 }
1790 }
1791 } else if (mpa->revision == 1)
1792 if (peer2peer)
1793 ep->mpa_attr.p2p_type = p2p_type;
1794
Steve Wisecfdda9d2010-04-21 15:30:06 -07001795 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1796 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1797 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1798 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1799 ep->mpa_attr.p2p_type);
1800
Hariprasad Se4b76a22016-05-06 22:17:59 +05301801 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802
Hariprasad Se4b76a22016-05-06 22:17:59 +05301803 /* drive upcall */
1804 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1805 if (ep->parent_ep->com.state != DEAD) {
1806 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301807 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301808 } else {
1809 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301810 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301811 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301812 return 0;
1813
1814err_unlock_parent:
1815 mutex_unlock(&ep->parent_ep->com.mutex);
1816 goto err_out;
1817err_stop_timer:
1818 (void)stop_ep_timer(ep);
1819err_out:
1820 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001821}
1822
1823static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1824{
1825 struct c4iw_ep *ep;
1826 struct cpl_rx_data *hdr = cplhdr(skb);
1827 unsigned int dlen = ntohs(hdr->len);
1828 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001829 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001830 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831
Hariprasad S944661d2016-05-06 22:18:03 +05301832 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301833 if (!ep)
1834 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001835 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1836 skb_pull(skb, sizeof(*hdr));
1837 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301838 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001839
Steve Wisecfdda9d2010-04-21 15:30:06 -07001840 /* update RX credits */
1841 update_rx_credits(ep, dlen);
1842
Steve Wisec529fb52014-03-21 20:40:37 +05301843 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001844 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001845 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001846 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001847 break;
1848 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001849 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001850 process_mpa_request(ep, skb);
1851 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001852 case FPDU_MODE: {
1853 struct c4iw_qp_attributes attrs;
1854 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001855 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001856 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001857 " qpid %u ep %p state %d tid %u status %d\n",
1858 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301859 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301860 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001861 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001862 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1863 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001864 break;
1865 }
Vipul Pandya15579672013-01-07 13:11:52 +00001866 default:
1867 break;
1868 }
Steve Wisec529fb52014-03-21 20:40:37 +05301869 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001870 if (disconnect)
1871 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301872 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873 return 0;
1874}
1875
1876static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1877{
1878 struct c4iw_ep *ep;
1879 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001880 int release = 0;
1881 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001882
Hariprasad S944661d2016-05-06 22:18:03 +05301883 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301884 if (!ep) {
1885 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1886 return 0;
1887 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001888 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001889 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001890 switch (ep->com.state) {
1891 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001892 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001893 __state_set(&ep->com, DEAD);
1894 release = 1;
1895 break;
1896 default:
1897 printk(KERN_ERR "%s ep %p state %d\n",
1898 __func__, ep, ep->com.state);
1899 break;
1900 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001901 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001902
1903 if (release)
1904 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301905 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001906 return 0;
1907}
1908
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301909static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001910{
1911 struct sk_buff *skb;
1912 struct fw_ofld_connection_wr *req;
1913 unsigned int mtu_idx;
1914 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301915 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301916 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001917
1918 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1919 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1920 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001921 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301922 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301923 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1924 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001925 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001926 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301927 req->le.lport = sin->sin_port;
1928 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001929 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301930 req->le.pport = sin->sin_port;
1931 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001932 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301933 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1934 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001935 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301936 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001937 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001938 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301939 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301940 enable_tcp_timestamps,
1941 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001942 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301943
1944 /*
1945 * Specify the largest window that will fit in opt0. The
1946 * remainder will be specified in the rx_data_ack.
1947 */
1948 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001949 if (win > RCV_BUFSIZ_M)
1950 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301951
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001952 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1953 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001954 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001955 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001956 WND_SCALE_V(wscale) |
1957 MSS_IDX_V(mtu_idx) |
1958 L2T_IDX_V(ep->l2t->idx) |
1959 TX_CHAN_V(ep->tx_chan) |
1960 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301961 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001962 ULP_MODE_V(ULP_MODE_TCPDDP) |
1963 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001964 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1965 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001966 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001967 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001968 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001969 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001970 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001971 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001972 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001973 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001974 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1975 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1976 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001977 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1978 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301979 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001980}
1981
Steve Wisecfdda9d2010-04-21 15:30:06 -07001982/*
1983 * Return whether a failed active open has allocated a TID
1984 */
1985static inline int act_open_has_tid(int status)
1986{
1987 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1988 status != CPL_ERR_ARP_MISS;
1989}
1990
Steve Wise7a2cea22014-03-14 21:52:07 +05301991/* Returns whether a CPL status conveys negative advice.
1992 */
1993static int is_neg_adv(unsigned int status)
1994{
1995 return status == CPL_ERR_RTX_NEG_ADVICE ||
1996 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1997 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1998}
1999
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302000static char *neg_adv_str(unsigned int status)
2001{
2002 switch (status) {
2003 case CPL_ERR_RTX_NEG_ADVICE:
2004 return "Retransmit timeout";
2005 case CPL_ERR_PERSIST_NEG_ADVICE:
2006 return "Persist timeout";
2007 case CPL_ERR_KEEPALV_NEG_ADVICE:
2008 return "Keepalive timeout";
2009 default:
2010 return "Unknown";
2011 }
2012}
2013
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302014static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2015{
2016 ep->snd_win = snd_win;
2017 ep->rcv_win = rcv_win;
2018 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2019}
2020
Vipul Pandya793dad92012-12-10 09:30:56 +00002021#define ACT_OPEN_RETRY_COUNT 2
2022
Vipul Pandya830662f2013-07-04 16:10:47 +05302023static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2024 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302025 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302026{
2027 struct neighbour *n;
2028 int err, step;
2029 struct net_device *pdev;
2030
2031 n = dst_neigh_lookup(dst, peer_ip);
2032 if (!n)
2033 return -ENODEV;
2034
2035 rcu_read_lock();
2036 err = -ENOMEM;
2037 if (n->dev->flags & IFF_LOOPBACK) {
2038 if (iptype == 4)
2039 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2040 else if (IS_ENABLED(CONFIG_IPV6))
2041 for_each_netdev(&init_net, pdev) {
2042 if (ipv6_chk_addr(&init_net,
2043 (struct in6_addr *)peer_ip,
2044 pdev, 1))
2045 break;
2046 }
2047 else
2048 pdev = NULL;
2049
2050 if (!pdev) {
2051 err = -ENODEV;
2052 goto out;
2053 }
2054 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302055 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302056 if (!ep->l2t)
2057 goto out;
2058 ep->mtu = pdev->mtu;
2059 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302060 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2061 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302062 step = cdev->rdev.lldi.ntxq /
2063 cdev->rdev.lldi.nchan;
2064 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2065 step = cdev->rdev.lldi.nrxq /
2066 cdev->rdev.lldi.nchan;
2067 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2068 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2069 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302070 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302071 dev_put(pdev);
2072 } else {
2073 pdev = get_real_dev(n->dev);
2074 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2075 n, pdev, 0);
2076 if (!ep->l2t)
2077 goto out;
2078 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002079 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302080 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2081 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302082 step = cdev->rdev.lldi.ntxq /
2083 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002084 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2085 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302086 step = cdev->rdev.lldi.nrxq /
2087 cdev->rdev.lldi.nchan;
2088 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002089 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302090 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302091
2092 if (clear_mpa_v1) {
2093 ep->retry_with_mpa_v1 = 0;
2094 ep->tried_with_mpa_v1 = 0;
2095 }
2096 }
2097 err = 0;
2098out:
2099 rcu_read_unlock();
2100
2101 neigh_release(n);
2102
2103 return err;
2104}
2105
Vipul Pandya793dad92012-12-10 09:30:56 +00002106static int c4iw_reconnect(struct c4iw_ep *ep)
2107{
2108 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302109 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002110 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302111 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002112 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002114 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302115 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002116 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302117 int iptype;
2118 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002119
2120 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2121 init_timer(&ep->timer);
2122
2123 /*
2124 * Allocate an active TID to initiate a TCP connection.
2125 */
2126 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2127 if (ep->atid == -1) {
2128 pr_err("%s - cannot alloc atid.\n", __func__);
2129 err = -ENOMEM;
2130 goto fail2;
2131 }
2132 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2133
2134 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002135 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302136 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2137 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302138 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302139 iptype = 4;
2140 ra = (__u8 *)&raddr->sin_addr;
2141 } else {
2142 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2143 raddr6->sin6_addr.s6_addr,
2144 laddr6->sin6_port, raddr6->sin6_port, 0,
2145 raddr6->sin6_scope_id);
2146 iptype = 6;
2147 ra = (__u8 *)&raddr6->sin6_addr;
2148 }
2149 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002150 pr_err("%s - cannot find route.\n", __func__);
2151 err = -EHOSTUNREACH;
2152 goto fail3;
2153 }
Hariprasad S963cab52015-09-23 17:19:27 +05302154 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302155 ep->com.dev->rdev.lldi.adapter_type,
2156 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302157 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002158 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002159 goto fail4;
2160 }
2161
2162 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2163 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2164 ep->l2t->idx);
2165
2166 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302167 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002168
2169 /* send connect request to rnic */
2170 err = send_connect(ep);
2171 if (!err)
2172 goto out;
2173
2174 cxgb4_l2t_release(ep->l2t);
2175fail4:
2176 dst_release(ep->dst);
2177fail3:
2178 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2179 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2180fail2:
2181 /*
2182 * remember to send notification to upper layer.
2183 * We are in here so the upper layer is not aware that this is
2184 * re-connect attempt and so, upper layer is still waiting for
2185 * response of 1st connect request.
2186 */
2187 connect_reply_upcall(ep, -ECONNRESET);
2188 c4iw_put_ep(&ep->com);
2189out:
2190 return err;
2191}
2192
Steve Wisecfdda9d2010-04-21 15:30:06 -07002193static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2194{
2195 struct c4iw_ep *ep;
2196 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002197 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2198 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002199 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002200 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302201 struct sockaddr_in *la;
2202 struct sockaddr_in *ra;
2203 struct sockaddr_in6 *la6;
2204 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302205 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002206
2207 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002208 la = (struct sockaddr_in *)&ep->com.local_addr;
2209 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2210 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2211 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002212
2213 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2214 status, status2errno(status));
2215
Steve Wise7a2cea22014-03-14 21:52:07 +05302216 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302217 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2218 __func__, atid, status, neg_adv_str(status));
2219 ep->stats.connect_neg_adv++;
2220 mutex_lock(&dev->rdev.stats.lock);
2221 dev->rdev.stats.neg_adv++;
2222 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002223 return 0;
2224 }
2225
Vipul Pandya793dad92012-12-10 09:30:56 +00002226 set_bit(ACT_OPEN_RPL, &ep->com.history);
2227
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302228 /*
2229 * Log interesting failures.
2230 */
2231 switch (status) {
2232 case CPL_ERR_CONN_RESET:
2233 case CPL_ERR_CONN_TIMEDOUT:
2234 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002235 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302236 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002237 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302238 mutex_unlock(&dev->rdev.stats.lock);
2239 if (ep->com.local_addr.ss_family == AF_INET &&
2240 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302241 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2242 ntohl(rpl->atid_status))));
2243 if (ret)
2244 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002245 return 0;
2246 }
2247 break;
2248 case CPL_ERR_CONN_EXIST:
2249 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2250 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302251 if (ep->com.remote_addr.ss_family == AF_INET6) {
2252 struct sockaddr_in6 *sin6 =
2253 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002254 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302255 cxgb4_clip_release(
2256 ep->com.dev->rdev.lldi.ports[0],
2257 (const u32 *)
2258 &sin6->sin6_addr.s6_addr, 1);
2259 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002260 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2261 atid);
2262 cxgb4_free_atid(t, atid);
2263 dst_release(ep->dst);
2264 cxgb4_l2t_release(ep->l2t);
2265 c4iw_reconnect(ep);
2266 return 0;
2267 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002268 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302269 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302270 if (ep->com.local_addr.ss_family == AF_INET) {
2271 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2272 atid, status, status2errno(status),
2273 &la->sin_addr.s_addr, ntohs(la->sin_port),
2274 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2275 } else {
2276 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2277 atid, status, status2errno(status),
2278 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2279 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2280 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302281 break;
2282 }
2283
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302284fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002285 connect_reply_upcall(ep, status2errno(status));
2286 state_set(&ep->com, DEAD);
2287
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302288 if (ep->com.remote_addr.ss_family == AF_INET6) {
2289 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002290 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302291 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2292 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2293 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002294 if (status && act_open_has_tid(status))
2295 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2296
Vipul Pandya793dad92012-12-10 09:30:56 +00002297 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002298 cxgb4_free_atid(t, atid);
2299 dst_release(ep->dst);
2300 cxgb4_l2t_release(ep->l2t);
2301 c4iw_put_ep(&ep->com);
2302
2303 return 0;
2304}
2305
2306static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2307{
2308 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2309 struct tid_info *t = dev->rdev.lldi.tids;
2310 unsigned int stid = GET_TID(rpl);
2311 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2312
2313 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002314 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2315 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316 }
2317 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2318 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002319 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320
Vipul Pandya1cab7752012-12-10 09:30:55 +00002321out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002322 return 0;
2323}
2324
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2326{
2327 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2328 struct tid_info *t = dev->rdev.lldi.tids;
2329 unsigned int stid = GET_TID(rpl);
2330 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2331
2332 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002333 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002334 return 0;
2335}
2336
Hariprasad S9dec9002016-05-05 01:27:29 +05302337static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2338 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339{
2340 struct cpl_pass_accept_rpl *rpl;
2341 unsigned int mtu_idx;
2342 u64 opt0;
2343 u32 opt2;
2344 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302345 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302346 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302347 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348
2349 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2350 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302351
Steve Wisecfdda9d2010-04-21 15:30:06 -07002352 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302353 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302354 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302355 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2356 rpl5 = (void *)rpl;
2357 INIT_TP_WR(rpl5, ep->hwtid);
2358 } else {
2359 skb_trim(skb, sizeof(*rpl));
2360 INIT_TP_WR(rpl, ep->hwtid);
2361 }
2362 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2363 ep->hwtid));
2364
2365 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302366 enable_tcp_timestamps && req->tcpopt.tstamp,
2367 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302369
2370 /*
2371 * Specify the largest window that will fit in opt0. The
2372 * remainder will be specified in the rx_data_ack.
2373 */
2374 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002375 if (win > RCV_BUFSIZ_M)
2376 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002377 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002378 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002379 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002380 WND_SCALE_V(wscale) |
2381 MSS_IDX_V(mtu_idx) |
2382 L2T_IDX_V(ep->l2t->idx) |
2383 TX_CHAN_V(ep->tx_chan) |
2384 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002385 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002386 ULP_MODE_V(ULP_MODE_TCPDDP) |
2387 RCV_BUFSIZ_V(win);
2388 opt2 = RX_CHANNEL_V(0) |
2389 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002390
2391 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002392 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002394 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002395 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002396 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002397 if (enable_ecn) {
2398 const struct tcphdr *tcph;
2399 u32 hlen = ntohl(req->hdr_len);
2400
Hariprasad S963cab52015-09-23 17:19:27 +05302401 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2402 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2403 IP_HDR_LEN_G(hlen);
2404 else
2405 tcph = (const void *)(req + 1) +
2406 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002407 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002408 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002409 }
Hariprasad S963cab52015-09-23 17:19:27 +05302410 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302411 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002412 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302413 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302414 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302415 rpl5 = (void *)rpl;
2416 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2417 if (peer2peer)
2418 isn += 4;
2419 rpl5->iss = cpu_to_be32(isn);
2420 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002421 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002422
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423 rpl->opt0 = cpu_to_be64(opt0);
2424 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002425 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302426 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427
Hariprasad S9dec9002016-05-05 01:27:29 +05302428 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429}
2430
Vipul Pandya830662f2013-07-04 16:10:47 +05302431static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432{
Vipul Pandya830662f2013-07-04 16:10:47 +05302433 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 BUG_ON(skb_cloned(skb));
2435 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 release_tid(&dev->rdev, hwtid, skb);
2437 return;
2438}
2439
Hariprasad S963cab52015-09-23 17:19:27 +05302440static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2441 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002442 __be16 *local_port, __be16 *peer_port)
2443{
Hariprasad S963cab52015-09-23 17:19:27 +05302444 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2445 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2446 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2447 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2448 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2449 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302451 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002452 struct tcphdr *tcp = (struct tcphdr *)
2453 ((u8 *)(req + 1) + eth_len + ip_len);
2454
Vipul Pandya830662f2013-07-04 16:10:47 +05302455 if (ip->version == 4) {
2456 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2457 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2458 ntohs(tcp->dest));
2459 *iptype = 4;
2460 memcpy(peer_ip, &ip->saddr, 4);
2461 memcpy(local_ip, &ip->daddr, 4);
2462 } else {
2463 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2464 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2465 ntohs(tcp->dest));
2466 *iptype = 6;
2467 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2468 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2469 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 *peer_port = tcp->source;
2471 *local_port = tcp->dest;
2472
2473 return;
2474}
2475
2476static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2477{
Vipul Pandya793dad92012-12-10 09:30:56 +00002478 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002479 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002480 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002481 struct tid_info *t = dev->rdev.lldi.tids;
2482 unsigned int hwtid = GET_TID(req);
2483 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302484 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302486 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002487 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002488 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302489 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302490 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302491 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492
2493 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002494 if (!parent_ep) {
2495 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2496 goto reject;
2497 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002498
Steve Wisecfdda9d2010-04-21 15:30:06 -07002499 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302500 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002501 goto reject;
2502 }
2503
Hariprasad S963cab52015-09-23 17:19:27 +05302504 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2505 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302506
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302508 if (iptype == 4) {
2509 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2510 , __func__, parent_ep, hwtid,
2511 local_ip, peer_ip, ntohs(local_port),
2512 ntohs(peer_port), peer_mss);
2513 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2514 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302515 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302516 } else {
2517 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2518 , __func__, parent_ep, hwtid,
2519 local_ip, peer_ip, ntohs(local_port),
2520 ntohs(peer_port), peer_mss);
2521 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002522 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302523 ((struct sockaddr_in6 *)
2524 &parent_ep->com.local_addr)->sin6_scope_id);
2525 }
2526 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2528 __func__);
2529 goto reject;
2530 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531
2532 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2533 if (!child_ep) {
2534 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2535 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002536 dst_release(dst);
2537 goto reject;
2538 }
David Miller3786cf12011-12-02 16:52:31 +00002539
Hariprasad S963cab52015-09-23 17:19:27 +05302540 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302541 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002542 if (err) {
2543 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2544 __func__);
2545 dst_release(dst);
2546 kfree(child_ep);
2547 goto reject;
2548 }
2549
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302550 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2551 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2552 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2553 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002554
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 state_set(&child_ep->com, CONNECTING);
2556 child_ep->com.dev = dev;
2557 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002558
Vipul Pandya830662f2013-07-04 16:10:47 +05302559 if (iptype == 4) {
2560 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002561 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002562
Vipul Pandya830662f2013-07-04 16:10:47 +05302563 sin->sin_family = PF_INET;
2564 sin->sin_port = local_port;
2565 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002566
2567 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2568 sin->sin_family = PF_INET;
2569 sin->sin_port = ((struct sockaddr_in *)
2570 &parent_ep->com.local_addr)->sin_port;
2571 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2572
Steve Wise170003c2016-02-26 09:18:03 -06002573 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302574 sin->sin_family = PF_INET;
2575 sin->sin_port = peer_port;
2576 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2577 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002578 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302579 sin6->sin6_family = PF_INET6;
2580 sin6->sin6_port = local_port;
2581 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002582
2583 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2584 sin6->sin6_family = PF_INET6;
2585 sin6->sin6_port = ((struct sockaddr_in6 *)
2586 &parent_ep->com.local_addr)->sin6_port;
2587 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2588
Steve Wise170003c2016-02-26 09:18:03 -06002589 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302590 sin6->sin6_family = PF_INET6;
2591 sin6->sin6_port = peer_port;
2592 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2593 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002594
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595 c4iw_get_ep(&parent_ep->com);
2596 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302597 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002598 child_ep->dst = dst;
2599 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600
2601 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002602 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002603
2604 init_timer(&child_ep->timer);
2605 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302606 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302607 if (accept_cr(child_ep, skb, req)) {
2608 c4iw_put_ep(&parent_ep->com);
2609 release_ep_resources(child_ep);
2610 } else {
2611 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2612 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302613 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002614 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302615 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2616 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2617 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002618 goto out;
2619reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302620 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621out:
2622 return 0;
2623}
2624
2625static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2626{
2627 struct c4iw_ep *ep;
2628 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302630 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631
Hariprasad S944661d2016-05-06 22:18:03 +05302632 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002633 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2634 ep->snd_seq = be32_to_cpu(req->snd_isn);
2635 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2636
Vipul Pandya1cab7752012-12-10 09:30:55 +00002637 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2638 ntohs(req->tcp_opt));
2639
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 set_emss(ep, ntohs(req->tcp_opt));
2641
2642 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302643 mutex_lock(&ep->com.mutex);
2644 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002646 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302647 ret = send_flowc(ep, skb);
2648 mutex_unlock(&ep->com.mutex);
2649 if (ret)
2650 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302651 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002652
2653 return 0;
2654}
2655
2656static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2657{
2658 struct cpl_peer_close *hdr = cplhdr(skb);
2659 struct c4iw_ep *ep;
2660 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 int disconnect = 1;
2662 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002664 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665
Hariprasad S944661d2016-05-06 22:18:03 +05302666 ep = get_ep_from_tid(dev, tid);
2667 if (!ep)
2668 return 0;
2669
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2671 dst_confirm(ep->dst);
2672
Vipul Pandya793dad92012-12-10 09:30:56 +00002673 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002674 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 switch (ep->com.state) {
2676 case MPA_REQ_WAIT:
2677 __state_set(&ep->com, CLOSING);
2678 break;
2679 case MPA_REQ_SENT:
2680 __state_set(&ep->com, CLOSING);
2681 connect_reply_upcall(ep, -ECONNRESET);
2682 break;
2683 case MPA_REQ_RCVD:
2684
2685 /*
2686 * We're gonna mark this puppy DEAD, but keep
2687 * the reference on it until the ULP accepts or
2688 * rejects the CR. Also wake up anyone waiting
2689 * in rdma connection migration (see c4iw_accept_cr()).
2690 */
2691 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002692 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002693 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002694 break;
2695 case MPA_REP_SENT:
2696 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002698 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002699 break;
2700 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002701 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002702 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002703 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002704 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002705 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002706 if (ret != -ECONNRESET) {
2707 peer_close_upcall(ep);
2708 disconnect = 1;
2709 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 break;
2711 case ABORTING:
2712 disconnect = 0;
2713 break;
2714 case CLOSING:
2715 __state_set(&ep->com, MORIBUND);
2716 disconnect = 0;
2717 break;
2718 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002719 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 if (ep->com.cm_id && ep->com.qp) {
2721 attrs.next_state = C4IW_QP_STATE_IDLE;
2722 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2723 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2724 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302725 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002726 __state_set(&ep->com, DEAD);
2727 release = 1;
2728 disconnect = 0;
2729 break;
2730 case DEAD:
2731 disconnect = 0;
2732 break;
2733 default:
2734 BUG_ON(1);
2735 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002736 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002737 if (disconnect)
2738 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2739 if (release)
2740 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302741 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002742 return 0;
2743}
2744
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2746{
2747 struct cpl_abort_req_rss *req = cplhdr(skb);
2748 struct c4iw_ep *ep;
2749 struct cpl_abort_rpl *rpl;
2750 struct sk_buff *rpl_skb;
2751 struct c4iw_qp_attributes attrs;
2752 int ret;
2753 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755
Hariprasad S944661d2016-05-06 22:18:03 +05302756 ep = get_ep_from_tid(dev, tid);
2757 if (!ep)
2758 return 0;
2759
Steve Wise7a2cea22014-03-14 21:52:07 +05302760 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302761 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2762 __func__, ep->hwtid, req->status,
2763 neg_adv_str(req->status));
2764 ep->stats.abort_neg_adv++;
2765 mutex_lock(&dev->rdev.stats.lock);
2766 dev->rdev.stats.neg_adv++;
2767 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302768 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002769 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2771 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002772 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002773
2774 /*
2775 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302776 * However, this is not needed if com state is just
2777 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002778 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302779 if (ep->com.state != MPA_REQ_SENT)
2780 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002781
2782 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783 switch (ep->com.state) {
2784 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302785 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002786 break;
2787 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002788 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002789 break;
2790 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002791 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002792 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302793 connect_reply_upcall(ep, -ECONNRESET);
2794 else {
2795 /*
2796 * we just don't send notification upwards because we
2797 * want to retry with mpa_v1 without upper layers even
2798 * knowing it.
2799 *
2800 * do some housekeeping so as to re-initiate the
2801 * connection
2802 */
2803 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2804 mpa_rev);
2805 ep->retry_with_mpa_v1 = 1;
2806 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002807 break;
2808 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 break;
2810 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002811 break;
2812 case MORIBUND:
2813 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002814 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002815 /*FALLTHROUGH*/
2816 case FPDU_MODE:
2817 if (ep->com.cm_id && ep->com.qp) {
2818 attrs.next_state = C4IW_QP_STATE_ERROR;
2819 ret = c4iw_modify_qp(ep->com.qp->rhp,
2820 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2821 &attrs, 1);
2822 if (ret)
2823 printk(KERN_ERR MOD
2824 "%s - qp <- error failed!\n",
2825 __func__);
2826 }
2827 peer_abort_upcall(ep);
2828 break;
2829 case ABORTING:
2830 break;
2831 case DEAD:
2832 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002833 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302834 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 default:
2836 BUG_ON(1);
2837 break;
2838 }
2839 dst_confirm(ep->dst);
2840 if (ep->com.state != ABORTING) {
2841 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302842 /* we don't release if we want to retry with mpa_v1 */
2843 if (!ep->retry_with_mpa_v1)
2844 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002846 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847
2848 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2849 if (!rpl_skb) {
2850 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2851 __func__);
2852 release = 1;
2853 goto out;
2854 }
2855 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2856 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2857 INIT_TP_WR(rpl, ep->hwtid);
2858 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2859 rpl->cmd = CPL_ABORT_NO_RST;
2860 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2861out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 if (release)
2863 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002864 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302865 if (ep->com.remote_addr.ss_family == AF_INET6) {
2866 struct sockaddr_in6 *sin6 =
2867 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002868 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302869 cxgb4_clip_release(
2870 ep->com.dev->rdev.lldi.ports[0],
2871 (const u32 *)&sin6->sin6_addr.s6_addr,
2872 1);
2873 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002874 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302875 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2876 dst_release(ep->dst);
2877 cxgb4_l2t_release(ep->l2t);
2878 c4iw_reconnect(ep);
2879 }
2880
Hariprasad S944661d2016-05-06 22:18:03 +05302881deref_ep:
2882 c4iw_put_ep(&ep->com);
2883 /* Dereferencing ep, referenced in peer_abort_intr() */
2884 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885 return 0;
2886}
2887
2888static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2889{
2890 struct c4iw_ep *ep;
2891 struct c4iw_qp_attributes attrs;
2892 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002893 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002894 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895
Hariprasad S944661d2016-05-06 22:18:03 +05302896 ep = get_ep_from_tid(dev, tid);
2897 if (!ep)
2898 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002899
2900 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2901 BUG_ON(!ep);
2902
2903 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002904 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302905 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002906 switch (ep->com.state) {
2907 case CLOSING:
2908 __state_set(&ep->com, MORIBUND);
2909 break;
2910 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002911 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002912 if ((ep->com.cm_id) && (ep->com.qp)) {
2913 attrs.next_state = C4IW_QP_STATE_IDLE;
2914 c4iw_modify_qp(ep->com.qp->rhp,
2915 ep->com.qp,
2916 C4IW_QP_ATTR_NEXT_STATE,
2917 &attrs, 1);
2918 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302919 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002920 __state_set(&ep->com, DEAD);
2921 release = 1;
2922 break;
2923 case ABORTING:
2924 case DEAD:
2925 break;
2926 default:
2927 BUG_ON(1);
2928 break;
2929 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002930 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002931 if (release)
2932 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302933 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 return 0;
2935}
2936
2937static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2938{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002939 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002940 unsigned int tid = GET_TID(rpl);
2941 struct c4iw_ep *ep;
2942 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943
Hariprasad S944661d2016-05-06 22:18:03 +05302944 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002945 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946
Steve Wise30c95c22011-05-09 22:06:22 -07002947 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002948 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2949 ep->com.qp->wq.sq.qid);
2950 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2951 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2952 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2953 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002954 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302955 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 return 0;
2958}
2959
2960/*
2961 * Upcall from the adapter indicating data has been transmitted.
2962 * For us its just the single MPA request or reply. We can now free
2963 * the skb holding the mpa message.
2964 */
2965static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2966{
2967 struct c4iw_ep *ep;
2968 struct cpl_fw4_ack *hdr = cplhdr(skb);
2969 u8 credits = hdr->credits;
2970 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971
2972
Hariprasad S944661d2016-05-06 22:18:03 +05302973 ep = get_ep_from_tid(dev, tid);
2974 if (!ep)
2975 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002976 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2977 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002978 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2979 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302980 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 }
2982
2983 dst_confirm(ep->dst);
2984 if (ep->mpa_skb) {
2985 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2986 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2987 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2988 kfree_skb(ep->mpa_skb);
2989 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302990 mutex_lock(&ep->com.mutex);
2991 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2992 stop_ep_timer(ep);
2993 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002994 }
Hariprasad S944661d2016-05-06 22:18:03 +05302995out:
2996 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002997 return 0;
2998}
2999
Steve Wisecfdda9d2010-04-21 15:30:06 -07003000int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3001{
Steve Wisea7db89e2014-03-21 20:40:35 +05303002 int err = 0;
3003 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003004 struct c4iw_ep *ep = to_ep(cm_id);
3005 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3006
Steve Wisea7db89e2014-03-21 20:40:35 +05303007 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303008 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303009 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003010 c4iw_put_ep(&ep->com);
3011 return -ECONNRESET;
3012 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003013 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303015 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003016 else {
3017 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303018 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003019 }
Steve Wisea7db89e2014-03-21 20:40:35 +05303020 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303021 if (disconnect) {
3022 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303023 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303024 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003025 c4iw_put_ep(&ep->com);
3026 return 0;
3027}
3028
3029int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3030{
3031 int err;
3032 struct c4iw_qp_attributes attrs;
3033 enum c4iw_qp_attr_mask mask;
3034 struct c4iw_ep *ep = to_ep(cm_id);
3035 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3036 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303037 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038
3039 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303040
3041 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303042 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303044 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003045 }
3046
Steve Wisecfdda9d2010-04-21 15:30:06 -07003047 BUG_ON(!qp);
3048
Vipul Pandya793dad92012-12-10 09:30:56 +00003049 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303050 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3051 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003052 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303053 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003054 }
3055
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303056 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3057 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303058 if (RELAXED_IRD_NEGOTIATION) {
3059 ep->ord = ep->ird;
3060 } else {
3061 ep->ird = conn_param->ird;
3062 ep->ord = conn_param->ord;
3063 send_mpa_reject(ep, conn_param->private_data,
3064 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303065 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303066 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303067 }
3068 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303069 if (conn_param->ird < ep->ord) {
3070 if (RELAXED_IRD_NEGOTIATION &&
3071 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3072 conn_param->ird = ep->ord;
3073 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303074 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303075 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303076 }
3077 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303078 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003079 ep->ird = conn_param->ird;
3080 ep->ord = conn_param->ord;
3081
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303082 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303083 if (peer2peer && ep->ird == 0)
3084 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303085 } else {
3086 if (peer2peer &&
3087 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303088 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303089 ep->ird = 1;
3090 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003091
3092 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3093
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303094 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303095 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303096 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003097 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303098
Steve Wisecfdda9d2010-04-21 15:30:06 -07003099 /* bind QP to EP and move to RTS */
3100 attrs.mpa_attr = ep->mpa_attr;
3101 attrs.max_ird = ep->ird;
3102 attrs.max_ord = ep->ord;
3103 attrs.llp_stream_handle = ep;
3104 attrs.next_state = C4IW_QP_STATE_RTS;
3105
3106 /* bind QP and TID with INIT_WR */
3107 mask = C4IW_QP_ATTR_NEXT_STATE |
3108 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3109 C4IW_QP_ATTR_MPA_ATTR |
3110 C4IW_QP_ATTR_MAX_IRD |
3111 C4IW_QP_ATTR_MAX_ORD;
3112
3113 err = c4iw_modify_qp(ep->com.qp->rhp,
3114 ep->com.qp, mask, &attrs, 1);
3115 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303116 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303117
3118 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003119 err = send_mpa_reply(ep, conn_param->private_data,
3120 conn_param->private_data_len);
3121 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303122 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003123
Steve Wisea7db89e2014-03-21 20:40:35 +05303124 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003125 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303126 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003127 c4iw_put_ep(&ep->com);
3128 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303129err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303130 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303131err_abort:
3132 abort = 1;
3133err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303134 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303135 if (abort)
3136 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003137 c4iw_put_ep(&ep->com);
3138 return err;
3139}
3140
Vipul Pandya830662f2013-07-04 16:10:47 +05303141static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3142{
3143 struct in_device *ind;
3144 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003145 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3146 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303147
3148 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3149 if (!ind)
3150 return -EADDRNOTAVAIL;
3151 for_primary_ifa(ind) {
3152 laddr->sin_addr.s_addr = ifa->ifa_address;
3153 raddr->sin_addr.s_addr = ifa->ifa_address;
3154 found = 1;
3155 break;
3156 }
3157 endfor_ifa(ind);
3158 in_dev_put(ind);
3159 return found ? 0 : -EADDRNOTAVAIL;
3160}
3161
3162static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3163 unsigned char banned_flags)
3164{
3165 struct inet6_dev *idev;
3166 int err = -EADDRNOTAVAIL;
3167
3168 rcu_read_lock();
3169 idev = __in6_dev_get(dev);
3170 if (idev != NULL) {
3171 struct inet6_ifaddr *ifp;
3172
3173 read_lock_bh(&idev->lock);
3174 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3175 if (ifp->scope == IFA_LINK &&
3176 !(ifp->flags & banned_flags)) {
3177 memcpy(addr, &ifp->addr, 16);
3178 err = 0;
3179 break;
3180 }
3181 }
3182 read_unlock_bh(&idev->lock);
3183 }
3184 rcu_read_unlock();
3185 return err;
3186}
3187
3188static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3189{
3190 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003191 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3192 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303193
Nicholas Krause54b9a962015-08-26 23:00:59 -04003194 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303195 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3196 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3197 return 0;
3198 }
3199 return -EADDRNOTAVAIL;
3200}
3201
Steve Wisecfdda9d2010-04-21 15:30:06 -07003202int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3203{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003204 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3205 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003206 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003207 struct sockaddr_in *laddr;
3208 struct sockaddr_in *raddr;
3209 struct sockaddr_in6 *laddr6;
3210 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303211 __u8 *ra;
3212 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003213
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303214 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3215 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003216 err = -EINVAL;
3217 goto out;
3218 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003219 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3220 if (!ep) {
3221 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3222 err = -ENOMEM;
3223 goto out;
3224 }
3225 init_timer(&ep->timer);
3226 ep->plen = conn_param->private_data_len;
3227 if (ep->plen)
3228 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3229 conn_param->private_data, ep->plen);
3230 ep->ird = conn_param->ird;
3231 ep->ord = conn_param->ord;
3232
3233 if (peer2peer && ep->ord == 0)
3234 ep->ord = 1;
3235
Steve Wisecfdda9d2010-04-21 15:30:06 -07003236 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303237 ref_cm_id(&ep->com);
3238 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303240 if (!ep->com.qp) {
3241 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3242 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003243 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303244 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003245 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3247 ep->com.qp, cm_id);
3248
3249 /*
3250 * Allocate an active TID to initiate a TCP connection.
3251 */
3252 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3253 if (ep->atid == -1) {
3254 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3255 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003256 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003257 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003258 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003259
Steve Wise170003c2016-02-26 09:18:03 -06003260 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003261 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003262 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003263 sizeof(ep->com.remote_addr));
3264
Steve Wise170003c2016-02-26 09:18:03 -06003265 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3266 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3267 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3268 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003269
Steve Wise170003c2016-02-26 09:18:03 -06003270 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303271 iptype = 4;
3272 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003273
Vipul Pandya830662f2013-07-04 16:10:47 +05303274 /*
3275 * Handle loopback requests to INADDR_ANY.
3276 */
3277 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3278 err = pick_local_ipaddrs(dev, cm_id);
3279 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003280 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303281 }
3282
3283 /* find a route */
3284 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3285 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3286 ra, ntohs(raddr->sin_port));
3287 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3288 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303289 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303290 } else {
3291 iptype = 6;
3292 ra = (__u8 *)&raddr6->sin6_addr;
3293
3294 /*
3295 * Handle loopback requests to INADDR_ANY.
3296 */
3297 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3298 err = pick_local_ip6addrs(dev, cm_id);
3299 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003300 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303301 }
3302
3303 /* find a route */
3304 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3305 __func__, laddr6->sin6_addr.s6_addr,
3306 ntohs(laddr6->sin6_port),
3307 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3308 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3309 raddr6->sin6_addr.s6_addr,
3310 laddr6->sin6_port, raddr6->sin6_port, 0,
3311 raddr6->sin6_scope_id);
3312 }
3313 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003314 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3315 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003316 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003317 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318
Hariprasad S963cab52015-09-23 17:19:27 +05303319 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303320 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003321 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003322 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003323 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003324 }
3325
3326 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3327 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3328 ep->l2t->idx);
3329
3330 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303331 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003332
3333 /* send connect request to rnic */
3334 err = send_connect(ep);
3335 if (!err)
3336 goto out;
3337
3338 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003339fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003340 dst_release(ep->dst);
3341fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003342 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003343 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003344fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303345 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003346 c4iw_put_ep(&ep->com);
3347out:
3348 return err;
3349}
3350
Vipul Pandya830662f2013-07-04 16:10:47 +05303351static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3352{
3353 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003354 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003355 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303356
Hariprasad S28de1f72016-01-13 10:03:14 +05303357 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3358 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3359 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3360 if (err)
3361 return err;
3362 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303363 c4iw_init_wr_wait(&ep->com.wr_wait);
3364 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3365 ep->stid, &sin6->sin6_addr,
3366 sin6->sin6_port,
3367 ep->com.dev->rdev.lldi.rxq_ids[0]);
3368 if (!err)
3369 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3370 &ep->com.wr_wait,
3371 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303372 else if (err > 0)
3373 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303374 if (err) {
3375 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3376 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303377 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3378 err, ep->stid,
3379 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303380 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303381 return err;
3382}
3383
3384static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3385{
3386 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003387 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003388 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303389
3390 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3391 do {
3392 err = cxgb4_create_server_filter(
3393 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3394 sin->sin_addr.s_addr, sin->sin_port, 0,
3395 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3396 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303397 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3398 err = -EIO;
3399 break;
3400 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303401 set_current_state(TASK_UNINTERRUPTIBLE);
3402 schedule_timeout(usecs_to_jiffies(100));
3403 }
3404 } while (err == -EBUSY);
3405 } else {
3406 c4iw_init_wr_wait(&ep->com.wr_wait);
3407 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3408 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3409 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3410 if (!err)
3411 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3412 &ep->com.wr_wait,
3413 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303414 else if (err > 0)
3415 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303416 }
3417 if (err)
3418 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3419 , err, ep->stid,
3420 &sin->sin_addr, ntohs(sin->sin_port));
3421 return err;
3422}
3423
Steve Wisecfdda9d2010-04-21 15:30:06 -07003424int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3425{
3426 int err = 0;
3427 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3428 struct c4iw_listen_ep *ep;
3429
Steve Wisecfdda9d2010-04-21 15:30:06 -07003430 might_sleep();
3431
3432 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3433 if (!ep) {
3434 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3435 err = -ENOMEM;
3436 goto fail1;
3437 }
3438 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003439 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303440 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003441 ep->com.dev = dev;
3442 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003443 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303444 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003445
3446 /*
3447 * Allocate a server TID.
3448 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303449 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3450 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303451 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003452 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003453 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303454 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003455 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003456
Steve Wisecfdda9d2010-04-21 15:30:06 -07003457 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003458 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459 err = -ENOMEM;
3460 goto fail2;
3461 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003462 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003463
Steve Wise170003c2016-02-26 09:18:03 -06003464 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3465 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003466
Steve Wisecfdda9d2010-04-21 15:30:06 -07003467 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303468 if (ep->com.local_addr.ss_family == AF_INET)
3469 err = create_server4(dev, ep);
3470 else
3471 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003472 if (!err) {
3473 cm_id->provider_data = ep;
3474 goto out;
3475 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003476
Vipul Pandya830662f2013-07-04 16:10:47 +05303477 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3478 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003479fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303480 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003481 c4iw_put_ep(&ep->com);
3482fail1:
3483out:
3484 return err;
3485}
3486
3487int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3488{
3489 int err;
3490 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3491
3492 PDBG("%s ep %p\n", __func__, ep);
3493
3494 might_sleep();
3495 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303496 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3497 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003498 err = cxgb4_remove_server_filter(
3499 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3500 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3501 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303502 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003503 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303504 err = cxgb4_remove_server(
3505 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3506 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003507 if (err)
3508 goto done;
3509 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3510 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003511 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303512 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3513 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003514 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003515 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303516 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3517 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303519 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003520 c4iw_put_ep(&ep->com);
3521 return err;
3522}
3523
3524int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3525{
3526 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003527 int close = 0;
3528 int fatal = 0;
3529 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003530
Steve Wise2f5b48c2010-09-10 11:15:36 -05003531 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003532
3533 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3534 states[ep->com.state], abrupt);
3535
Hariprasad S6e410d82016-05-05 01:27:31 +05303536 /*
3537 * Ref the ep here in case we have fatal errors causing the
3538 * ep to be released and freed.
3539 */
3540 c4iw_get_ep(&ep->com);
3541
Steve Wisecfdda9d2010-04-21 15:30:06 -07003542 rdev = &ep->com.dev->rdev;
3543 if (c4iw_fatal_error(rdev)) {
3544 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303545 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003546 ep->com.state = DEAD;
3547 }
3548 switch (ep->com.state) {
3549 case MPA_REQ_WAIT:
3550 case MPA_REQ_SENT:
3551 case MPA_REQ_RCVD:
3552 case MPA_REP_SENT:
3553 case FPDU_MODE:
3554 close = 1;
3555 if (abrupt)
3556 ep->com.state = ABORTING;
3557 else {
3558 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003559 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003560 }
3561 set_bit(CLOSE_SENT, &ep->com.flags);
3562 break;
3563 case CLOSING:
3564 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3565 close = 1;
3566 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003567 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003568 ep->com.state = ABORTING;
3569 } else
3570 ep->com.state = MORIBUND;
3571 }
3572 break;
3573 case MORIBUND:
3574 case ABORTING:
3575 case DEAD:
3576 PDBG("%s ignoring disconnect ep %p state %u\n",
3577 __func__, ep, ep->com.state);
3578 break;
3579 default:
3580 BUG();
3581 break;
3582 }
3583
Steve Wisecfdda9d2010-04-21 15:30:06 -07003584 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003585 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003586 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303587 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003588 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003589 } else {
3590 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003591 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003592 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303593 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303594 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303595 if (!abrupt) {
3596 stop_ep_timer(ep);
3597 close_complete_upcall(ep, -EIO);
3598 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303599 if (ep->com.qp) {
3600 struct c4iw_qp_attributes attrs;
3601
3602 attrs.next_state = C4IW_QP_STATE_ERROR;
3603 ret = c4iw_modify_qp(ep->com.qp->rhp,
3604 ep->com.qp,
3605 C4IW_QP_ATTR_NEXT_STATE,
3606 &attrs, 1);
3607 if (ret)
3608 pr_err(MOD
3609 "%s - qp <- error failed!\n",
3610 __func__);
3611 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003612 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303613 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003614 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003615 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303616 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003617 if (fatal)
3618 release_ep_resources(ep);
3619 return ret;
3620}
3621
Vipul Pandya1cab7752012-12-10 09:30:55 +00003622static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3623 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3624{
3625 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003626 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003627
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003628 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3629 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630 if (!ep)
3631 return;
3632
3633 switch (req->retval) {
3634 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003635 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3636 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3637 send_fw_act_open_req(ep, atid);
3638 return;
3639 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003640 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003641 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3642 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3643 send_fw_act_open_req(ep, atid);
3644 return;
3645 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003646 break;
3647 default:
3648 pr_info("%s unexpected ofld conn wr retval %d\n",
3649 __func__, req->retval);
3650 break;
3651 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003652 pr_err("active ofld_connect_wr failure %d atid %d\n",
3653 req->retval, atid);
3654 mutex_lock(&dev->rdev.stats.lock);
3655 dev->rdev.stats.act_ofld_conn_fails++;
3656 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003657 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003658 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303659 if (ep->com.remote_addr.ss_family == AF_INET6) {
3660 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003661 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303662 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3663 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3664 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003665 remove_handle(dev, &dev->atid_idr, atid);
3666 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3667 dst_release(ep->dst);
3668 cxgb4_l2t_release(ep->l2t);
3669 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670}
3671
3672static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3673 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3674{
3675 struct sk_buff *rpl_skb;
3676 struct cpl_pass_accept_req *cpl;
3677 int ret;
3678
Paul Bolle710a3112013-02-05 20:51:30 +00003679 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003680 BUG_ON(!rpl_skb);
3681 if (req->retval) {
3682 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003683 mutex_lock(&dev->rdev.stats.lock);
3684 dev->rdev.stats.pas_ofld_conn_fails++;
3685 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003686 kfree_skb(rpl_skb);
3687 } else {
3688 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3689 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003690 (__force u32) htonl(
3691 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003692 ret = pass_accept_req(dev, rpl_skb);
3693 if (!ret)
3694 kfree_skb(rpl_skb);
3695 }
3696 return;
3697}
3698
3699static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003700{
3701 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003702 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3703
3704 switch (rpl->type) {
3705 case FW6_TYPE_CQE:
3706 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3707 break;
3708 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3709 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3710 switch (req->t_state) {
3711 case TCP_SYN_SENT:
3712 active_ofld_conn_reply(dev, skb, req);
3713 break;
3714 case TCP_SYN_RECV:
3715 passive_ofld_conn_reply(dev, skb, req);
3716 break;
3717 default:
3718 pr_err("%s unexpected ofld conn wr state %d\n",
3719 __func__, req->t_state);
3720 break;
3721 }
3722 break;
3723 }
3724 return 0;
3725}
3726
3727static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3728{
Hariprasad S963cab52015-09-23 17:19:27 +05303729 __be32 l2info;
3730 __be16 hdr_len, vlantag, len;
3731 u16 eth_hdr_len;
3732 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003733 u8 intf;
3734 struct cpl_rx_pkt *cpl = cplhdr(skb);
3735 struct cpl_pass_accept_req *req;
3736 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003737 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303738 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003739
Vipul Pandyaf079af72013-03-14 05:08:58 +00003740 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003741 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303742 vlantag = cpl->vlan;
3743 len = cpl->len;
3744 l2info = cpl->l2info;
3745 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003746 intf = cpl->iff;
3747
3748 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3749
3750 /*
3751 * We need to parse the TCP options from SYN packet.
3752 * to generate cpl_pass_accept_req.
3753 */
3754 memset(&tmp_opt, 0, sizeof(tmp_opt));
3755 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003756 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003757
3758 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3759 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303760 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3761 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303762 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303763 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303764 type = dev->rdev.lldi.adapter_type;
3765 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3766 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3767 req->hdr_len =
3768 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3769 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3770 eth_hdr_len = is_t4(type) ?
3771 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3772 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3773 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3774 IP_HDR_LEN_V(ip_hdr_len) |
3775 ETH_HDR_LEN_V(eth_hdr_len));
3776 } else { /* T6 and later */
3777 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3778 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3779 T6_IP_HDR_LEN_V(ip_hdr_len) |
3780 T6_ETH_HDR_LEN_V(eth_hdr_len));
3781 }
3782 req->vlan = vlantag;
3783 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003784 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3785 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003786 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3787 if (tmp_opt.wscale_ok)
3788 req->tcpopt.wsf = tmp_opt.snd_wscale;
3789 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3790 if (tmp_opt.sack_ok)
3791 req->tcpopt.sack = 1;
3792 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3793 return;
3794}
3795
3796static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3797 __be32 laddr, __be16 lport,
3798 __be32 raddr, __be16 rport,
3799 u32 rcv_isn, u32 filter, u16 window,
3800 u32 rss_qid, u8 port_id)
3801{
3802 struct sk_buff *req_skb;
3803 struct fw_ofld_connection_wr *req;
3804 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303805 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003806
3807 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3808 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3809 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003810 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303811 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303812 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003813 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814 req->le.lport = lport;
3815 req->le.pport = rport;
3816 req->le.u.ipv4.lip = laddr;
3817 req->le.u.ipv4.pip = raddr;
3818 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3819 req->tcb.rcv_adv = htons(window);
3820 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303821 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3822 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3823 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003824 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003825
3826 /*
3827 * We store the qid in opt2 which will be used by the firmware
3828 * to send us the wr response.
3829 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003830 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003831
3832 /*
3833 * We initialize the MSS index in TCB to 0xF.
3834 * So that when driver sends cpl_pass_accept_rpl
3835 * TCB picks up the correct value. If this was 0
3836 * TP will ignore any value > 0 for MSS index.
3837 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003838 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303839 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003840
3841 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303842 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3843 if (ret < 0) {
3844 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3845 ret);
3846 kfree_skb(skb);
3847 kfree_skb(req_skb);
3848 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003849}
3850
3851/*
3852 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3853 * messages when a filter is being used instead of server to
3854 * redirect a syn packet. When packets hit filter they are redirected
3855 * to the offload queue and driver tries to establish the connection
3856 * using firmware work request.
3857 */
3858static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3859{
3860 int stid;
3861 unsigned int filter;
3862 struct ethhdr *eh = NULL;
3863 struct vlan_ethhdr *vlan_eh = NULL;
3864 struct iphdr *iph;
3865 struct tcphdr *tcph;
3866 struct rss_header *rss = (void *)skb->data;
3867 struct cpl_rx_pkt *cpl = (void *)skb->data;
3868 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3869 struct l2t_entry *e;
3870 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 struct c4iw_ep *lep;
3872 u16 window;
3873 struct port_info *pi;
3874 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003875 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003876 int step;
3877 u32 tx_chan;
3878 struct neighbour *neigh;
3879
3880 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003881 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003882 goto reject;
3883
3884 /*
3885 * Drop all packets which did not hit the filter.
3886 * Unlikely to happen.
3887 */
3888 if (!(rss->filter_hit && rss->filter_tid))
3889 goto reject;
3890
3891 /*
3892 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3893 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303894 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003895
3896 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3897 if (!lep) {
3898 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3899 goto reject;
3900 }
3901
Hariprasad S963cab52015-09-23 17:19:27 +05303902 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3903 case CHELSIO_T4:
3904 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3905 break;
3906 case CHELSIO_T5:
3907 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3908 break;
3909 case CHELSIO_T6:
3910 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3911 break;
3912 default:
3913 pr_err("T%d Chip is not supported\n",
3914 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3915 goto reject;
3916 }
3917
Vipul Pandyaf079af72013-03-14 05:08:58 +00003918 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003919 eh = (struct ethhdr *)(req + 1);
3920 iph = (struct iphdr *)(eh + 1);
3921 } else {
3922 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3923 iph = (struct iphdr *)(vlan_eh + 1);
3924 skb->vlan_tci = ntohs(cpl->vlan);
3925 }
3926
3927 if (iph->version != 0x4)
3928 goto reject;
3929
3930 tcph = (struct tcphdr *)(iph + 1);
3931 skb_set_network_header(skb, (void *)iph - (void *)rss);
3932 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3933 skb_get(skb);
3934
3935 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3936 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3937 ntohs(tcph->source), iph->tos);
3938
Vipul Pandya830662f2013-07-04 16:10:47 +05303939 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3940 iph->tos);
3941 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003942 pr_err("%s - failed to find dst entry!\n",
3943 __func__);
3944 goto reject;
3945 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003946 neigh = dst_neigh_lookup_skb(dst, skb);
3947
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003948 if (!neigh) {
3949 pr_err("%s - failed to allocate neigh!\n",
3950 __func__);
3951 goto free_dst;
3952 }
3953
Vipul Pandya1cab7752012-12-10 09:30:55 +00003954 if (neigh->dev->flags & IFF_LOOPBACK) {
3955 pdev = ip_dev_find(&init_net, iph->daddr);
3956 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3957 pdev, 0);
3958 pi = (struct port_info *)netdev_priv(pdev);
3959 tx_chan = cxgb4_port_chan(pdev);
3960 dev_put(pdev);
3961 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303962 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003963 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303964 pdev, 0);
3965 pi = (struct port_info *)netdev_priv(pdev);
3966 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003967 }
Steve Wiseebf00062014-03-19 17:44:40 +05303968 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003969 if (!e) {
3970 pr_err("%s - failed to allocate l2t entry!\n",
3971 __func__);
3972 goto free_dst;
3973 }
3974
3975 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3976 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003977 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003978
3979 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303980 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3981 dev->rdev.lldi.ports[0],
3982 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003983
3984 /*
3985 * Synthesize the cpl_pass_accept_req. We have everything except the
3986 * TID. Once firmware sends a reply with TID we update the TID field
3987 * in cpl and pass it through the regular cpl_pass_accept_req path.
3988 */
3989 build_cpl_pass_accept_req(skb, stid, iph->tos);
3990 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3991 tcph->source, ntohl(tcph->seq), filter, window,
3992 rss_qid, pi->port_id);
3993 cxgb4_l2t_release(e);
3994free_dst:
3995 dst_release(dst);
3996reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003997 return 0;
3998}
3999
Steve Wisecfdda9d2010-04-21 15:30:06 -07004000/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004001 * These are the real handlers that are called from a
4002 * work queue.
4003 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304004static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004005 [CPL_ACT_ESTABLISH] = act_establish,
4006 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4007 [CPL_RX_DATA] = rx_data,
4008 [CPL_ABORT_RPL_RSS] = abort_rpl,
4009 [CPL_ABORT_RPL] = abort_rpl,
4010 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4011 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4012 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4013 [CPL_PASS_ESTABLISH] = pass_establish,
4014 [CPL_PEER_CLOSE] = peer_close,
4015 [CPL_ABORT_REQ_RSS] = peer_abort,
4016 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4017 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004018 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004019 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304020 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304021 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4022 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004023};
4024
4025static void process_timeout(struct c4iw_ep *ep)
4026{
4027 struct c4iw_qp_attributes attrs;
4028 int abort = 1;
4029
Steve Wise2f5b48c2010-09-10 11:15:36 -05004030 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004031 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4032 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004033 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004034 switch (ep->com.state) {
4035 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004036 connect_reply_upcall(ep, -ETIMEDOUT);
4037 break;
4038 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304039 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304040 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304041 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004042 break;
4043 case CLOSING:
4044 case MORIBUND:
4045 if (ep->com.cm_id && ep->com.qp) {
4046 attrs.next_state = C4IW_QP_STATE_ERROR;
4047 c4iw_modify_qp(ep->com.qp->rhp,
4048 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4049 &attrs, 1);
4050 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304051 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004053 case ABORTING:
4054 case DEAD:
4055
4056 /*
4057 * These states are expected if the ep timed out at the same
4058 * time as another thread was calling stop_ep_timer().
4059 * So we silently do nothing for these states.
4060 */
4061 abort = 0;
4062 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004064 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004065 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004066 abort = 0;
4067 }
Steve Wisecc18b932014-04-24 14:31:53 -05004068 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304069 if (abort)
4070 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004071 c4iw_put_ep(&ep->com);
4072}
4073
4074static void process_timedout_eps(void)
4075{
4076 struct c4iw_ep *ep;
4077
4078 spin_lock_irq(&timeout_lock);
4079 while (!list_empty(&timeout_list)) {
4080 struct list_head *tmp;
4081
4082 tmp = timeout_list.next;
4083 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004084 tmp->next = NULL;
4085 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004086 spin_unlock_irq(&timeout_lock);
4087 ep = list_entry(tmp, struct c4iw_ep, entry);
4088 process_timeout(ep);
4089 spin_lock_irq(&timeout_lock);
4090 }
4091 spin_unlock_irq(&timeout_lock);
4092}
4093
4094static void process_work(struct work_struct *work)
4095{
4096 struct sk_buff *skb = NULL;
4097 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004098 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004099 unsigned int opcode;
4100 int ret;
4101
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004102 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103 while ((skb = skb_dequeue(&rxq))) {
4104 rpl = cplhdr(skb);
4105 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4106 opcode = rpl->ot.opcode;
4107
4108 BUG_ON(!work_handlers[opcode]);
4109 ret = work_handlers[opcode](dev, skb);
4110 if (!ret)
4111 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004112 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004113 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004114}
4115
4116static DECLARE_WORK(skb_work, process_work);
4117
4118static void ep_timeout(unsigned long arg)
4119{
4120 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004121 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004122
4123 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004124 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004125 /*
4126 * Only insert if it is not already on the list.
4127 */
4128 if (!ep->entry.next) {
4129 list_add_tail(&ep->entry, &timeout_list);
4130 kickit = 1;
4131 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004132 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004133 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004134 if (kickit)
4135 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004136}
4137
4138/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004139 * All the CM events are handled on a work queue to have a safe context.
4140 */
4141static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4142{
4143
4144 /*
4145 * Save dev in the skb->cb area.
4146 */
4147 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4148
4149 /*
4150 * Queue the skb and schedule the worker thread.
4151 */
4152 skb_queue_tail(&rxq, skb);
4153 queue_work(workq, &skb_work);
4154 return 0;
4155}
4156
4157static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4158{
4159 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4160
4161 if (rpl->status != CPL_ERR_NONE) {
4162 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4163 "for tid %u\n", rpl->status, GET_TID(rpl));
4164 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004165 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004166 return 0;
4167}
4168
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004169static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4170{
4171 struct cpl_fw6_msg *rpl = cplhdr(skb);
4172 struct c4iw_wr_wait *wr_waitp;
4173 int ret;
4174
4175 PDBG("%s type %u\n", __func__, rpl->type);
4176
4177 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004178 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004179 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004180 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004182 if (wr_waitp)
4183 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004184 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004185 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004186 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004187 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004188 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004189 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004190 default:
4191 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4192 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004193 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004194 break;
4195 }
4196 return 0;
4197}
4198
Steve Wise8da7e7a2011-06-14 20:59:27 +00004199static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4200{
4201 struct cpl_abort_req_rss *req = cplhdr(skb);
4202 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004203 unsigned int tid = GET_TID(req);
4204
Hariprasad S944661d2016-05-06 22:18:03 +05304205 ep = get_ep_from_tid(dev, tid);
4206 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004207 if (!ep) {
4208 printk(KERN_WARNING MOD
4209 "Abort on non-existent endpoint, tid %d\n", tid);
4210 kfree_skb(skb);
4211 return 0;
4212 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304213 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304214 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4215 __func__, ep->hwtid, req->status,
4216 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304217 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004218 }
4219 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4220 ep->com.state);
4221
4222 /*
4223 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004224 * However, if we are on MPAv2 and want to retry with MPAv1
4225 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004226 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004227 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4228 if (ep->com.state != MPA_REQ_SENT)
4229 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4230 } else
4231 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304232out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004233 sched(dev, skb);
4234 return 0;
4235}
4236
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004237/*
4238 * Most upcalls from the T4 Core go to sched() to
4239 * schedule the processing on a work queue.
4240 */
4241c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4242 [CPL_ACT_ESTABLISH] = sched,
4243 [CPL_ACT_OPEN_RPL] = sched,
4244 [CPL_RX_DATA] = sched,
4245 [CPL_ABORT_RPL_RSS] = sched,
4246 [CPL_ABORT_RPL] = sched,
4247 [CPL_PASS_OPEN_RPL] = sched,
4248 [CPL_CLOSE_LISTSRV_RPL] = sched,
4249 [CPL_PASS_ACCEPT_REQ] = sched,
4250 [CPL_PASS_ESTABLISH] = sched,
4251 [CPL_PEER_CLOSE] = sched,
4252 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004253 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004254 [CPL_RDMA_TERMINATE] = sched,
4255 [CPL_FW4_ACK] = sched,
4256 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004257 [CPL_FW6_MSG] = fw6_msg,
4258 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004259};
4260
Steve Wisecfdda9d2010-04-21 15:30:06 -07004261int __init c4iw_cm_init(void)
4262{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004263 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004264 skb_queue_head_init(&rxq);
4265
4266 workq = create_singlethread_workqueue("iw_cxgb4");
4267 if (!workq)
4268 return -ENOMEM;
4269
Steve Wisecfdda9d2010-04-21 15:30:06 -07004270 return 0;
4271}
4272
Steve Wise46c13762014-06-20 14:26:25 -05004273void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004274{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004275 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004276 flush_workqueue(workq);
4277 destroy_workqueue(workq);
4278}