blob: c247812fd38ce6d0054141274ddfaa3761f02939 [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);
367 }
368 kfree(ep);
369}
370
371static void release_ep_resources(struct c4iw_ep *ep)
372{
373 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530374
375 /*
376 * If we have a hwtid, then remove it from the idr table
377 * so lookups will no longer find this endpoint. Otherwise
378 * we have a race where one thread finds the ep ptr just
379 * before the other thread is freeing the ep memory.
380 */
381 if (ep->hwtid != -1)
382 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700383 c4iw_put_ep(&ep->com);
384}
385
Steve Wisecfdda9d2010-04-21 15:30:06 -0700386static int status2errno(int status)
387{
388 switch (status) {
389 case CPL_ERR_NONE:
390 return 0;
391 case CPL_ERR_CONN_RESET:
392 return -ECONNRESET;
393 case CPL_ERR_ARP_MISS:
394 return -EHOSTUNREACH;
395 case CPL_ERR_CONN_TIMEDOUT:
396 return -ETIMEDOUT;
397 case CPL_ERR_TCAM_FULL:
398 return -ENOMEM;
399 case CPL_ERR_CONN_EXIST:
400 return -EADDRINUSE;
401 default:
402 return -EIO;
403 }
404}
405
406/*
407 * Try and reuse skbs already allocated...
408 */
409static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
410{
411 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
412 skb_trim(skb, 0);
413 skb_get(skb);
414 skb_reset_transport_header(skb);
415 } else {
416 skb = alloc_skb(len, gfp);
417 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530418 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700419 return skb;
420}
421
Vipul Pandya830662f2013-07-04 16:10:47 +0530422static struct net_device *get_real_dev(struct net_device *egress_dev)
423{
Steve Wise11b8e222014-05-16 12:42:46 -0500424 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530425}
426
427static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
428{
429 int i;
430
431 egress_dev = get_real_dev(egress_dev);
432 for (i = 0; i < dev->rdev.lldi.nports; i++)
433 if (dev->rdev.lldi.ports[i] == egress_dev)
434 return 1;
435 return 0;
436}
437
438static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
439 __u8 *peer_ip, __be16 local_port,
440 __be16 peer_port, u8 tos,
441 __u32 sin6_scope_id)
442{
443 struct dst_entry *dst = NULL;
444
445 if (IS_ENABLED(CONFIG_IPV6)) {
446 struct flowi6 fl6;
447
448 memset(&fl6, 0, sizeof(fl6));
449 memcpy(&fl6.daddr, peer_ip, 16);
450 memcpy(&fl6.saddr, local_ip, 16);
451 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
452 fl6.flowi6_oif = sin6_scope_id;
453 dst = ip6_route_output(&init_net, NULL, &fl6);
454 if (!dst)
455 goto out;
456 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
457 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
458 dst_release(dst);
459 dst = NULL;
460 }
461 }
462
463out:
464 return dst;
465}
466
467static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700468 __be32 peer_ip, __be16 local_port,
469 __be16 peer_port, u8 tos)
470{
471 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700472 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530473 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700474
David S. Miller31e4543d2011-05-03 20:25:42 -0700475 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500476 peer_port, local_port, IPPROTO_TCP,
477 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800478 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700479 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530480 n = dst_neigh_lookup(&rt->dst, &peer_ip);
481 if (!n)
482 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530483 if (!our_interface(dev, n->dev) &&
484 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530485 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530486 dst_release(&rt->dst);
487 return NULL;
488 }
489 neigh_release(n);
490 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700491}
492
493static void arp_failure_discard(void *handle, struct sk_buff *skb)
494{
Hariprasad S9dec9002016-05-05 01:27:29 +0530495 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700496 kfree_skb(skb);
497}
498
Hariprasad S9dec9002016-05-05 01:27:29 +0530499enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530500 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530501 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530502 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530503};
504
505static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
506{
507 struct c4iw_ep *ep;
508
509 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
510 release_ep_resources(ep);
511 return 0;
512}
513
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530514static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
515{
516 struct c4iw_ep *ep;
517
518 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
519 c4iw_put_ep(&ep->parent_ep->com);
520 release_ep_resources(ep);
521 return 0;
522}
523
Hariprasad S9dec9002016-05-05 01:27:29 +0530524/*
525 * Fake up a special CPL opcode and call sched() so process_work() will call
526 * _put_ep_safe() in a safe context to free the ep resources. This is needed
527 * because ARP error handlers are called in an ATOMIC context, and
528 * _c4iw_free_ep() needs to block.
529 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530530static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
531 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530532{
533 struct cpl_act_establish *rpl = cplhdr(skb);
534
535 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530536 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530537
538 /*
539 * Save ep in the skb->cb area, after where sched() will save the dev
540 * ptr.
541 */
542 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
543 sched(ep->com.dev, skb);
544}
545
546/* Handle an ARP failure for an accept */
547static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
548{
549 struct c4iw_ep *ep = handle;
550
551 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
552 ep->hwtid);
553
554 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530555 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530556}
557
Steve Wisecfdda9d2010-04-21 15:30:06 -0700558/*
559 * Handle an ARP failure for an active open.
560 */
561static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
562{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530563 struct c4iw_ep *ep = handle;
564
Masanari Iidae3d132d2015-10-16 21:14:29 +0900565 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530566 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530567 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530568 if (ep->com.remote_addr.ss_family == AF_INET6) {
569 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600570 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530571 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
572 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
573 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530574 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
575 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530576 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577}
578
579/*
580 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
581 * and send it along.
582 */
583static void abort_arp_failure(void *handle, struct sk_buff *skb)
584{
Hariprasad S761e19a2016-05-06 22:18:02 +0530585 int ret;
586 struct c4iw_ep *ep = handle;
587 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700588 struct cpl_abort_req *req = cplhdr(skb);
589
590 PDBG("%s rdev %p\n", __func__, rdev);
591 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530592 ret = c4iw_ofld_send(rdev, skb);
593 if (ret) {
594 __state_set(&ep->com, DEAD);
595 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
596 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700597}
598
Hariprasad Sfef44222016-05-05 01:27:33 +0530599static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600{
601 unsigned int flowclen = 80;
602 struct fw_flowc_wr *flowc;
603 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530604 u16 vlan = ep->l2t->vlan;
605 int nparams;
606
607 if (vlan == CPL_L2T_VLAN_NONE)
608 nparams = 8;
609 else
610 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700611
612 skb = get_skb(skb, flowclen, GFP_KERNEL);
613 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
614
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530615 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530616 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530617 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
618 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700619
620 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530621 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530622 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700623 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
624 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
625 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
626 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
627 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
628 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
629 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
630 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
631 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
632 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
633 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530634 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700635 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
636 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530637 if (nparams == 9) {
638 u16 pri;
639
640 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
641 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
642 flowc->mnemval[8].val = cpu_to_be32(pri);
643 } else {
644 /* Pad WR to 16 byte boundary */
645 flowc->mnemval[8].mnemonic = 0;
646 flowc->mnemval[8].val = 0;
647 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 for (i = 0; i < 9; i++) {
649 flowc->mnemval[i].r4[0] = 0;
650 flowc->mnemval[i].r4[1] = 0;
651 flowc->mnemval[i].r4[2] = 0;
652 }
653
654 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530655 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700656}
657
658static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
659{
660 struct cpl_close_con_req *req;
661 struct sk_buff *skb;
662 int wrlen = roundup(sizeof *req, 16);
663
664 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
665 skb = get_skb(NULL, wrlen, gfp);
666 if (!skb) {
667 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
668 return -ENOMEM;
669 }
670 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
671 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
672 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
673 memset(req, 0, wrlen);
674 INIT_TP_WR(req, ep->hwtid);
675 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
676 ep->hwtid));
677 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
678}
679
680static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
681{
682 struct cpl_abort_req *req;
683 int wrlen = roundup(sizeof *req, 16);
684
685 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
686 skb = get_skb(skb, wrlen, gfp);
687 if (!skb) {
688 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
689 __func__);
690 return -ENOMEM;
691 }
692 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530693 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700694 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
695 memset(req, 0, wrlen);
696 INIT_TP_WR(req, ep->hwtid);
697 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
698 req->cmd = CPL_ABORT_SEND_RST;
699 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
700}
701
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530702static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530703 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530704{
Hariprasad S04524a42014-09-24 03:53:41 +0530705 unsigned short hdr_size = (ipv6 ?
706 sizeof(struct ipv6hdr) :
707 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530708 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530709 (use_ts ?
710 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530711 unsigned short data_size = mtu - hdr_size;
712
713 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
714}
715
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716static int send_connect(struct c4iw_ep *ep)
717{
Hariprasad S963cab52015-09-23 17:19:27 +0530718 struct cpl_act_open_req *req = NULL;
719 struct cpl_t5_act_open_req *t5req = NULL;
720 struct cpl_t6_act_open_req *t6req = NULL;
721 struct cpl_act_open_req6 *req6 = NULL;
722 struct cpl_t5_act_open_req6 *t5req6 = NULL;
723 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700724 struct sk_buff *skb;
725 u64 opt0;
726 u32 opt2;
727 unsigned int mtu_idx;
728 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530729 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500730 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600731 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500732 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600733 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500734 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600735 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500736 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600737 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530738 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530739 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
740 u32 isn = (prandom_u32() & ~7UL) - 1;
741
742 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
743 case CHELSIO_T4:
744 sizev4 = sizeof(struct cpl_act_open_req);
745 sizev6 = sizeof(struct cpl_act_open_req6);
746 break;
747 case CHELSIO_T5:
748 sizev4 = sizeof(struct cpl_t5_act_open_req);
749 sizev6 = sizeof(struct cpl_t5_act_open_req6);
750 break;
751 case CHELSIO_T6:
752 sizev4 = sizeof(struct cpl_t6_act_open_req);
753 sizev6 = sizeof(struct cpl_t6_act_open_req6);
754 break;
755 default:
756 pr_err("T%d Chip is not supported\n",
757 CHELSIO_CHIP_VERSION(adapter_type));
758 return -EINVAL;
759 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530760
761 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
762 roundup(sizev4, 16) :
763 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700764
765 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
766
767 skb = get_skb(NULL, wrlen, GFP_KERNEL);
768 if (!skb) {
769 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
770 __func__);
771 return -ENOMEM;
772 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000773 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700774
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530775 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530776 enable_tcp_timestamps,
777 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700778 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530779
780 /*
781 * Specify the largest window that will fit in opt0. The
782 * remainder will be specified in the rx_data_ack.
783 */
784 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800785 if (win > RCV_BUFSIZ_M)
786 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530787
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800788 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800789 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800790 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800791 WND_SCALE_V(wscale) |
792 MSS_IDX_V(mtu_idx) |
793 L2T_IDX_V(ep->l2t->idx) |
794 TX_CHAN_V(ep->tx_chan) |
795 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530796 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800797 ULP_MODE_V(ULP_MODE_TCPDDP) |
798 RCV_BUFSIZ_V(win);
799 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800800 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800801 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700802 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800803 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700804 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800805 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700806 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800807 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530808 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
809 if (peer2peer)
810 isn += 4;
811
Anish Bhattd7990b02014-11-12 17:15:57 -0800812 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530813 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530814 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500815 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530816
817 if (ep->com.remote_addr.ss_family == AF_INET6)
818 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
819 (const u32 *)&la6->sin6_addr.s6_addr, 1);
820
Hariprasad S5dab6d32014-06-23 19:12:36 +0530821 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700822
Hariprasad S963cab52015-09-23 17:19:27 +0530823 if (ep->com.remote_addr.ss_family == AF_INET) {
824 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
825 case CHELSIO_T4:
826 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530827 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530828 break;
829 case CHELSIO_T5:
830 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
831 wrlen);
832 INIT_TP_WR(t5req, 0);
833 req = (struct cpl_act_open_req *)t5req;
834 break;
835 case CHELSIO_T6:
836 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
837 wrlen);
838 INIT_TP_WR(t6req, 0);
839 req = (struct cpl_act_open_req *)t6req;
840 t5req = (struct cpl_t5_act_open_req *)t6req;
841 break;
842 default:
843 pr_err("T%d Chip is not supported\n",
844 CHELSIO_CHIP_VERSION(adapter_type));
845 ret = -EINVAL;
846 goto clip_release;
847 }
848
849 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
850 ((ep->rss_qid<<14) | ep->atid)));
851 req->local_port = la->sin_port;
852 req->peer_port = ra->sin_port;
853 req->local_ip = la->sin_addr.s_addr;
854 req->peer_ip = ra->sin_addr.s_addr;
855 req->opt0 = cpu_to_be64(opt0);
856
857 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530858 req->params = cpu_to_be32(cxgb4_select_ntuple(
859 ep->com.dev->rdev.lldi.ports[0],
860 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530861 req->opt2 = cpu_to_be32(opt2);
862 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530863 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
864 cxgb4_select_ntuple(
865 ep->com.dev->rdev.lldi.ports[0],
866 ep->l2t)));
867 t5req->rsvd = cpu_to_be32(isn);
868 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
869 t5req->opt2 = cpu_to_be32(opt2);
870 }
871 } else {
872 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
873 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530874 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530875 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530876 break;
877 case CHELSIO_T5:
878 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
879 wrlen);
880 INIT_TP_WR(t5req6, 0);
881 req6 = (struct cpl_act_open_req6 *)t5req6;
882 break;
883 case CHELSIO_T6:
884 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
885 wrlen);
886 INIT_TP_WR(t6req6, 0);
887 req6 = (struct cpl_act_open_req6 *)t6req6;
888 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
889 break;
890 default:
891 pr_err("T%d Chip is not supported\n",
892 CHELSIO_CHIP_VERSION(adapter_type));
893 ret = -EINVAL;
894 goto clip_release;
895 }
896
897 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
898 ((ep->rss_qid<<14)|ep->atid)));
899 req6->local_port = la6->sin6_port;
900 req6->peer_port = ra6->sin6_port;
901 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
902 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
903 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
904 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
905 req6->opt0 = cpu_to_be64(opt0);
906
907 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530908 req6->params = cpu_to_be32(cxgb4_select_ntuple(
909 ep->com.dev->rdev.lldi.ports[0],
910 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530911 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530912 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530913 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
914 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530915 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530916 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530917 t5req6->rsvd = cpu_to_be32(isn);
918 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
919 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530920 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000921 }
922
Vipul Pandya793dad92012-12-10 09:30:56 +0000923 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530924 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530925clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530926 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
927 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
928 (const u32 *)&la6->sin6_addr.s6_addr, 1);
929 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930}
931
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530932static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
933 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700934{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530935 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700936 struct fw_ofld_tx_data_wr *req;
937 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530938 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700939
940 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
941
942 BUG_ON(skb_cloned(skb));
943
944 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530945 if (mpa_rev_to_use == 2)
946 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700947 wrlen = roundup(mpalen + sizeof *req, 16);
948 skb = get_skb(skb, wrlen, GFP_KERNEL);
949 if (!skb) {
950 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530951 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700952 }
953 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
954
955 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
956 memset(req, 0, wrlen);
957 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530958 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
959 FW_WR_COMPL_F |
960 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700961 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530962 FW_WR_FLOWID_V(ep->hwtid) |
963 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700964 req->plen = cpu_to_be32(mpalen);
965 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530966 FW_OFLD_TX_DATA_WR_FLUSH_F |
967 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700968
969 mpa = (struct mpa_message *)(req + 1);
970 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
971 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530972 (markers_enabled ? MPA_MARKERS : 0) |
973 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700974 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530975 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530976 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530977 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530978 ep->retry_with_mpa_v1 = 0;
979 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700980
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530981 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700982 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
983 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530984 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
985 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530986 mpa_v2_params.ird = htons((u16)ep->ird);
987 mpa_v2_params.ord = htons((u16)ep->ord);
988
989 if (peer2peer) {
990 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
991 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
992 mpa_v2_params.ord |=
993 htons(MPA_V2_RDMA_WRITE_RTR);
994 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
995 mpa_v2_params.ord |=
996 htons(MPA_V2_RDMA_READ_RTR);
997 }
998 memcpy(mpa->private_data, &mpa_v2_params,
999 sizeof(struct mpa_v2_conn_params));
1000
1001 if (ep->plen)
1002 memcpy(mpa->private_data +
1003 sizeof(struct mpa_v2_conn_params),
1004 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1005 } else
1006 if (ep->plen)
1007 memcpy(mpa->private_data,
1008 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001009
1010 /*
1011 * Reference the mpa skb. This ensures the data area
1012 * will remain in memory until the hw acks the tx.
1013 * Function fw4_ack() will deref it.
1014 */
1015 skb_get(skb);
1016 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1017 BUG_ON(ep->mpa_skb);
1018 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301019 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1020 if (ret)
1021 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001022 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301023 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301025 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301026 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027}
1028
1029static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1030{
1031 int mpalen, wrlen;
1032 struct fw_ofld_tx_data_wr *req;
1033 struct mpa_message *mpa;
1034 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301035 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001036
1037 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1038
1039 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301040 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1041 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001042 wrlen = roundup(mpalen + sizeof *req, 16);
1043
1044 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1045 if (!skb) {
1046 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1047 return -ENOMEM;
1048 }
1049 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1050
1051 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1052 memset(req, 0, wrlen);
1053 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301054 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1055 FW_WR_COMPL_F |
1056 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001057 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301058 FW_WR_FLOWID_V(ep->hwtid) |
1059 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060 req->plen = cpu_to_be32(mpalen);
1061 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301062 FW_OFLD_TX_DATA_WR_FLUSH_F |
1063 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001064
1065 mpa = (struct mpa_message *)(req + 1);
1066 memset(mpa, 0, sizeof(*mpa));
1067 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1068 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001069 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301071
1072 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1073 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001074 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1075 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301076 mpa_v2_params.ird = htons(((u16)ep->ird) |
1077 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1078 0));
1079 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1080 (p2p_type ==
1081 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1082 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1083 FW_RI_INIT_P2PTYPE_READ_REQ ?
1084 MPA_V2_RDMA_READ_RTR : 0) : 0));
1085 memcpy(mpa->private_data, &mpa_v2_params,
1086 sizeof(struct mpa_v2_conn_params));
1087
1088 if (ep->plen)
1089 memcpy(mpa->private_data +
1090 sizeof(struct mpa_v2_conn_params), pdata, plen);
1091 } else
1092 if (plen)
1093 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094
1095 /*
1096 * Reference the mpa skb again. This ensures the data area
1097 * will remain in memory until the hw acks the tx.
1098 * Function fw4_ack() will deref it.
1099 */
1100 skb_get(skb);
1101 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001102 BUG_ON(ep->mpa_skb);
1103 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301104 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001105 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1106}
1107
1108static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1109{
1110 int mpalen, wrlen;
1111 struct fw_ofld_tx_data_wr *req;
1112 struct mpa_message *mpa;
1113 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301114 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001115
1116 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1117
1118 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301119 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1120 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 wrlen = roundup(mpalen + sizeof *req, 16);
1122
1123 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1124 if (!skb) {
1125 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1126 return -ENOMEM;
1127 }
1128 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1129
1130 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1131 memset(req, 0, wrlen);
1132 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301133 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1134 FW_WR_COMPL_F |
1135 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001136 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301137 FW_WR_FLOWID_V(ep->hwtid) |
1138 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001139 req->plen = cpu_to_be32(mpalen);
1140 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301141 FW_OFLD_TX_DATA_WR_FLUSH_F |
1142 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001143
1144 mpa = (struct mpa_message *)(req + 1);
1145 memset(mpa, 0, sizeof(*mpa));
1146 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1147 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1148 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301149 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001150 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301151
1152 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1153 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001154 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1155 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301156 mpa_v2_params.ird = htons((u16)ep->ird);
1157 mpa_v2_params.ord = htons((u16)ep->ord);
1158 if (peer2peer && (ep->mpa_attr.p2p_type !=
1159 FW_RI_INIT_P2PTYPE_DISABLED)) {
1160 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1161
1162 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1163 mpa_v2_params.ord |=
1164 htons(MPA_V2_RDMA_WRITE_RTR);
1165 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1166 mpa_v2_params.ord |=
1167 htons(MPA_V2_RDMA_READ_RTR);
1168 }
1169
1170 memcpy(mpa->private_data, &mpa_v2_params,
1171 sizeof(struct mpa_v2_conn_params));
1172
1173 if (ep->plen)
1174 memcpy(mpa->private_data +
1175 sizeof(struct mpa_v2_conn_params), pdata, plen);
1176 } else
1177 if (plen)
1178 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179
1180 /*
1181 * Reference the mpa skb. This ensures the data area
1182 * will remain in memory until the hw acks the tx.
1183 * Function fw4_ack() will deref it.
1184 */
1185 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001186 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301187 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301188 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001189 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1190}
1191
1192static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1193{
1194 struct c4iw_ep *ep;
1195 struct cpl_act_establish *req = cplhdr(skb);
1196 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001197 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301199 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200
1201 ep = lookup_atid(t, atid);
1202
1203 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1204 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1205
Steve Wisea7db89e2014-03-21 20:40:35 +05301206 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001207 dst_confirm(ep->dst);
1208
1209 /* setup the hwtid for this connection */
1210 ep->hwtid = tid;
1211 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301212 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001213
1214 ep->snd_seq = be32_to_cpu(req->snd_isn);
1215 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1216
1217 set_emss(ep, ntohs(req->tcp_opt));
1218
1219 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001220 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001222 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001223
1224 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301225 ret = send_flowc(ep, NULL);
1226 if (ret)
1227 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301228 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301229 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301230 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301231 ret = send_mpa_req(ep, skb, mpa_rev);
1232 if (ret)
1233 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301234 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301236err:
1237 mutex_unlock(&ep->com.mutex);
1238 connect_reply_upcall(ep, -ENOMEM);
1239 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1240 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001241}
1242
Steve Wisebe13b2d2014-03-21 20:40:33 +05301243static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001244{
1245 struct iw_cm_event event;
1246
1247 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1248 memset(&event, 0, sizeof(event));
1249 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301250 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251 if (ep->com.cm_id) {
1252 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1253 ep, ep->com.cm_id, ep->hwtid);
1254 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301255 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001256 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001257 }
1258}
1259
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260static void peer_close_upcall(struct c4iw_ep *ep)
1261{
1262 struct iw_cm_event event;
1263
1264 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1265 memset(&event, 0, sizeof(event));
1266 event.event = IW_CM_EVENT_DISCONNECT;
1267 if (ep->com.cm_id) {
1268 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1269 ep, ep->com.cm_id, ep->hwtid);
1270 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001271 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001272 }
1273}
1274
1275static void peer_abort_upcall(struct c4iw_ep *ep)
1276{
1277 struct iw_cm_event event;
1278
1279 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1280 memset(&event, 0, sizeof(event));
1281 event.event = IW_CM_EVENT_CLOSE;
1282 event.status = -ECONNRESET;
1283 if (ep->com.cm_id) {
1284 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1285 ep->com.cm_id, ep->hwtid);
1286 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301287 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001288 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001289 }
1290}
1291
1292static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1293{
1294 struct iw_cm_event event;
1295
1296 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1297 memset(&event, 0, sizeof(event));
1298 event.event = IW_CM_EVENT_CONNECT_REPLY;
1299 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301300 memcpy(&event.local_addr, &ep->com.local_addr,
1301 sizeof(ep->com.local_addr));
1302 memcpy(&event.remote_addr, &ep->com.remote_addr,
1303 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304
1305 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301306 if (!ep->tried_with_mpa_v1) {
1307 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301308 event.ord = ep->ird;
1309 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301310 event.private_data_len = ep->plen -
1311 sizeof(struct mpa_v2_conn_params);
1312 event.private_data = ep->mpa_pkt +
1313 sizeof(struct mpa_message) +
1314 sizeof(struct mpa_v2_conn_params);
1315 } else {
1316 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301317 event.ord = cur_max_read_depth(ep->com.dev);
1318 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301319 event.private_data_len = ep->plen;
1320 event.private_data = ep->mpa_pkt +
1321 sizeof(struct mpa_message);
1322 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001323 }
Roland Dreier85963e42010-07-19 13:13:09 -07001324
1325 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1326 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001327 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001328 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1329
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301330 if (status < 0)
1331 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001332}
1333
Steve Wisebe13b2d2014-03-21 20:40:33 +05301334static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001335{
1336 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301337 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001338
1339 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1340 memset(&event, 0, sizeof(event));
1341 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301342 memcpy(&event.local_addr, &ep->com.local_addr,
1343 sizeof(ep->com.local_addr));
1344 memcpy(&event.remote_addr, &ep->com.remote_addr,
1345 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001346 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301347 if (!ep->tried_with_mpa_v1) {
1348 /* this means MPA_v2 is used */
1349 event.ord = ep->ord;
1350 event.ird = ep->ird;
1351 event.private_data_len = ep->plen -
1352 sizeof(struct mpa_v2_conn_params);
1353 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1354 sizeof(struct mpa_v2_conn_params);
1355 } else {
1356 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301357 event.ord = cur_max_read_depth(ep->com.dev);
1358 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301359 event.private_data_len = ep->plen;
1360 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1361 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301362 c4iw_get_ep(&ep->com);
1363 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1364 &event);
1365 if (ret)
1366 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001367 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001368 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301369 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370}
1371
1372static void established_upcall(struct c4iw_ep *ep)
1373{
1374 struct iw_cm_event event;
1375
1376 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1377 memset(&event, 0, sizeof(event));
1378 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301379 event.ird = ep->ord;
1380 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001381 if (ep->com.cm_id) {
1382 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1383 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001384 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001385 }
1386}
1387
1388static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1389{
1390 struct cpl_rx_data_ack *req;
1391 struct sk_buff *skb;
1392 int wrlen = roundup(sizeof *req, 16);
1393
1394 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1395 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1396 if (!skb) {
1397 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1398 return 0;
1399 }
1400
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301401 /*
1402 * If we couldn't specify the entire rcv window at connection setup
1403 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1404 * then add the overage in to the credits returned.
1405 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001406 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1407 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301408
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1410 memset(req, 0, wrlen);
1411 INIT_TP_WR(req, ep->hwtid);
1412 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1413 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001414 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301415 RX_DACK_CHANGE_F |
1416 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001417 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001418 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1419 return credits;
1420}
1421
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301422#define RELAXED_IRD_NEGOTIATION 1
1423
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301424/*
1425 * process_mpa_reply - process streaming mode MPA reply
1426 *
1427 * Returns:
1428 *
1429 * 0 upon success indicating a connect request was delivered to the ULP
1430 * or the mpa request is incomplete but valid so far.
1431 *
1432 * 1 if a failure requires the caller to close the connection.
1433 *
1434 * 2 if a failure requires the caller to abort the connection.
1435 */
Steve Wisecc18b932014-04-24 14:31:53 -05001436static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437{
1438 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301439 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001440 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301441 u16 resp_ird, resp_ord;
1442 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001443 struct c4iw_qp_attributes attrs;
1444 enum c4iw_qp_attr_mask mask;
1445 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001446 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001447
1448 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1449
1450 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001451 * If we get more than the supported amount of private data
1452 * then we must fail this connection.
1453 */
1454 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1455 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301456 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001457 }
1458
1459 /*
1460 * copy the new data into our accumulation buffer.
1461 */
1462 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1463 skb->len);
1464 ep->mpa_pkt_len += skb->len;
1465
1466 /*
1467 * if we don't even have the mpa message, then bail.
1468 */
1469 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001470 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001471 mpa = (struct mpa_message *) ep->mpa_pkt;
1472
1473 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301474 if (mpa->revision > mpa_rev) {
1475 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1476 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301478 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001479 }
1480 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1481 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301482 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483 }
1484
1485 plen = ntohs(mpa->private_data_size);
1486
1487 /*
1488 * Fail if there's too much private data.
1489 */
1490 if (plen > MPA_MAX_PRIVATE_DATA) {
1491 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301492 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001493 }
1494
1495 /*
1496 * If plen does not account for pkt size
1497 */
1498 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1499 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301500 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001501 }
1502
1503 ep->plen = (u8) plen;
1504
1505 /*
1506 * If we don't have all the pdata yet, then bail.
1507 * We'll continue process when more data arrives.
1508 */
1509 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001510 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001511
1512 if (mpa->flags & MPA_REJECT) {
1513 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301514 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001515 }
1516
1517 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301518 * Stop mpa timer. If it expired, then
1519 * we ignore the MPA reply. process_timeout()
1520 * will abort the connection.
1521 */
1522 if (stop_ep_timer(ep))
1523 return 0;
1524
1525 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001526 * If we get here we have accumulated the entire mpa
1527 * start reply message including private data. And
1528 * the MPA header is valid.
1529 */
Steve Wisec529fb52014-03-21 20:40:37 +05301530 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001531 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1532 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1533 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301534 ep->mpa_attr.version = mpa->revision;
1535 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1536
1537 if (mpa->revision == 2) {
1538 ep->mpa_attr.enhanced_rdma_conn =
1539 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1540 if (ep->mpa_attr.enhanced_rdma_conn) {
1541 mpa_v2_params = (struct mpa_v2_conn_params *)
1542 (ep->mpa_pkt + sizeof(*mpa));
1543 resp_ird = ntohs(mpa_v2_params->ird) &
1544 MPA_V2_IRD_ORD_MASK;
1545 resp_ord = ntohs(mpa_v2_params->ord) &
1546 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301547 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1548 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301549
1550 /*
1551 * This is a double-check. Ideally, below checks are
1552 * not required since ird/ord stuff has been taken
1553 * care of in c4iw_accept_cr
1554 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301555 if (ep->ird < resp_ord) {
1556 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1557 ep->com.dev->rdev.lldi.max_ordird_qp)
1558 ep->ird = resp_ord;
1559 else
1560 insuff_ird = 1;
1561 } else if (ep->ird > resp_ord) {
1562 ep->ird = resp_ord;
1563 }
1564 if (ep->ord > resp_ird) {
1565 if (RELAXED_IRD_NEGOTIATION)
1566 ep->ord = resp_ird;
1567 else
1568 insuff_ird = 1;
1569 }
1570 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301571 err = -ENOMEM;
1572 ep->ird = resp_ord;
1573 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301574 }
1575
1576 if (ntohs(mpa_v2_params->ird) &
1577 MPA_V2_PEER2PEER_MODEL) {
1578 if (ntohs(mpa_v2_params->ord) &
1579 MPA_V2_RDMA_WRITE_RTR)
1580 ep->mpa_attr.p2p_type =
1581 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1582 else if (ntohs(mpa_v2_params->ord) &
1583 MPA_V2_RDMA_READ_RTR)
1584 ep->mpa_attr.p2p_type =
1585 FW_RI_INIT_P2PTYPE_READ_REQ;
1586 }
1587 }
1588 } else if (mpa->revision == 1)
1589 if (peer2peer)
1590 ep->mpa_attr.p2p_type = p2p_type;
1591
Steve Wisecfdda9d2010-04-21 15:30:06 -07001592 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301593 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1594 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1595 ep->mpa_attr.recv_marker_enabled,
1596 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1597 ep->mpa_attr.p2p_type, p2p_type);
1598
1599 /*
1600 * If responder's RTR does not match with that of initiator, assign
1601 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1602 * generated when moving QP to RTS state.
1603 * A TERM message will be sent after QP has moved to RTS state
1604 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001605 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301606 (ep->mpa_attr.p2p_type != p2p_type)) {
1607 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1608 rtr_mismatch = 1;
1609 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001610
1611 attrs.mpa_attr = ep->mpa_attr;
1612 attrs.max_ird = ep->ird;
1613 attrs.max_ord = ep->ord;
1614 attrs.llp_stream_handle = ep;
1615 attrs.next_state = C4IW_QP_STATE_RTS;
1616
1617 mask = C4IW_QP_ATTR_NEXT_STATE |
1618 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1619 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1620
1621 /* bind QP and TID with INIT_WR */
1622 err = c4iw_modify_qp(ep->com.qp->rhp,
1623 ep->com.qp, mask, &attrs, 1);
1624 if (err)
1625 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301626
1627 /*
1628 * If responder's RTR requirement did not match with what initiator
1629 * supports, generate TERM message
1630 */
1631 if (rtr_mismatch) {
1632 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1633 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1634 attrs.ecode = MPA_NOMATCH_RTR;
1635 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001636 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301637 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001638 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301639 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001640 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301641 goto out;
1642 }
1643
1644 /*
1645 * Generate TERM if initiator IRD is not sufficient for responder
1646 * provided ORD. Currently, we do the same behaviour even when
1647 * responder provided IRD is also not sufficient as regards to
1648 * initiator ORD.
1649 */
1650 if (insuff_ird) {
1651 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1652 __func__);
1653 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1654 attrs.ecode = MPA_INSUFF_IRD;
1655 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001656 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301657 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001658 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301659 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001660 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301661 goto out;
1662 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001663 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301664err_stop_timer:
1665 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001666err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301667 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668out:
1669 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001670 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001671}
1672
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301673/*
1674 * process_mpa_request - process streaming mode MPA request
1675 *
1676 * Returns:
1677 *
1678 * 0 upon success indicating a connect request was delivered to the ULP
1679 * or the mpa request is incomplete but valid so far.
1680 *
1681 * 1 if a failure requires the caller to close the connection.
1682 *
1683 * 2 if a failure requires the caller to abort the connection.
1684 */
1685static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001686{
1687 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301688 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001689 u16 plen;
1690
1691 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1692
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693 /*
1694 * If we get more than the supported amount of private data
1695 * then we must fail this connection.
1696 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301697 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1698 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001699
1700 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1701
1702 /*
1703 * Copy the new data into our accumulation buffer.
1704 */
1705 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1706 skb->len);
1707 ep->mpa_pkt_len += skb->len;
1708
1709 /*
1710 * If we don't even have the mpa message, then bail.
1711 * We'll continue process when more data arrives.
1712 */
1713 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301714 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001715
1716 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001717 mpa = (struct mpa_message *) ep->mpa_pkt;
1718
1719 /*
1720 * Validate MPA Header.
1721 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301722 if (mpa->revision > mpa_rev) {
1723 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1724 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301725 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726 }
1727
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301728 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1729 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001730
1731 plen = ntohs(mpa->private_data_size);
1732
1733 /*
1734 * Fail if there's too much private data.
1735 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301736 if (plen > MPA_MAX_PRIVATE_DATA)
1737 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001738
1739 /*
1740 * If plen does not account for pkt size
1741 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301742 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1743 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001744 ep->plen = (u8) plen;
1745
1746 /*
1747 * If we don't have all the pdata yet, then bail.
1748 */
1749 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301750 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001751
1752 /*
1753 * If we get here we have accumulated the entire mpa
1754 * start reply message including private data.
1755 */
1756 ep->mpa_attr.initiator = 0;
1757 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1758 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1759 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301760 ep->mpa_attr.version = mpa->revision;
1761 if (mpa->revision == 1)
1762 ep->tried_with_mpa_v1 = 1;
1763 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1764
1765 if (mpa->revision == 2) {
1766 ep->mpa_attr.enhanced_rdma_conn =
1767 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1768 if (ep->mpa_attr.enhanced_rdma_conn) {
1769 mpa_v2_params = (struct mpa_v2_conn_params *)
1770 (ep->mpa_pkt + sizeof(*mpa));
1771 ep->ird = ntohs(mpa_v2_params->ird) &
1772 MPA_V2_IRD_ORD_MASK;
1773 ep->ord = ntohs(mpa_v2_params->ord) &
1774 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301775 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1776 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301777 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1778 if (peer2peer) {
1779 if (ntohs(mpa_v2_params->ord) &
1780 MPA_V2_RDMA_WRITE_RTR)
1781 ep->mpa_attr.p2p_type =
1782 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1783 else if (ntohs(mpa_v2_params->ord) &
1784 MPA_V2_RDMA_READ_RTR)
1785 ep->mpa_attr.p2p_type =
1786 FW_RI_INIT_P2PTYPE_READ_REQ;
1787 }
1788 }
1789 } else if (mpa->revision == 1)
1790 if (peer2peer)
1791 ep->mpa_attr.p2p_type = p2p_type;
1792
Steve Wisecfdda9d2010-04-21 15:30:06 -07001793 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1794 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1795 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1796 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1797 ep->mpa_attr.p2p_type);
1798
Hariprasad Se4b76a22016-05-06 22:17:59 +05301799 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001800
Hariprasad Se4b76a22016-05-06 22:17:59 +05301801 /* drive upcall */
1802 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1803 if (ep->parent_ep->com.state != DEAD) {
1804 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301805 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301806 } else {
1807 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301808 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301809 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301810 return 0;
1811
1812err_unlock_parent:
1813 mutex_unlock(&ep->parent_ep->com.mutex);
1814 goto err_out;
1815err_stop_timer:
1816 (void)stop_ep_timer(ep);
1817err_out:
1818 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001819}
1820
1821static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1822{
1823 struct c4iw_ep *ep;
1824 struct cpl_rx_data *hdr = cplhdr(skb);
1825 unsigned int dlen = ntohs(hdr->len);
1826 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001827 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001828 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829
Hariprasad S944661d2016-05-06 22:18:03 +05301830 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301831 if (!ep)
1832 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001833 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1834 skb_pull(skb, sizeof(*hdr));
1835 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301836 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001837
Steve Wisecfdda9d2010-04-21 15:30:06 -07001838 /* update RX credits */
1839 update_rx_credits(ep, dlen);
1840
Steve Wisec529fb52014-03-21 20:40:37 +05301841 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001842 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001843 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001844 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845 break;
1846 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001847 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001848 process_mpa_request(ep, skb);
1849 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001850 case FPDU_MODE: {
1851 struct c4iw_qp_attributes attrs;
1852 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001853 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001854 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001855 " qpid %u ep %p state %d tid %u status %d\n",
1856 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301857 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301858 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001859 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001860 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1861 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001862 break;
1863 }
Vipul Pandya15579672013-01-07 13:11:52 +00001864 default:
1865 break;
1866 }
Steve Wisec529fb52014-03-21 20:40:37 +05301867 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001868 if (disconnect)
1869 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301870 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001871 return 0;
1872}
1873
1874static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1875{
1876 struct c4iw_ep *ep;
1877 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001878 int release = 0;
1879 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001880
Hariprasad S944661d2016-05-06 22:18:03 +05301881 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301882 if (!ep) {
1883 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1884 return 0;
1885 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001886 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001887 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001888 switch (ep->com.state) {
1889 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001890 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001891 __state_set(&ep->com, DEAD);
1892 release = 1;
1893 break;
1894 default:
1895 printk(KERN_ERR "%s ep %p state %d\n",
1896 __func__, ep, ep->com.state);
1897 break;
1898 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001899 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001900
1901 if (release)
1902 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301903 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001904 return 0;
1905}
1906
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301907static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001908{
1909 struct sk_buff *skb;
1910 struct fw_ofld_connection_wr *req;
1911 unsigned int mtu_idx;
1912 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301913 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301914 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915
1916 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1917 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1918 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001919 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301920 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301921 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1922 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001923 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001924 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301925 req->le.lport = sin->sin_port;
1926 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001927 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301928 req->le.pport = sin->sin_port;
1929 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001930 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301931 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1932 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001933 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301934 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001935 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001936 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301937 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301938 enable_tcp_timestamps,
1939 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001940 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301941
1942 /*
1943 * Specify the largest window that will fit in opt0. The
1944 * remainder will be specified in the rx_data_ack.
1945 */
1946 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001947 if (win > RCV_BUFSIZ_M)
1948 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301949
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001950 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1951 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001952 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001953 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001954 WND_SCALE_V(wscale) |
1955 MSS_IDX_V(mtu_idx) |
1956 L2T_IDX_V(ep->l2t->idx) |
1957 TX_CHAN_V(ep->tx_chan) |
1958 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301959 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001960 ULP_MODE_V(ULP_MODE_TCPDDP) |
1961 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001962 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1963 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001964 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001965 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001966 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001967 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001968 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001969 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001970 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001971 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001972 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1973 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1974 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001975 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1976 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301977 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001978}
1979
Steve Wisecfdda9d2010-04-21 15:30:06 -07001980/*
1981 * Return whether a failed active open has allocated a TID
1982 */
1983static inline int act_open_has_tid(int status)
1984{
1985 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1986 status != CPL_ERR_ARP_MISS;
1987}
1988
Steve Wise7a2cea22014-03-14 21:52:07 +05301989/* Returns whether a CPL status conveys negative advice.
1990 */
1991static int is_neg_adv(unsigned int status)
1992{
1993 return status == CPL_ERR_RTX_NEG_ADVICE ||
1994 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1995 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1996}
1997
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301998static char *neg_adv_str(unsigned int status)
1999{
2000 switch (status) {
2001 case CPL_ERR_RTX_NEG_ADVICE:
2002 return "Retransmit timeout";
2003 case CPL_ERR_PERSIST_NEG_ADVICE:
2004 return "Persist timeout";
2005 case CPL_ERR_KEEPALV_NEG_ADVICE:
2006 return "Keepalive timeout";
2007 default:
2008 return "Unknown";
2009 }
2010}
2011
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302012static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2013{
2014 ep->snd_win = snd_win;
2015 ep->rcv_win = rcv_win;
2016 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2017}
2018
Vipul Pandya793dad92012-12-10 09:30:56 +00002019#define ACT_OPEN_RETRY_COUNT 2
2020
Vipul Pandya830662f2013-07-04 16:10:47 +05302021static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2022 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302023 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302024{
2025 struct neighbour *n;
2026 int err, step;
2027 struct net_device *pdev;
2028
2029 n = dst_neigh_lookup(dst, peer_ip);
2030 if (!n)
2031 return -ENODEV;
2032
2033 rcu_read_lock();
2034 err = -ENOMEM;
2035 if (n->dev->flags & IFF_LOOPBACK) {
2036 if (iptype == 4)
2037 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2038 else if (IS_ENABLED(CONFIG_IPV6))
2039 for_each_netdev(&init_net, pdev) {
2040 if (ipv6_chk_addr(&init_net,
2041 (struct in6_addr *)peer_ip,
2042 pdev, 1))
2043 break;
2044 }
2045 else
2046 pdev = NULL;
2047
2048 if (!pdev) {
2049 err = -ENODEV;
2050 goto out;
2051 }
2052 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302053 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302054 if (!ep->l2t)
2055 goto out;
2056 ep->mtu = pdev->mtu;
2057 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302058 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2059 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302060 step = cdev->rdev.lldi.ntxq /
2061 cdev->rdev.lldi.nchan;
2062 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2063 step = cdev->rdev.lldi.nrxq /
2064 cdev->rdev.lldi.nchan;
2065 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2066 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2067 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302068 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302069 dev_put(pdev);
2070 } else {
2071 pdev = get_real_dev(n->dev);
2072 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2073 n, pdev, 0);
2074 if (!ep->l2t)
2075 goto out;
2076 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002077 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302078 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2079 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302080 step = cdev->rdev.lldi.ntxq /
2081 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002082 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2083 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 step = cdev->rdev.lldi.nrxq /
2085 cdev->rdev.lldi.nchan;
2086 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002087 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302088 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302089
2090 if (clear_mpa_v1) {
2091 ep->retry_with_mpa_v1 = 0;
2092 ep->tried_with_mpa_v1 = 0;
2093 }
2094 }
2095 err = 0;
2096out:
2097 rcu_read_unlock();
2098
2099 neigh_release(n);
2100
2101 return err;
2102}
2103
Vipul Pandya793dad92012-12-10 09:30:56 +00002104static int c4iw_reconnect(struct c4iw_ep *ep)
2105{
2106 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302107 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002108 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302109 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002110 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302111 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002112 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002114 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302115 int iptype;
2116 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002117
2118 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2119 init_timer(&ep->timer);
2120
2121 /*
2122 * Allocate an active TID to initiate a TCP connection.
2123 */
2124 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2125 if (ep->atid == -1) {
2126 pr_err("%s - cannot alloc atid.\n", __func__);
2127 err = -ENOMEM;
2128 goto fail2;
2129 }
2130 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2131
2132 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002133 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302134 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2135 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302136 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302137 iptype = 4;
2138 ra = (__u8 *)&raddr->sin_addr;
2139 } else {
2140 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2141 raddr6->sin6_addr.s6_addr,
2142 laddr6->sin6_port, raddr6->sin6_port, 0,
2143 raddr6->sin6_scope_id);
2144 iptype = 6;
2145 ra = (__u8 *)&raddr6->sin6_addr;
2146 }
2147 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002148 pr_err("%s - cannot find route.\n", __func__);
2149 err = -EHOSTUNREACH;
2150 goto fail3;
2151 }
Hariprasad S963cab52015-09-23 17:19:27 +05302152 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302153 ep->com.dev->rdev.lldi.adapter_type,
2154 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302155 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002156 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002157 goto fail4;
2158 }
2159
2160 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2161 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2162 ep->l2t->idx);
2163
2164 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302165 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002166
2167 /* send connect request to rnic */
2168 err = send_connect(ep);
2169 if (!err)
2170 goto out;
2171
2172 cxgb4_l2t_release(ep->l2t);
2173fail4:
2174 dst_release(ep->dst);
2175fail3:
2176 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2177 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2178fail2:
2179 /*
2180 * remember to send notification to upper layer.
2181 * We are in here so the upper layer is not aware that this is
2182 * re-connect attempt and so, upper layer is still waiting for
2183 * response of 1st connect request.
2184 */
2185 connect_reply_upcall(ep, -ECONNRESET);
2186 c4iw_put_ep(&ep->com);
2187out:
2188 return err;
2189}
2190
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2192{
2193 struct c4iw_ep *ep;
2194 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002195 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2196 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002197 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002198 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302199 struct sockaddr_in *la;
2200 struct sockaddr_in *ra;
2201 struct sockaddr_in6 *la6;
2202 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302203 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002204
2205 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002206 la = (struct sockaddr_in *)&ep->com.local_addr;
2207 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2208 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2209 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002210
2211 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2212 status, status2errno(status));
2213
Steve Wise7a2cea22014-03-14 21:52:07 +05302214 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302215 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2216 __func__, atid, status, neg_adv_str(status));
2217 ep->stats.connect_neg_adv++;
2218 mutex_lock(&dev->rdev.stats.lock);
2219 dev->rdev.stats.neg_adv++;
2220 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002221 return 0;
2222 }
2223
Vipul Pandya793dad92012-12-10 09:30:56 +00002224 set_bit(ACT_OPEN_RPL, &ep->com.history);
2225
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302226 /*
2227 * Log interesting failures.
2228 */
2229 switch (status) {
2230 case CPL_ERR_CONN_RESET:
2231 case CPL_ERR_CONN_TIMEDOUT:
2232 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002233 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302234 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002235 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302236 mutex_unlock(&dev->rdev.stats.lock);
2237 if (ep->com.local_addr.ss_family == AF_INET &&
2238 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302239 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2240 ntohl(rpl->atid_status))));
2241 if (ret)
2242 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002243 return 0;
2244 }
2245 break;
2246 case CPL_ERR_CONN_EXIST:
2247 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2248 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302249 if (ep->com.remote_addr.ss_family == AF_INET6) {
2250 struct sockaddr_in6 *sin6 =
2251 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002252 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302253 cxgb4_clip_release(
2254 ep->com.dev->rdev.lldi.ports[0],
2255 (const u32 *)
2256 &sin6->sin6_addr.s6_addr, 1);
2257 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002258 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2259 atid);
2260 cxgb4_free_atid(t, atid);
2261 dst_release(ep->dst);
2262 cxgb4_l2t_release(ep->l2t);
2263 c4iw_reconnect(ep);
2264 return 0;
2265 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002266 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302267 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302268 if (ep->com.local_addr.ss_family == AF_INET) {
2269 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2270 atid, status, status2errno(status),
2271 &la->sin_addr.s_addr, ntohs(la->sin_port),
2272 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2273 } else {
2274 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2275 atid, status, status2errno(status),
2276 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2277 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2278 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302279 break;
2280 }
2281
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302282fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002283 connect_reply_upcall(ep, status2errno(status));
2284 state_set(&ep->com, DEAD);
2285
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302286 if (ep->com.remote_addr.ss_family == AF_INET6) {
2287 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002288 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302289 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2290 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2291 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002292 if (status && act_open_has_tid(status))
2293 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2294
Vipul Pandya793dad92012-12-10 09:30:56 +00002295 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 cxgb4_free_atid(t, atid);
2297 dst_release(ep->dst);
2298 cxgb4_l2t_release(ep->l2t);
2299 c4iw_put_ep(&ep->com);
2300
2301 return 0;
2302}
2303
2304static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2305{
2306 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2307 struct tid_info *t = dev->rdev.lldi.tids;
2308 unsigned int stid = GET_TID(rpl);
2309 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2310
2311 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002312 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2313 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002314 }
2315 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2316 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002317 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318
Vipul Pandya1cab7752012-12-10 09:30:55 +00002319out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 return 0;
2321}
2322
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2324{
2325 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2326 struct tid_info *t = dev->rdev.lldi.tids;
2327 unsigned int stid = GET_TID(rpl);
2328 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2329
2330 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002331 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 return 0;
2333}
2334
Hariprasad S9dec9002016-05-05 01:27:29 +05302335static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2336 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002337{
2338 struct cpl_pass_accept_rpl *rpl;
2339 unsigned int mtu_idx;
2340 u64 opt0;
2341 u32 opt2;
2342 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302343 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302344 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302345 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346
2347 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2348 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302349
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302351 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302352 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302353 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2354 rpl5 = (void *)rpl;
2355 INIT_TP_WR(rpl5, ep->hwtid);
2356 } else {
2357 skb_trim(skb, sizeof(*rpl));
2358 INIT_TP_WR(rpl, ep->hwtid);
2359 }
2360 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2361 ep->hwtid));
2362
2363 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302364 enable_tcp_timestamps && req->tcpopt.tstamp,
2365 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002366 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302367
2368 /*
2369 * Specify the largest window that will fit in opt0. The
2370 * remainder will be specified in the rx_data_ack.
2371 */
2372 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002373 if (win > RCV_BUFSIZ_M)
2374 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002375 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002376 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002377 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002378 WND_SCALE_V(wscale) |
2379 MSS_IDX_V(mtu_idx) |
2380 L2T_IDX_V(ep->l2t->idx) |
2381 TX_CHAN_V(ep->tx_chan) |
2382 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002383 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002384 ULP_MODE_V(ULP_MODE_TCPDDP) |
2385 RCV_BUFSIZ_V(win);
2386 opt2 = RX_CHANNEL_V(0) |
2387 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388
2389 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002390 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002392 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002394 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002395 if (enable_ecn) {
2396 const struct tcphdr *tcph;
2397 u32 hlen = ntohl(req->hdr_len);
2398
Hariprasad S963cab52015-09-23 17:19:27 +05302399 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2400 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2401 IP_HDR_LEN_G(hlen);
2402 else
2403 tcph = (const void *)(req + 1) +
2404 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002405 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002406 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002407 }
Hariprasad S963cab52015-09-23 17:19:27 +05302408 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302409 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002410 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302411 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302412 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302413 rpl5 = (void *)rpl;
2414 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2415 if (peer2peer)
2416 isn += 4;
2417 rpl5->iss = cpu_to_be32(isn);
2418 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002419 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 rpl->opt0 = cpu_to_be64(opt0);
2422 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002423 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302424 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425
Hariprasad S9dec9002016-05-05 01:27:29 +05302426 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427}
2428
Vipul Pandya830662f2013-07-04 16:10:47 +05302429static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430{
Vipul Pandya830662f2013-07-04 16:10:47 +05302431 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 BUG_ON(skb_cloned(skb));
2433 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 release_tid(&dev->rdev, hwtid, skb);
2435 return;
2436}
2437
Hariprasad S963cab52015-09-23 17:19:27 +05302438static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2439 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 __be16 *local_port, __be16 *peer_port)
2441{
Hariprasad S963cab52015-09-23 17:19:27 +05302442 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2443 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2444 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2445 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2446 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2447 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 struct tcphdr *tcp = (struct tcphdr *)
2451 ((u8 *)(req + 1) + eth_len + ip_len);
2452
Vipul Pandya830662f2013-07-04 16:10:47 +05302453 if (ip->version == 4) {
2454 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2455 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2456 ntohs(tcp->dest));
2457 *iptype = 4;
2458 memcpy(peer_ip, &ip->saddr, 4);
2459 memcpy(local_ip, &ip->daddr, 4);
2460 } else {
2461 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2462 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2463 ntohs(tcp->dest));
2464 *iptype = 6;
2465 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2466 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2467 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468 *peer_port = tcp->source;
2469 *local_port = tcp->dest;
2470
2471 return;
2472}
2473
2474static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2475{
Vipul Pandya793dad92012-12-10 09:30:56 +00002476 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002478 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002479 struct tid_info *t = dev->rdev.lldi.tids;
2480 unsigned int hwtid = GET_TID(req);
2481 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302482 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302484 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002485 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002486 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302487 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302488 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302489 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490
2491 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002492 if (!parent_ep) {
2493 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2494 goto reject;
2495 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002496
Steve Wisecfdda9d2010-04-21 15:30:06 -07002497 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302498 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002499 goto reject;
2500 }
2501
Hariprasad S963cab52015-09-23 17:19:27 +05302502 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2503 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302504
Steve Wisecfdda9d2010-04-21 15:30:06 -07002505 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302506 if (iptype == 4) {
2507 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2508 , __func__, parent_ep, hwtid,
2509 local_ip, peer_ip, ntohs(local_port),
2510 ntohs(peer_port), peer_mss);
2511 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2512 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302513 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302514 } else {
2515 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2516 , __func__, parent_ep, hwtid,
2517 local_ip, peer_ip, ntohs(local_port),
2518 ntohs(peer_port), peer_mss);
2519 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002520 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302521 ((struct sockaddr_in6 *)
2522 &parent_ep->com.local_addr)->sin6_scope_id);
2523 }
2524 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2526 __func__);
2527 goto reject;
2528 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529
2530 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2531 if (!child_ep) {
2532 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2533 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002534 dst_release(dst);
2535 goto reject;
2536 }
David Miller3786cf12011-12-02 16:52:31 +00002537
Hariprasad S963cab52015-09-23 17:19:27 +05302538 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302539 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002540 if (err) {
2541 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2542 __func__);
2543 dst_release(dst);
2544 kfree(child_ep);
2545 goto reject;
2546 }
2547
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302548 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2549 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2550 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2551 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002552
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553 state_set(&child_ep->com, CONNECTING);
2554 child_ep->com.dev = dev;
2555 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002556
Vipul Pandya830662f2013-07-04 16:10:47 +05302557 if (iptype == 4) {
2558 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002559 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002560
Vipul Pandya830662f2013-07-04 16:10:47 +05302561 sin->sin_family = PF_INET;
2562 sin->sin_port = local_port;
2563 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002564
2565 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2566 sin->sin_family = PF_INET;
2567 sin->sin_port = ((struct sockaddr_in *)
2568 &parent_ep->com.local_addr)->sin_port;
2569 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2570
Steve Wise170003c2016-02-26 09:18:03 -06002571 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302572 sin->sin_family = PF_INET;
2573 sin->sin_port = peer_port;
2574 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2575 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002576 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302577 sin6->sin6_family = PF_INET6;
2578 sin6->sin6_port = local_port;
2579 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002580
2581 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2582 sin6->sin6_family = PF_INET6;
2583 sin6->sin6_port = ((struct sockaddr_in6 *)
2584 &parent_ep->com.local_addr)->sin6_port;
2585 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2586
Steve Wise170003c2016-02-26 09:18:03 -06002587 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302588 sin6->sin6_family = PF_INET6;
2589 sin6->sin6_port = peer_port;
2590 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2591 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002592
Steve Wisecfdda9d2010-04-21 15:30:06 -07002593 c4iw_get_ep(&parent_ep->com);
2594 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302595 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002596 child_ep->dst = dst;
2597 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002598
2599 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002600 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601
2602 init_timer(&child_ep->timer);
2603 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302604 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302605 if (accept_cr(child_ep, skb, req)) {
2606 c4iw_put_ep(&parent_ep->com);
2607 release_ep_resources(child_ep);
2608 } else {
2609 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2610 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302611 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002612 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302613 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2614 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2615 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 goto out;
2617reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302618 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619out:
2620 return 0;
2621}
2622
2623static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2624{
2625 struct c4iw_ep *ep;
2626 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002627 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302628 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629
Hariprasad S944661d2016-05-06 22:18:03 +05302630 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2632 ep->snd_seq = be32_to_cpu(req->snd_isn);
2633 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2634
Vipul Pandya1cab7752012-12-10 09:30:55 +00002635 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2636 ntohs(req->tcp_opt));
2637
Steve Wisecfdda9d2010-04-21 15:30:06 -07002638 set_emss(ep, ntohs(req->tcp_opt));
2639
2640 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302641 mutex_lock(&ep->com.mutex);
2642 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002643 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002644 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302645 ret = send_flowc(ep, skb);
2646 mutex_unlock(&ep->com.mutex);
2647 if (ret)
2648 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302649 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650
2651 return 0;
2652}
2653
2654static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2655{
2656 struct cpl_peer_close *hdr = cplhdr(skb);
2657 struct c4iw_ep *ep;
2658 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 int disconnect = 1;
2660 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002662 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663
Hariprasad S944661d2016-05-06 22:18:03 +05302664 ep = get_ep_from_tid(dev, tid);
2665 if (!ep)
2666 return 0;
2667
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2669 dst_confirm(ep->dst);
2670
Vipul Pandya793dad92012-12-10 09:30:56 +00002671 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002672 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 switch (ep->com.state) {
2674 case MPA_REQ_WAIT:
2675 __state_set(&ep->com, CLOSING);
2676 break;
2677 case MPA_REQ_SENT:
2678 __state_set(&ep->com, CLOSING);
2679 connect_reply_upcall(ep, -ECONNRESET);
2680 break;
2681 case MPA_REQ_RCVD:
2682
2683 /*
2684 * We're gonna mark this puppy DEAD, but keep
2685 * the reference on it until the ULP accepts or
2686 * rejects the CR. Also wake up anyone waiting
2687 * in rdma connection migration (see c4iw_accept_cr()).
2688 */
2689 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002691 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002692 break;
2693 case MPA_REP_SENT:
2694 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002695 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002696 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 break;
2698 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002699 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002701 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002702 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002703 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002704 if (ret != -ECONNRESET) {
2705 peer_close_upcall(ep);
2706 disconnect = 1;
2707 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708 break;
2709 case ABORTING:
2710 disconnect = 0;
2711 break;
2712 case CLOSING:
2713 __state_set(&ep->com, MORIBUND);
2714 disconnect = 0;
2715 break;
2716 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002717 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 if (ep->com.cm_id && ep->com.qp) {
2719 attrs.next_state = C4IW_QP_STATE_IDLE;
2720 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2721 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2722 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302723 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724 __state_set(&ep->com, DEAD);
2725 release = 1;
2726 disconnect = 0;
2727 break;
2728 case DEAD:
2729 disconnect = 0;
2730 break;
2731 default:
2732 BUG_ON(1);
2733 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002734 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002735 if (disconnect)
2736 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2737 if (release)
2738 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302739 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 return 0;
2741}
2742
Steve Wisecfdda9d2010-04-21 15:30:06 -07002743static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2744{
2745 struct cpl_abort_req_rss *req = cplhdr(skb);
2746 struct c4iw_ep *ep;
2747 struct cpl_abort_rpl *rpl;
2748 struct sk_buff *rpl_skb;
2749 struct c4iw_qp_attributes attrs;
2750 int ret;
2751 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753
Hariprasad S944661d2016-05-06 22:18:03 +05302754 ep = get_ep_from_tid(dev, tid);
2755 if (!ep)
2756 return 0;
2757
Steve Wise7a2cea22014-03-14 21:52:07 +05302758 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302759 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2760 __func__, ep->hwtid, req->status,
2761 neg_adv_str(req->status));
2762 ep->stats.abort_neg_adv++;
2763 mutex_lock(&dev->rdev.stats.lock);
2764 dev->rdev.stats.neg_adv++;
2765 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302766 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002767 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2769 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002770 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002771
2772 /*
2773 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302774 * However, this is not needed if com state is just
2775 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002776 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302777 if (ep->com.state != MPA_REQ_SENT)
2778 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002779
2780 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002781 switch (ep->com.state) {
2782 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302783 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002784 break;
2785 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002786 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002787 break;
2788 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002789 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002790 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302791 connect_reply_upcall(ep, -ECONNRESET);
2792 else {
2793 /*
2794 * we just don't send notification upwards because we
2795 * want to retry with mpa_v1 without upper layers even
2796 * knowing it.
2797 *
2798 * do some housekeeping so as to re-initiate the
2799 * connection
2800 */
2801 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2802 mpa_rev);
2803 ep->retry_with_mpa_v1 = 1;
2804 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805 break;
2806 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002807 break;
2808 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 break;
2810 case MORIBUND:
2811 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002812 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 /*FALLTHROUGH*/
2814 case FPDU_MODE:
2815 if (ep->com.cm_id && ep->com.qp) {
2816 attrs.next_state = C4IW_QP_STATE_ERROR;
2817 ret = c4iw_modify_qp(ep->com.qp->rhp,
2818 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2819 &attrs, 1);
2820 if (ret)
2821 printk(KERN_ERR MOD
2822 "%s - qp <- error failed!\n",
2823 __func__);
2824 }
2825 peer_abort_upcall(ep);
2826 break;
2827 case ABORTING:
2828 break;
2829 case DEAD:
2830 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002831 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302832 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002833 default:
2834 BUG_ON(1);
2835 break;
2836 }
2837 dst_confirm(ep->dst);
2838 if (ep->com.state != ABORTING) {
2839 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302840 /* we don't release if we want to retry with mpa_v1 */
2841 if (!ep->retry_with_mpa_v1)
2842 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002844 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845
2846 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2847 if (!rpl_skb) {
2848 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2849 __func__);
2850 release = 1;
2851 goto out;
2852 }
2853 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2854 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2855 INIT_TP_WR(rpl, ep->hwtid);
2856 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2857 rpl->cmd = CPL_ABORT_NO_RST;
2858 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2859out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860 if (release)
2861 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002862 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302863 if (ep->com.remote_addr.ss_family == AF_INET6) {
2864 struct sockaddr_in6 *sin6 =
2865 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002866 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302867 cxgb4_clip_release(
2868 ep->com.dev->rdev.lldi.ports[0],
2869 (const u32 *)&sin6->sin6_addr.s6_addr,
2870 1);
2871 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002872 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302873 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2874 dst_release(ep->dst);
2875 cxgb4_l2t_release(ep->l2t);
2876 c4iw_reconnect(ep);
2877 }
2878
Hariprasad S944661d2016-05-06 22:18:03 +05302879deref_ep:
2880 c4iw_put_ep(&ep->com);
2881 /* Dereferencing ep, referenced in peer_abort_intr() */
2882 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883 return 0;
2884}
2885
2886static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2887{
2888 struct c4iw_ep *ep;
2889 struct c4iw_qp_attributes attrs;
2890 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002891 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002892 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002893
Hariprasad S944661d2016-05-06 22:18:03 +05302894 ep = get_ep_from_tid(dev, tid);
2895 if (!ep)
2896 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002897
2898 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2899 BUG_ON(!ep);
2900
2901 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002902 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302903 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002904 switch (ep->com.state) {
2905 case CLOSING:
2906 __state_set(&ep->com, MORIBUND);
2907 break;
2908 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002909 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002910 if ((ep->com.cm_id) && (ep->com.qp)) {
2911 attrs.next_state = C4IW_QP_STATE_IDLE;
2912 c4iw_modify_qp(ep->com.qp->rhp,
2913 ep->com.qp,
2914 C4IW_QP_ATTR_NEXT_STATE,
2915 &attrs, 1);
2916 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302917 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002918 __state_set(&ep->com, DEAD);
2919 release = 1;
2920 break;
2921 case ABORTING:
2922 case DEAD:
2923 break;
2924 default:
2925 BUG_ON(1);
2926 break;
2927 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002928 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002929 if (release)
2930 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302931 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002932 return 0;
2933}
2934
2935static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2936{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002937 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002938 unsigned int tid = GET_TID(rpl);
2939 struct c4iw_ep *ep;
2940 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002941
Hariprasad S944661d2016-05-06 22:18:03 +05302942 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002943 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002944
Steve Wise30c95c22011-05-09 22:06:22 -07002945 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002946 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2947 ep->com.qp->wq.sq.qid);
2948 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2949 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2950 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2951 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002952 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302953 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002954
Steve Wisecfdda9d2010-04-21 15:30:06 -07002955 return 0;
2956}
2957
2958/*
2959 * Upcall from the adapter indicating data has been transmitted.
2960 * For us its just the single MPA request or reply. We can now free
2961 * the skb holding the mpa message.
2962 */
2963static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2964{
2965 struct c4iw_ep *ep;
2966 struct cpl_fw4_ack *hdr = cplhdr(skb);
2967 u8 credits = hdr->credits;
2968 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002969
2970
Hariprasad S944661d2016-05-06 22:18:03 +05302971 ep = get_ep_from_tid(dev, tid);
2972 if (!ep)
2973 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2975 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002976 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2977 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302978 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002979 }
2980
2981 dst_confirm(ep->dst);
2982 if (ep->mpa_skb) {
2983 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2984 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2985 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2986 kfree_skb(ep->mpa_skb);
2987 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302988 mutex_lock(&ep->com.mutex);
2989 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2990 stop_ep_timer(ep);
2991 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992 }
Hariprasad S944661d2016-05-06 22:18:03 +05302993out:
2994 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002995 return 0;
2996}
2997
Steve Wisecfdda9d2010-04-21 15:30:06 -07002998int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2999{
Steve Wisea7db89e2014-03-21 20:40:35 +05303000 int err = 0;
3001 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002 struct c4iw_ep *ep = to_ep(cm_id);
3003 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3004
Steve Wisea7db89e2014-03-21 20:40:35 +05303005 mutex_lock(&ep->com.mutex);
3006 if (ep->com.state == DEAD) {
3007 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003008 c4iw_put_ep(&ep->com);
3009 return -ECONNRESET;
3010 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003011 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05303012 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003013 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303014 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003015 else {
3016 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303017 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 }
Steve Wisea7db89e2014-03-21 20:40:35 +05303019 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303020 if (disconnect) {
3021 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303022 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303023 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003024 c4iw_put_ep(&ep->com);
3025 return 0;
3026}
3027
3028int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3029{
3030 int err;
3031 struct c4iw_qp_attributes attrs;
3032 enum c4iw_qp_attr_mask mask;
3033 struct c4iw_ep *ep = to_ep(cm_id);
3034 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3035 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303036 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003037
3038 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303039
3040 mutex_lock(&ep->com.mutex);
3041 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303043 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 }
3045
Steve Wisea7db89e2014-03-21 20:40:35 +05303046 BUG_ON(ep->com.state != MPA_REQ_RCVD);
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 Se4b76a22016-05-06 22:17:59 +05304039 case MPA_REP_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004040 break;
4041 case CLOSING:
4042 case MORIBUND:
4043 if (ep->com.cm_id && ep->com.qp) {
4044 attrs.next_state = C4IW_QP_STATE_ERROR;
4045 c4iw_modify_qp(ep->com.qp->rhp,
4046 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4047 &attrs, 1);
4048 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304049 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004050 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004051 case ABORTING:
4052 case DEAD:
4053
4054 /*
4055 * These states are expected if the ep timed out at the same
4056 * time as another thread was calling stop_ep_timer().
4057 * So we silently do nothing for these states.
4058 */
4059 abort = 0;
4060 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004061 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004062 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004064 abort = 0;
4065 }
Steve Wisecc18b932014-04-24 14:31:53 -05004066 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304067 if (abort)
4068 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004069 c4iw_put_ep(&ep->com);
4070}
4071
4072static void process_timedout_eps(void)
4073{
4074 struct c4iw_ep *ep;
4075
4076 spin_lock_irq(&timeout_lock);
4077 while (!list_empty(&timeout_list)) {
4078 struct list_head *tmp;
4079
4080 tmp = timeout_list.next;
4081 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004082 tmp->next = NULL;
4083 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004084 spin_unlock_irq(&timeout_lock);
4085 ep = list_entry(tmp, struct c4iw_ep, entry);
4086 process_timeout(ep);
4087 spin_lock_irq(&timeout_lock);
4088 }
4089 spin_unlock_irq(&timeout_lock);
4090}
4091
4092static void process_work(struct work_struct *work)
4093{
4094 struct sk_buff *skb = NULL;
4095 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004096 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 unsigned int opcode;
4098 int ret;
4099
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004100 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004101 while ((skb = skb_dequeue(&rxq))) {
4102 rpl = cplhdr(skb);
4103 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4104 opcode = rpl->ot.opcode;
4105
4106 BUG_ON(!work_handlers[opcode]);
4107 ret = work_handlers[opcode](dev, skb);
4108 if (!ret)
4109 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004110 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004111 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004112}
4113
4114static DECLARE_WORK(skb_work, process_work);
4115
4116static void ep_timeout(unsigned long arg)
4117{
4118 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004119 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004120
4121 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004122 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004123 /*
4124 * Only insert if it is not already on the list.
4125 */
4126 if (!ep->entry.next) {
4127 list_add_tail(&ep->entry, &timeout_list);
4128 kickit = 1;
4129 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004130 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004131 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004132 if (kickit)
4133 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004134}
4135
4136/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004137 * All the CM events are handled on a work queue to have a safe context.
4138 */
4139static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4140{
4141
4142 /*
4143 * Save dev in the skb->cb area.
4144 */
4145 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4146
4147 /*
4148 * Queue the skb and schedule the worker thread.
4149 */
4150 skb_queue_tail(&rxq, skb);
4151 queue_work(workq, &skb_work);
4152 return 0;
4153}
4154
4155static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4156{
4157 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4158
4159 if (rpl->status != CPL_ERR_NONE) {
4160 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4161 "for tid %u\n", rpl->status, GET_TID(rpl));
4162 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004163 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004164 return 0;
4165}
4166
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004167static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4168{
4169 struct cpl_fw6_msg *rpl = cplhdr(skb);
4170 struct c4iw_wr_wait *wr_waitp;
4171 int ret;
4172
4173 PDBG("%s type %u\n", __func__, rpl->type);
4174
4175 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004176 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004177 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004178 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004179 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004180 if (wr_waitp)
4181 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004182 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004183 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004184 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004185 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004186 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004187 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004188 default:
4189 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4190 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004191 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004192 break;
4193 }
4194 return 0;
4195}
4196
Steve Wise8da7e7a2011-06-14 20:59:27 +00004197static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4198{
4199 struct cpl_abort_req_rss *req = cplhdr(skb);
4200 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004201 unsigned int tid = GET_TID(req);
4202
Hariprasad S944661d2016-05-06 22:18:03 +05304203 ep = get_ep_from_tid(dev, tid);
4204 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004205 if (!ep) {
4206 printk(KERN_WARNING MOD
4207 "Abort on non-existent endpoint, tid %d\n", tid);
4208 kfree_skb(skb);
4209 return 0;
4210 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304211 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304212 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4213 __func__, ep->hwtid, req->status,
4214 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304215 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004216 }
4217 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4218 ep->com.state);
4219
4220 /*
4221 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004222 * However, if we are on MPAv2 and want to retry with MPAv1
4223 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004224 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004225 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4226 if (ep->com.state != MPA_REQ_SENT)
4227 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4228 } else
4229 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304230out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004231 sched(dev, skb);
4232 return 0;
4233}
4234
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004235/*
4236 * Most upcalls from the T4 Core go to sched() to
4237 * schedule the processing on a work queue.
4238 */
4239c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4240 [CPL_ACT_ESTABLISH] = sched,
4241 [CPL_ACT_OPEN_RPL] = sched,
4242 [CPL_RX_DATA] = sched,
4243 [CPL_ABORT_RPL_RSS] = sched,
4244 [CPL_ABORT_RPL] = sched,
4245 [CPL_PASS_OPEN_RPL] = sched,
4246 [CPL_CLOSE_LISTSRV_RPL] = sched,
4247 [CPL_PASS_ACCEPT_REQ] = sched,
4248 [CPL_PASS_ESTABLISH] = sched,
4249 [CPL_PEER_CLOSE] = sched,
4250 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004251 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004252 [CPL_RDMA_TERMINATE] = sched,
4253 [CPL_FW4_ACK] = sched,
4254 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004255 [CPL_FW6_MSG] = fw6_msg,
4256 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004257};
4258
Steve Wisecfdda9d2010-04-21 15:30:06 -07004259int __init c4iw_cm_init(void)
4260{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004261 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004262 skb_queue_head_init(&rxq);
4263
4264 workq = create_singlethread_workqueue("iw_cxgb4");
4265 if (!workq)
4266 return -ENOMEM;
4267
Steve Wisecfdda9d2010-04-21 15:30:06 -07004268 return 0;
4269}
4270
Steve Wise46c13762014-06-20 14:26:25 -05004271void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004272{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004273 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004274 flush_workqueue(workq);
4275 destroy_workqueue(workq);
4276}