blob: 5621270664f4949bca4a7153402145f597ff39b2 [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);
Steve Wise37eb8162016-09-01 06:44:52 -0700317 if (idr_is_empty(&ep->com.dev->hwtid_idr))
318 wake_up(&ep->com.dev->wait);
Hariprasad S944661d2016-05-06 22:18:03 +0530319 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
320}
321
322static void insert_ep_tid(struct c4iw_ep *ep)
323{
324 unsigned long flags;
325
326 spin_lock_irqsave(&ep->com.dev->lock, flags);
327 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
328 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
329}
330
331/*
332 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
333 */
334static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
335{
336 struct c4iw_ep *ep;
337 unsigned long flags;
338
339 spin_lock_irqsave(&dev->lock, flags);
340 ep = idr_find(&dev->hwtid_idr, tid);
341 if (ep)
342 c4iw_get_ep(&ep->com);
343 spin_unlock_irqrestore(&dev->lock, flags);
344 return ep;
345}
346
Hariprasad Sf86fac72016-05-06 22:18:07 +0530347/*
348 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
349 */
350static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
351 unsigned int stid)
352{
353 struct c4iw_listen_ep *ep;
354 unsigned long flags;
355
356 spin_lock_irqsave(&dev->lock, flags);
357 ep = idr_find(&dev->stid_idr, stid);
358 if (ep)
359 c4iw_get_ep(&ep->com);
360 spin_unlock_irqrestore(&dev->lock, flags);
361 return ep;
362}
363
Steve Wisecfdda9d2010-04-21 15:30:06 -0700364void _c4iw_free_ep(struct kref *kref)
365{
366 struct c4iw_ep *ep;
367
368 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530369 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000370 if (test_bit(QP_REFERENCED, &ep->com.flags))
371 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700372 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530373 if (ep->com.remote_addr.ss_family == AF_INET6) {
374 struct sockaddr_in6 *sin6 =
375 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600376 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530377
378 cxgb4_clip_release(
379 ep->com.dev->rdev.lldi.ports[0],
380 (const u32 *)&sin6->sin6_addr.s6_addr,
381 1);
382 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700383 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
384 dst_release(ep->dst);
385 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530386 if (ep->mpa_skb)
387 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700388 }
389 kfree(ep);
390}
391
392static void release_ep_resources(struct c4iw_ep *ep)
393{
394 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530395
396 /*
397 * If we have a hwtid, then remove it from the idr table
398 * so lookups will no longer find this endpoint. Otherwise
399 * we have a race where one thread finds the ep ptr just
400 * before the other thread is freeing the ep memory.
401 */
402 if (ep->hwtid != -1)
403 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700404 c4iw_put_ep(&ep->com);
405}
406
Steve Wisecfdda9d2010-04-21 15:30:06 -0700407static int status2errno(int status)
408{
409 switch (status) {
410 case CPL_ERR_NONE:
411 return 0;
412 case CPL_ERR_CONN_RESET:
413 return -ECONNRESET;
414 case CPL_ERR_ARP_MISS:
415 return -EHOSTUNREACH;
416 case CPL_ERR_CONN_TIMEDOUT:
417 return -ETIMEDOUT;
418 case CPL_ERR_TCAM_FULL:
419 return -ENOMEM;
420 case CPL_ERR_CONN_EXIST:
421 return -EADDRINUSE;
422 default:
423 return -EIO;
424 }
425}
426
427/*
428 * Try and reuse skbs already allocated...
429 */
430static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
431{
432 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
433 skb_trim(skb, 0);
434 skb_get(skb);
435 skb_reset_transport_header(skb);
436 } else {
437 skb = alloc_skb(len, gfp);
438 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530439 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700440 return skb;
441}
442
Vipul Pandya830662f2013-07-04 16:10:47 +0530443static struct net_device *get_real_dev(struct net_device *egress_dev)
444{
Steve Wise11b8e222014-05-16 12:42:46 -0500445 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530446}
447
448static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
449{
450 int i;
451
452 egress_dev = get_real_dev(egress_dev);
453 for (i = 0; i < dev->rdev.lldi.nports; i++)
454 if (dev->rdev.lldi.ports[i] == egress_dev)
455 return 1;
456 return 0;
457}
458
459static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
460 __u8 *peer_ip, __be16 local_port,
461 __be16 peer_port, u8 tos,
462 __u32 sin6_scope_id)
463{
464 struct dst_entry *dst = NULL;
465
466 if (IS_ENABLED(CONFIG_IPV6)) {
467 struct flowi6 fl6;
468
469 memset(&fl6, 0, sizeof(fl6));
470 memcpy(&fl6.daddr, peer_ip, 16);
471 memcpy(&fl6.saddr, local_ip, 16);
472 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
473 fl6.flowi6_oif = sin6_scope_id;
474 dst = ip6_route_output(&init_net, NULL, &fl6);
475 if (!dst)
476 goto out;
477 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
478 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
479 dst_release(dst);
480 dst = NULL;
481 }
482 }
483
484out:
485 return dst;
486}
487
488static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700489 __be32 peer_ip, __be16 local_port,
490 __be16 peer_port, u8 tos)
491{
492 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700493 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530494 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700495
David S. Miller31e4543d2011-05-03 20:25:42 -0700496 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500497 peer_port, local_port, IPPROTO_TCP,
498 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800499 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700500 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530501 n = dst_neigh_lookup(&rt->dst, &peer_ip);
502 if (!n)
503 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530504 if (!our_interface(dev, n->dev) &&
505 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530506 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530507 dst_release(&rt->dst);
508 return NULL;
509 }
510 neigh_release(n);
511 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700512}
513
514static void arp_failure_discard(void *handle, struct sk_buff *skb)
515{
Hariprasad S9dec9002016-05-05 01:27:29 +0530516 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700517 kfree_skb(skb);
518}
519
Hariprasad S64bec742016-05-06 22:18:10 +0530520static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
521{
522 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
523}
524
Hariprasad S9dec9002016-05-05 01:27:29 +0530525enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530526 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530527 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530528 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530529};
530
531static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
532{
533 struct c4iw_ep *ep;
534
535 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
536 release_ep_resources(ep);
537 return 0;
538}
539
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530540static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
541{
542 struct c4iw_ep *ep;
543
544 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
545 c4iw_put_ep(&ep->parent_ep->com);
546 release_ep_resources(ep);
547 return 0;
548}
549
Hariprasad S9dec9002016-05-05 01:27:29 +0530550/*
551 * Fake up a special CPL opcode and call sched() so process_work() will call
552 * _put_ep_safe() in a safe context to free the ep resources. This is needed
553 * because ARP error handlers are called in an ATOMIC context, and
554 * _c4iw_free_ep() needs to block.
555 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530556static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
557 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530558{
559 struct cpl_act_establish *rpl = cplhdr(skb);
560
561 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530562 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530563
564 /*
565 * Save ep in the skb->cb area, after where sched() will save the dev
566 * ptr.
567 */
568 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
569 sched(ep->com.dev, skb);
570}
571
572/* Handle an ARP failure for an accept */
573static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
574{
575 struct c4iw_ep *ep = handle;
576
577 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
578 ep->hwtid);
579
580 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530581 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530582}
583
Steve Wisecfdda9d2010-04-21 15:30:06 -0700584/*
585 * Handle an ARP failure for an active open.
586 */
587static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
588{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530589 struct c4iw_ep *ep = handle;
590
Masanari Iidae3d132d2015-10-16 21:14:29 +0900591 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530592 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530593 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530594 if (ep->com.remote_addr.ss_family == AF_INET6) {
595 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600596 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530597 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
598 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
599 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530600 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
601 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530602 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700603}
604
605/*
606 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
607 * and send it along.
608 */
609static void abort_arp_failure(void *handle, struct sk_buff *skb)
610{
Hariprasad S761e19a2016-05-06 22:18:02 +0530611 int ret;
612 struct c4iw_ep *ep = handle;
613 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700614 struct cpl_abort_req *req = cplhdr(skb);
615
616 PDBG("%s rdev %p\n", __func__, rdev);
617 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530618 ret = c4iw_ofld_send(rdev, skb);
619 if (ret) {
620 __state_set(&ep->com, DEAD);
621 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
622 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700623}
624
Hariprasad Sfef44222016-05-05 01:27:33 +0530625static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700626{
627 unsigned int flowclen = 80;
628 struct fw_flowc_wr *flowc;
629 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530630 u16 vlan = ep->l2t->vlan;
631 int nparams;
632
633 if (vlan == CPL_L2T_VLAN_NONE)
634 nparams = 8;
635 else
636 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700637
638 skb = get_skb(skb, flowclen, GFP_KERNEL);
639 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
640
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530641 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530642 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530643 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
644 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645
646 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530647 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530648 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700649 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
650 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
651 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
652 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
653 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
654 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
655 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
656 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
657 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
658 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
659 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530660 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
662 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530663 if (nparams == 9) {
664 u16 pri;
665
666 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
667 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
668 flowc->mnemval[8].val = cpu_to_be32(pri);
669 } else {
670 /* Pad WR to 16 byte boundary */
671 flowc->mnemval[8].mnemonic = 0;
672 flowc->mnemval[8].val = 0;
673 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700674 for (i = 0; i < 9; i++) {
675 flowc->mnemval[i].r4[0] = 0;
676 flowc->mnemval[i].r4[1] = 0;
677 flowc->mnemval[i].r4[2] = 0;
678 }
679
680 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530681 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700682}
683
684static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
685{
686 struct cpl_close_con_req *req;
687 struct sk_buff *skb;
688 int wrlen = roundup(sizeof *req, 16);
689
690 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
691 skb = get_skb(NULL, wrlen, gfp);
692 if (!skb) {
693 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
694 return -ENOMEM;
695 }
696 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
697 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
698 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
699 memset(req, 0, wrlen);
700 INIT_TP_WR(req, ep->hwtid);
701 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
702 ep->hwtid));
703 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
704}
705
706static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
707{
708 struct cpl_abort_req *req;
709 int wrlen = roundup(sizeof *req, 16);
710
711 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
712 skb = get_skb(skb, wrlen, gfp);
713 if (!skb) {
714 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
715 __func__);
716 return -ENOMEM;
717 }
718 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530719 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700720 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
721 memset(req, 0, wrlen);
722 INIT_TP_WR(req, ep->hwtid);
723 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
724 req->cmd = CPL_ABORT_SEND_RST;
725 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
726}
727
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530728static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530729 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530730{
Hariprasad S04524a42014-09-24 03:53:41 +0530731 unsigned short hdr_size = (ipv6 ?
732 sizeof(struct ipv6hdr) :
733 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530734 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530735 (use_ts ?
736 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530737 unsigned short data_size = mtu - hdr_size;
738
739 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
740}
741
Steve Wisecfdda9d2010-04-21 15:30:06 -0700742static int send_connect(struct c4iw_ep *ep)
743{
Hariprasad S963cab52015-09-23 17:19:27 +0530744 struct cpl_act_open_req *req = NULL;
745 struct cpl_t5_act_open_req *t5req = NULL;
746 struct cpl_t6_act_open_req *t6req = NULL;
747 struct cpl_act_open_req6 *req6 = NULL;
748 struct cpl_t5_act_open_req6 *t5req6 = NULL;
749 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700750 struct sk_buff *skb;
751 u64 opt0;
752 u32 opt2;
753 unsigned int mtu_idx;
754 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530755 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500756 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600757 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500758 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600759 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500760 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600761 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500762 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600763 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530764 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530765 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
766 u32 isn = (prandom_u32() & ~7UL) - 1;
767
768 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
769 case CHELSIO_T4:
770 sizev4 = sizeof(struct cpl_act_open_req);
771 sizev6 = sizeof(struct cpl_act_open_req6);
772 break;
773 case CHELSIO_T5:
774 sizev4 = sizeof(struct cpl_t5_act_open_req);
775 sizev6 = sizeof(struct cpl_t5_act_open_req6);
776 break;
777 case CHELSIO_T6:
778 sizev4 = sizeof(struct cpl_t6_act_open_req);
779 sizev6 = sizeof(struct cpl_t6_act_open_req6);
780 break;
781 default:
782 pr_err("T%d Chip is not supported\n",
783 CHELSIO_CHIP_VERSION(adapter_type));
784 return -EINVAL;
785 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530786
787 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
788 roundup(sizev4, 16) :
789 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700790
791 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
792
793 skb = get_skb(NULL, wrlen, GFP_KERNEL);
794 if (!skb) {
795 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
796 __func__);
797 return -ENOMEM;
798 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000799 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700800
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530801 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530802 enable_tcp_timestamps,
803 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700804 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530805
806 /*
807 * Specify the largest window that will fit in opt0. The
808 * remainder will be specified in the rx_data_ack.
809 */
810 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800811 if (win > RCV_BUFSIZ_M)
812 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530813
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800814 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800815 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800816 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800817 WND_SCALE_V(wscale) |
818 MSS_IDX_V(mtu_idx) |
819 L2T_IDX_V(ep->l2t->idx) |
820 TX_CHAN_V(ep->tx_chan) |
821 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530822 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800823 ULP_MODE_V(ULP_MODE_TCPDDP) |
824 RCV_BUFSIZ_V(win);
825 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800826 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800827 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700828 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800829 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700830 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800831 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700832 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800833 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530834 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
835 if (peer2peer)
836 isn += 4;
837
Anish Bhattd7990b02014-11-12 17:15:57 -0800838 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530839 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530840 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500841 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530842
843 if (ep->com.remote_addr.ss_family == AF_INET6)
844 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
845 (const u32 *)&la6->sin6_addr.s6_addr, 1);
846
Hariprasad S5dab6d32014-06-23 19:12:36 +0530847 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700848
Hariprasad S963cab52015-09-23 17:19:27 +0530849 if (ep->com.remote_addr.ss_family == AF_INET) {
850 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
851 case CHELSIO_T4:
852 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530853 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530854 break;
855 case CHELSIO_T5:
856 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
857 wrlen);
858 INIT_TP_WR(t5req, 0);
859 req = (struct cpl_act_open_req *)t5req;
860 break;
861 case CHELSIO_T6:
862 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
863 wrlen);
864 INIT_TP_WR(t6req, 0);
865 req = (struct cpl_act_open_req *)t6req;
866 t5req = (struct cpl_t5_act_open_req *)t6req;
867 break;
868 default:
869 pr_err("T%d Chip is not supported\n",
870 CHELSIO_CHIP_VERSION(adapter_type));
871 ret = -EINVAL;
872 goto clip_release;
873 }
874
875 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
876 ((ep->rss_qid<<14) | ep->atid)));
877 req->local_port = la->sin_port;
878 req->peer_port = ra->sin_port;
879 req->local_ip = la->sin_addr.s_addr;
880 req->peer_ip = ra->sin_addr.s_addr;
881 req->opt0 = cpu_to_be64(opt0);
882
883 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530884 req->params = cpu_to_be32(cxgb4_select_ntuple(
885 ep->com.dev->rdev.lldi.ports[0],
886 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530887 req->opt2 = cpu_to_be32(opt2);
888 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530889 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
890 cxgb4_select_ntuple(
891 ep->com.dev->rdev.lldi.ports[0],
892 ep->l2t)));
893 t5req->rsvd = cpu_to_be32(isn);
894 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
895 t5req->opt2 = cpu_to_be32(opt2);
896 }
897 } else {
898 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
899 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530900 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530901 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530902 break;
903 case CHELSIO_T5:
904 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
905 wrlen);
906 INIT_TP_WR(t5req6, 0);
907 req6 = (struct cpl_act_open_req6 *)t5req6;
908 break;
909 case CHELSIO_T6:
910 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
911 wrlen);
912 INIT_TP_WR(t6req6, 0);
913 req6 = (struct cpl_act_open_req6 *)t6req6;
914 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
915 break;
916 default:
917 pr_err("T%d Chip is not supported\n",
918 CHELSIO_CHIP_VERSION(adapter_type));
919 ret = -EINVAL;
920 goto clip_release;
921 }
922
923 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
924 ((ep->rss_qid<<14)|ep->atid)));
925 req6->local_port = la6->sin6_port;
926 req6->peer_port = ra6->sin6_port;
927 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
928 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
929 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
930 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
931 req6->opt0 = cpu_to_be64(opt0);
932
933 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530934 req6->params = cpu_to_be32(cxgb4_select_ntuple(
935 ep->com.dev->rdev.lldi.ports[0],
936 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530937 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530938 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530939 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
940 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530941 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530942 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530943 t5req6->rsvd = cpu_to_be32(isn);
944 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
945 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530946 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000947 }
948
Vipul Pandya793dad92012-12-10 09:30:56 +0000949 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530950 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530951clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530952 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
953 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
954 (const u32 *)&la6->sin6_addr.s6_addr, 1);
955 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700956}
957
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530958static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
959 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700960{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530961 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700962 struct fw_ofld_tx_data_wr *req;
963 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530964 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700965
966 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
967
968 BUG_ON(skb_cloned(skb));
969
970 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530971 if (mpa_rev_to_use == 2)
972 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700973 wrlen = roundup(mpalen + sizeof *req, 16);
974 skb = get_skb(skb, wrlen, GFP_KERNEL);
975 if (!skb) {
976 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530977 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978 }
979 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
980
981 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
982 memset(req, 0, wrlen);
983 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530984 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
985 FW_WR_COMPL_F |
986 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700987 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530988 FW_WR_FLOWID_V(ep->hwtid) |
989 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700990 req->plen = cpu_to_be32(mpalen);
991 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530992 FW_OFLD_TX_DATA_WR_FLUSH_F |
993 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994
995 mpa = (struct mpa_message *)(req + 1);
996 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
997 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530998 (markers_enabled ? MPA_MARKERS : 0) |
999 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001000 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301001 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301002 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301003 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301004 ep->retry_with_mpa_v1 = 0;
1005 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001006
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301007 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001008 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1009 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301010 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1011 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301012 mpa_v2_params.ird = htons((u16)ep->ird);
1013 mpa_v2_params.ord = htons((u16)ep->ord);
1014
1015 if (peer2peer) {
1016 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1017 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1018 mpa_v2_params.ord |=
1019 htons(MPA_V2_RDMA_WRITE_RTR);
1020 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1021 mpa_v2_params.ord |=
1022 htons(MPA_V2_RDMA_READ_RTR);
1023 }
1024 memcpy(mpa->private_data, &mpa_v2_params,
1025 sizeof(struct mpa_v2_conn_params));
1026
1027 if (ep->plen)
1028 memcpy(mpa->private_data +
1029 sizeof(struct mpa_v2_conn_params),
1030 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1031 } else
1032 if (ep->plen)
1033 memcpy(mpa->private_data,
1034 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001035
1036 /*
1037 * Reference the mpa skb. This ensures the data area
1038 * will remain in memory until the hw acks the tx.
1039 * Function fw4_ack() will deref it.
1040 */
1041 skb_get(skb);
1042 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1043 BUG_ON(ep->mpa_skb);
1044 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301045 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1046 if (ret)
1047 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001048 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301049 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001050 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301051 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301052 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001053}
1054
1055static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1056{
1057 int mpalen, wrlen;
1058 struct fw_ofld_tx_data_wr *req;
1059 struct mpa_message *mpa;
1060 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301061 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001062
1063 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1064
1065 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301066 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1067 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001068 wrlen = roundup(mpalen + sizeof *req, 16);
1069
1070 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1071 if (!skb) {
1072 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1073 return -ENOMEM;
1074 }
1075 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1076
1077 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1078 memset(req, 0, wrlen);
1079 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301080 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1081 FW_WR_COMPL_F |
1082 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001083 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301084 FW_WR_FLOWID_V(ep->hwtid) |
1085 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001086 req->plen = cpu_to_be32(mpalen);
1087 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301088 FW_OFLD_TX_DATA_WR_FLUSH_F |
1089 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001090
1091 mpa = (struct mpa_message *)(req + 1);
1092 memset(mpa, 0, sizeof(*mpa));
1093 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1094 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001095 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001096 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301097
1098 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1099 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001100 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1101 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301102 mpa_v2_params.ird = htons(((u16)ep->ird) |
1103 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1104 0));
1105 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1106 (p2p_type ==
1107 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1108 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1109 FW_RI_INIT_P2PTYPE_READ_REQ ?
1110 MPA_V2_RDMA_READ_RTR : 0) : 0));
1111 memcpy(mpa->private_data, &mpa_v2_params,
1112 sizeof(struct mpa_v2_conn_params));
1113
1114 if (ep->plen)
1115 memcpy(mpa->private_data +
1116 sizeof(struct mpa_v2_conn_params), pdata, plen);
1117 } else
1118 if (plen)
1119 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001120
1121 /*
1122 * Reference the mpa skb again. This ensures the data area
1123 * will remain in memory until the hw acks the tx.
1124 * Function fw4_ack() will deref it.
1125 */
1126 skb_get(skb);
1127 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301128 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001129 BUG_ON(ep->mpa_skb);
1130 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301131 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001132 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1133}
1134
1135static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1136{
1137 int mpalen, wrlen;
1138 struct fw_ofld_tx_data_wr *req;
1139 struct mpa_message *mpa;
1140 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301141 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001142
1143 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1144
1145 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301146 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1147 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001148 wrlen = roundup(mpalen + sizeof *req, 16);
1149
1150 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1151 if (!skb) {
1152 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1153 return -ENOMEM;
1154 }
1155 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1156
1157 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1158 memset(req, 0, wrlen);
1159 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301160 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1161 FW_WR_COMPL_F |
1162 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001163 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301164 FW_WR_FLOWID_V(ep->hwtid) |
1165 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001166 req->plen = cpu_to_be32(mpalen);
1167 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301168 FW_OFLD_TX_DATA_WR_FLUSH_F |
1169 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001170
1171 mpa = (struct mpa_message *)(req + 1);
1172 memset(mpa, 0, sizeof(*mpa));
1173 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1174 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1175 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301176 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301178
1179 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1180 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001181 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1182 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301183 mpa_v2_params.ird = htons((u16)ep->ird);
1184 mpa_v2_params.ord = htons((u16)ep->ord);
1185 if (peer2peer && (ep->mpa_attr.p2p_type !=
1186 FW_RI_INIT_P2PTYPE_DISABLED)) {
1187 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1188
1189 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1190 mpa_v2_params.ord |=
1191 htons(MPA_V2_RDMA_WRITE_RTR);
1192 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1193 mpa_v2_params.ord |=
1194 htons(MPA_V2_RDMA_READ_RTR);
1195 }
1196
1197 memcpy(mpa->private_data, &mpa_v2_params,
1198 sizeof(struct mpa_v2_conn_params));
1199
1200 if (ep->plen)
1201 memcpy(mpa->private_data +
1202 sizeof(struct mpa_v2_conn_params), pdata, plen);
1203 } else
1204 if (plen)
1205 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206
1207 /*
1208 * Reference the mpa skb. This ensures the data area
1209 * will remain in memory until the hw acks the tx.
1210 * Function fw4_ack() will deref it.
1211 */
1212 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301213 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001214 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301215 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301216 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001217 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1218}
1219
1220static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1221{
1222 struct c4iw_ep *ep;
1223 struct cpl_act_establish *req = cplhdr(skb);
1224 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001225 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001226 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301227 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001228
1229 ep = lookup_atid(t, atid);
1230
1231 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1232 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1233
Steve Wisea7db89e2014-03-21 20:40:35 +05301234 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235 dst_confirm(ep->dst);
1236
1237 /* setup the hwtid for this connection */
1238 ep->hwtid = tid;
1239 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301240 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001241
1242 ep->snd_seq = be32_to_cpu(req->snd_isn);
1243 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1244
1245 set_emss(ep, ntohs(req->tcp_opt));
1246
1247 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001248 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001249 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001250 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251
1252 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301253 ret = send_flowc(ep, NULL);
1254 if (ret)
1255 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301256 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301257 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301258 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301259 ret = send_mpa_req(ep, skb, mpa_rev);
1260 if (ret)
1261 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301262 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001263 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301264err:
1265 mutex_unlock(&ep->com.mutex);
1266 connect_reply_upcall(ep, -ENOMEM);
1267 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1268 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001269}
1270
Steve Wisebe13b2d2014-03-21 20:40:33 +05301271static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001272{
1273 struct iw_cm_event event;
1274
1275 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1276 memset(&event, 0, sizeof(event));
1277 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301278 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001279 if (ep->com.cm_id) {
1280 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1281 ep, ep->com.cm_id, ep->hwtid);
1282 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301283 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001284 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001285 }
1286}
1287
Steve Wisecfdda9d2010-04-21 15:30:06 -07001288static void peer_close_upcall(struct c4iw_ep *ep)
1289{
1290 struct iw_cm_event event;
1291
1292 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1293 memset(&event, 0, sizeof(event));
1294 event.event = IW_CM_EVENT_DISCONNECT;
1295 if (ep->com.cm_id) {
1296 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1297 ep, ep->com.cm_id, ep->hwtid);
1298 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001299 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300 }
1301}
1302
1303static void peer_abort_upcall(struct c4iw_ep *ep)
1304{
1305 struct iw_cm_event event;
1306
1307 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1308 memset(&event, 0, sizeof(event));
1309 event.event = IW_CM_EVENT_CLOSE;
1310 event.status = -ECONNRESET;
1311 if (ep->com.cm_id) {
1312 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1313 ep->com.cm_id, ep->hwtid);
1314 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301315 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001316 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001317 }
1318}
1319
1320static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1321{
1322 struct iw_cm_event event;
1323
1324 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1325 memset(&event, 0, sizeof(event));
1326 event.event = IW_CM_EVENT_CONNECT_REPLY;
1327 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301328 memcpy(&event.local_addr, &ep->com.local_addr,
1329 sizeof(ep->com.local_addr));
1330 memcpy(&event.remote_addr, &ep->com.remote_addr,
1331 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001332
1333 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301334 if (!ep->tried_with_mpa_v1) {
1335 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301336 event.ord = ep->ird;
1337 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301338 event.private_data_len = ep->plen -
1339 sizeof(struct mpa_v2_conn_params);
1340 event.private_data = ep->mpa_pkt +
1341 sizeof(struct mpa_message) +
1342 sizeof(struct mpa_v2_conn_params);
1343 } else {
1344 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301345 event.ord = cur_max_read_depth(ep->com.dev);
1346 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301347 event.private_data_len = ep->plen;
1348 event.private_data = ep->mpa_pkt +
1349 sizeof(struct mpa_message);
1350 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001351 }
Roland Dreier85963e42010-07-19 13:13:09 -07001352
1353 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1354 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001355 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001356 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1357
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301358 if (status < 0)
1359 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360}
1361
Steve Wisebe13b2d2014-03-21 20:40:33 +05301362static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001363{
1364 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301365 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001366
1367 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1368 memset(&event, 0, sizeof(event));
1369 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301370 memcpy(&event.local_addr, &ep->com.local_addr,
1371 sizeof(ep->com.local_addr));
1372 memcpy(&event.remote_addr, &ep->com.remote_addr,
1373 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001374 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301375 if (!ep->tried_with_mpa_v1) {
1376 /* this means MPA_v2 is used */
1377 event.ord = ep->ord;
1378 event.ird = ep->ird;
1379 event.private_data_len = ep->plen -
1380 sizeof(struct mpa_v2_conn_params);
1381 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1382 sizeof(struct mpa_v2_conn_params);
1383 } else {
1384 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301385 event.ord = cur_max_read_depth(ep->com.dev);
1386 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301387 event.private_data_len = ep->plen;
1388 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1389 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301390 c4iw_get_ep(&ep->com);
1391 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1392 &event);
1393 if (ret)
1394 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001395 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001396 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301397 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001398}
1399
1400static void established_upcall(struct c4iw_ep *ep)
1401{
1402 struct iw_cm_event event;
1403
1404 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1405 memset(&event, 0, sizeof(event));
1406 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301407 event.ird = ep->ord;
1408 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 if (ep->com.cm_id) {
1410 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1411 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001412 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001413 }
1414}
1415
1416static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1417{
1418 struct cpl_rx_data_ack *req;
1419 struct sk_buff *skb;
1420 int wrlen = roundup(sizeof *req, 16);
1421
1422 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1423 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1424 if (!skb) {
1425 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1426 return 0;
1427 }
1428
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301429 /*
1430 * If we couldn't specify the entire rcv window at connection setup
1431 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1432 * then add the overage in to the credits returned.
1433 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001434 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1435 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301436
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1438 memset(req, 0, wrlen);
1439 INIT_TP_WR(req, ep->hwtid);
1440 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1441 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001442 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301443 RX_DACK_CHANGE_F |
1444 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001445 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001446 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1447 return credits;
1448}
1449
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301450#define RELAXED_IRD_NEGOTIATION 1
1451
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301452/*
1453 * process_mpa_reply - process streaming mode MPA reply
1454 *
1455 * Returns:
1456 *
1457 * 0 upon success indicating a connect request was delivered to the ULP
1458 * or the mpa request is incomplete but valid so far.
1459 *
1460 * 1 if a failure requires the caller to close the connection.
1461 *
1462 * 2 if a failure requires the caller to abort the connection.
1463 */
Steve Wisecc18b932014-04-24 14:31:53 -05001464static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001465{
1466 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301467 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001468 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301469 u16 resp_ird, resp_ord;
1470 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001471 struct c4iw_qp_attributes attrs;
1472 enum c4iw_qp_attr_mask mask;
1473 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001474 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001475
1476 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1477
1478 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001479 * If we get more than the supported amount of private data
1480 * then we must fail this connection.
1481 */
1482 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1483 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301484 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001485 }
1486
1487 /*
1488 * copy the new data into our accumulation buffer.
1489 */
1490 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1491 skb->len);
1492 ep->mpa_pkt_len += skb->len;
1493
1494 /*
1495 * if we don't even have the mpa message, then bail.
1496 */
1497 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001498 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001499 mpa = (struct mpa_message *) ep->mpa_pkt;
1500
1501 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301502 if (mpa->revision > mpa_rev) {
1503 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1504 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301506 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001507 }
1508 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1509 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301510 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001511 }
1512
1513 plen = ntohs(mpa->private_data_size);
1514
1515 /*
1516 * Fail if there's too much private data.
1517 */
1518 if (plen > MPA_MAX_PRIVATE_DATA) {
1519 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301520 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001521 }
1522
1523 /*
1524 * If plen does not account for pkt size
1525 */
1526 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1527 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301528 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001529 }
1530
1531 ep->plen = (u8) plen;
1532
1533 /*
1534 * If we don't have all the pdata yet, then bail.
1535 * We'll continue process when more data arrives.
1536 */
1537 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001538 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001539
1540 if (mpa->flags & MPA_REJECT) {
1541 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301542 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001543 }
1544
1545 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301546 * Stop mpa timer. If it expired, then
1547 * we ignore the MPA reply. process_timeout()
1548 * will abort the connection.
1549 */
1550 if (stop_ep_timer(ep))
1551 return 0;
1552
1553 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001554 * If we get here we have accumulated the entire mpa
1555 * start reply message including private data. And
1556 * the MPA header is valid.
1557 */
Steve Wisec529fb52014-03-21 20:40:37 +05301558 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001559 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1560 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1561 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301562 ep->mpa_attr.version = mpa->revision;
1563 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1564
1565 if (mpa->revision == 2) {
1566 ep->mpa_attr.enhanced_rdma_conn =
1567 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1568 if (ep->mpa_attr.enhanced_rdma_conn) {
1569 mpa_v2_params = (struct mpa_v2_conn_params *)
1570 (ep->mpa_pkt + sizeof(*mpa));
1571 resp_ird = ntohs(mpa_v2_params->ird) &
1572 MPA_V2_IRD_ORD_MASK;
1573 resp_ord = ntohs(mpa_v2_params->ord) &
1574 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301575 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1576 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301577
1578 /*
1579 * This is a double-check. Ideally, below checks are
1580 * not required since ird/ord stuff has been taken
1581 * care of in c4iw_accept_cr
1582 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301583 if (ep->ird < resp_ord) {
1584 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1585 ep->com.dev->rdev.lldi.max_ordird_qp)
1586 ep->ird = resp_ord;
1587 else
1588 insuff_ird = 1;
1589 } else if (ep->ird > resp_ord) {
1590 ep->ird = resp_ord;
1591 }
1592 if (ep->ord > resp_ird) {
1593 if (RELAXED_IRD_NEGOTIATION)
1594 ep->ord = resp_ird;
1595 else
1596 insuff_ird = 1;
1597 }
1598 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301599 err = -ENOMEM;
1600 ep->ird = resp_ord;
1601 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301602 }
1603
1604 if (ntohs(mpa_v2_params->ird) &
1605 MPA_V2_PEER2PEER_MODEL) {
1606 if (ntohs(mpa_v2_params->ord) &
1607 MPA_V2_RDMA_WRITE_RTR)
1608 ep->mpa_attr.p2p_type =
1609 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1610 else if (ntohs(mpa_v2_params->ord) &
1611 MPA_V2_RDMA_READ_RTR)
1612 ep->mpa_attr.p2p_type =
1613 FW_RI_INIT_P2PTYPE_READ_REQ;
1614 }
1615 }
1616 } else if (mpa->revision == 1)
1617 if (peer2peer)
1618 ep->mpa_attr.p2p_type = p2p_type;
1619
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301621 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1622 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1623 ep->mpa_attr.recv_marker_enabled,
1624 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1625 ep->mpa_attr.p2p_type, p2p_type);
1626
1627 /*
1628 * If responder's RTR does not match with that of initiator, assign
1629 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1630 * generated when moving QP to RTS state.
1631 * A TERM message will be sent after QP has moved to RTS state
1632 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001633 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301634 (ep->mpa_attr.p2p_type != p2p_type)) {
1635 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1636 rtr_mismatch = 1;
1637 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638
1639 attrs.mpa_attr = ep->mpa_attr;
1640 attrs.max_ird = ep->ird;
1641 attrs.max_ord = ep->ord;
1642 attrs.llp_stream_handle = ep;
1643 attrs.next_state = C4IW_QP_STATE_RTS;
1644
1645 mask = C4IW_QP_ATTR_NEXT_STATE |
1646 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1647 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1648
1649 /* bind QP and TID with INIT_WR */
1650 err = c4iw_modify_qp(ep->com.qp->rhp,
1651 ep->com.qp, mask, &attrs, 1);
1652 if (err)
1653 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301654
1655 /*
1656 * If responder's RTR requirement did not match with what initiator
1657 * supports, generate TERM message
1658 */
1659 if (rtr_mismatch) {
1660 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1661 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1662 attrs.ecode = MPA_NOMATCH_RTR;
1663 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001664 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301665 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001666 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301667 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001668 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301669 goto out;
1670 }
1671
1672 /*
1673 * Generate TERM if initiator IRD is not sufficient for responder
1674 * provided ORD. Currently, we do the same behaviour even when
1675 * responder provided IRD is also not sufficient as regards to
1676 * initiator ORD.
1677 */
1678 if (insuff_ird) {
1679 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1680 __func__);
1681 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1682 attrs.ecode = MPA_INSUFF_IRD;
1683 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001684 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301685 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001686 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301687 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001688 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301689 goto out;
1690 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301692err_stop_timer:
1693 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001694err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301695 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696out:
1697 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001698 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001699}
1700
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301701/*
1702 * process_mpa_request - process streaming mode MPA request
1703 *
1704 * Returns:
1705 *
1706 * 0 upon success indicating a connect request was delivered to the ULP
1707 * or the mpa request is incomplete but valid so far.
1708 *
1709 * 1 if a failure requires the caller to close the connection.
1710 *
1711 * 2 if a failure requires the caller to abort the connection.
1712 */
1713static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001714{
1715 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301716 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001717 u16 plen;
1718
1719 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1720
Steve Wisecfdda9d2010-04-21 15:30:06 -07001721 /*
1722 * If we get more than the supported amount of private data
1723 * then we must fail this connection.
1724 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301725 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1726 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727
1728 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1729
1730 /*
1731 * Copy the new data into our accumulation buffer.
1732 */
1733 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1734 skb->len);
1735 ep->mpa_pkt_len += skb->len;
1736
1737 /*
1738 * If we don't even have the mpa message, then bail.
1739 * We'll continue process when more data arrives.
1740 */
1741 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301742 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001743
1744 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001745 mpa = (struct mpa_message *) ep->mpa_pkt;
1746
1747 /*
1748 * Validate MPA Header.
1749 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301750 if (mpa->revision > mpa_rev) {
1751 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1752 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301753 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001754 }
1755
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301756 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1757 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001758
1759 plen = ntohs(mpa->private_data_size);
1760
1761 /*
1762 * Fail if there's too much private data.
1763 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301764 if (plen > MPA_MAX_PRIVATE_DATA)
1765 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001766
1767 /*
1768 * If plen does not account for pkt size
1769 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301770 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1771 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001772 ep->plen = (u8) plen;
1773
1774 /*
1775 * If we don't have all the pdata yet, then bail.
1776 */
1777 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301778 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001779
1780 /*
1781 * If we get here we have accumulated the entire mpa
1782 * start reply message including private data.
1783 */
1784 ep->mpa_attr.initiator = 0;
1785 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1786 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1787 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301788 ep->mpa_attr.version = mpa->revision;
1789 if (mpa->revision == 1)
1790 ep->tried_with_mpa_v1 = 1;
1791 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1792
1793 if (mpa->revision == 2) {
1794 ep->mpa_attr.enhanced_rdma_conn =
1795 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1796 if (ep->mpa_attr.enhanced_rdma_conn) {
1797 mpa_v2_params = (struct mpa_v2_conn_params *)
1798 (ep->mpa_pkt + sizeof(*mpa));
1799 ep->ird = ntohs(mpa_v2_params->ird) &
1800 MPA_V2_IRD_ORD_MASK;
1801 ep->ord = ntohs(mpa_v2_params->ord) &
1802 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301803 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1804 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301805 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1806 if (peer2peer) {
1807 if (ntohs(mpa_v2_params->ord) &
1808 MPA_V2_RDMA_WRITE_RTR)
1809 ep->mpa_attr.p2p_type =
1810 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1811 else if (ntohs(mpa_v2_params->ord) &
1812 MPA_V2_RDMA_READ_RTR)
1813 ep->mpa_attr.p2p_type =
1814 FW_RI_INIT_P2PTYPE_READ_REQ;
1815 }
1816 }
1817 } else if (mpa->revision == 1)
1818 if (peer2peer)
1819 ep->mpa_attr.p2p_type = p2p_type;
1820
Steve Wisecfdda9d2010-04-21 15:30:06 -07001821 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1822 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1823 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1824 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1825 ep->mpa_attr.p2p_type);
1826
Hariprasad Se4b76a22016-05-06 22:17:59 +05301827 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001828
Hariprasad Se4b76a22016-05-06 22:17:59 +05301829 /* drive upcall */
1830 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1831 if (ep->parent_ep->com.state != DEAD) {
1832 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301833 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301834 } else {
1835 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301836 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301837 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301838 return 0;
1839
1840err_unlock_parent:
1841 mutex_unlock(&ep->parent_ep->com.mutex);
1842 goto err_out;
1843err_stop_timer:
1844 (void)stop_ep_timer(ep);
1845err_out:
1846 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001847}
1848
1849static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1850{
1851 struct c4iw_ep *ep;
1852 struct cpl_rx_data *hdr = cplhdr(skb);
1853 unsigned int dlen = ntohs(hdr->len);
1854 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001855 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001856 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001857
Hariprasad S944661d2016-05-06 22:18:03 +05301858 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301859 if (!ep)
1860 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001861 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1862 skb_pull(skb, sizeof(*hdr));
1863 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301864 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001865
Steve Wisecfdda9d2010-04-21 15:30:06 -07001866 /* update RX credits */
1867 update_rx_credits(ep, dlen);
1868
Steve Wisec529fb52014-03-21 20:40:37 +05301869 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001870 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001871 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001872 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873 break;
1874 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001875 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301876 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001877 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001878 case FPDU_MODE: {
1879 struct c4iw_qp_attributes attrs;
1880 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001881 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001882 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001883 " qpid %u ep %p state %d tid %u status %d\n",
1884 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301885 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301886 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001887 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001888 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1889 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001890 break;
1891 }
Vipul Pandya15579672013-01-07 13:11:52 +00001892 default:
1893 break;
1894 }
Steve Wisec529fb52014-03-21 20:40:37 +05301895 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001896 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301897 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301898 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899 return 0;
1900}
1901
1902static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1903{
1904 struct c4iw_ep *ep;
1905 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001906 int release = 0;
1907 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001908
Hariprasad S944661d2016-05-06 22:18:03 +05301909 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301910 if (!ep) {
1911 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1912 return 0;
1913 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001914 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001915 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001916 switch (ep->com.state) {
1917 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001918 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001919 __state_set(&ep->com, DEAD);
1920 release = 1;
1921 break;
1922 default:
1923 printk(KERN_ERR "%s ep %p state %d\n",
1924 __func__, ep, ep->com.state);
1925 break;
1926 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001927 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001928
1929 if (release)
1930 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301931 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001932 return 0;
1933}
1934
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301935static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001936{
1937 struct sk_buff *skb;
1938 struct fw_ofld_connection_wr *req;
1939 unsigned int mtu_idx;
1940 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301941 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301942 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001943
1944 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1945 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1946 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001947 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301948 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301949 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1950 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001951 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001952 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301953 req->le.lport = sin->sin_port;
1954 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001955 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301956 req->le.pport = sin->sin_port;
1957 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001958 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301959 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1960 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001961 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301962 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001963 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001964 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301965 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301966 enable_tcp_timestamps,
1967 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001968 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301969
1970 /*
1971 * Specify the largest window that will fit in opt0. The
1972 * remainder will be specified in the rx_data_ack.
1973 */
1974 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001975 if (win > RCV_BUFSIZ_M)
1976 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301977
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001978 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1979 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001980 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001981 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001982 WND_SCALE_V(wscale) |
1983 MSS_IDX_V(mtu_idx) |
1984 L2T_IDX_V(ep->l2t->idx) |
1985 TX_CHAN_V(ep->tx_chan) |
1986 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301987 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001988 ULP_MODE_V(ULP_MODE_TCPDDP) |
1989 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001990 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1991 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001992 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001993 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001994 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001995 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001996 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001997 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001998 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001999 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002000 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
2001 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2002 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00002003 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2004 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302005 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002006}
2007
Steve Wisecfdda9d2010-04-21 15:30:06 -07002008/*
2009 * Return whether a failed active open has allocated a TID
2010 */
2011static inline int act_open_has_tid(int status)
2012{
2013 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
2014 status != CPL_ERR_ARP_MISS;
2015}
2016
Steve Wise7a2cea22014-03-14 21:52:07 +05302017/* Returns whether a CPL status conveys negative advice.
2018 */
2019static int is_neg_adv(unsigned int status)
2020{
2021 return status == CPL_ERR_RTX_NEG_ADVICE ||
2022 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2023 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2024}
2025
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302026static char *neg_adv_str(unsigned int status)
2027{
2028 switch (status) {
2029 case CPL_ERR_RTX_NEG_ADVICE:
2030 return "Retransmit timeout";
2031 case CPL_ERR_PERSIST_NEG_ADVICE:
2032 return "Persist timeout";
2033 case CPL_ERR_KEEPALV_NEG_ADVICE:
2034 return "Keepalive timeout";
2035 default:
2036 return "Unknown";
2037 }
2038}
2039
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302040static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2041{
2042 ep->snd_win = snd_win;
2043 ep->rcv_win = rcv_win;
2044 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2045}
2046
Vipul Pandya793dad92012-12-10 09:30:56 +00002047#define ACT_OPEN_RETRY_COUNT 2
2048
Vipul Pandya830662f2013-07-04 16:10:47 +05302049static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2050 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302051 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302052{
2053 struct neighbour *n;
2054 int err, step;
2055 struct net_device *pdev;
2056
2057 n = dst_neigh_lookup(dst, peer_ip);
2058 if (!n)
2059 return -ENODEV;
2060
2061 rcu_read_lock();
2062 err = -ENOMEM;
2063 if (n->dev->flags & IFF_LOOPBACK) {
2064 if (iptype == 4)
2065 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2066 else if (IS_ENABLED(CONFIG_IPV6))
2067 for_each_netdev(&init_net, pdev) {
2068 if (ipv6_chk_addr(&init_net,
2069 (struct in6_addr *)peer_ip,
2070 pdev, 1))
2071 break;
2072 }
2073 else
2074 pdev = NULL;
2075
2076 if (!pdev) {
2077 err = -ENODEV;
2078 goto out;
2079 }
2080 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302081 n, pdev, rt_tos2priority(tos));
Steve Wise609e9412016-09-01 06:43:46 -07002082 if (!ep->l2t) {
2083 dev_put(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 goto out;
Steve Wise609e9412016-09-01 06:43:46 -07002085 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302086 ep->mtu = pdev->mtu;
2087 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302088 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2089 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302090 step = cdev->rdev.lldi.ntxq /
2091 cdev->rdev.lldi.nchan;
2092 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2093 step = cdev->rdev.lldi.nrxq /
2094 cdev->rdev.lldi.nchan;
2095 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2096 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2097 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302098 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302099 dev_put(pdev);
2100 } else {
2101 pdev = get_real_dev(n->dev);
2102 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2103 n, pdev, 0);
2104 if (!ep->l2t)
2105 goto out;
2106 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002107 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302108 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2109 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302110 step = cdev->rdev.lldi.ntxq /
2111 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002112 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2113 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302114 step = cdev->rdev.lldi.nrxq /
2115 cdev->rdev.lldi.nchan;
2116 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002117 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302118 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302119
2120 if (clear_mpa_v1) {
2121 ep->retry_with_mpa_v1 = 0;
2122 ep->tried_with_mpa_v1 = 0;
2123 }
2124 }
2125 err = 0;
2126out:
2127 rcu_read_unlock();
2128
2129 neigh_release(n);
2130
2131 return err;
2132}
2133
Vipul Pandya793dad92012-12-10 09:30:56 +00002134static int c4iw_reconnect(struct c4iw_ep *ep)
2135{
2136 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302137 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002138 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302139 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002140 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302141 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002142 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302143 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002144 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302145 int iptype;
2146 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002147
2148 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2149 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302150 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002151
2152 /*
2153 * Allocate an active TID to initiate a TCP connection.
2154 */
2155 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2156 if (ep->atid == -1) {
2157 pr_err("%s - cannot alloc atid.\n", __func__);
2158 err = -ENOMEM;
2159 goto fail2;
2160 }
2161 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2162
2163 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002164 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302165 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2166 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302167 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302168 iptype = 4;
2169 ra = (__u8 *)&raddr->sin_addr;
2170 } else {
2171 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2172 raddr6->sin6_addr.s6_addr,
2173 laddr6->sin6_port, raddr6->sin6_port, 0,
2174 raddr6->sin6_scope_id);
2175 iptype = 6;
2176 ra = (__u8 *)&raddr6->sin6_addr;
2177 }
2178 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 pr_err("%s - cannot find route.\n", __func__);
2180 err = -EHOSTUNREACH;
2181 goto fail3;
2182 }
Hariprasad S963cab52015-09-23 17:19:27 +05302183 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302184 ep->com.dev->rdev.lldi.adapter_type,
2185 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302186 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002187 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002188 goto fail4;
2189 }
2190
2191 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2192 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2193 ep->l2t->idx);
2194
2195 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302196 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002197
2198 /* send connect request to rnic */
2199 err = send_connect(ep);
2200 if (!err)
2201 goto out;
2202
2203 cxgb4_l2t_release(ep->l2t);
2204fail4:
2205 dst_release(ep->dst);
2206fail3:
2207 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2208 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2209fail2:
2210 /*
2211 * remember to send notification to upper layer.
2212 * We are in here so the upper layer is not aware that this is
2213 * re-connect attempt and so, upper layer is still waiting for
2214 * response of 1st connect request.
2215 */
2216 connect_reply_upcall(ep, -ECONNRESET);
2217 c4iw_put_ep(&ep->com);
2218out:
2219 return err;
2220}
2221
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2223{
2224 struct c4iw_ep *ep;
2225 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002226 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2227 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002228 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002229 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302230 struct sockaddr_in *la;
2231 struct sockaddr_in *ra;
2232 struct sockaddr_in6 *la6;
2233 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302234 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235
2236 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002237 la = (struct sockaddr_in *)&ep->com.local_addr;
2238 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2239 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2240 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002241
2242 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2243 status, status2errno(status));
2244
Steve Wise7a2cea22014-03-14 21:52:07 +05302245 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302246 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2247 __func__, atid, status, neg_adv_str(status));
2248 ep->stats.connect_neg_adv++;
2249 mutex_lock(&dev->rdev.stats.lock);
2250 dev->rdev.stats.neg_adv++;
2251 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002252 return 0;
2253 }
2254
Vipul Pandya793dad92012-12-10 09:30:56 +00002255 set_bit(ACT_OPEN_RPL, &ep->com.history);
2256
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302257 /*
2258 * Log interesting failures.
2259 */
2260 switch (status) {
2261 case CPL_ERR_CONN_RESET:
2262 case CPL_ERR_CONN_TIMEDOUT:
2263 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002264 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302265 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002266 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302267 mutex_unlock(&dev->rdev.stats.lock);
2268 if (ep->com.local_addr.ss_family == AF_INET &&
2269 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302270 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2271 ntohl(rpl->atid_status))));
2272 if (ret)
2273 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002274 return 0;
2275 }
2276 break;
2277 case CPL_ERR_CONN_EXIST:
2278 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2279 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302280 if (ep->com.remote_addr.ss_family == AF_INET6) {
2281 struct sockaddr_in6 *sin6 =
2282 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002283 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302284 cxgb4_clip_release(
2285 ep->com.dev->rdev.lldi.ports[0],
2286 (const u32 *)
2287 &sin6->sin6_addr.s6_addr, 1);
2288 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002289 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2290 atid);
2291 cxgb4_free_atid(t, atid);
2292 dst_release(ep->dst);
2293 cxgb4_l2t_release(ep->l2t);
2294 c4iw_reconnect(ep);
2295 return 0;
2296 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002297 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302298 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302299 if (ep->com.local_addr.ss_family == AF_INET) {
2300 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2301 atid, status, status2errno(status),
2302 &la->sin_addr.s_addr, ntohs(la->sin_port),
2303 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2304 } else {
2305 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2306 atid, status, status2errno(status),
2307 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2308 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2309 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302310 break;
2311 }
2312
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302313fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002314 connect_reply_upcall(ep, status2errno(status));
2315 state_set(&ep->com, DEAD);
2316
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302317 if (ep->com.remote_addr.ss_family == AF_INET6) {
2318 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002319 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302320 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2321 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2322 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323 if (status && act_open_has_tid(status))
2324 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2325
Vipul Pandya793dad92012-12-10 09:30:56 +00002326 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327 cxgb4_free_atid(t, atid);
2328 dst_release(ep->dst);
2329 cxgb4_l2t_release(ep->l2t);
2330 c4iw_put_ep(&ep->com);
2331
2332 return 0;
2333}
2334
2335static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2336{
2337 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002338 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302339 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340
2341 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002342 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2343 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 }
2345 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2346 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002347 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302348 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002349out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 return 0;
2351}
2352
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2354{
2355 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302357 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002358
2359 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002360 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302361 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002362 return 0;
2363}
2364
Hariprasad S9dec9002016-05-05 01:27:29 +05302365static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2366 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002367{
2368 struct cpl_pass_accept_rpl *rpl;
2369 unsigned int mtu_idx;
2370 u64 opt0;
2371 u32 opt2;
2372 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302373 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302374 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302375 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376
2377 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2378 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302379
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302381 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302382 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302383 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2384 rpl5 = (void *)rpl;
2385 INIT_TP_WR(rpl5, ep->hwtid);
2386 } else {
2387 skb_trim(skb, sizeof(*rpl));
2388 INIT_TP_WR(rpl, ep->hwtid);
2389 }
2390 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2391 ep->hwtid));
2392
2393 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302394 enable_tcp_timestamps && req->tcpopt.tstamp,
2395 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302397
2398 /*
2399 * Specify the largest window that will fit in opt0. The
2400 * remainder will be specified in the rx_data_ack.
2401 */
2402 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002403 if (win > RCV_BUFSIZ_M)
2404 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002405 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002406 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002407 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002408 WND_SCALE_V(wscale) |
2409 MSS_IDX_V(mtu_idx) |
2410 L2T_IDX_V(ep->l2t->idx) |
2411 TX_CHAN_V(ep->tx_chan) |
2412 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002413 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002414 ULP_MODE_V(ULP_MODE_TCPDDP) |
2415 RCV_BUFSIZ_V(win);
2416 opt2 = RX_CHANNEL_V(0) |
2417 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
2419 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002420 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002422 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002424 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002425 if (enable_ecn) {
2426 const struct tcphdr *tcph;
2427 u32 hlen = ntohl(req->hdr_len);
2428
Hariprasad S963cab52015-09-23 17:19:27 +05302429 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2430 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2431 IP_HDR_LEN_G(hlen);
2432 else
2433 tcph = (const void *)(req + 1) +
2434 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002435 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002436 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002437 }
Hariprasad S963cab52015-09-23 17:19:27 +05302438 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302439 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002440 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302441 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302442 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302443 rpl5 = (void *)rpl;
2444 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2445 if (peer2peer)
2446 isn += 4;
2447 rpl5->iss = cpu_to_be32(isn);
2448 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002449 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 rpl->opt0 = cpu_to_be64(opt0);
2452 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002453 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302454 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455
Hariprasad S9dec9002016-05-05 01:27:29 +05302456 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457}
2458
Vipul Pandya830662f2013-07-04 16:10:47 +05302459static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002460{
Vipul Pandya830662f2013-07-04 16:10:47 +05302461 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 BUG_ON(skb_cloned(skb));
2463 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 release_tid(&dev->rdev, hwtid, skb);
2465 return;
2466}
2467
Hariprasad S963cab52015-09-23 17:19:27 +05302468static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2469 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 __be16 *local_port, __be16 *peer_port)
2471{
Hariprasad S963cab52015-09-23 17:19:27 +05302472 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2473 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2474 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2475 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2476 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2477 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302479 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480 struct tcphdr *tcp = (struct tcphdr *)
2481 ((u8 *)(req + 1) + eth_len + ip_len);
2482
Vipul Pandya830662f2013-07-04 16:10:47 +05302483 if (ip->version == 4) {
2484 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2485 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2486 ntohs(tcp->dest));
2487 *iptype = 4;
2488 memcpy(peer_ip, &ip->saddr, 4);
2489 memcpy(local_ip, &ip->daddr, 4);
2490 } else {
2491 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2492 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2493 ntohs(tcp->dest));
2494 *iptype = 6;
2495 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2496 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2497 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002498 *peer_port = tcp->source;
2499 *local_port = tcp->dest;
2500
2501 return;
2502}
2503
2504static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2505{
Vipul Pandya793dad92012-12-10 09:30:56 +00002506 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002508 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509 struct tid_info *t = dev->rdev.lldi.tids;
2510 unsigned int hwtid = GET_TID(req);
2511 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302512 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002513 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302514 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002515 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002516 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302517 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302518 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302519 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002520
Hariprasad Sf86fac72016-05-06 22:18:07 +05302521 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002522 if (!parent_ep) {
2523 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2524 goto reject;
2525 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002526
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302528 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529 goto reject;
2530 }
2531
Hariprasad S963cab52015-09-23 17:19:27 +05302532 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2533 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302534
Steve Wisecfdda9d2010-04-21 15:30:06 -07002535 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302536 if (iptype == 4) {
2537 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2538 , __func__, parent_ep, hwtid,
2539 local_ip, peer_ip, ntohs(local_port),
2540 ntohs(peer_port), peer_mss);
2541 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2542 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302543 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302544 } else {
2545 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2546 , __func__, parent_ep, hwtid,
2547 local_ip, peer_ip, ntohs(local_port),
2548 ntohs(peer_port), peer_mss);
2549 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002550 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302551 ((struct sockaddr_in6 *)
2552 &parent_ep->com.local_addr)->sin6_scope_id);
2553 }
2554 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2556 __func__);
2557 goto reject;
2558 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002559
2560 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2561 if (!child_ep) {
2562 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2563 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002564 dst_release(dst);
2565 goto reject;
2566 }
David Miller3786cf12011-12-02 16:52:31 +00002567
Hariprasad S963cab52015-09-23 17:19:27 +05302568 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302569 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002570 if (err) {
2571 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2572 __func__);
2573 dst_release(dst);
2574 kfree(child_ep);
2575 goto reject;
2576 }
2577
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302578 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2579 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2580 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2581 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002582
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583 state_set(&child_ep->com, CONNECTING);
2584 child_ep->com.dev = dev;
2585 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002586
Vipul Pandya830662f2013-07-04 16:10:47 +05302587 if (iptype == 4) {
2588 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002589 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002590
Vipul Pandya830662f2013-07-04 16:10:47 +05302591 sin->sin_family = PF_INET;
2592 sin->sin_port = local_port;
2593 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002594
2595 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2596 sin->sin_family = PF_INET;
2597 sin->sin_port = ((struct sockaddr_in *)
2598 &parent_ep->com.local_addr)->sin_port;
2599 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2600
Steve Wise170003c2016-02-26 09:18:03 -06002601 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302602 sin->sin_family = PF_INET;
2603 sin->sin_port = peer_port;
2604 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2605 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002606 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302607 sin6->sin6_family = PF_INET6;
2608 sin6->sin6_port = local_port;
2609 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002610
2611 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2612 sin6->sin6_family = PF_INET6;
2613 sin6->sin6_port = ((struct sockaddr_in6 *)
2614 &parent_ep->com.local_addr)->sin6_port;
2615 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2616
Steve Wise170003c2016-02-26 09:18:03 -06002617 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302618 sin6->sin6_family = PF_INET6;
2619 sin6->sin6_port = peer_port;
2620 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2621 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002622
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 c4iw_get_ep(&parent_ep->com);
2624 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302625 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626 child_ep->dst = dst;
2627 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628
2629 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002630 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631
2632 init_timer(&child_ep->timer);
2633 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302634 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302635 if (accept_cr(child_ep, skb, req)) {
2636 c4iw_put_ep(&parent_ep->com);
2637 release_ep_resources(child_ep);
2638 } else {
2639 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2640 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302641 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002642 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302643 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2644 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2645 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 goto out;
2647reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302648 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302649 if (parent_ep)
2650 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651out:
2652 return 0;
2653}
2654
2655static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2656{
2657 struct c4iw_ep *ep;
2658 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302660 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661
Hariprasad S944661d2016-05-06 22:18:03 +05302662 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2664 ep->snd_seq = be32_to_cpu(req->snd_isn);
2665 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2666
Vipul Pandya1cab7752012-12-10 09:30:55 +00002667 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2668 ntohs(req->tcp_opt));
2669
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 set_emss(ep, ntohs(req->tcp_opt));
2671
2672 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302673 mutex_lock(&ep->com.mutex);
2674 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002676 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302677 ret = send_flowc(ep, skb);
2678 mutex_unlock(&ep->com.mutex);
2679 if (ret)
2680 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302681 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002682
2683 return 0;
2684}
2685
2686static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2687{
2688 struct cpl_peer_close *hdr = cplhdr(skb);
2689 struct c4iw_ep *ep;
2690 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 int disconnect = 1;
2692 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002694 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002695
Hariprasad S944661d2016-05-06 22:18:03 +05302696 ep = get_ep_from_tid(dev, tid);
2697 if (!ep)
2698 return 0;
2699
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2701 dst_confirm(ep->dst);
2702
Vipul Pandya793dad92012-12-10 09:30:56 +00002703 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002704 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 switch (ep->com.state) {
2706 case MPA_REQ_WAIT:
2707 __state_set(&ep->com, CLOSING);
2708 break;
2709 case MPA_REQ_SENT:
2710 __state_set(&ep->com, CLOSING);
2711 connect_reply_upcall(ep, -ECONNRESET);
2712 break;
2713 case MPA_REQ_RCVD:
2714
2715 /*
2716 * We're gonna mark this puppy DEAD, but keep
2717 * the reference on it until the ULP accepts or
2718 * rejects the CR. Also wake up anyone waiting
2719 * in rdma connection migration (see c4iw_accept_cr()).
2720 */
2721 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002723 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724 break;
2725 case MPA_REP_SENT:
2726 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002728 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 break;
2730 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002731 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002733 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002734 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002735 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002736 if (ret != -ECONNRESET) {
2737 peer_close_upcall(ep);
2738 disconnect = 1;
2739 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 break;
2741 case ABORTING:
2742 disconnect = 0;
2743 break;
2744 case CLOSING:
2745 __state_set(&ep->com, MORIBUND);
2746 disconnect = 0;
2747 break;
2748 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002749 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 if (ep->com.cm_id && ep->com.qp) {
2751 attrs.next_state = C4IW_QP_STATE_IDLE;
2752 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2753 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2754 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302755 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 __state_set(&ep->com, DEAD);
2757 release = 1;
2758 disconnect = 0;
2759 break;
2760 case DEAD:
2761 disconnect = 0;
2762 break;
2763 default:
2764 BUG_ON(1);
2765 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002766 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002767 if (disconnect)
2768 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2769 if (release)
2770 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302771 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 return 0;
2773}
2774
Steve Wisecfdda9d2010-04-21 15:30:06 -07002775static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2776{
2777 struct cpl_abort_req_rss *req = cplhdr(skb);
2778 struct c4iw_ep *ep;
2779 struct cpl_abort_rpl *rpl;
2780 struct sk_buff *rpl_skb;
2781 struct c4iw_qp_attributes attrs;
2782 int ret;
2783 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002784 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785
Hariprasad S944661d2016-05-06 22:18:03 +05302786 ep = get_ep_from_tid(dev, tid);
2787 if (!ep)
2788 return 0;
2789
Steve Wise7a2cea22014-03-14 21:52:07 +05302790 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302791 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2792 __func__, ep->hwtid, req->status,
2793 neg_adv_str(req->status));
2794 ep->stats.abort_neg_adv++;
2795 mutex_lock(&dev->rdev.stats.lock);
2796 dev->rdev.stats.neg_adv++;
2797 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302798 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002800 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2801 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002802 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002803
2804 /*
2805 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302806 * However, this is not needed if com state is just
2807 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002808 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302809 if (ep->com.state != MPA_REQ_SENT)
2810 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002811
2812 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 switch (ep->com.state) {
2814 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302815 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 break;
2817 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002818 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002819 break;
2820 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002821 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002822 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302823 connect_reply_upcall(ep, -ECONNRESET);
2824 else {
2825 /*
2826 * we just don't send notification upwards because we
2827 * want to retry with mpa_v1 without upper layers even
2828 * knowing it.
2829 *
2830 * do some housekeeping so as to re-initiate the
2831 * connection
2832 */
2833 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2834 mpa_rev);
2835 ep->retry_with_mpa_v1 = 1;
2836 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 break;
2838 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 break;
2840 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002841 break;
2842 case MORIBUND:
2843 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002844 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845 /*FALLTHROUGH*/
2846 case FPDU_MODE:
2847 if (ep->com.cm_id && ep->com.qp) {
2848 attrs.next_state = C4IW_QP_STATE_ERROR;
2849 ret = c4iw_modify_qp(ep->com.qp->rhp,
2850 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2851 &attrs, 1);
2852 if (ret)
2853 printk(KERN_ERR MOD
2854 "%s - qp <- error failed!\n",
2855 __func__);
2856 }
2857 peer_abort_upcall(ep);
2858 break;
2859 case ABORTING:
2860 break;
2861 case DEAD:
2862 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002863 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302864 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865 default:
2866 BUG_ON(1);
2867 break;
2868 }
2869 dst_confirm(ep->dst);
2870 if (ep->com.state != ABORTING) {
2871 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302872 /* we don't release if we want to retry with mpa_v1 */
2873 if (!ep->retry_with_mpa_v1)
2874 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002875 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002876 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877
2878 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2879 if (!rpl_skb) {
2880 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2881 __func__);
2882 release = 1;
2883 goto out;
2884 }
2885 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2886 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2887 INIT_TP_WR(rpl, ep->hwtid);
2888 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2889 rpl->cmd = CPL_ABORT_NO_RST;
2890 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2891out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002892 if (release)
2893 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002894 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302895 if (ep->com.remote_addr.ss_family == AF_INET6) {
2896 struct sockaddr_in6 *sin6 =
2897 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002898 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302899 cxgb4_clip_release(
2900 ep->com.dev->rdev.lldi.ports[0],
2901 (const u32 *)&sin6->sin6_addr.s6_addr,
2902 1);
2903 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002904 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302905 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2906 dst_release(ep->dst);
2907 cxgb4_l2t_release(ep->l2t);
2908 c4iw_reconnect(ep);
2909 }
2910
Hariprasad S944661d2016-05-06 22:18:03 +05302911deref_ep:
2912 c4iw_put_ep(&ep->com);
2913 /* Dereferencing ep, referenced in peer_abort_intr() */
2914 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002915 return 0;
2916}
2917
2918static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2919{
2920 struct c4iw_ep *ep;
2921 struct c4iw_qp_attributes attrs;
2922 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002925
Hariprasad S944661d2016-05-06 22:18:03 +05302926 ep = get_ep_from_tid(dev, tid);
2927 if (!ep)
2928 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002929
2930 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2931 BUG_ON(!ep);
2932
2933 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002934 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302935 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936 switch (ep->com.state) {
2937 case CLOSING:
2938 __state_set(&ep->com, MORIBUND);
2939 break;
2940 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002941 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002942 if ((ep->com.cm_id) && (ep->com.qp)) {
2943 attrs.next_state = C4IW_QP_STATE_IDLE;
2944 c4iw_modify_qp(ep->com.qp->rhp,
2945 ep->com.qp,
2946 C4IW_QP_ATTR_NEXT_STATE,
2947 &attrs, 1);
2948 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302949 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002950 __state_set(&ep->com, DEAD);
2951 release = 1;
2952 break;
2953 case ABORTING:
2954 case DEAD:
2955 break;
2956 default:
2957 BUG_ON(1);
2958 break;
2959 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002960 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961 if (release)
2962 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302963 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002964 return 0;
2965}
2966
2967static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2968{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002969 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002970 unsigned int tid = GET_TID(rpl);
2971 struct c4iw_ep *ep;
2972 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973
Hariprasad S944661d2016-05-06 22:18:03 +05302974 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002975 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002976
Steve Wise30c95c22011-05-09 22:06:22 -07002977 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002978 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2979 ep->com.qp->wq.sq.qid);
2980 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2981 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2982 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2983 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002984 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302985 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986
Steve Wisecfdda9d2010-04-21 15:30:06 -07002987 return 0;
2988}
2989
2990/*
2991 * Upcall from the adapter indicating data has been transmitted.
2992 * For us its just the single MPA request or reply. We can now free
2993 * the skb holding the mpa message.
2994 */
2995static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2996{
2997 struct c4iw_ep *ep;
2998 struct cpl_fw4_ack *hdr = cplhdr(skb);
2999 u8 credits = hdr->credits;
3000 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003001
3002
Hariprasad S944661d2016-05-06 22:18:03 +05303003 ep = get_ep_from_tid(dev, tid);
3004 if (!ep)
3005 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
3007 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07003008 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3009 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05303010 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 }
3012
3013 dst_confirm(ep->dst);
3014 if (ep->mpa_skb) {
3015 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3016 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3017 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
3018 kfree_skb(ep->mpa_skb);
3019 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303020 mutex_lock(&ep->com.mutex);
3021 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3022 stop_ep_timer(ep);
3023 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003024 }
Hariprasad S944661d2016-05-06 22:18:03 +05303025out:
3026 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003027 return 0;
3028}
3029
Steve Wisecfdda9d2010-04-21 15:30:06 -07003030int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3031{
Steve Wisea7db89e2014-03-21 20:40:35 +05303032 int err = 0;
3033 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003034 struct c4iw_ep *ep = to_ep(cm_id);
3035 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3036
Steve Wisea7db89e2014-03-21 20:40:35 +05303037 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303038 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303039 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003040 c4iw_put_ep(&ep->com);
3041 return -ECONNRESET;
3042 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003043 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303045 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003046 else {
3047 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303048 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003049 }
Steve Wisea7db89e2014-03-21 20:40:35 +05303050 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303051 if (disconnect) {
3052 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303053 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303054 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003055 c4iw_put_ep(&ep->com);
3056 return 0;
3057}
3058
3059int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3060{
3061 int err;
3062 struct c4iw_qp_attributes attrs;
3063 enum c4iw_qp_attr_mask mask;
3064 struct c4iw_ep *ep = to_ep(cm_id);
3065 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3066 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303067 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068
3069 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303070
3071 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303072 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003073 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303074 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003075 }
3076
Steve Wisecfdda9d2010-04-21 15:30:06 -07003077 BUG_ON(!qp);
3078
Vipul Pandya793dad92012-12-10 09:30:56 +00003079 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303080 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3081 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303083 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003084 }
3085
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303086 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3087 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303088 if (RELAXED_IRD_NEGOTIATION) {
3089 ep->ord = ep->ird;
3090 } else {
3091 ep->ird = conn_param->ird;
3092 ep->ord = conn_param->ord;
3093 send_mpa_reject(ep, conn_param->private_data,
3094 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303095 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303096 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303097 }
3098 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303099 if (conn_param->ird < ep->ord) {
3100 if (RELAXED_IRD_NEGOTIATION &&
3101 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3102 conn_param->ird = ep->ord;
3103 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303104 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303105 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303106 }
3107 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303108 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003109 ep->ird = conn_param->ird;
3110 ep->ord = conn_param->ord;
3111
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303112 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303113 if (peer2peer && ep->ird == 0)
3114 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303115 } else {
3116 if (peer2peer &&
3117 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303118 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303119 ep->ird = 1;
3120 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003121
3122 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3123
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303124 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303125 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303126 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003127 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303128
Steve Wisecfdda9d2010-04-21 15:30:06 -07003129 /* bind QP to EP and move to RTS */
3130 attrs.mpa_attr = ep->mpa_attr;
3131 attrs.max_ird = ep->ird;
3132 attrs.max_ord = ep->ord;
3133 attrs.llp_stream_handle = ep;
3134 attrs.next_state = C4IW_QP_STATE_RTS;
3135
3136 /* bind QP and TID with INIT_WR */
3137 mask = C4IW_QP_ATTR_NEXT_STATE |
3138 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3139 C4IW_QP_ATTR_MPA_ATTR |
3140 C4IW_QP_ATTR_MAX_IRD |
3141 C4IW_QP_ATTR_MAX_ORD;
3142
3143 err = c4iw_modify_qp(ep->com.qp->rhp,
3144 ep->com.qp, mask, &attrs, 1);
3145 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303146 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303147
3148 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003149 err = send_mpa_reply(ep, conn_param->private_data,
3150 conn_param->private_data_len);
3151 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303152 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153
Steve Wisea7db89e2014-03-21 20:40:35 +05303154 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003155 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303156 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003157 c4iw_put_ep(&ep->com);
3158 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303159err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303160 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303161err_abort:
3162 abort = 1;
3163err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303164 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303165 if (abort)
3166 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003167 c4iw_put_ep(&ep->com);
3168 return err;
3169}
3170
Vipul Pandya830662f2013-07-04 16:10:47 +05303171static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3172{
3173 struct in_device *ind;
3174 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003175 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3176 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303177
3178 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3179 if (!ind)
3180 return -EADDRNOTAVAIL;
3181 for_primary_ifa(ind) {
3182 laddr->sin_addr.s_addr = ifa->ifa_address;
3183 raddr->sin_addr.s_addr = ifa->ifa_address;
3184 found = 1;
3185 break;
3186 }
3187 endfor_ifa(ind);
3188 in_dev_put(ind);
3189 return found ? 0 : -EADDRNOTAVAIL;
3190}
3191
3192static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3193 unsigned char banned_flags)
3194{
3195 struct inet6_dev *idev;
3196 int err = -EADDRNOTAVAIL;
3197
3198 rcu_read_lock();
3199 idev = __in6_dev_get(dev);
3200 if (idev != NULL) {
3201 struct inet6_ifaddr *ifp;
3202
3203 read_lock_bh(&idev->lock);
3204 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3205 if (ifp->scope == IFA_LINK &&
3206 !(ifp->flags & banned_flags)) {
3207 memcpy(addr, &ifp->addr, 16);
3208 err = 0;
3209 break;
3210 }
3211 }
3212 read_unlock_bh(&idev->lock);
3213 }
3214 rcu_read_unlock();
3215 return err;
3216}
3217
3218static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3219{
3220 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003221 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3222 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303223
Nicholas Krause54b9a962015-08-26 23:00:59 -04003224 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303225 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3226 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3227 return 0;
3228 }
3229 return -EADDRNOTAVAIL;
3230}
3231
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3233{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003234 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3235 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003236 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003237 struct sockaddr_in *laddr;
3238 struct sockaddr_in *raddr;
3239 struct sockaddr_in6 *laddr6;
3240 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303241 __u8 *ra;
3242 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003243
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303244 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3245 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003246 err = -EINVAL;
3247 goto out;
3248 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003249 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3250 if (!ep) {
3251 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3252 err = -ENOMEM;
3253 goto out;
3254 }
3255 init_timer(&ep->timer);
3256 ep->plen = conn_param->private_data_len;
3257 if (ep->plen)
3258 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3259 conn_param->private_data, ep->plen);
3260 ep->ird = conn_param->ird;
3261 ep->ord = conn_param->ord;
3262
3263 if (peer2peer && ep->ord == 0)
3264 ep->ord = 1;
3265
Steve Wisecfdda9d2010-04-21 15:30:06 -07003266 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303267 ref_cm_id(&ep->com);
3268 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003269 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303270 if (!ep->com.qp) {
3271 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3272 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003273 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303274 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003275 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003276 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3277 ep->com.qp, cm_id);
3278
3279 /*
3280 * Allocate an active TID to initiate a TCP connection.
3281 */
3282 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3283 if (ep->atid == -1) {
3284 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3285 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003286 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003287 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003288 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003289
Steve Wise170003c2016-02-26 09:18:03 -06003290 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003291 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003292 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003293 sizeof(ep->com.remote_addr));
3294
Steve Wise170003c2016-02-26 09:18:03 -06003295 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3296 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3297 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3298 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003299
Steve Wise170003c2016-02-26 09:18:03 -06003300 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303301 iptype = 4;
3302 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303
Vipul Pandya830662f2013-07-04 16:10:47 +05303304 /*
3305 * Handle loopback requests to INADDR_ANY.
3306 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003307 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303308 err = pick_local_ipaddrs(dev, cm_id);
3309 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003310 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303311 }
3312
3313 /* find a route */
3314 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3315 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3316 ra, ntohs(raddr->sin_port));
3317 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3318 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303319 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303320 } else {
3321 iptype = 6;
3322 ra = (__u8 *)&raddr6->sin6_addr;
3323
3324 /*
3325 * Handle loopback requests to INADDR_ANY.
3326 */
3327 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3328 err = pick_local_ip6addrs(dev, cm_id);
3329 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003330 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303331 }
3332
3333 /* find a route */
3334 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3335 __func__, laddr6->sin6_addr.s6_addr,
3336 ntohs(laddr6->sin6_port),
3337 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3338 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3339 raddr6->sin6_addr.s6_addr,
3340 laddr6->sin6_port, raddr6->sin6_port, 0,
3341 raddr6->sin6_scope_id);
3342 }
3343 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003344 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3345 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003346 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003347 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003348
Hariprasad S963cab52015-09-23 17:19:27 +05303349 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303350 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003351 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003352 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003353 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003354 }
3355
3356 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3357 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3358 ep->l2t->idx);
3359
3360 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303361 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003362
3363 /* send connect request to rnic */
3364 err = send_connect(ep);
3365 if (!err)
3366 goto out;
3367
3368 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003369fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003370 dst_release(ep->dst);
3371fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003372 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003373 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003374fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303375 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003376 c4iw_put_ep(&ep->com);
3377out:
3378 return err;
3379}
3380
Vipul Pandya830662f2013-07-04 16:10:47 +05303381static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3382{
3383 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003384 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003385 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303386
Hariprasad S28de1f72016-01-13 10:03:14 +05303387 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3388 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3389 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3390 if (err)
3391 return err;
3392 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303393 c4iw_init_wr_wait(&ep->com.wr_wait);
3394 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3395 ep->stid, &sin6->sin6_addr,
3396 sin6->sin6_port,
3397 ep->com.dev->rdev.lldi.rxq_ids[0]);
3398 if (!err)
3399 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3400 &ep->com.wr_wait,
3401 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303402 else if (err > 0)
3403 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303404 if (err) {
3405 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3406 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303407 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3408 err, ep->stid,
3409 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303410 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303411 return err;
3412}
3413
3414static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3415{
3416 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003417 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003418 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303419
3420 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3421 do {
3422 err = cxgb4_create_server_filter(
3423 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3424 sin->sin_addr.s_addr, sin->sin_port, 0,
3425 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3426 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303427 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3428 err = -EIO;
3429 break;
3430 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303431 set_current_state(TASK_UNINTERRUPTIBLE);
3432 schedule_timeout(usecs_to_jiffies(100));
3433 }
3434 } while (err == -EBUSY);
3435 } else {
3436 c4iw_init_wr_wait(&ep->com.wr_wait);
3437 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3438 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3439 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3440 if (!err)
3441 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3442 &ep->com.wr_wait,
3443 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303444 else if (err > 0)
3445 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303446 }
3447 if (err)
3448 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3449 , err, ep->stid,
3450 &sin->sin_addr, ntohs(sin->sin_port));
3451 return err;
3452}
3453
Steve Wisecfdda9d2010-04-21 15:30:06 -07003454int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3455{
3456 int err = 0;
3457 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3458 struct c4iw_listen_ep *ep;
3459
Steve Wisecfdda9d2010-04-21 15:30:06 -07003460 might_sleep();
3461
3462 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3463 if (!ep) {
3464 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3465 err = -ENOMEM;
3466 goto fail1;
3467 }
3468 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003469 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303470 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003471 ep->com.dev = dev;
3472 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003473 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303474 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475
3476 /*
3477 * Allocate a server TID.
3478 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303479 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3480 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303481 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003482 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003483 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303484 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003485 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003486
Steve Wisecfdda9d2010-04-21 15:30:06 -07003487 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003488 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003489 err = -ENOMEM;
3490 goto fail2;
3491 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003492 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003493
Steve Wise170003c2016-02-26 09:18:03 -06003494 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3495 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003496
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303498 if (ep->com.local_addr.ss_family == AF_INET)
3499 err = create_server4(dev, ep);
3500 else
3501 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003502 if (!err) {
3503 cm_id->provider_data = ep;
3504 goto out;
3505 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003506
Vipul Pandya830662f2013-07-04 16:10:47 +05303507 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3508 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303510 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003511 c4iw_put_ep(&ep->com);
3512fail1:
3513out:
3514 return err;
3515}
3516
3517int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3518{
3519 int err;
3520 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3521
3522 PDBG("%s ep %p\n", __func__, ep);
3523
3524 might_sleep();
3525 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303526 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3527 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003528 err = cxgb4_remove_server_filter(
3529 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3530 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3531 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303532 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003533 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303534 err = cxgb4_remove_server(
3535 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3536 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003537 if (err)
3538 goto done;
3539 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3540 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003541 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303542 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3543 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003544 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003545 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303546 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3547 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003548done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303549 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003550 c4iw_put_ep(&ep->com);
3551 return err;
3552}
3553
3554int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3555{
3556 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003557 int close = 0;
3558 int fatal = 0;
3559 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003560
Steve Wise2f5b48c2010-09-10 11:15:36 -05003561 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003562
3563 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3564 states[ep->com.state], abrupt);
3565
Hariprasad S6e410d82016-05-05 01:27:31 +05303566 /*
3567 * Ref the ep here in case we have fatal errors causing the
3568 * ep to be released and freed.
3569 */
3570 c4iw_get_ep(&ep->com);
3571
Steve Wisecfdda9d2010-04-21 15:30:06 -07003572 rdev = &ep->com.dev->rdev;
3573 if (c4iw_fatal_error(rdev)) {
3574 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303575 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003576 ep->com.state = DEAD;
3577 }
3578 switch (ep->com.state) {
3579 case MPA_REQ_WAIT:
3580 case MPA_REQ_SENT:
3581 case MPA_REQ_RCVD:
3582 case MPA_REP_SENT:
3583 case FPDU_MODE:
3584 close = 1;
3585 if (abrupt)
3586 ep->com.state = ABORTING;
3587 else {
3588 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003589 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003590 }
3591 set_bit(CLOSE_SENT, &ep->com.flags);
3592 break;
3593 case CLOSING:
3594 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3595 close = 1;
3596 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003597 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003598 ep->com.state = ABORTING;
3599 } else
3600 ep->com.state = MORIBUND;
3601 }
3602 break;
3603 case MORIBUND:
3604 case ABORTING:
3605 case DEAD:
3606 PDBG("%s ignoring disconnect ep %p state %u\n",
3607 __func__, ep, ep->com.state);
3608 break;
3609 default:
3610 BUG();
3611 break;
3612 }
3613
Steve Wisecfdda9d2010-04-21 15:30:06 -07003614 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003615 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003616 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303617 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003618 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003619 } else {
3620 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003621 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003622 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303623 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303624 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303625 if (!abrupt) {
3626 stop_ep_timer(ep);
3627 close_complete_upcall(ep, -EIO);
3628 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303629 if (ep->com.qp) {
3630 struct c4iw_qp_attributes attrs;
3631
3632 attrs.next_state = C4IW_QP_STATE_ERROR;
3633 ret = c4iw_modify_qp(ep->com.qp->rhp,
3634 ep->com.qp,
3635 C4IW_QP_ATTR_NEXT_STATE,
3636 &attrs, 1);
3637 if (ret)
3638 pr_err(MOD
3639 "%s - qp <- error failed!\n",
3640 __func__);
3641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003642 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303643 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003644 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003645 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303646 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003647 if (fatal)
3648 release_ep_resources(ep);
3649 return ret;
3650}
3651
Vipul Pandya1cab7752012-12-10 09:30:55 +00003652static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3653 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3654{
3655 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003656 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003657
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003658 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3659 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003660 if (!ep)
3661 return;
3662
3663 switch (req->retval) {
3664 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003665 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3666 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3667 send_fw_act_open_req(ep, atid);
3668 return;
3669 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003671 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3672 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3673 send_fw_act_open_req(ep, atid);
3674 return;
3675 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003676 break;
3677 default:
3678 pr_info("%s unexpected ofld conn wr retval %d\n",
3679 __func__, req->retval);
3680 break;
3681 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003682 pr_err("active ofld_connect_wr failure %d atid %d\n",
3683 req->retval, atid);
3684 mutex_lock(&dev->rdev.stats.lock);
3685 dev->rdev.stats.act_ofld_conn_fails++;
3686 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003687 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003688 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303689 if (ep->com.remote_addr.ss_family == AF_INET6) {
3690 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003691 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303692 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3693 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3694 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003695 remove_handle(dev, &dev->atid_idr, atid);
3696 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3697 dst_release(ep->dst);
3698 cxgb4_l2t_release(ep->l2t);
3699 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003700}
3701
3702static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3703 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3704{
3705 struct sk_buff *rpl_skb;
3706 struct cpl_pass_accept_req *cpl;
3707 int ret;
3708
Paul Bolle710a3112013-02-05 20:51:30 +00003709 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003710 BUG_ON(!rpl_skb);
3711 if (req->retval) {
3712 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003713 mutex_lock(&dev->rdev.stats.lock);
3714 dev->rdev.stats.pas_ofld_conn_fails++;
3715 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003716 kfree_skb(rpl_skb);
3717 } else {
3718 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3719 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003720 (__force u32) htonl(
3721 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003722 ret = pass_accept_req(dev, rpl_skb);
3723 if (!ret)
3724 kfree_skb(rpl_skb);
3725 }
3726 return;
3727}
3728
3729static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003730{
3731 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3733
3734 switch (rpl->type) {
3735 case FW6_TYPE_CQE:
3736 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3737 break;
3738 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3739 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3740 switch (req->t_state) {
3741 case TCP_SYN_SENT:
3742 active_ofld_conn_reply(dev, skb, req);
3743 break;
3744 case TCP_SYN_RECV:
3745 passive_ofld_conn_reply(dev, skb, req);
3746 break;
3747 default:
3748 pr_err("%s unexpected ofld conn wr state %d\n",
3749 __func__, req->t_state);
3750 break;
3751 }
3752 break;
3753 }
3754 return 0;
3755}
3756
3757static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3758{
Hariprasad S963cab52015-09-23 17:19:27 +05303759 __be32 l2info;
3760 __be16 hdr_len, vlantag, len;
3761 u16 eth_hdr_len;
3762 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003763 u8 intf;
3764 struct cpl_rx_pkt *cpl = cplhdr(skb);
3765 struct cpl_pass_accept_req *req;
3766 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003767 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303768 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769
Vipul Pandyaf079af72013-03-14 05:08:58 +00003770 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003771 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303772 vlantag = cpl->vlan;
3773 len = cpl->len;
3774 l2info = cpl->l2info;
3775 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003776 intf = cpl->iff;
3777
3778 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3779
3780 /*
3781 * We need to parse the TCP options from SYN packet.
3782 * to generate cpl_pass_accept_req.
3783 */
3784 memset(&tmp_opt, 0, sizeof(tmp_opt));
3785 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003786 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003787
3788 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3789 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303790 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3791 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303792 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303793 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303794 type = dev->rdev.lldi.adapter_type;
3795 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3796 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3797 req->hdr_len =
3798 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3799 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3800 eth_hdr_len = is_t4(type) ?
3801 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3802 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3803 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3804 IP_HDR_LEN_V(ip_hdr_len) |
3805 ETH_HDR_LEN_V(eth_hdr_len));
3806 } else { /* T6 and later */
3807 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3808 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3809 T6_IP_HDR_LEN_V(ip_hdr_len) |
3810 T6_ETH_HDR_LEN_V(eth_hdr_len));
3811 }
3812 req->vlan = vlantag;
3813 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003814 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3815 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003816 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3817 if (tmp_opt.wscale_ok)
3818 req->tcpopt.wsf = tmp_opt.snd_wscale;
3819 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3820 if (tmp_opt.sack_ok)
3821 req->tcpopt.sack = 1;
3822 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3823 return;
3824}
3825
3826static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3827 __be32 laddr, __be16 lport,
3828 __be32 raddr, __be16 rport,
3829 u32 rcv_isn, u32 filter, u16 window,
3830 u32 rss_qid, u8 port_id)
3831{
3832 struct sk_buff *req_skb;
3833 struct fw_ofld_connection_wr *req;
3834 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303835 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003836
3837 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3838 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3839 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003840 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303841 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303842 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003843 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003844 req->le.lport = lport;
3845 req->le.pport = rport;
3846 req->le.u.ipv4.lip = laddr;
3847 req->le.u.ipv4.pip = raddr;
3848 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3849 req->tcb.rcv_adv = htons(window);
3850 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303851 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3852 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3853 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003854 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003855
3856 /*
3857 * We store the qid in opt2 which will be used by the firmware
3858 * to send us the wr response.
3859 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003860 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003861
3862 /*
3863 * We initialize the MSS index in TCB to 0xF.
3864 * So that when driver sends cpl_pass_accept_rpl
3865 * TCB picks up the correct value. If this was 0
3866 * TP will ignore any value > 0 for MSS index.
3867 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003868 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303869 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003870
3871 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303872 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3873 if (ret < 0) {
3874 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3875 ret);
3876 kfree_skb(skb);
3877 kfree_skb(req_skb);
3878 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003879}
3880
3881/*
3882 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3883 * messages when a filter is being used instead of server to
3884 * redirect a syn packet. When packets hit filter they are redirected
3885 * to the offload queue and driver tries to establish the connection
3886 * using firmware work request.
3887 */
3888static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3889{
3890 int stid;
3891 unsigned int filter;
3892 struct ethhdr *eh = NULL;
3893 struct vlan_ethhdr *vlan_eh = NULL;
3894 struct iphdr *iph;
3895 struct tcphdr *tcph;
3896 struct rss_header *rss = (void *)skb->data;
3897 struct cpl_rx_pkt *cpl = (void *)skb->data;
3898 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3899 struct l2t_entry *e;
3900 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303901 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003902 u16 window;
3903 struct port_info *pi;
3904 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003905 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003906 int step;
3907 u32 tx_chan;
3908 struct neighbour *neigh;
3909
3910 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003911 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003912 goto reject;
3913
3914 /*
3915 * Drop all packets which did not hit the filter.
3916 * Unlikely to happen.
3917 */
3918 if (!(rss->filter_hit && rss->filter_tid))
3919 goto reject;
3920
3921 /*
3922 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3923 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303924 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003925
Hariprasad Sf86fac72016-05-06 22:18:07 +05303926 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003927 if (!lep) {
3928 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3929 goto reject;
3930 }
3931
Hariprasad S963cab52015-09-23 17:19:27 +05303932 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3933 case CHELSIO_T4:
3934 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3935 break;
3936 case CHELSIO_T5:
3937 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3938 break;
3939 case CHELSIO_T6:
3940 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3941 break;
3942 default:
3943 pr_err("T%d Chip is not supported\n",
3944 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3945 goto reject;
3946 }
3947
Vipul Pandyaf079af72013-03-14 05:08:58 +00003948 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003949 eh = (struct ethhdr *)(req + 1);
3950 iph = (struct iphdr *)(eh + 1);
3951 } else {
3952 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3953 iph = (struct iphdr *)(vlan_eh + 1);
3954 skb->vlan_tci = ntohs(cpl->vlan);
3955 }
3956
3957 if (iph->version != 0x4)
3958 goto reject;
3959
3960 tcph = (struct tcphdr *)(iph + 1);
3961 skb_set_network_header(skb, (void *)iph - (void *)rss);
3962 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3963 skb_get(skb);
3964
3965 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3966 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3967 ntohs(tcph->source), iph->tos);
3968
Vipul Pandya830662f2013-07-04 16:10:47 +05303969 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3970 iph->tos);
3971 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003972 pr_err("%s - failed to find dst entry!\n",
3973 __func__);
3974 goto reject;
3975 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003976 neigh = dst_neigh_lookup_skb(dst, skb);
3977
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003978 if (!neigh) {
3979 pr_err("%s - failed to allocate neigh!\n",
3980 __func__);
3981 goto free_dst;
3982 }
3983
Vipul Pandya1cab7752012-12-10 09:30:55 +00003984 if (neigh->dev->flags & IFF_LOOPBACK) {
3985 pdev = ip_dev_find(&init_net, iph->daddr);
3986 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3987 pdev, 0);
3988 pi = (struct port_info *)netdev_priv(pdev);
3989 tx_chan = cxgb4_port_chan(pdev);
3990 dev_put(pdev);
3991 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303992 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003993 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303994 pdev, 0);
3995 pi = (struct port_info *)netdev_priv(pdev);
3996 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003997 }
Steve Wiseebf00062014-03-19 17:44:40 +05303998 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003999 if (!e) {
4000 pr_err("%s - failed to allocate l2t entry!\n",
4001 __func__);
4002 goto free_dst;
4003 }
4004
4005 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4006 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00004007 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004008
4009 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05304010 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4011 dev->rdev.lldi.ports[0],
4012 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004013
4014 /*
4015 * Synthesize the cpl_pass_accept_req. We have everything except the
4016 * TID. Once firmware sends a reply with TID we update the TID field
4017 * in cpl and pass it through the regular cpl_pass_accept_req path.
4018 */
4019 build_cpl_pass_accept_req(skb, stid, iph->tos);
4020 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4021 tcph->source, ntohl(tcph->seq), filter, window,
4022 rss_qid, pi->port_id);
4023 cxgb4_l2t_release(e);
4024free_dst:
4025 dst_release(dst);
4026reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304027 if (lep)
4028 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004029 return 0;
4030}
4031
Steve Wisecfdda9d2010-04-21 15:30:06 -07004032/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004033 * These are the real handlers that are called from a
4034 * work queue.
4035 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304036static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004037 [CPL_ACT_ESTABLISH] = act_establish,
4038 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4039 [CPL_RX_DATA] = rx_data,
4040 [CPL_ABORT_RPL_RSS] = abort_rpl,
4041 [CPL_ABORT_RPL] = abort_rpl,
4042 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4043 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4044 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4045 [CPL_PASS_ESTABLISH] = pass_establish,
4046 [CPL_PEER_CLOSE] = peer_close,
4047 [CPL_ABORT_REQ_RSS] = peer_abort,
4048 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4049 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004050 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004051 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304052 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304053 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4054 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055};
4056
4057static void process_timeout(struct c4iw_ep *ep)
4058{
4059 struct c4iw_qp_attributes attrs;
4060 int abort = 1;
4061
Steve Wise2f5b48c2010-09-10 11:15:36 -05004062 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4064 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004065 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004066 switch (ep->com.state) {
4067 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004068 connect_reply_upcall(ep, -ETIMEDOUT);
4069 break;
4070 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304071 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304072 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304073 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004074 break;
4075 case CLOSING:
4076 case MORIBUND:
4077 if (ep->com.cm_id && ep->com.qp) {
4078 attrs.next_state = C4IW_QP_STATE_ERROR;
4079 c4iw_modify_qp(ep->com.qp->rhp,
4080 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4081 &attrs, 1);
4082 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304083 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004084 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004085 case ABORTING:
4086 case DEAD:
4087
4088 /*
4089 * These states are expected if the ep timed out at the same
4090 * time as another thread was calling stop_ep_timer().
4091 * So we silently do nothing for these states.
4092 */
4093 abort = 0;
4094 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004096 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004098 abort = 0;
4099 }
Steve Wisecc18b932014-04-24 14:31:53 -05004100 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304101 if (abort)
4102 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103 c4iw_put_ep(&ep->com);
4104}
4105
4106static void process_timedout_eps(void)
4107{
4108 struct c4iw_ep *ep;
4109
4110 spin_lock_irq(&timeout_lock);
4111 while (!list_empty(&timeout_list)) {
4112 struct list_head *tmp;
4113
4114 tmp = timeout_list.next;
4115 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004116 tmp->next = NULL;
4117 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004118 spin_unlock_irq(&timeout_lock);
4119 ep = list_entry(tmp, struct c4iw_ep, entry);
4120 process_timeout(ep);
4121 spin_lock_irq(&timeout_lock);
4122 }
4123 spin_unlock_irq(&timeout_lock);
4124}
4125
4126static void process_work(struct work_struct *work)
4127{
4128 struct sk_buff *skb = NULL;
4129 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004130 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004131 unsigned int opcode;
4132 int ret;
4133
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004134 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004135 while ((skb = skb_dequeue(&rxq))) {
4136 rpl = cplhdr(skb);
4137 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4138 opcode = rpl->ot.opcode;
4139
4140 BUG_ON(!work_handlers[opcode]);
4141 ret = work_handlers[opcode](dev, skb);
4142 if (!ret)
4143 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004144 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004145 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004146}
4147
4148static DECLARE_WORK(skb_work, process_work);
4149
4150static void ep_timeout(unsigned long arg)
4151{
4152 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004153 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004154
4155 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004156 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004157 /*
4158 * Only insert if it is not already on the list.
4159 */
4160 if (!ep->entry.next) {
4161 list_add_tail(&ep->entry, &timeout_list);
4162 kickit = 1;
4163 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004164 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004165 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004166 if (kickit)
4167 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004168}
4169
4170/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004171 * All the CM events are handled on a work queue to have a safe context.
4172 */
4173static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4174{
4175
4176 /*
4177 * Save dev in the skb->cb area.
4178 */
4179 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4180
4181 /*
4182 * Queue the skb and schedule the worker thread.
4183 */
4184 skb_queue_tail(&rxq, skb);
4185 queue_work(workq, &skb_work);
4186 return 0;
4187}
4188
4189static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4190{
4191 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4192
4193 if (rpl->status != CPL_ERR_NONE) {
4194 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4195 "for tid %u\n", rpl->status, GET_TID(rpl));
4196 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004197 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004198 return 0;
4199}
4200
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004201static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4202{
4203 struct cpl_fw6_msg *rpl = cplhdr(skb);
4204 struct c4iw_wr_wait *wr_waitp;
4205 int ret;
4206
4207 PDBG("%s type %u\n", __func__, rpl->type);
4208
4209 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004210 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004211 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004212 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004213 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004214 if (wr_waitp)
4215 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004216 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004217 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004218 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004219 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004220 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004221 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004222 default:
4223 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4224 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004225 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004226 break;
4227 }
4228 return 0;
4229}
4230
Steve Wise8da7e7a2011-06-14 20:59:27 +00004231static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4232{
4233 struct cpl_abort_req_rss *req = cplhdr(skb);
4234 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004235 unsigned int tid = GET_TID(req);
4236
Hariprasad S944661d2016-05-06 22:18:03 +05304237 ep = get_ep_from_tid(dev, tid);
4238 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004239 if (!ep) {
4240 printk(KERN_WARNING MOD
4241 "Abort on non-existent endpoint, tid %d\n", tid);
4242 kfree_skb(skb);
4243 return 0;
4244 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304245 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304246 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4247 __func__, ep->hwtid, req->status,
4248 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304249 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004250 }
4251 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4252 ep->com.state);
4253
Hariprasad S093108c2016-05-06 22:18:09 +05304254 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304255out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004256 sched(dev, skb);
4257 return 0;
4258}
4259
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004260/*
4261 * Most upcalls from the T4 Core go to sched() to
4262 * schedule the processing on a work queue.
4263 */
4264c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4265 [CPL_ACT_ESTABLISH] = sched,
4266 [CPL_ACT_OPEN_RPL] = sched,
4267 [CPL_RX_DATA] = sched,
4268 [CPL_ABORT_RPL_RSS] = sched,
4269 [CPL_ABORT_RPL] = sched,
4270 [CPL_PASS_OPEN_RPL] = sched,
4271 [CPL_CLOSE_LISTSRV_RPL] = sched,
4272 [CPL_PASS_ACCEPT_REQ] = sched,
4273 [CPL_PASS_ESTABLISH] = sched,
4274 [CPL_PEER_CLOSE] = sched,
4275 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004276 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004277 [CPL_RDMA_TERMINATE] = sched,
4278 [CPL_FW4_ACK] = sched,
4279 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004280 [CPL_FW6_MSG] = fw6_msg,
4281 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004282};
4283
Steve Wisecfdda9d2010-04-21 15:30:06 -07004284int __init c4iw_cm_init(void)
4285{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004286 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004287 skb_queue_head_init(&rxq);
4288
4289 workq = create_singlethread_workqueue("iw_cxgb4");
4290 if (!workq)
4291 return -ENOMEM;
4292
Steve Wisecfdda9d2010-04-21 15:30:06 -07004293 return 0;
4294}
4295
Steve Wise46c13762014-06-20 14:26:25 -05004296void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004297{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004298 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004299 flush_workqueue(workq);
4300 destroy_workqueue(workq);
4301}