blob: 0502fac4a2148c7ecb6425d984cfe3561a9da040 [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
Hariprasad Sf86fac72016-05-06 22:18:07 +0530345/*
346 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
347 */
348static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
349 unsigned int stid)
350{
351 struct c4iw_listen_ep *ep;
352 unsigned long flags;
353
354 spin_lock_irqsave(&dev->lock, flags);
355 ep = idr_find(&dev->stid_idr, stid);
356 if (ep)
357 c4iw_get_ep(&ep->com);
358 spin_unlock_irqrestore(&dev->lock, flags);
359 return ep;
360}
361
Steve Wisecfdda9d2010-04-21 15:30:06 -0700362void _c4iw_free_ep(struct kref *kref)
363{
364 struct c4iw_ep *ep;
365
366 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530367 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000368 if (test_bit(QP_REFERENCED, &ep->com.flags))
369 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700370 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530371 if (ep->com.remote_addr.ss_family == AF_INET6) {
372 struct sockaddr_in6 *sin6 =
373 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600374 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530375
376 cxgb4_clip_release(
377 ep->com.dev->rdev.lldi.ports[0],
378 (const u32 *)&sin6->sin6_addr.s6_addr,
379 1);
380 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700381 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
382 dst_release(ep->dst);
383 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530384 if (ep->mpa_skb)
385 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700386 }
387 kfree(ep);
388}
389
390static void release_ep_resources(struct c4iw_ep *ep)
391{
392 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530393
394 /*
395 * If we have a hwtid, then remove it from the idr table
396 * so lookups will no longer find this endpoint. Otherwise
397 * we have a race where one thread finds the ep ptr just
398 * before the other thread is freeing the ep memory.
399 */
400 if (ep->hwtid != -1)
401 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700402 c4iw_put_ep(&ep->com);
403}
404
Steve Wisecfdda9d2010-04-21 15:30:06 -0700405static int status2errno(int status)
406{
407 switch (status) {
408 case CPL_ERR_NONE:
409 return 0;
410 case CPL_ERR_CONN_RESET:
411 return -ECONNRESET;
412 case CPL_ERR_ARP_MISS:
413 return -EHOSTUNREACH;
414 case CPL_ERR_CONN_TIMEDOUT:
415 return -ETIMEDOUT;
416 case CPL_ERR_TCAM_FULL:
417 return -ENOMEM;
418 case CPL_ERR_CONN_EXIST:
419 return -EADDRINUSE;
420 default:
421 return -EIO;
422 }
423}
424
425/*
426 * Try and reuse skbs already allocated...
427 */
428static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
429{
430 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
431 skb_trim(skb, 0);
432 skb_get(skb);
433 skb_reset_transport_header(skb);
434 } else {
435 skb = alloc_skb(len, gfp);
436 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530437 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700438 return skb;
439}
440
Vipul Pandya830662f2013-07-04 16:10:47 +0530441static struct net_device *get_real_dev(struct net_device *egress_dev)
442{
Steve Wise11b8e222014-05-16 12:42:46 -0500443 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530444}
445
446static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
447{
448 int i;
449
450 egress_dev = get_real_dev(egress_dev);
451 for (i = 0; i < dev->rdev.lldi.nports; i++)
452 if (dev->rdev.lldi.ports[i] == egress_dev)
453 return 1;
454 return 0;
455}
456
457static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
458 __u8 *peer_ip, __be16 local_port,
459 __be16 peer_port, u8 tos,
460 __u32 sin6_scope_id)
461{
462 struct dst_entry *dst = NULL;
463
464 if (IS_ENABLED(CONFIG_IPV6)) {
465 struct flowi6 fl6;
466
467 memset(&fl6, 0, sizeof(fl6));
468 memcpy(&fl6.daddr, peer_ip, 16);
469 memcpy(&fl6.saddr, local_ip, 16);
470 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
471 fl6.flowi6_oif = sin6_scope_id;
472 dst = ip6_route_output(&init_net, NULL, &fl6);
473 if (!dst)
474 goto out;
475 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
476 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
477 dst_release(dst);
478 dst = NULL;
479 }
480 }
481
482out:
483 return dst;
484}
485
486static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700487 __be32 peer_ip, __be16 local_port,
488 __be16 peer_port, u8 tos)
489{
490 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700491 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530492 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700493
David S. Miller31e4543d2011-05-03 20:25:42 -0700494 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500495 peer_port, local_port, IPPROTO_TCP,
496 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800497 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700498 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530499 n = dst_neigh_lookup(&rt->dst, &peer_ip);
500 if (!n)
501 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530502 if (!our_interface(dev, n->dev) &&
503 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530504 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530505 dst_release(&rt->dst);
506 return NULL;
507 }
508 neigh_release(n);
509 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700510}
511
512static void arp_failure_discard(void *handle, struct sk_buff *skb)
513{
Hariprasad S9dec9002016-05-05 01:27:29 +0530514 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700515 kfree_skb(skb);
516}
517
Hariprasad S9dec9002016-05-05 01:27:29 +0530518enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530519 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530520 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530521 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530522};
523
524static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
525{
526 struct c4iw_ep *ep;
527
528 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
529 release_ep_resources(ep);
530 return 0;
531}
532
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530533static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
534{
535 struct c4iw_ep *ep;
536
537 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
538 c4iw_put_ep(&ep->parent_ep->com);
539 release_ep_resources(ep);
540 return 0;
541}
542
Hariprasad S9dec9002016-05-05 01:27:29 +0530543/*
544 * Fake up a special CPL opcode and call sched() so process_work() will call
545 * _put_ep_safe() in a safe context to free the ep resources. This is needed
546 * because ARP error handlers are called in an ATOMIC context, and
547 * _c4iw_free_ep() needs to block.
548 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530549static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
550 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530551{
552 struct cpl_act_establish *rpl = cplhdr(skb);
553
554 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530555 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530556
557 /*
558 * Save ep in the skb->cb area, after where sched() will save the dev
559 * ptr.
560 */
561 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
562 sched(ep->com.dev, skb);
563}
564
565/* Handle an ARP failure for an accept */
566static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
567{
568 struct c4iw_ep *ep = handle;
569
570 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
571 ep->hwtid);
572
573 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530574 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530575}
576
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577/*
578 * Handle an ARP failure for an active open.
579 */
580static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
581{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530582 struct c4iw_ep *ep = handle;
583
Masanari Iidae3d132d2015-10-16 21:14:29 +0900584 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530585 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530586 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530587 if (ep->com.remote_addr.ss_family == AF_INET6) {
588 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600589 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530590 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
591 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
592 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530593 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
594 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530595 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596}
597
598/*
599 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
600 * and send it along.
601 */
602static void abort_arp_failure(void *handle, struct sk_buff *skb)
603{
Hariprasad S761e19a2016-05-06 22:18:02 +0530604 int ret;
605 struct c4iw_ep *ep = handle;
606 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700607 struct cpl_abort_req *req = cplhdr(skb);
608
609 PDBG("%s rdev %p\n", __func__, rdev);
610 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530611 ret = c4iw_ofld_send(rdev, skb);
612 if (ret) {
613 __state_set(&ep->com, DEAD);
614 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
615 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700616}
617
Hariprasad Sfef44222016-05-05 01:27:33 +0530618static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700619{
620 unsigned int flowclen = 80;
621 struct fw_flowc_wr *flowc;
622 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530623 u16 vlan = ep->l2t->vlan;
624 int nparams;
625
626 if (vlan == CPL_L2T_VLAN_NONE)
627 nparams = 8;
628 else
629 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700630
631 skb = get_skb(skb, flowclen, GFP_KERNEL);
632 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
633
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530634 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530635 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530636 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
637 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700638
639 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530640 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530641 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
643 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
644 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
645 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
646 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
647 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
648 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
649 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
650 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
651 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
652 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530653 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700654 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
655 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530656 if (nparams == 9) {
657 u16 pri;
658
659 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
660 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
661 flowc->mnemval[8].val = cpu_to_be32(pri);
662 } else {
663 /* Pad WR to 16 byte boundary */
664 flowc->mnemval[8].mnemonic = 0;
665 flowc->mnemval[8].val = 0;
666 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700667 for (i = 0; i < 9; i++) {
668 flowc->mnemval[i].r4[0] = 0;
669 flowc->mnemval[i].r4[1] = 0;
670 flowc->mnemval[i].r4[2] = 0;
671 }
672
673 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530674 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700675}
676
677static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
678{
679 struct cpl_close_con_req *req;
680 struct sk_buff *skb;
681 int wrlen = roundup(sizeof *req, 16);
682
683 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
684 skb = get_skb(NULL, wrlen, gfp);
685 if (!skb) {
686 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
687 return -ENOMEM;
688 }
689 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
690 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
691 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
692 memset(req, 0, wrlen);
693 INIT_TP_WR(req, ep->hwtid);
694 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
695 ep->hwtid));
696 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
697}
698
699static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
700{
701 struct cpl_abort_req *req;
702 int wrlen = roundup(sizeof *req, 16);
703
704 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
705 skb = get_skb(skb, wrlen, gfp);
706 if (!skb) {
707 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
708 __func__);
709 return -ENOMEM;
710 }
711 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530712 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700713 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
714 memset(req, 0, wrlen);
715 INIT_TP_WR(req, ep->hwtid);
716 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
717 req->cmd = CPL_ABORT_SEND_RST;
718 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
719}
720
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530721static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530722 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530723{
Hariprasad S04524a42014-09-24 03:53:41 +0530724 unsigned short hdr_size = (ipv6 ?
725 sizeof(struct ipv6hdr) :
726 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530727 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530728 (use_ts ?
729 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530730 unsigned short data_size = mtu - hdr_size;
731
732 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
733}
734
Steve Wisecfdda9d2010-04-21 15:30:06 -0700735static int send_connect(struct c4iw_ep *ep)
736{
Hariprasad S963cab52015-09-23 17:19:27 +0530737 struct cpl_act_open_req *req = NULL;
738 struct cpl_t5_act_open_req *t5req = NULL;
739 struct cpl_t6_act_open_req *t6req = NULL;
740 struct cpl_act_open_req6 *req6 = NULL;
741 struct cpl_t5_act_open_req6 *t5req6 = NULL;
742 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700743 struct sk_buff *skb;
744 u64 opt0;
745 u32 opt2;
746 unsigned int mtu_idx;
747 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530748 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500749 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600750 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500751 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600752 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500753 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600754 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500755 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600756 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530757 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530758 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
759 u32 isn = (prandom_u32() & ~7UL) - 1;
760
761 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
762 case CHELSIO_T4:
763 sizev4 = sizeof(struct cpl_act_open_req);
764 sizev6 = sizeof(struct cpl_act_open_req6);
765 break;
766 case CHELSIO_T5:
767 sizev4 = sizeof(struct cpl_t5_act_open_req);
768 sizev6 = sizeof(struct cpl_t5_act_open_req6);
769 break;
770 case CHELSIO_T6:
771 sizev4 = sizeof(struct cpl_t6_act_open_req);
772 sizev6 = sizeof(struct cpl_t6_act_open_req6);
773 break;
774 default:
775 pr_err("T%d Chip is not supported\n",
776 CHELSIO_CHIP_VERSION(adapter_type));
777 return -EINVAL;
778 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530779
780 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
781 roundup(sizev4, 16) :
782 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700783
784 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
785
786 skb = get_skb(NULL, wrlen, GFP_KERNEL);
787 if (!skb) {
788 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
789 __func__);
790 return -ENOMEM;
791 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000792 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700793
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530794 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530795 enable_tcp_timestamps,
796 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700797 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530798
799 /*
800 * Specify the largest window that will fit in opt0. The
801 * remainder will be specified in the rx_data_ack.
802 */
803 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800804 if (win > RCV_BUFSIZ_M)
805 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530806
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800807 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800808 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800809 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800810 WND_SCALE_V(wscale) |
811 MSS_IDX_V(mtu_idx) |
812 L2T_IDX_V(ep->l2t->idx) |
813 TX_CHAN_V(ep->tx_chan) |
814 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530815 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800816 ULP_MODE_V(ULP_MODE_TCPDDP) |
817 RCV_BUFSIZ_V(win);
818 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800819 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800820 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700821 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800822 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700823 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800824 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700825 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800826 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530827 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
828 if (peer2peer)
829 isn += 4;
830
Anish Bhattd7990b02014-11-12 17:15:57 -0800831 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530832 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530833 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500834 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530835
836 if (ep->com.remote_addr.ss_family == AF_INET6)
837 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
838 (const u32 *)&la6->sin6_addr.s6_addr, 1);
839
Hariprasad S5dab6d32014-06-23 19:12:36 +0530840 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700841
Hariprasad S963cab52015-09-23 17:19:27 +0530842 if (ep->com.remote_addr.ss_family == AF_INET) {
843 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
844 case CHELSIO_T4:
845 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530846 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530847 break;
848 case CHELSIO_T5:
849 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
850 wrlen);
851 INIT_TP_WR(t5req, 0);
852 req = (struct cpl_act_open_req *)t5req;
853 break;
854 case CHELSIO_T6:
855 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
856 wrlen);
857 INIT_TP_WR(t6req, 0);
858 req = (struct cpl_act_open_req *)t6req;
859 t5req = (struct cpl_t5_act_open_req *)t6req;
860 break;
861 default:
862 pr_err("T%d Chip is not supported\n",
863 CHELSIO_CHIP_VERSION(adapter_type));
864 ret = -EINVAL;
865 goto clip_release;
866 }
867
868 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
869 ((ep->rss_qid<<14) | ep->atid)));
870 req->local_port = la->sin_port;
871 req->peer_port = ra->sin_port;
872 req->local_ip = la->sin_addr.s_addr;
873 req->peer_ip = ra->sin_addr.s_addr;
874 req->opt0 = cpu_to_be64(opt0);
875
876 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530877 req->params = cpu_to_be32(cxgb4_select_ntuple(
878 ep->com.dev->rdev.lldi.ports[0],
879 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530880 req->opt2 = cpu_to_be32(opt2);
881 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530882 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
883 cxgb4_select_ntuple(
884 ep->com.dev->rdev.lldi.ports[0],
885 ep->l2t)));
886 t5req->rsvd = cpu_to_be32(isn);
887 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
888 t5req->opt2 = cpu_to_be32(opt2);
889 }
890 } else {
891 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
892 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530893 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530894 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530895 break;
896 case CHELSIO_T5:
897 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
898 wrlen);
899 INIT_TP_WR(t5req6, 0);
900 req6 = (struct cpl_act_open_req6 *)t5req6;
901 break;
902 case CHELSIO_T6:
903 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
904 wrlen);
905 INIT_TP_WR(t6req6, 0);
906 req6 = (struct cpl_act_open_req6 *)t6req6;
907 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
908 break;
909 default:
910 pr_err("T%d Chip is not supported\n",
911 CHELSIO_CHIP_VERSION(adapter_type));
912 ret = -EINVAL;
913 goto clip_release;
914 }
915
916 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
917 ((ep->rss_qid<<14)|ep->atid)));
918 req6->local_port = la6->sin6_port;
919 req6->peer_port = ra6->sin6_port;
920 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
921 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
922 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
923 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
924 req6->opt0 = cpu_to_be64(opt0);
925
926 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530927 req6->params = cpu_to_be32(cxgb4_select_ntuple(
928 ep->com.dev->rdev.lldi.ports[0],
929 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530930 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530931 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530932 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
933 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530934 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530935 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530936 t5req6->rsvd = cpu_to_be32(isn);
937 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
938 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530939 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000940 }
941
Vipul Pandya793dad92012-12-10 09:30:56 +0000942 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530943 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530944clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530945 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
946 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
947 (const u32 *)&la6->sin6_addr.s6_addr, 1);
948 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700949}
950
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530951static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
952 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700953{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530954 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700955 struct fw_ofld_tx_data_wr *req;
956 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530957 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700958
959 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
960
961 BUG_ON(skb_cloned(skb));
962
963 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530964 if (mpa_rev_to_use == 2)
965 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700966 wrlen = roundup(mpalen + sizeof *req, 16);
967 skb = get_skb(skb, wrlen, GFP_KERNEL);
968 if (!skb) {
969 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530970 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700971 }
972 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
973
974 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
975 memset(req, 0, wrlen);
976 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530977 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
978 FW_WR_COMPL_F |
979 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700980 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530981 FW_WR_FLOWID_V(ep->hwtid) |
982 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700983 req->plen = cpu_to_be32(mpalen);
984 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530985 FW_OFLD_TX_DATA_WR_FLUSH_F |
986 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700987
988 mpa = (struct mpa_message *)(req + 1);
989 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
990 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530991 (markers_enabled ? MPA_MARKERS : 0) |
992 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700993 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530994 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530995 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530996 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530997 ep->retry_with_mpa_v1 = 0;
998 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700999
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301000 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001001 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1002 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301003 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1004 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301005 mpa_v2_params.ird = htons((u16)ep->ird);
1006 mpa_v2_params.ord = htons((u16)ep->ord);
1007
1008 if (peer2peer) {
1009 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1010 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1011 mpa_v2_params.ord |=
1012 htons(MPA_V2_RDMA_WRITE_RTR);
1013 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1014 mpa_v2_params.ord |=
1015 htons(MPA_V2_RDMA_READ_RTR);
1016 }
1017 memcpy(mpa->private_data, &mpa_v2_params,
1018 sizeof(struct mpa_v2_conn_params));
1019
1020 if (ep->plen)
1021 memcpy(mpa->private_data +
1022 sizeof(struct mpa_v2_conn_params),
1023 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1024 } else
1025 if (ep->plen)
1026 memcpy(mpa->private_data,
1027 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001028
1029 /*
1030 * Reference the mpa skb. This ensures the data area
1031 * will remain in memory until the hw acks the tx.
1032 * Function fw4_ack() will deref it.
1033 */
1034 skb_get(skb);
1035 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1036 BUG_ON(ep->mpa_skb);
1037 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301038 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1039 if (ret)
1040 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001041 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301042 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001043 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301044 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301045 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001046}
1047
1048static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1049{
1050 int mpalen, wrlen;
1051 struct fw_ofld_tx_data_wr *req;
1052 struct mpa_message *mpa;
1053 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301054 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001055
1056 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1057
1058 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301059 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1060 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001061 wrlen = roundup(mpalen + sizeof *req, 16);
1062
1063 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1064 if (!skb) {
1065 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1066 return -ENOMEM;
1067 }
1068 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1069
1070 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1071 memset(req, 0, wrlen);
1072 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301073 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1074 FW_WR_COMPL_F |
1075 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001076 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301077 FW_WR_FLOWID_V(ep->hwtid) |
1078 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001079 req->plen = cpu_to_be32(mpalen);
1080 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301081 FW_OFLD_TX_DATA_WR_FLUSH_F |
1082 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001083
1084 mpa = (struct mpa_message *)(req + 1);
1085 memset(mpa, 0, sizeof(*mpa));
1086 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1087 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001088 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301090
1091 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1092 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001093 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1094 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301095 mpa_v2_params.ird = htons(((u16)ep->ird) |
1096 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1097 0));
1098 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1099 (p2p_type ==
1100 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1101 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1102 FW_RI_INIT_P2PTYPE_READ_REQ ?
1103 MPA_V2_RDMA_READ_RTR : 0) : 0));
1104 memcpy(mpa->private_data, &mpa_v2_params,
1105 sizeof(struct mpa_v2_conn_params));
1106
1107 if (ep->plen)
1108 memcpy(mpa->private_data +
1109 sizeof(struct mpa_v2_conn_params), pdata, plen);
1110 } else
1111 if (plen)
1112 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001113
1114 /*
1115 * Reference the mpa skb again. This ensures the data area
1116 * will remain in memory until the hw acks the tx.
1117 * Function fw4_ack() will deref it.
1118 */
1119 skb_get(skb);
1120 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 BUG_ON(ep->mpa_skb);
1122 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301123 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001124 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1125}
1126
1127static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1128{
1129 int mpalen, wrlen;
1130 struct fw_ofld_tx_data_wr *req;
1131 struct mpa_message *mpa;
1132 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301133 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001134
1135 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1136
1137 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301138 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1139 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001140 wrlen = roundup(mpalen + sizeof *req, 16);
1141
1142 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1143 if (!skb) {
1144 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1145 return -ENOMEM;
1146 }
1147 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1148
1149 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1150 memset(req, 0, wrlen);
1151 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301152 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1153 FW_WR_COMPL_F |
1154 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301156 FW_WR_FLOWID_V(ep->hwtid) |
1157 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158 req->plen = cpu_to_be32(mpalen);
1159 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301160 FW_OFLD_TX_DATA_WR_FLUSH_F |
1161 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162
1163 mpa = (struct mpa_message *)(req + 1);
1164 memset(mpa, 0, sizeof(*mpa));
1165 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1166 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1167 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301168 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301170
1171 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1172 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001173 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1174 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301175 mpa_v2_params.ird = htons((u16)ep->ird);
1176 mpa_v2_params.ord = htons((u16)ep->ord);
1177 if (peer2peer && (ep->mpa_attr.p2p_type !=
1178 FW_RI_INIT_P2PTYPE_DISABLED)) {
1179 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1180
1181 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1182 mpa_v2_params.ord |=
1183 htons(MPA_V2_RDMA_WRITE_RTR);
1184 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1185 mpa_v2_params.ord |=
1186 htons(MPA_V2_RDMA_READ_RTR);
1187 }
1188
1189 memcpy(mpa->private_data, &mpa_v2_params,
1190 sizeof(struct mpa_v2_conn_params));
1191
1192 if (ep->plen)
1193 memcpy(mpa->private_data +
1194 sizeof(struct mpa_v2_conn_params), pdata, plen);
1195 } else
1196 if (plen)
1197 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198
1199 /*
1200 * Reference the mpa skb. This ensures the data area
1201 * will remain in memory until the hw acks the tx.
1202 * Function fw4_ack() will deref it.
1203 */
1204 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001205 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301206 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301207 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1209}
1210
1211static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1212{
1213 struct c4iw_ep *ep;
1214 struct cpl_act_establish *req = cplhdr(skb);
1215 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001216 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001217 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301218 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001219
1220 ep = lookup_atid(t, atid);
1221
1222 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1223 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1224
Steve Wisea7db89e2014-03-21 20:40:35 +05301225 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001226 dst_confirm(ep->dst);
1227
1228 /* setup the hwtid for this connection */
1229 ep->hwtid = tid;
1230 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301231 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001232
1233 ep->snd_seq = be32_to_cpu(req->snd_isn);
1234 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1235
1236 set_emss(ep, ntohs(req->tcp_opt));
1237
1238 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001239 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001241 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001242
1243 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301244 ret = send_flowc(ep, NULL);
1245 if (ret)
1246 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301247 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301248 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301249 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301250 ret = send_mpa_req(ep, skb, mpa_rev);
1251 if (ret)
1252 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301253 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001254 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301255err:
1256 mutex_unlock(&ep->com.mutex);
1257 connect_reply_upcall(ep, -ENOMEM);
1258 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1259 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001260}
1261
Steve Wisebe13b2d2014-03-21 20:40:33 +05301262static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001263{
1264 struct iw_cm_event event;
1265
1266 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1267 memset(&event, 0, sizeof(event));
1268 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301269 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001270 if (ep->com.cm_id) {
1271 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1272 ep, ep->com.cm_id, ep->hwtid);
1273 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301274 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001275 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001276 }
1277}
1278
Steve Wisecfdda9d2010-04-21 15:30:06 -07001279static void peer_close_upcall(struct c4iw_ep *ep)
1280{
1281 struct iw_cm_event event;
1282
1283 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1284 memset(&event, 0, sizeof(event));
1285 event.event = IW_CM_EVENT_DISCONNECT;
1286 if (ep->com.cm_id) {
1287 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1288 ep, ep->com.cm_id, ep->hwtid);
1289 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001290 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001291 }
1292}
1293
1294static void peer_abort_upcall(struct c4iw_ep *ep)
1295{
1296 struct iw_cm_event event;
1297
1298 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1299 memset(&event, 0, sizeof(event));
1300 event.event = IW_CM_EVENT_CLOSE;
1301 event.status = -ECONNRESET;
1302 if (ep->com.cm_id) {
1303 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1304 ep->com.cm_id, ep->hwtid);
1305 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301306 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001307 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001308 }
1309}
1310
1311static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1312{
1313 struct iw_cm_event event;
1314
1315 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1316 memset(&event, 0, sizeof(event));
1317 event.event = IW_CM_EVENT_CONNECT_REPLY;
1318 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301319 memcpy(&event.local_addr, &ep->com.local_addr,
1320 sizeof(ep->com.local_addr));
1321 memcpy(&event.remote_addr, &ep->com.remote_addr,
1322 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001323
1324 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301325 if (!ep->tried_with_mpa_v1) {
1326 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301327 event.ord = ep->ird;
1328 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301329 event.private_data_len = ep->plen -
1330 sizeof(struct mpa_v2_conn_params);
1331 event.private_data = ep->mpa_pkt +
1332 sizeof(struct mpa_message) +
1333 sizeof(struct mpa_v2_conn_params);
1334 } else {
1335 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301336 event.ord = cur_max_read_depth(ep->com.dev);
1337 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301338 event.private_data_len = ep->plen;
1339 event.private_data = ep->mpa_pkt +
1340 sizeof(struct mpa_message);
1341 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001342 }
Roland Dreier85963e42010-07-19 13:13:09 -07001343
1344 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1345 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001346 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001347 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1348
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301349 if (status < 0)
1350 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001351}
1352
Steve Wisebe13b2d2014-03-21 20:40:33 +05301353static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001354{
1355 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301356 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001357
1358 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1359 memset(&event, 0, sizeof(event));
1360 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301361 memcpy(&event.local_addr, &ep->com.local_addr,
1362 sizeof(ep->com.local_addr));
1363 memcpy(&event.remote_addr, &ep->com.remote_addr,
1364 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301366 if (!ep->tried_with_mpa_v1) {
1367 /* this means MPA_v2 is used */
1368 event.ord = ep->ord;
1369 event.ird = ep->ird;
1370 event.private_data_len = ep->plen -
1371 sizeof(struct mpa_v2_conn_params);
1372 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1373 sizeof(struct mpa_v2_conn_params);
1374 } else {
1375 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301376 event.ord = cur_max_read_depth(ep->com.dev);
1377 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301378 event.private_data_len = ep->plen;
1379 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1380 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301381 c4iw_get_ep(&ep->com);
1382 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1383 &event);
1384 if (ret)
1385 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001386 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001387 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301388 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001389}
1390
1391static void established_upcall(struct c4iw_ep *ep)
1392{
1393 struct iw_cm_event event;
1394
1395 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1396 memset(&event, 0, sizeof(event));
1397 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301398 event.ird = ep->ord;
1399 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001400 if (ep->com.cm_id) {
1401 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1402 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001403 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 }
1405}
1406
1407static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1408{
1409 struct cpl_rx_data_ack *req;
1410 struct sk_buff *skb;
1411 int wrlen = roundup(sizeof *req, 16);
1412
1413 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1414 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1415 if (!skb) {
1416 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1417 return 0;
1418 }
1419
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301420 /*
1421 * If we couldn't specify the entire rcv window at connection setup
1422 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1423 * then add the overage in to the credits returned.
1424 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001425 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1426 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301427
Steve Wisecfdda9d2010-04-21 15:30:06 -07001428 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1429 memset(req, 0, wrlen);
1430 INIT_TP_WR(req, ep->hwtid);
1431 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1432 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001433 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301434 RX_DACK_CHANGE_F |
1435 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001436 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1438 return credits;
1439}
1440
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301441#define RELAXED_IRD_NEGOTIATION 1
1442
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301443/*
1444 * process_mpa_reply - process streaming mode MPA reply
1445 *
1446 * Returns:
1447 *
1448 * 0 upon success indicating a connect request was delivered to the ULP
1449 * or the mpa request is incomplete but valid so far.
1450 *
1451 * 1 if a failure requires the caller to close the connection.
1452 *
1453 * 2 if a failure requires the caller to abort the connection.
1454 */
Steve Wisecc18b932014-04-24 14:31:53 -05001455static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001456{
1457 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301458 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301460 u16 resp_ird, resp_ord;
1461 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001462 struct c4iw_qp_attributes attrs;
1463 enum c4iw_qp_attr_mask mask;
1464 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001465 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001466
1467 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1468
1469 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001470 * If we get more than the supported amount of private data
1471 * then we must fail this connection.
1472 */
1473 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1474 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301475 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001476 }
1477
1478 /*
1479 * copy the new data into our accumulation buffer.
1480 */
1481 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1482 skb->len);
1483 ep->mpa_pkt_len += skb->len;
1484
1485 /*
1486 * if we don't even have the mpa message, then bail.
1487 */
1488 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001489 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001490 mpa = (struct mpa_message *) ep->mpa_pkt;
1491
1492 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301493 if (mpa->revision > mpa_rev) {
1494 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1495 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001496 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301497 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001498 }
1499 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1500 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301501 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001502 }
1503
1504 plen = ntohs(mpa->private_data_size);
1505
1506 /*
1507 * Fail if there's too much private data.
1508 */
1509 if (plen > MPA_MAX_PRIVATE_DATA) {
1510 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301511 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001512 }
1513
1514 /*
1515 * If plen does not account for pkt size
1516 */
1517 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1518 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301519 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001520 }
1521
1522 ep->plen = (u8) plen;
1523
1524 /*
1525 * If we don't have all the pdata yet, then bail.
1526 * We'll continue process when more data arrives.
1527 */
1528 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001529 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001530
1531 if (mpa->flags & MPA_REJECT) {
1532 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301533 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001534 }
1535
1536 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301537 * Stop mpa timer. If it expired, then
1538 * we ignore the MPA reply. process_timeout()
1539 * will abort the connection.
1540 */
1541 if (stop_ep_timer(ep))
1542 return 0;
1543
1544 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001545 * If we get here we have accumulated the entire mpa
1546 * start reply message including private data. And
1547 * the MPA header is valid.
1548 */
Steve Wisec529fb52014-03-21 20:40:37 +05301549 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001550 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1551 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1552 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301553 ep->mpa_attr.version = mpa->revision;
1554 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1555
1556 if (mpa->revision == 2) {
1557 ep->mpa_attr.enhanced_rdma_conn =
1558 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1559 if (ep->mpa_attr.enhanced_rdma_conn) {
1560 mpa_v2_params = (struct mpa_v2_conn_params *)
1561 (ep->mpa_pkt + sizeof(*mpa));
1562 resp_ird = ntohs(mpa_v2_params->ird) &
1563 MPA_V2_IRD_ORD_MASK;
1564 resp_ord = ntohs(mpa_v2_params->ord) &
1565 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301566 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1567 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301568
1569 /*
1570 * This is a double-check. Ideally, below checks are
1571 * not required since ird/ord stuff has been taken
1572 * care of in c4iw_accept_cr
1573 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301574 if (ep->ird < resp_ord) {
1575 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1576 ep->com.dev->rdev.lldi.max_ordird_qp)
1577 ep->ird = resp_ord;
1578 else
1579 insuff_ird = 1;
1580 } else if (ep->ird > resp_ord) {
1581 ep->ird = resp_ord;
1582 }
1583 if (ep->ord > resp_ird) {
1584 if (RELAXED_IRD_NEGOTIATION)
1585 ep->ord = resp_ird;
1586 else
1587 insuff_ird = 1;
1588 }
1589 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301590 err = -ENOMEM;
1591 ep->ird = resp_ord;
1592 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301593 }
1594
1595 if (ntohs(mpa_v2_params->ird) &
1596 MPA_V2_PEER2PEER_MODEL) {
1597 if (ntohs(mpa_v2_params->ord) &
1598 MPA_V2_RDMA_WRITE_RTR)
1599 ep->mpa_attr.p2p_type =
1600 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1601 else if (ntohs(mpa_v2_params->ord) &
1602 MPA_V2_RDMA_READ_RTR)
1603 ep->mpa_attr.p2p_type =
1604 FW_RI_INIT_P2PTYPE_READ_REQ;
1605 }
1606 }
1607 } else if (mpa->revision == 1)
1608 if (peer2peer)
1609 ep->mpa_attr.p2p_type = p2p_type;
1610
Steve Wisecfdda9d2010-04-21 15:30:06 -07001611 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301612 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1613 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1614 ep->mpa_attr.recv_marker_enabled,
1615 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1616 ep->mpa_attr.p2p_type, p2p_type);
1617
1618 /*
1619 * If responder's RTR does not match with that of initiator, assign
1620 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1621 * generated when moving QP to RTS state.
1622 * A TERM message will be sent after QP has moved to RTS state
1623 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001624 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301625 (ep->mpa_attr.p2p_type != p2p_type)) {
1626 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1627 rtr_mismatch = 1;
1628 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629
1630 attrs.mpa_attr = ep->mpa_attr;
1631 attrs.max_ird = ep->ird;
1632 attrs.max_ord = ep->ord;
1633 attrs.llp_stream_handle = ep;
1634 attrs.next_state = C4IW_QP_STATE_RTS;
1635
1636 mask = C4IW_QP_ATTR_NEXT_STATE |
1637 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1638 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1639
1640 /* bind QP and TID with INIT_WR */
1641 err = c4iw_modify_qp(ep->com.qp->rhp,
1642 ep->com.qp, mask, &attrs, 1);
1643 if (err)
1644 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301645
1646 /*
1647 * If responder's RTR requirement did not match with what initiator
1648 * supports, generate TERM message
1649 */
1650 if (rtr_mismatch) {
1651 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1652 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1653 attrs.ecode = MPA_NOMATCH_RTR;
1654 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001655 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301656 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001657 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301658 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001659 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301660 goto out;
1661 }
1662
1663 /*
1664 * Generate TERM if initiator IRD is not sufficient for responder
1665 * provided ORD. Currently, we do the same behaviour even when
1666 * responder provided IRD is also not sufficient as regards to
1667 * initiator ORD.
1668 */
1669 if (insuff_ird) {
1670 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1671 __func__);
1672 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1673 attrs.ecode = MPA_INSUFF_IRD;
1674 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001675 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301676 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001677 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301678 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001679 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301680 goto out;
1681 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301683err_stop_timer:
1684 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001685err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301686 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001687out:
1688 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001689 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690}
1691
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301692/*
1693 * process_mpa_request - process streaming mode MPA request
1694 *
1695 * Returns:
1696 *
1697 * 0 upon success indicating a connect request was delivered to the ULP
1698 * or the mpa request is incomplete but valid so far.
1699 *
1700 * 1 if a failure requires the caller to close the connection.
1701 *
1702 * 2 if a failure requires the caller to abort the connection.
1703 */
1704static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001705{
1706 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301707 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001708 u16 plen;
1709
1710 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1711
Steve Wisecfdda9d2010-04-21 15:30:06 -07001712 /*
1713 * If we get more than the supported amount of private data
1714 * then we must fail this connection.
1715 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301716 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1717 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718
1719 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1720
1721 /*
1722 * Copy the new data into our accumulation buffer.
1723 */
1724 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1725 skb->len);
1726 ep->mpa_pkt_len += skb->len;
1727
1728 /*
1729 * If we don't even have the mpa message, then bail.
1730 * We'll continue process when more data arrives.
1731 */
1732 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301733 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001734
1735 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001736 mpa = (struct mpa_message *) ep->mpa_pkt;
1737
1738 /*
1739 * Validate MPA Header.
1740 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301741 if (mpa->revision > mpa_rev) {
1742 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1743 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301744 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001745 }
1746
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301747 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1748 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001749
1750 plen = ntohs(mpa->private_data_size);
1751
1752 /*
1753 * Fail if there's too much private data.
1754 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301755 if (plen > MPA_MAX_PRIVATE_DATA)
1756 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757
1758 /*
1759 * If plen does not account for pkt size
1760 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301761 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1762 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001763 ep->plen = (u8) plen;
1764
1765 /*
1766 * If we don't have all the pdata yet, then bail.
1767 */
1768 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301769 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001770
1771 /*
1772 * If we get here we have accumulated the entire mpa
1773 * start reply message including private data.
1774 */
1775 ep->mpa_attr.initiator = 0;
1776 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1777 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1778 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301779 ep->mpa_attr.version = mpa->revision;
1780 if (mpa->revision == 1)
1781 ep->tried_with_mpa_v1 = 1;
1782 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1783
1784 if (mpa->revision == 2) {
1785 ep->mpa_attr.enhanced_rdma_conn =
1786 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1787 if (ep->mpa_attr.enhanced_rdma_conn) {
1788 mpa_v2_params = (struct mpa_v2_conn_params *)
1789 (ep->mpa_pkt + sizeof(*mpa));
1790 ep->ird = ntohs(mpa_v2_params->ird) &
1791 MPA_V2_IRD_ORD_MASK;
1792 ep->ord = ntohs(mpa_v2_params->ord) &
1793 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301794 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1795 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301796 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1797 if (peer2peer) {
1798 if (ntohs(mpa_v2_params->ord) &
1799 MPA_V2_RDMA_WRITE_RTR)
1800 ep->mpa_attr.p2p_type =
1801 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1802 else if (ntohs(mpa_v2_params->ord) &
1803 MPA_V2_RDMA_READ_RTR)
1804 ep->mpa_attr.p2p_type =
1805 FW_RI_INIT_P2PTYPE_READ_REQ;
1806 }
1807 }
1808 } else if (mpa->revision == 1)
1809 if (peer2peer)
1810 ep->mpa_attr.p2p_type = p2p_type;
1811
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1813 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1814 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1815 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1816 ep->mpa_attr.p2p_type);
1817
Hariprasad Se4b76a22016-05-06 22:17:59 +05301818 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001819
Hariprasad Se4b76a22016-05-06 22:17:59 +05301820 /* drive upcall */
1821 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1822 if (ep->parent_ep->com.state != DEAD) {
1823 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301824 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301825 } else {
1826 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301827 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301828 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301829 return 0;
1830
1831err_unlock_parent:
1832 mutex_unlock(&ep->parent_ep->com.mutex);
1833 goto err_out;
1834err_stop_timer:
1835 (void)stop_ep_timer(ep);
1836err_out:
1837 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001838}
1839
1840static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1841{
1842 struct c4iw_ep *ep;
1843 struct cpl_rx_data *hdr = cplhdr(skb);
1844 unsigned int dlen = ntohs(hdr->len);
1845 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001846 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001847 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001848
Hariprasad S944661d2016-05-06 22:18:03 +05301849 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301850 if (!ep)
1851 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001852 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1853 skb_pull(skb, sizeof(*hdr));
1854 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301855 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001856
Steve Wisecfdda9d2010-04-21 15:30:06 -07001857 /* update RX credits */
1858 update_rx_credits(ep, dlen);
1859
Steve Wisec529fb52014-03-21 20:40:37 +05301860 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001861 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001862 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001863 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001864 break;
1865 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001866 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301867 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001868 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001869 case FPDU_MODE: {
1870 struct c4iw_qp_attributes attrs;
1871 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001872 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001873 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001874 " qpid %u ep %p state %d tid %u status %d\n",
1875 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301876 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301877 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001878 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001879 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1880 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001881 break;
1882 }
Vipul Pandya15579672013-01-07 13:11:52 +00001883 default:
1884 break;
1885 }
Steve Wisec529fb52014-03-21 20:40:37 +05301886 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001887 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301888 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301889 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001890 return 0;
1891}
1892
1893static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1894{
1895 struct c4iw_ep *ep;
1896 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001897 int release = 0;
1898 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899
Hariprasad S944661d2016-05-06 22:18:03 +05301900 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301901 if (!ep) {
1902 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1903 return 0;
1904 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001905 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001906 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001907 switch (ep->com.state) {
1908 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001909 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001910 __state_set(&ep->com, DEAD);
1911 release = 1;
1912 break;
1913 default:
1914 printk(KERN_ERR "%s ep %p state %d\n",
1915 __func__, ep, ep->com.state);
1916 break;
1917 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001918 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001919
1920 if (release)
1921 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301922 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001923 return 0;
1924}
1925
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301926static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001927{
1928 struct sk_buff *skb;
1929 struct fw_ofld_connection_wr *req;
1930 unsigned int mtu_idx;
1931 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301932 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301933 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001934
1935 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1936 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1937 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001938 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301939 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301940 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1941 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001942 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001943 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301944 req->le.lport = sin->sin_port;
1945 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001946 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301947 req->le.pport = sin->sin_port;
1948 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001949 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301950 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1951 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001952 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301953 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001954 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001955 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301956 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301957 enable_tcp_timestamps,
1958 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001959 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301960
1961 /*
1962 * Specify the largest window that will fit in opt0. The
1963 * remainder will be specified in the rx_data_ack.
1964 */
1965 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001966 if (win > RCV_BUFSIZ_M)
1967 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301968
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001969 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1970 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001971 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001972 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001973 WND_SCALE_V(wscale) |
1974 MSS_IDX_V(mtu_idx) |
1975 L2T_IDX_V(ep->l2t->idx) |
1976 TX_CHAN_V(ep->tx_chan) |
1977 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301978 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001979 ULP_MODE_V(ULP_MODE_TCPDDP) |
1980 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001981 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1982 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001983 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001984 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001985 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001986 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001987 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001988 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001989 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001990 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001991 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1992 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1993 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001994 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1995 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301996 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001997}
1998
Steve Wisecfdda9d2010-04-21 15:30:06 -07001999/*
2000 * Return whether a failed active open has allocated a TID
2001 */
2002static inline int act_open_has_tid(int status)
2003{
2004 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
2005 status != CPL_ERR_ARP_MISS;
2006}
2007
Steve Wise7a2cea22014-03-14 21:52:07 +05302008/* Returns whether a CPL status conveys negative advice.
2009 */
2010static int is_neg_adv(unsigned int status)
2011{
2012 return status == CPL_ERR_RTX_NEG_ADVICE ||
2013 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2014 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2015}
2016
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302017static char *neg_adv_str(unsigned int status)
2018{
2019 switch (status) {
2020 case CPL_ERR_RTX_NEG_ADVICE:
2021 return "Retransmit timeout";
2022 case CPL_ERR_PERSIST_NEG_ADVICE:
2023 return "Persist timeout";
2024 case CPL_ERR_KEEPALV_NEG_ADVICE:
2025 return "Keepalive timeout";
2026 default:
2027 return "Unknown";
2028 }
2029}
2030
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302031static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2032{
2033 ep->snd_win = snd_win;
2034 ep->rcv_win = rcv_win;
2035 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2036}
2037
Vipul Pandya793dad92012-12-10 09:30:56 +00002038#define ACT_OPEN_RETRY_COUNT 2
2039
Vipul Pandya830662f2013-07-04 16:10:47 +05302040static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2041 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302042 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302043{
2044 struct neighbour *n;
2045 int err, step;
2046 struct net_device *pdev;
2047
2048 n = dst_neigh_lookup(dst, peer_ip);
2049 if (!n)
2050 return -ENODEV;
2051
2052 rcu_read_lock();
2053 err = -ENOMEM;
2054 if (n->dev->flags & IFF_LOOPBACK) {
2055 if (iptype == 4)
2056 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2057 else if (IS_ENABLED(CONFIG_IPV6))
2058 for_each_netdev(&init_net, pdev) {
2059 if (ipv6_chk_addr(&init_net,
2060 (struct in6_addr *)peer_ip,
2061 pdev, 1))
2062 break;
2063 }
2064 else
2065 pdev = NULL;
2066
2067 if (!pdev) {
2068 err = -ENODEV;
2069 goto out;
2070 }
2071 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302072 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302073 if (!ep->l2t)
2074 goto out;
2075 ep->mtu = pdev->mtu;
2076 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302077 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2078 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302079 step = cdev->rdev.lldi.ntxq /
2080 cdev->rdev.lldi.nchan;
2081 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2082 step = cdev->rdev.lldi.nrxq /
2083 cdev->rdev.lldi.nchan;
2084 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2085 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2086 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302087 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 dev_put(pdev);
2089 } else {
2090 pdev = get_real_dev(n->dev);
2091 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2092 n, pdev, 0);
2093 if (!ep->l2t)
2094 goto out;
2095 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002096 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302097 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2098 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302099 step = cdev->rdev.lldi.ntxq /
2100 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002101 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2102 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302103 step = cdev->rdev.lldi.nrxq /
2104 cdev->rdev.lldi.nchan;
2105 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002106 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302107 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302108
2109 if (clear_mpa_v1) {
2110 ep->retry_with_mpa_v1 = 0;
2111 ep->tried_with_mpa_v1 = 0;
2112 }
2113 }
2114 err = 0;
2115out:
2116 rcu_read_unlock();
2117
2118 neigh_release(n);
2119
2120 return err;
2121}
2122
Vipul Pandya793dad92012-12-10 09:30:56 +00002123static int c4iw_reconnect(struct c4iw_ep *ep)
2124{
2125 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302126 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002127 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302128 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002129 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302130 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002131 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302132 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002133 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302134 int iptype;
2135 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002136
2137 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2138 init_timer(&ep->timer);
2139
2140 /*
2141 * Allocate an active TID to initiate a TCP connection.
2142 */
2143 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2144 if (ep->atid == -1) {
2145 pr_err("%s - cannot alloc atid.\n", __func__);
2146 err = -ENOMEM;
2147 goto fail2;
2148 }
2149 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2150
2151 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002152 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302153 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2154 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302155 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302156 iptype = 4;
2157 ra = (__u8 *)&raddr->sin_addr;
2158 } else {
2159 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2160 raddr6->sin6_addr.s6_addr,
2161 laddr6->sin6_port, raddr6->sin6_port, 0,
2162 raddr6->sin6_scope_id);
2163 iptype = 6;
2164 ra = (__u8 *)&raddr6->sin6_addr;
2165 }
2166 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002167 pr_err("%s - cannot find route.\n", __func__);
2168 err = -EHOSTUNREACH;
2169 goto fail3;
2170 }
Hariprasad S963cab52015-09-23 17:19:27 +05302171 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302172 ep->com.dev->rdev.lldi.adapter_type,
2173 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302174 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002175 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002176 goto fail4;
2177 }
2178
2179 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2180 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2181 ep->l2t->idx);
2182
2183 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302184 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002185
2186 /* send connect request to rnic */
2187 err = send_connect(ep);
2188 if (!err)
2189 goto out;
2190
2191 cxgb4_l2t_release(ep->l2t);
2192fail4:
2193 dst_release(ep->dst);
2194fail3:
2195 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2196 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2197fail2:
2198 /*
2199 * remember to send notification to upper layer.
2200 * We are in here so the upper layer is not aware that this is
2201 * re-connect attempt and so, upper layer is still waiting for
2202 * response of 1st connect request.
2203 */
2204 connect_reply_upcall(ep, -ECONNRESET);
2205 c4iw_put_ep(&ep->com);
2206out:
2207 return err;
2208}
2209
Steve Wisecfdda9d2010-04-21 15:30:06 -07002210static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2211{
2212 struct c4iw_ep *ep;
2213 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002214 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2215 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002216 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002217 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302218 struct sockaddr_in *la;
2219 struct sockaddr_in *ra;
2220 struct sockaddr_in6 *la6;
2221 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302222 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002223
2224 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002225 la = (struct sockaddr_in *)&ep->com.local_addr;
2226 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2227 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2228 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002229
2230 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2231 status, status2errno(status));
2232
Steve Wise7a2cea22014-03-14 21:52:07 +05302233 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302234 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2235 __func__, atid, status, neg_adv_str(status));
2236 ep->stats.connect_neg_adv++;
2237 mutex_lock(&dev->rdev.stats.lock);
2238 dev->rdev.stats.neg_adv++;
2239 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002240 return 0;
2241 }
2242
Vipul Pandya793dad92012-12-10 09:30:56 +00002243 set_bit(ACT_OPEN_RPL, &ep->com.history);
2244
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302245 /*
2246 * Log interesting failures.
2247 */
2248 switch (status) {
2249 case CPL_ERR_CONN_RESET:
2250 case CPL_ERR_CONN_TIMEDOUT:
2251 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002252 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302253 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002254 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302255 mutex_unlock(&dev->rdev.stats.lock);
2256 if (ep->com.local_addr.ss_family == AF_INET &&
2257 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302258 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2259 ntohl(rpl->atid_status))));
2260 if (ret)
2261 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002262 return 0;
2263 }
2264 break;
2265 case CPL_ERR_CONN_EXIST:
2266 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2267 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302268 if (ep->com.remote_addr.ss_family == AF_INET6) {
2269 struct sockaddr_in6 *sin6 =
2270 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002271 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302272 cxgb4_clip_release(
2273 ep->com.dev->rdev.lldi.ports[0],
2274 (const u32 *)
2275 &sin6->sin6_addr.s6_addr, 1);
2276 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002277 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2278 atid);
2279 cxgb4_free_atid(t, atid);
2280 dst_release(ep->dst);
2281 cxgb4_l2t_release(ep->l2t);
2282 c4iw_reconnect(ep);
2283 return 0;
2284 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002285 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302286 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302287 if (ep->com.local_addr.ss_family == AF_INET) {
2288 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2289 atid, status, status2errno(status),
2290 &la->sin_addr.s_addr, ntohs(la->sin_port),
2291 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2292 } else {
2293 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2294 atid, status, status2errno(status),
2295 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2296 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2297 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302298 break;
2299 }
2300
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302301fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002302 connect_reply_upcall(ep, status2errno(status));
2303 state_set(&ep->com, DEAD);
2304
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302305 if (ep->com.remote_addr.ss_family == AF_INET6) {
2306 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002307 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302308 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2309 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2310 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 if (status && act_open_has_tid(status))
2312 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2313
Vipul Pandya793dad92012-12-10 09:30:56 +00002314 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002315 cxgb4_free_atid(t, atid);
2316 dst_release(ep->dst);
2317 cxgb4_l2t_release(ep->l2t);
2318 c4iw_put_ep(&ep->com);
2319
2320 return 0;
2321}
2322
2323static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2324{
2325 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002326 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302327 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328
2329 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002330 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2331 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 }
2333 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2334 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002335 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302336 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002337out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002338 return 0;
2339}
2340
Steve Wisecfdda9d2010-04-21 15:30:06 -07002341static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2342{
2343 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302345 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346
2347 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002348 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302349 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 return 0;
2351}
2352
Hariprasad S9dec9002016-05-05 01:27:29 +05302353static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2354 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355{
2356 struct cpl_pass_accept_rpl *rpl;
2357 unsigned int mtu_idx;
2358 u64 opt0;
2359 u32 opt2;
2360 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302361 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302362 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302363 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002364
2365 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2366 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302367
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302369 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302370 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302371 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2372 rpl5 = (void *)rpl;
2373 INIT_TP_WR(rpl5, ep->hwtid);
2374 } else {
2375 skb_trim(skb, sizeof(*rpl));
2376 INIT_TP_WR(rpl, ep->hwtid);
2377 }
2378 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2379 ep->hwtid));
2380
2381 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302382 enable_tcp_timestamps && req->tcpopt.tstamp,
2383 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302385
2386 /*
2387 * Specify the largest window that will fit in opt0. The
2388 * remainder will be specified in the rx_data_ack.
2389 */
2390 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002391 if (win > RCV_BUFSIZ_M)
2392 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002393 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002394 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002395 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002396 WND_SCALE_V(wscale) |
2397 MSS_IDX_V(mtu_idx) |
2398 L2T_IDX_V(ep->l2t->idx) |
2399 TX_CHAN_V(ep->tx_chan) |
2400 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002401 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002402 ULP_MODE_V(ULP_MODE_TCPDDP) |
2403 RCV_BUFSIZ_V(win);
2404 opt2 = RX_CHANNEL_V(0) |
2405 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406
2407 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002408 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002410 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002412 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002413 if (enable_ecn) {
2414 const struct tcphdr *tcph;
2415 u32 hlen = ntohl(req->hdr_len);
2416
Hariprasad S963cab52015-09-23 17:19:27 +05302417 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2418 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2419 IP_HDR_LEN_G(hlen);
2420 else
2421 tcph = (const void *)(req + 1) +
2422 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002423 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002424 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002425 }
Hariprasad S963cab52015-09-23 17:19:27 +05302426 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302427 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002428 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302429 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302430 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302431 rpl5 = (void *)rpl;
2432 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2433 if (peer2peer)
2434 isn += 4;
2435 rpl5->iss = cpu_to_be32(isn);
2436 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002437 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438
Steve Wisecfdda9d2010-04-21 15:30:06 -07002439 rpl->opt0 = cpu_to_be64(opt0);
2440 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002441 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302442 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443
Hariprasad S9dec9002016-05-05 01:27:29 +05302444 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445}
2446
Vipul Pandya830662f2013-07-04 16:10:47 +05302447static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448{
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 BUG_ON(skb_cloned(skb));
2451 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002452 release_tid(&dev->rdev, hwtid, skb);
2453 return;
2454}
2455
Hariprasad S963cab52015-09-23 17:19:27 +05302456static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2457 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002458 __be16 *local_port, __be16 *peer_port)
2459{
Hariprasad S963cab52015-09-23 17:19:27 +05302460 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2461 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2462 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2463 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2464 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2465 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302467 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468 struct tcphdr *tcp = (struct tcphdr *)
2469 ((u8 *)(req + 1) + eth_len + ip_len);
2470
Vipul Pandya830662f2013-07-04 16:10:47 +05302471 if (ip->version == 4) {
2472 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2473 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2474 ntohs(tcp->dest));
2475 *iptype = 4;
2476 memcpy(peer_ip, &ip->saddr, 4);
2477 memcpy(local_ip, &ip->daddr, 4);
2478 } else {
2479 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2480 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2481 ntohs(tcp->dest));
2482 *iptype = 6;
2483 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2484 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2485 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 *peer_port = tcp->source;
2487 *local_port = tcp->dest;
2488
2489 return;
2490}
2491
2492static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2493{
Vipul Pandya793dad92012-12-10 09:30:56 +00002494 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002495 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002496 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002497 struct tid_info *t = dev->rdev.lldi.tids;
2498 unsigned int hwtid = GET_TID(req);
2499 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302500 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002501 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302502 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002503 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002504 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302505 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302506 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302507 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002508
Hariprasad Sf86fac72016-05-06 22:18:07 +05302509 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002510 if (!parent_ep) {
2511 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2512 goto reject;
2513 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002514
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302516 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 goto reject;
2518 }
2519
Hariprasad S963cab52015-09-23 17:19:27 +05302520 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2521 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302522
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302524 if (iptype == 4) {
2525 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2526 , __func__, parent_ep, hwtid,
2527 local_ip, peer_ip, ntohs(local_port),
2528 ntohs(peer_port), peer_mss);
2529 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2530 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302531 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302532 } else {
2533 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2534 , __func__, parent_ep, hwtid,
2535 local_ip, peer_ip, ntohs(local_port),
2536 ntohs(peer_port), peer_mss);
2537 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002538 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302539 ((struct sockaddr_in6 *)
2540 &parent_ep->com.local_addr)->sin6_scope_id);
2541 }
2542 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002543 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2544 __func__);
2545 goto reject;
2546 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547
2548 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2549 if (!child_ep) {
2550 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2551 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552 dst_release(dst);
2553 goto reject;
2554 }
David Miller3786cf12011-12-02 16:52:31 +00002555
Hariprasad S963cab52015-09-23 17:19:27 +05302556 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302557 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002558 if (err) {
2559 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2560 __func__);
2561 dst_release(dst);
2562 kfree(child_ep);
2563 goto reject;
2564 }
2565
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302566 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2567 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2568 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2569 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002570
Steve Wisecfdda9d2010-04-21 15:30:06 -07002571 state_set(&child_ep->com, CONNECTING);
2572 child_ep->com.dev = dev;
2573 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002574
Vipul Pandya830662f2013-07-04 16:10:47 +05302575 if (iptype == 4) {
2576 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002577 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002578
Vipul Pandya830662f2013-07-04 16:10:47 +05302579 sin->sin_family = PF_INET;
2580 sin->sin_port = local_port;
2581 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002582
2583 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2584 sin->sin_family = PF_INET;
2585 sin->sin_port = ((struct sockaddr_in *)
2586 &parent_ep->com.local_addr)->sin_port;
2587 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2588
Steve Wise170003c2016-02-26 09:18:03 -06002589 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302590 sin->sin_family = PF_INET;
2591 sin->sin_port = peer_port;
2592 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2593 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002594 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302595 sin6->sin6_family = PF_INET6;
2596 sin6->sin6_port = local_port;
2597 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002598
2599 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2600 sin6->sin6_family = PF_INET6;
2601 sin6->sin6_port = ((struct sockaddr_in6 *)
2602 &parent_ep->com.local_addr)->sin6_port;
2603 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2604
Steve Wise170003c2016-02-26 09:18:03 -06002605 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302606 sin6->sin6_family = PF_INET6;
2607 sin6->sin6_port = peer_port;
2608 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2609 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002610
Steve Wisecfdda9d2010-04-21 15:30:06 -07002611 c4iw_get_ep(&parent_ep->com);
2612 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302613 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 child_ep->dst = dst;
2615 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616
2617 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002618 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619
2620 init_timer(&child_ep->timer);
2621 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302622 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302623 if (accept_cr(child_ep, skb, req)) {
2624 c4iw_put_ep(&parent_ep->com);
2625 release_ep_resources(child_ep);
2626 } else {
2627 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2628 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302629 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002630 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302631 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2632 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2633 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 goto out;
2635reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302636 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302637 if (parent_ep)
2638 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639out:
2640 return 0;
2641}
2642
2643static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2644{
2645 struct c4iw_ep *ep;
2646 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302648 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002649
Hariprasad S944661d2016-05-06 22:18:03 +05302650 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2652 ep->snd_seq = be32_to_cpu(req->snd_isn);
2653 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2654
Vipul Pandya1cab7752012-12-10 09:30:55 +00002655 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2656 ntohs(req->tcp_opt));
2657
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 set_emss(ep, ntohs(req->tcp_opt));
2659
2660 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302661 mutex_lock(&ep->com.mutex);
2662 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002664 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302665 ret = send_flowc(ep, skb);
2666 mutex_unlock(&ep->com.mutex);
2667 if (ret)
2668 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302669 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670
2671 return 0;
2672}
2673
2674static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2675{
2676 struct cpl_peer_close *hdr = cplhdr(skb);
2677 struct c4iw_ep *ep;
2678 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002679 int disconnect = 1;
2680 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002682 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002683
Hariprasad S944661d2016-05-06 22:18:03 +05302684 ep = get_ep_from_tid(dev, tid);
2685 if (!ep)
2686 return 0;
2687
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2689 dst_confirm(ep->dst);
2690
Vipul Pandya793dad92012-12-10 09:30:56 +00002691 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002692 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 switch (ep->com.state) {
2694 case MPA_REQ_WAIT:
2695 __state_set(&ep->com, CLOSING);
2696 break;
2697 case MPA_REQ_SENT:
2698 __state_set(&ep->com, CLOSING);
2699 connect_reply_upcall(ep, -ECONNRESET);
2700 break;
2701 case MPA_REQ_RCVD:
2702
2703 /*
2704 * We're gonna mark this puppy DEAD, but keep
2705 * the reference on it until the ULP accepts or
2706 * rejects the CR. Also wake up anyone waiting
2707 * in rdma connection migration (see c4iw_accept_cr()).
2708 */
2709 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002711 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002712 break;
2713 case MPA_REP_SENT:
2714 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002716 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002717 break;
2718 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002719 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002721 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002722 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002723 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002724 if (ret != -ECONNRESET) {
2725 peer_close_upcall(ep);
2726 disconnect = 1;
2727 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002728 break;
2729 case ABORTING:
2730 disconnect = 0;
2731 break;
2732 case CLOSING:
2733 __state_set(&ep->com, MORIBUND);
2734 disconnect = 0;
2735 break;
2736 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002737 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 if (ep->com.cm_id && ep->com.qp) {
2739 attrs.next_state = C4IW_QP_STATE_IDLE;
2740 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2741 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2742 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302743 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 __state_set(&ep->com, DEAD);
2745 release = 1;
2746 disconnect = 0;
2747 break;
2748 case DEAD:
2749 disconnect = 0;
2750 break;
2751 default:
2752 BUG_ON(1);
2753 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002754 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 if (disconnect)
2756 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2757 if (release)
2758 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302759 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760 return 0;
2761}
2762
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2764{
2765 struct cpl_abort_req_rss *req = cplhdr(skb);
2766 struct c4iw_ep *ep;
2767 struct cpl_abort_rpl *rpl;
2768 struct sk_buff *rpl_skb;
2769 struct c4iw_qp_attributes attrs;
2770 int ret;
2771 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002773
Hariprasad S944661d2016-05-06 22:18:03 +05302774 ep = get_ep_from_tid(dev, tid);
2775 if (!ep)
2776 return 0;
2777
Steve Wise7a2cea22014-03-14 21:52:07 +05302778 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302779 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2780 __func__, ep->hwtid, req->status,
2781 neg_adv_str(req->status));
2782 ep->stats.abort_neg_adv++;
2783 mutex_lock(&dev->rdev.stats.lock);
2784 dev->rdev.stats.neg_adv++;
2785 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302786 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002787 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002788 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2789 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002790 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002791
2792 /*
2793 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302794 * However, this is not needed if com state is just
2795 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002796 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302797 if (ep->com.state != MPA_REQ_SENT)
2798 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002799
2800 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002801 switch (ep->com.state) {
2802 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302803 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002804 break;
2805 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002806 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002807 break;
2808 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002809 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002810 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302811 connect_reply_upcall(ep, -ECONNRESET);
2812 else {
2813 /*
2814 * we just don't send notification upwards because we
2815 * want to retry with mpa_v1 without upper layers even
2816 * knowing it.
2817 *
2818 * do some housekeeping so as to re-initiate the
2819 * connection
2820 */
2821 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2822 mpa_rev);
2823 ep->retry_with_mpa_v1 = 1;
2824 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002825 break;
2826 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827 break;
2828 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 break;
2830 case MORIBUND:
2831 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002832 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002833 /*FALLTHROUGH*/
2834 case FPDU_MODE:
2835 if (ep->com.cm_id && ep->com.qp) {
2836 attrs.next_state = C4IW_QP_STATE_ERROR;
2837 ret = c4iw_modify_qp(ep->com.qp->rhp,
2838 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2839 &attrs, 1);
2840 if (ret)
2841 printk(KERN_ERR MOD
2842 "%s - qp <- error failed!\n",
2843 __func__);
2844 }
2845 peer_abort_upcall(ep);
2846 break;
2847 case ABORTING:
2848 break;
2849 case DEAD:
2850 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002851 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302852 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002853 default:
2854 BUG_ON(1);
2855 break;
2856 }
2857 dst_confirm(ep->dst);
2858 if (ep->com.state != ABORTING) {
2859 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302860 /* we don't release if we want to retry with mpa_v1 */
2861 if (!ep->retry_with_mpa_v1)
2862 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002864 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865
2866 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2867 if (!rpl_skb) {
2868 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2869 __func__);
2870 release = 1;
2871 goto out;
2872 }
2873 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2874 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2875 INIT_TP_WR(rpl, ep->hwtid);
2876 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2877 rpl->cmd = CPL_ABORT_NO_RST;
2878 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2879out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002880 if (release)
2881 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002882 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302883 if (ep->com.remote_addr.ss_family == AF_INET6) {
2884 struct sockaddr_in6 *sin6 =
2885 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002886 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302887 cxgb4_clip_release(
2888 ep->com.dev->rdev.lldi.ports[0],
2889 (const u32 *)&sin6->sin6_addr.s6_addr,
2890 1);
2891 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002892 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302893 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2894 dst_release(ep->dst);
2895 cxgb4_l2t_release(ep->l2t);
2896 c4iw_reconnect(ep);
2897 }
2898
Hariprasad S944661d2016-05-06 22:18:03 +05302899deref_ep:
2900 c4iw_put_ep(&ep->com);
2901 /* Dereferencing ep, referenced in peer_abort_intr() */
2902 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002903 return 0;
2904}
2905
2906static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2907{
2908 struct c4iw_ep *ep;
2909 struct c4iw_qp_attributes attrs;
2910 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002911 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002912 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913
Hariprasad S944661d2016-05-06 22:18:03 +05302914 ep = get_ep_from_tid(dev, tid);
2915 if (!ep)
2916 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002917
2918 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2919 BUG_ON(!ep);
2920
2921 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002922 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302923 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 switch (ep->com.state) {
2925 case CLOSING:
2926 __state_set(&ep->com, MORIBUND);
2927 break;
2928 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002929 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002930 if ((ep->com.cm_id) && (ep->com.qp)) {
2931 attrs.next_state = C4IW_QP_STATE_IDLE;
2932 c4iw_modify_qp(ep->com.qp->rhp,
2933 ep->com.qp,
2934 C4IW_QP_ATTR_NEXT_STATE,
2935 &attrs, 1);
2936 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302937 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938 __state_set(&ep->com, DEAD);
2939 release = 1;
2940 break;
2941 case ABORTING:
2942 case DEAD:
2943 break;
2944 default:
2945 BUG_ON(1);
2946 break;
2947 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002948 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 if (release)
2950 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302951 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002952 return 0;
2953}
2954
2955static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2956{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002957 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002958 unsigned int tid = GET_TID(rpl);
2959 struct c4iw_ep *ep;
2960 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961
Hariprasad S944661d2016-05-06 22:18:03 +05302962 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002963 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002964
Steve Wise30c95c22011-05-09 22:06:22 -07002965 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002966 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2967 ep->com.qp->wq.sq.qid);
2968 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2969 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2970 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2971 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002972 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302973 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975 return 0;
2976}
2977
2978/*
2979 * Upcall from the adapter indicating data has been transmitted.
2980 * For us its just the single MPA request or reply. We can now free
2981 * the skb holding the mpa message.
2982 */
2983static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2984{
2985 struct c4iw_ep *ep;
2986 struct cpl_fw4_ack *hdr = cplhdr(skb);
2987 u8 credits = hdr->credits;
2988 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002989
2990
Hariprasad S944661d2016-05-06 22:18:03 +05302991 ep = get_ep_from_tid(dev, tid);
2992 if (!ep)
2993 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002994 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2995 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002996 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2997 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302998 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999 }
3000
3001 dst_confirm(ep->dst);
3002 if (ep->mpa_skb) {
3003 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3004 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3005 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
3006 kfree_skb(ep->mpa_skb);
3007 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303008 mutex_lock(&ep->com.mutex);
3009 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3010 stop_ep_timer(ep);
3011 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003012 }
Hariprasad S944661d2016-05-06 22:18:03 +05303013out:
3014 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003015 return 0;
3016}
3017
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3019{
Steve Wisea7db89e2014-03-21 20:40:35 +05303020 int err = 0;
3021 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022 struct c4iw_ep *ep = to_ep(cm_id);
3023 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3024
Steve Wisea7db89e2014-03-21 20:40:35 +05303025 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303026 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303027 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 c4iw_put_ep(&ep->com);
3029 return -ECONNRESET;
3030 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003031 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303033 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003034 else {
3035 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303036 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003037 }
Steve Wisea7db89e2014-03-21 20:40:35 +05303038 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303039 if (disconnect) {
3040 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303041 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303042 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 c4iw_put_ep(&ep->com);
3044 return 0;
3045}
3046
3047int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3048{
3049 int err;
3050 struct c4iw_qp_attributes attrs;
3051 enum c4iw_qp_attr_mask mask;
3052 struct c4iw_ep *ep = to_ep(cm_id);
3053 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3054 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303055 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003056
3057 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303058
3059 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303060 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003061 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303062 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063 }
3064
Steve Wisecfdda9d2010-04-21 15:30:06 -07003065 BUG_ON(!qp);
3066
Vipul Pandya793dad92012-12-10 09:30:56 +00003067 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303068 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3069 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003070 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303071 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003072 }
3073
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303074 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3075 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303076 if (RELAXED_IRD_NEGOTIATION) {
3077 ep->ord = ep->ird;
3078 } else {
3079 ep->ird = conn_param->ird;
3080 ep->ord = conn_param->ord;
3081 send_mpa_reject(ep, conn_param->private_data,
3082 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303083 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303084 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303085 }
3086 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303087 if (conn_param->ird < ep->ord) {
3088 if (RELAXED_IRD_NEGOTIATION &&
3089 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3090 conn_param->ird = ep->ord;
3091 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303092 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303093 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303094 }
3095 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303096 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003097 ep->ird = conn_param->ird;
3098 ep->ord = conn_param->ord;
3099
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303100 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303101 if (peer2peer && ep->ird == 0)
3102 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303103 } else {
3104 if (peer2peer &&
3105 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303106 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303107 ep->ird = 1;
3108 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003109
3110 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3111
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303112 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303113 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303114 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003115 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303116
Steve Wisecfdda9d2010-04-21 15:30:06 -07003117 /* bind QP to EP and move to RTS */
3118 attrs.mpa_attr = ep->mpa_attr;
3119 attrs.max_ird = ep->ird;
3120 attrs.max_ord = ep->ord;
3121 attrs.llp_stream_handle = ep;
3122 attrs.next_state = C4IW_QP_STATE_RTS;
3123
3124 /* bind QP and TID with INIT_WR */
3125 mask = C4IW_QP_ATTR_NEXT_STATE |
3126 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3127 C4IW_QP_ATTR_MPA_ATTR |
3128 C4IW_QP_ATTR_MAX_IRD |
3129 C4IW_QP_ATTR_MAX_ORD;
3130
3131 err = c4iw_modify_qp(ep->com.qp->rhp,
3132 ep->com.qp, mask, &attrs, 1);
3133 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303134 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303135
3136 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003137 err = send_mpa_reply(ep, conn_param->private_data,
3138 conn_param->private_data_len);
3139 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303140 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003141
Steve Wisea7db89e2014-03-21 20:40:35 +05303142 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003143 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303144 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003145 c4iw_put_ep(&ep->com);
3146 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303147err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303148 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303149err_abort:
3150 abort = 1;
3151err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303152 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303153 if (abort)
3154 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003155 c4iw_put_ep(&ep->com);
3156 return err;
3157}
3158
Vipul Pandya830662f2013-07-04 16:10:47 +05303159static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3160{
3161 struct in_device *ind;
3162 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003163 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3164 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303165
3166 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3167 if (!ind)
3168 return -EADDRNOTAVAIL;
3169 for_primary_ifa(ind) {
3170 laddr->sin_addr.s_addr = ifa->ifa_address;
3171 raddr->sin_addr.s_addr = ifa->ifa_address;
3172 found = 1;
3173 break;
3174 }
3175 endfor_ifa(ind);
3176 in_dev_put(ind);
3177 return found ? 0 : -EADDRNOTAVAIL;
3178}
3179
3180static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3181 unsigned char banned_flags)
3182{
3183 struct inet6_dev *idev;
3184 int err = -EADDRNOTAVAIL;
3185
3186 rcu_read_lock();
3187 idev = __in6_dev_get(dev);
3188 if (idev != NULL) {
3189 struct inet6_ifaddr *ifp;
3190
3191 read_lock_bh(&idev->lock);
3192 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3193 if (ifp->scope == IFA_LINK &&
3194 !(ifp->flags & banned_flags)) {
3195 memcpy(addr, &ifp->addr, 16);
3196 err = 0;
3197 break;
3198 }
3199 }
3200 read_unlock_bh(&idev->lock);
3201 }
3202 rcu_read_unlock();
3203 return err;
3204}
3205
3206static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3207{
3208 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003209 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3210 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303211
Nicholas Krause54b9a962015-08-26 23:00:59 -04003212 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303213 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3214 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3215 return 0;
3216 }
3217 return -EADDRNOTAVAIL;
3218}
3219
Steve Wisecfdda9d2010-04-21 15:30:06 -07003220int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3221{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003222 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3223 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003224 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003225 struct sockaddr_in *laddr;
3226 struct sockaddr_in *raddr;
3227 struct sockaddr_in6 *laddr6;
3228 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303229 __u8 *ra;
3230 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003231
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303232 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3233 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003234 err = -EINVAL;
3235 goto out;
3236 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003237 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3238 if (!ep) {
3239 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3240 err = -ENOMEM;
3241 goto out;
3242 }
3243 init_timer(&ep->timer);
3244 ep->plen = conn_param->private_data_len;
3245 if (ep->plen)
3246 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3247 conn_param->private_data, ep->plen);
3248 ep->ird = conn_param->ird;
3249 ep->ord = conn_param->ord;
3250
3251 if (peer2peer && ep->ord == 0)
3252 ep->ord = 1;
3253
Steve Wisecfdda9d2010-04-21 15:30:06 -07003254 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303255 ref_cm_id(&ep->com);
3256 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003257 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303258 if (!ep->com.qp) {
3259 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3260 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003261 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303262 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003263 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003264 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3265 ep->com.qp, cm_id);
3266
3267 /*
3268 * Allocate an active TID to initiate a TCP connection.
3269 */
3270 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3271 if (ep->atid == -1) {
3272 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3273 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003274 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003275 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003276 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003277
Steve Wise170003c2016-02-26 09:18:03 -06003278 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003279 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003280 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003281 sizeof(ep->com.remote_addr));
3282
Steve Wise170003c2016-02-26 09:18:03 -06003283 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3284 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3285 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3286 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003287
Steve Wise170003c2016-02-26 09:18:03 -06003288 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303289 iptype = 4;
3290 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291
Vipul Pandya830662f2013-07-04 16:10:47 +05303292 /*
3293 * Handle loopback requests to INADDR_ANY.
3294 */
3295 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3296 err = pick_local_ipaddrs(dev, cm_id);
3297 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003298 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303299 }
3300
3301 /* find a route */
3302 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3303 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3304 ra, ntohs(raddr->sin_port));
3305 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3306 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303307 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303308 } else {
3309 iptype = 6;
3310 ra = (__u8 *)&raddr6->sin6_addr;
3311
3312 /*
3313 * Handle loopback requests to INADDR_ANY.
3314 */
3315 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3316 err = pick_local_ip6addrs(dev, cm_id);
3317 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003318 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303319 }
3320
3321 /* find a route */
3322 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3323 __func__, laddr6->sin6_addr.s6_addr,
3324 ntohs(laddr6->sin6_port),
3325 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3326 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3327 raddr6->sin6_addr.s6_addr,
3328 laddr6->sin6_port, raddr6->sin6_port, 0,
3329 raddr6->sin6_scope_id);
3330 }
3331 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003332 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3333 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003334 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003335 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003336
Hariprasad S963cab52015-09-23 17:19:27 +05303337 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303338 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003339 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003340 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003341 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003342 }
3343
3344 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3345 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3346 ep->l2t->idx);
3347
3348 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303349 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003350
3351 /* send connect request to rnic */
3352 err = send_connect(ep);
3353 if (!err)
3354 goto out;
3355
3356 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003357fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003358 dst_release(ep->dst);
3359fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003360 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003361 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003362fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303363 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364 c4iw_put_ep(&ep->com);
3365out:
3366 return err;
3367}
3368
Vipul Pandya830662f2013-07-04 16:10:47 +05303369static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3370{
3371 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003372 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003373 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303374
Hariprasad S28de1f72016-01-13 10:03:14 +05303375 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3376 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3377 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3378 if (err)
3379 return err;
3380 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303381 c4iw_init_wr_wait(&ep->com.wr_wait);
3382 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3383 ep->stid, &sin6->sin6_addr,
3384 sin6->sin6_port,
3385 ep->com.dev->rdev.lldi.rxq_ids[0]);
3386 if (!err)
3387 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3388 &ep->com.wr_wait,
3389 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303390 else if (err > 0)
3391 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303392 if (err) {
3393 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3394 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303395 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3396 err, ep->stid,
3397 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303398 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303399 return err;
3400}
3401
3402static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3403{
3404 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003405 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003406 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303407
3408 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3409 do {
3410 err = cxgb4_create_server_filter(
3411 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3412 sin->sin_addr.s_addr, sin->sin_port, 0,
3413 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3414 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303415 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3416 err = -EIO;
3417 break;
3418 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303419 set_current_state(TASK_UNINTERRUPTIBLE);
3420 schedule_timeout(usecs_to_jiffies(100));
3421 }
3422 } while (err == -EBUSY);
3423 } else {
3424 c4iw_init_wr_wait(&ep->com.wr_wait);
3425 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3426 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3427 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3428 if (!err)
3429 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3430 &ep->com.wr_wait,
3431 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303432 else if (err > 0)
3433 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303434 }
3435 if (err)
3436 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3437 , err, ep->stid,
3438 &sin->sin_addr, ntohs(sin->sin_port));
3439 return err;
3440}
3441
Steve Wisecfdda9d2010-04-21 15:30:06 -07003442int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3443{
3444 int err = 0;
3445 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3446 struct c4iw_listen_ep *ep;
3447
Steve Wisecfdda9d2010-04-21 15:30:06 -07003448 might_sleep();
3449
3450 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3451 if (!ep) {
3452 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3453 err = -ENOMEM;
3454 goto fail1;
3455 }
3456 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003457 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303458 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459 ep->com.dev = dev;
3460 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003461 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303462 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003463
3464 /*
3465 * Allocate a server TID.
3466 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303467 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3468 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303469 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003470 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003471 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303472 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003473 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003474
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003476 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003477 err = -ENOMEM;
3478 goto fail2;
3479 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003480 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003481
Steve Wise170003c2016-02-26 09:18:03 -06003482 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3483 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003484
Steve Wisecfdda9d2010-04-21 15:30:06 -07003485 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303486 if (ep->com.local_addr.ss_family == AF_INET)
3487 err = create_server4(dev, ep);
3488 else
3489 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003490 if (!err) {
3491 cm_id->provider_data = ep;
3492 goto out;
3493 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003494
Vipul Pandya830662f2013-07-04 16:10:47 +05303495 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3496 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303498 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003499 c4iw_put_ep(&ep->com);
3500fail1:
3501out:
3502 return err;
3503}
3504
3505int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3506{
3507 int err;
3508 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3509
3510 PDBG("%s ep %p\n", __func__, ep);
3511
3512 might_sleep();
3513 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303514 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3515 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003516 err = cxgb4_remove_server_filter(
3517 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3518 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3519 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303520 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003521 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303522 err = cxgb4_remove_server(
3523 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3524 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003525 if (err)
3526 goto done;
3527 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3528 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003529 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303530 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3531 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003532 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003533 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303534 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3535 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003536done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303537 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003538 c4iw_put_ep(&ep->com);
3539 return err;
3540}
3541
3542int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3543{
3544 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003545 int close = 0;
3546 int fatal = 0;
3547 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003548
Steve Wise2f5b48c2010-09-10 11:15:36 -05003549 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003550
3551 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3552 states[ep->com.state], abrupt);
3553
Hariprasad S6e410d82016-05-05 01:27:31 +05303554 /*
3555 * Ref the ep here in case we have fatal errors causing the
3556 * ep to be released and freed.
3557 */
3558 c4iw_get_ep(&ep->com);
3559
Steve Wisecfdda9d2010-04-21 15:30:06 -07003560 rdev = &ep->com.dev->rdev;
3561 if (c4iw_fatal_error(rdev)) {
3562 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303563 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003564 ep->com.state = DEAD;
3565 }
3566 switch (ep->com.state) {
3567 case MPA_REQ_WAIT:
3568 case MPA_REQ_SENT:
3569 case MPA_REQ_RCVD:
3570 case MPA_REP_SENT:
3571 case FPDU_MODE:
3572 close = 1;
3573 if (abrupt)
3574 ep->com.state = ABORTING;
3575 else {
3576 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003577 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003578 }
3579 set_bit(CLOSE_SENT, &ep->com.flags);
3580 break;
3581 case CLOSING:
3582 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3583 close = 1;
3584 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003585 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003586 ep->com.state = ABORTING;
3587 } else
3588 ep->com.state = MORIBUND;
3589 }
3590 break;
3591 case MORIBUND:
3592 case ABORTING:
3593 case DEAD:
3594 PDBG("%s ignoring disconnect ep %p state %u\n",
3595 __func__, ep, ep->com.state);
3596 break;
3597 default:
3598 BUG();
3599 break;
3600 }
3601
Steve Wisecfdda9d2010-04-21 15:30:06 -07003602 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003603 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003604 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303605 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003606 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003607 } else {
3608 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003609 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003610 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303611 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303612 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303613 if (!abrupt) {
3614 stop_ep_timer(ep);
3615 close_complete_upcall(ep, -EIO);
3616 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303617 if (ep->com.qp) {
3618 struct c4iw_qp_attributes attrs;
3619
3620 attrs.next_state = C4IW_QP_STATE_ERROR;
3621 ret = c4iw_modify_qp(ep->com.qp->rhp,
3622 ep->com.qp,
3623 C4IW_QP_ATTR_NEXT_STATE,
3624 &attrs, 1);
3625 if (ret)
3626 pr_err(MOD
3627 "%s - qp <- error failed!\n",
3628 __func__);
3629 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003630 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303631 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003632 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003633 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303634 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003635 if (fatal)
3636 release_ep_resources(ep);
3637 return ret;
3638}
3639
Vipul Pandya1cab7752012-12-10 09:30:55 +00003640static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3641 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3642{
3643 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003644 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003645
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003646 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3647 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003648 if (!ep)
3649 return;
3650
3651 switch (req->retval) {
3652 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003653 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3654 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3655 send_fw_act_open_req(ep, atid);
3656 return;
3657 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003658 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003659 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3660 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3661 send_fw_act_open_req(ep, atid);
3662 return;
3663 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003664 break;
3665 default:
3666 pr_info("%s unexpected ofld conn wr retval %d\n",
3667 __func__, req->retval);
3668 break;
3669 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003670 pr_err("active ofld_connect_wr failure %d atid %d\n",
3671 req->retval, atid);
3672 mutex_lock(&dev->rdev.stats.lock);
3673 dev->rdev.stats.act_ofld_conn_fails++;
3674 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003675 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003676 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303677 if (ep->com.remote_addr.ss_family == AF_INET6) {
3678 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003679 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303680 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3681 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3682 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003683 remove_handle(dev, &dev->atid_idr, atid);
3684 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3685 dst_release(ep->dst);
3686 cxgb4_l2t_release(ep->l2t);
3687 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003688}
3689
3690static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3691 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3692{
3693 struct sk_buff *rpl_skb;
3694 struct cpl_pass_accept_req *cpl;
3695 int ret;
3696
Paul Bolle710a3112013-02-05 20:51:30 +00003697 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003698 BUG_ON(!rpl_skb);
3699 if (req->retval) {
3700 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003701 mutex_lock(&dev->rdev.stats.lock);
3702 dev->rdev.stats.pas_ofld_conn_fails++;
3703 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003704 kfree_skb(rpl_skb);
3705 } else {
3706 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3707 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003708 (__force u32) htonl(
3709 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003710 ret = pass_accept_req(dev, rpl_skb);
3711 if (!ret)
3712 kfree_skb(rpl_skb);
3713 }
3714 return;
3715}
3716
3717static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003718{
3719 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003720 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3721
3722 switch (rpl->type) {
3723 case FW6_TYPE_CQE:
3724 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3725 break;
3726 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3727 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3728 switch (req->t_state) {
3729 case TCP_SYN_SENT:
3730 active_ofld_conn_reply(dev, skb, req);
3731 break;
3732 case TCP_SYN_RECV:
3733 passive_ofld_conn_reply(dev, skb, req);
3734 break;
3735 default:
3736 pr_err("%s unexpected ofld conn wr state %d\n",
3737 __func__, req->t_state);
3738 break;
3739 }
3740 break;
3741 }
3742 return 0;
3743}
3744
3745static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3746{
Hariprasad S963cab52015-09-23 17:19:27 +05303747 __be32 l2info;
3748 __be16 hdr_len, vlantag, len;
3749 u16 eth_hdr_len;
3750 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003751 u8 intf;
3752 struct cpl_rx_pkt *cpl = cplhdr(skb);
3753 struct cpl_pass_accept_req *req;
3754 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003755 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303756 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003757
Vipul Pandyaf079af72013-03-14 05:08:58 +00003758 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003759 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303760 vlantag = cpl->vlan;
3761 len = cpl->len;
3762 l2info = cpl->l2info;
3763 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003764 intf = cpl->iff;
3765
3766 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3767
3768 /*
3769 * We need to parse the TCP options from SYN packet.
3770 * to generate cpl_pass_accept_req.
3771 */
3772 memset(&tmp_opt, 0, sizeof(tmp_opt));
3773 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003774 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775
3776 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3777 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303778 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3779 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303780 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303781 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303782 type = dev->rdev.lldi.adapter_type;
3783 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3784 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3785 req->hdr_len =
3786 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3787 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3788 eth_hdr_len = is_t4(type) ?
3789 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3790 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3791 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3792 IP_HDR_LEN_V(ip_hdr_len) |
3793 ETH_HDR_LEN_V(eth_hdr_len));
3794 } else { /* T6 and later */
3795 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3796 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3797 T6_IP_HDR_LEN_V(ip_hdr_len) |
3798 T6_ETH_HDR_LEN_V(eth_hdr_len));
3799 }
3800 req->vlan = vlantag;
3801 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003802 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3803 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003804 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3805 if (tmp_opt.wscale_ok)
3806 req->tcpopt.wsf = tmp_opt.snd_wscale;
3807 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3808 if (tmp_opt.sack_ok)
3809 req->tcpopt.sack = 1;
3810 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3811 return;
3812}
3813
3814static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3815 __be32 laddr, __be16 lport,
3816 __be32 raddr, __be16 rport,
3817 u32 rcv_isn, u32 filter, u16 window,
3818 u32 rss_qid, u8 port_id)
3819{
3820 struct sk_buff *req_skb;
3821 struct fw_ofld_connection_wr *req;
3822 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303823 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003824
3825 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3826 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3827 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003828 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303829 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303830 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003831 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003832 req->le.lport = lport;
3833 req->le.pport = rport;
3834 req->le.u.ipv4.lip = laddr;
3835 req->le.u.ipv4.pip = raddr;
3836 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3837 req->tcb.rcv_adv = htons(window);
3838 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303839 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3840 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3841 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003842 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003843
3844 /*
3845 * We store the qid in opt2 which will be used by the firmware
3846 * to send us the wr response.
3847 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003848 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003849
3850 /*
3851 * We initialize the MSS index in TCB to 0xF.
3852 * So that when driver sends cpl_pass_accept_rpl
3853 * TCB picks up the correct value. If this was 0
3854 * TP will ignore any value > 0 for MSS index.
3855 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003856 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303857 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003858
3859 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303860 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3861 if (ret < 0) {
3862 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3863 ret);
3864 kfree_skb(skb);
3865 kfree_skb(req_skb);
3866 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003867}
3868
3869/*
3870 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3871 * messages when a filter is being used instead of server to
3872 * redirect a syn packet. When packets hit filter they are redirected
3873 * to the offload queue and driver tries to establish the connection
3874 * using firmware work request.
3875 */
3876static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3877{
3878 int stid;
3879 unsigned int filter;
3880 struct ethhdr *eh = NULL;
3881 struct vlan_ethhdr *vlan_eh = NULL;
3882 struct iphdr *iph;
3883 struct tcphdr *tcph;
3884 struct rss_header *rss = (void *)skb->data;
3885 struct cpl_rx_pkt *cpl = (void *)skb->data;
3886 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3887 struct l2t_entry *e;
3888 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303889 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003890 u16 window;
3891 struct port_info *pi;
3892 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003893 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003894 int step;
3895 u32 tx_chan;
3896 struct neighbour *neigh;
3897
3898 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003899 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003900 goto reject;
3901
3902 /*
3903 * Drop all packets which did not hit the filter.
3904 * Unlikely to happen.
3905 */
3906 if (!(rss->filter_hit && rss->filter_tid))
3907 goto reject;
3908
3909 /*
3910 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3911 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303912 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003913
Hariprasad Sf86fac72016-05-06 22:18:07 +05303914 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003915 if (!lep) {
3916 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3917 goto reject;
3918 }
3919
Hariprasad S963cab52015-09-23 17:19:27 +05303920 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3921 case CHELSIO_T4:
3922 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3923 break;
3924 case CHELSIO_T5:
3925 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3926 break;
3927 case CHELSIO_T6:
3928 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3929 break;
3930 default:
3931 pr_err("T%d Chip is not supported\n",
3932 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3933 goto reject;
3934 }
3935
Vipul Pandyaf079af72013-03-14 05:08:58 +00003936 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003937 eh = (struct ethhdr *)(req + 1);
3938 iph = (struct iphdr *)(eh + 1);
3939 } else {
3940 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3941 iph = (struct iphdr *)(vlan_eh + 1);
3942 skb->vlan_tci = ntohs(cpl->vlan);
3943 }
3944
3945 if (iph->version != 0x4)
3946 goto reject;
3947
3948 tcph = (struct tcphdr *)(iph + 1);
3949 skb_set_network_header(skb, (void *)iph - (void *)rss);
3950 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3951 skb_get(skb);
3952
3953 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3954 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3955 ntohs(tcph->source), iph->tos);
3956
Vipul Pandya830662f2013-07-04 16:10:47 +05303957 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3958 iph->tos);
3959 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003960 pr_err("%s - failed to find dst entry!\n",
3961 __func__);
3962 goto reject;
3963 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003964 neigh = dst_neigh_lookup_skb(dst, skb);
3965
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003966 if (!neigh) {
3967 pr_err("%s - failed to allocate neigh!\n",
3968 __func__);
3969 goto free_dst;
3970 }
3971
Vipul Pandya1cab7752012-12-10 09:30:55 +00003972 if (neigh->dev->flags & IFF_LOOPBACK) {
3973 pdev = ip_dev_find(&init_net, iph->daddr);
3974 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3975 pdev, 0);
3976 pi = (struct port_info *)netdev_priv(pdev);
3977 tx_chan = cxgb4_port_chan(pdev);
3978 dev_put(pdev);
3979 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303980 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003981 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303982 pdev, 0);
3983 pi = (struct port_info *)netdev_priv(pdev);
3984 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003985 }
Steve Wiseebf00062014-03-19 17:44:40 +05303986 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003987 if (!e) {
3988 pr_err("%s - failed to allocate l2t entry!\n",
3989 __func__);
3990 goto free_dst;
3991 }
3992
3993 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3994 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003995 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003996
3997 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303998 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3999 dev->rdev.lldi.ports[0],
4000 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004001
4002 /*
4003 * Synthesize the cpl_pass_accept_req. We have everything except the
4004 * TID. Once firmware sends a reply with TID we update the TID field
4005 * in cpl and pass it through the regular cpl_pass_accept_req path.
4006 */
4007 build_cpl_pass_accept_req(skb, stid, iph->tos);
4008 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4009 tcph->source, ntohl(tcph->seq), filter, window,
4010 rss_qid, pi->port_id);
4011 cxgb4_l2t_release(e);
4012free_dst:
4013 dst_release(dst);
4014reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304015 if (lep)
4016 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004017 return 0;
4018}
4019
Steve Wisecfdda9d2010-04-21 15:30:06 -07004020/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004021 * These are the real handlers that are called from a
4022 * work queue.
4023 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304024static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004025 [CPL_ACT_ESTABLISH] = act_establish,
4026 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4027 [CPL_RX_DATA] = rx_data,
4028 [CPL_ABORT_RPL_RSS] = abort_rpl,
4029 [CPL_ABORT_RPL] = abort_rpl,
4030 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4031 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4032 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4033 [CPL_PASS_ESTABLISH] = pass_establish,
4034 [CPL_PEER_CLOSE] = peer_close,
4035 [CPL_ABORT_REQ_RSS] = peer_abort,
4036 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4037 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004038 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004039 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304040 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304041 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4042 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004043};
4044
4045static void process_timeout(struct c4iw_ep *ep)
4046{
4047 struct c4iw_qp_attributes attrs;
4048 int abort = 1;
4049
Steve Wise2f5b48c2010-09-10 11:15:36 -05004050 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004051 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4052 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004053 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004054 switch (ep->com.state) {
4055 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004056 connect_reply_upcall(ep, -ETIMEDOUT);
4057 break;
4058 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304059 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304060 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304061 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004062 break;
4063 case CLOSING:
4064 case MORIBUND:
4065 if (ep->com.cm_id && ep->com.qp) {
4066 attrs.next_state = C4IW_QP_STATE_ERROR;
4067 c4iw_modify_qp(ep->com.qp->rhp,
4068 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4069 &attrs, 1);
4070 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304071 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004072 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004073 case ABORTING:
4074 case DEAD:
4075
4076 /*
4077 * These states are expected if the ep timed out at the same
4078 * time as another thread was calling stop_ep_timer().
4079 * So we silently do nothing for these states.
4080 */
4081 abort = 0;
4082 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004083 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004084 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004085 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004086 abort = 0;
4087 }
Steve Wisecc18b932014-04-24 14:31:53 -05004088 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304089 if (abort)
4090 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004091 c4iw_put_ep(&ep->com);
4092}
4093
4094static void process_timedout_eps(void)
4095{
4096 struct c4iw_ep *ep;
4097
4098 spin_lock_irq(&timeout_lock);
4099 while (!list_empty(&timeout_list)) {
4100 struct list_head *tmp;
4101
4102 tmp = timeout_list.next;
4103 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004104 tmp->next = NULL;
4105 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106 spin_unlock_irq(&timeout_lock);
4107 ep = list_entry(tmp, struct c4iw_ep, entry);
4108 process_timeout(ep);
4109 spin_lock_irq(&timeout_lock);
4110 }
4111 spin_unlock_irq(&timeout_lock);
4112}
4113
4114static void process_work(struct work_struct *work)
4115{
4116 struct sk_buff *skb = NULL;
4117 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004118 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004119 unsigned int opcode;
4120 int ret;
4121
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004122 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004123 while ((skb = skb_dequeue(&rxq))) {
4124 rpl = cplhdr(skb);
4125 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4126 opcode = rpl->ot.opcode;
4127
4128 BUG_ON(!work_handlers[opcode]);
4129 ret = work_handlers[opcode](dev, skb);
4130 if (!ret)
4131 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004132 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004133 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004134}
4135
4136static DECLARE_WORK(skb_work, process_work);
4137
4138static void ep_timeout(unsigned long arg)
4139{
4140 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004141 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004142
4143 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004144 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004145 /*
4146 * Only insert if it is not already on the list.
4147 */
4148 if (!ep->entry.next) {
4149 list_add_tail(&ep->entry, &timeout_list);
4150 kickit = 1;
4151 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004152 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004153 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004154 if (kickit)
4155 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004156}
4157
4158/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004159 * All the CM events are handled on a work queue to have a safe context.
4160 */
4161static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4162{
4163
4164 /*
4165 * Save dev in the skb->cb area.
4166 */
4167 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4168
4169 /*
4170 * Queue the skb and schedule the worker thread.
4171 */
4172 skb_queue_tail(&rxq, skb);
4173 queue_work(workq, &skb_work);
4174 return 0;
4175}
4176
4177static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4178{
4179 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4180
4181 if (rpl->status != CPL_ERR_NONE) {
4182 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4183 "for tid %u\n", rpl->status, GET_TID(rpl));
4184 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004185 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004186 return 0;
4187}
4188
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004189static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4190{
4191 struct cpl_fw6_msg *rpl = cplhdr(skb);
4192 struct c4iw_wr_wait *wr_waitp;
4193 int ret;
4194
4195 PDBG("%s type %u\n", __func__, rpl->type);
4196
4197 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004198 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004199 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004200 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004201 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004202 if (wr_waitp)
4203 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004204 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004205 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004206 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004207 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004208 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004209 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004210 default:
4211 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4212 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004213 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004214 break;
4215 }
4216 return 0;
4217}
4218
Steve Wise8da7e7a2011-06-14 20:59:27 +00004219static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4220{
4221 struct cpl_abort_req_rss *req = cplhdr(skb);
4222 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004223 unsigned int tid = GET_TID(req);
4224
Hariprasad S944661d2016-05-06 22:18:03 +05304225 ep = get_ep_from_tid(dev, tid);
4226 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004227 if (!ep) {
4228 printk(KERN_WARNING MOD
4229 "Abort on non-existent endpoint, tid %d\n", tid);
4230 kfree_skb(skb);
4231 return 0;
4232 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304233 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304234 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4235 __func__, ep->hwtid, req->status,
4236 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304237 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004238 }
4239 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4240 ep->com.state);
4241
4242 /*
4243 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004244 * However, if we are on MPAv2 and want to retry with MPAv1
4245 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004246 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004247 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4248 if (ep->com.state != MPA_REQ_SENT)
4249 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4250 } else
4251 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304252out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004253 sched(dev, skb);
4254 return 0;
4255}
4256
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004257/*
4258 * Most upcalls from the T4 Core go to sched() to
4259 * schedule the processing on a work queue.
4260 */
4261c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4262 [CPL_ACT_ESTABLISH] = sched,
4263 [CPL_ACT_OPEN_RPL] = sched,
4264 [CPL_RX_DATA] = sched,
4265 [CPL_ABORT_RPL_RSS] = sched,
4266 [CPL_ABORT_RPL] = sched,
4267 [CPL_PASS_OPEN_RPL] = sched,
4268 [CPL_CLOSE_LISTSRV_RPL] = sched,
4269 [CPL_PASS_ACCEPT_REQ] = sched,
4270 [CPL_PASS_ESTABLISH] = sched,
4271 [CPL_PEER_CLOSE] = sched,
4272 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004273 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004274 [CPL_RDMA_TERMINATE] = sched,
4275 [CPL_FW4_ACK] = sched,
4276 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004277 [CPL_FW6_MSG] = fw6_msg,
4278 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004279};
4280
Steve Wisecfdda9d2010-04-21 15:30:06 -07004281int __init c4iw_cm_init(void)
4282{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004283 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004284 skb_queue_head_init(&rxq);
4285
4286 workq = create_singlethread_workqueue("iw_cxgb4");
4287 if (!workq)
4288 return -ENOMEM;
4289
Steve Wisecfdda9d2010-04-21 15:30:06 -07004290 return 0;
4291}
4292
Steve Wise46c13762014-06-20 14:26:25 -05004293void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004294{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004295 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004296 flush_workqueue(workq);
4297 destroy_workqueue(workq);
4298}