blob: 57b5bb56cdbff3de99abd7f21f9a362211e3ce40 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Steve Wisecfdda9d2010-04-21 15:30:06 -070052#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053053#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070054
55static char *states[] = {
56 "idle",
57 "listen",
58 "connecting",
59 "mpa_wait_req",
60 "mpa_req_sent",
61 "mpa_req_rcvd",
62 "mpa_rep_sent",
63 "fpdu_mode",
64 "aborting",
65 "closing",
66 "moribund",
67 "dead",
68 NULL,
69};
70
Vipul Pandya5be78ee2012-12-10 09:30:54 +000071static int nocong;
72module_param(nocong, int, 0644);
73MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75static int enable_ecn;
76module_param(enable_ecn, int, 0644);
77MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
Steve Wiseb52fe092011-03-11 22:30:01 +000079static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000080module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000081MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000082
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053083uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070084module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053085MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070087
Steve Wisecfdda9d2010-04-21 15:30:06 -070088static int enable_tcp_timestamps;
89module_param(enable_tcp_timestamps, int, 0644);
90MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92static int enable_tcp_sack;
93module_param(enable_tcp_sack, int, 0644);
94MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96static int enable_tcp_window_scaling = 1;
97module_param(enable_tcp_window_scaling, int, 0644);
98MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101int c4iw_debug;
102module_param(c4iw_debug, int, 0644);
103MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
Steve Wisedf2d5132014-03-19 17:44:44 +0530105static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530107MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110module_param(p2p_type, int, 0644);
111MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114static int ep_timeout_secs = 60;
115module_param(ep_timeout_secs, int, 0644);
116MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530119static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120module_param(mpa_rev, int, 0644);
121MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530122 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530123 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
125static int markers_enabled;
126module_param(markers_enabled, int, 0644);
127MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129static int crc_enabled = 1;
130module_param(crc_enabled, int, 0644);
131MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133static int rcv_win = 256 * 1024;
134module_param(rcv_win, int, 0644);
135MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
Steve Wise98ae68b2010-09-10 11:15:41 -0500137static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500139MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700144
145static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146static void ep_timeout(unsigned long arg);
147static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530148static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700149
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700150static LIST_HEAD(timeout_list);
151static spinlock_t timeout_lock;
152
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530153static void deref_cm_id(struct c4iw_ep_common *epc)
154{
155 epc->cm_id->rem_ref(epc->cm_id);
156 epc->cm_id = NULL;
157 set_bit(CM_ID_DEREFED, &epc->history);
158}
159
160static void ref_cm_id(struct c4iw_ep_common *epc)
161{
162 set_bit(CM_ID_REFED, &epc->history);
163 epc->cm_id->add_ref(epc->cm_id);
164}
165
Vipul Pandya325abea2013-01-07 13:11:53 +0000166static void deref_qp(struct c4iw_ep *ep)
167{
168 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
169 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530170 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000171}
172
173static void ref_qp(struct c4iw_ep *ep)
174{
175 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530176 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000177 c4iw_qp_add_ref(&ep->com.qp->ibqp);
178}
179
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180static void start_ep_timer(struct c4iw_ep *ep)
181{
182 PDBG("%s ep %p\n", __func__, ep);
183 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000184 pr_err("%s timer already started! ep %p\n",
185 __func__, ep);
186 return;
187 }
188 clear_bit(TIMEOUT, &ep->com.flags);
189 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700190 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
191 ep->timer.data = (unsigned long)ep;
192 ep->timer.function = ep_timeout;
193 add_timer(&ep->timer);
194}
195
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500196static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700197{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000198 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700199 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500200 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000201 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500202 return 0;
203 }
204 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
208 struct l2t_entry *l2e)
209{
210 int error = 0;
211
212 if (c4iw_fatal_error(rdev)) {
213 kfree_skb(skb);
214 PDBG("%s - device in error state - dropping\n", __func__);
215 return -EIO;
216 }
217 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
218 if (error < 0)
219 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530220 else if (error == NET_XMIT_DROP)
221 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500222 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700223}
224
225int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
226{
227 int error = 0;
228
229 if (c4iw_fatal_error(rdev)) {
230 kfree_skb(skb);
231 PDBG("%s - device in error state - dropping\n", __func__);
232 return -EIO;
233 }
234 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
235 if (error < 0)
236 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500237 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700238}
239
240static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
241{
242 struct cpl_tid_release *req;
243
244 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
245 if (!skb)
246 return;
247 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
248 INIT_TP_WR(req, hwtid);
249 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
250 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
251 c4iw_ofld_send(rdev, skb);
252 return;
253}
254
255static void set_emss(struct c4iw_ep *ep, u16 opt)
256{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800257 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530258 ((AF_INET == ep->com.remote_addr.ss_family) ?
259 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
260 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800262 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530263 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700264 if (ep->emss < 128)
265 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530266 if (ep->emss & 7)
267 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800268 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
269 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700270 ep->mss, ep->emss);
271}
272
273static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
274{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 enum c4iw_ep_state state;
276
Steve Wise2f5b48c2010-09-10 11:15:36 -0500277 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500279 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700280 return state;
281}
282
283static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
284{
285 epc->state = new;
286}
287
288static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
289{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500290 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
292 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500293 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700294 return;
295}
296
297static void *alloc_ep(int size, gfp_t gfp)
298{
299 struct c4iw_ep_common *epc;
300
301 epc = kzalloc(size, gfp);
302 if (epc) {
303 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500304 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500305 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700306 }
307 PDBG("%s alloc ep %p\n", __func__, epc);
308 return epc;
309}
310
Hariprasad S944661d2016-05-06 22:18:03 +0530311static void remove_ep_tid(struct c4iw_ep *ep)
312{
313 unsigned long flags;
314
315 spin_lock_irqsave(&ep->com.dev->lock, flags);
316 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
317 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
318}
319
320static void insert_ep_tid(struct c4iw_ep *ep)
321{
322 unsigned long flags;
323
324 spin_lock_irqsave(&ep->com.dev->lock, flags);
325 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
326 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
327}
328
329/*
330 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
331 */
332static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
333{
334 struct c4iw_ep *ep;
335 unsigned long flags;
336
337 spin_lock_irqsave(&dev->lock, flags);
338 ep = idr_find(&dev->hwtid_idr, tid);
339 if (ep)
340 c4iw_get_ep(&ep->com);
341 spin_unlock_irqrestore(&dev->lock, flags);
342 return ep;
343}
344
Hariprasad Sf86fac72016-05-06 22:18:07 +0530345/*
346 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
347 */
348static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
349 unsigned int stid)
350{
351 struct c4iw_listen_ep *ep;
352 unsigned long flags;
353
354 spin_lock_irqsave(&dev->lock, flags);
355 ep = idr_find(&dev->stid_idr, stid);
356 if (ep)
357 c4iw_get_ep(&ep->com);
358 spin_unlock_irqrestore(&dev->lock, flags);
359 return ep;
360}
361
Steve Wisecfdda9d2010-04-21 15:30:06 -0700362void _c4iw_free_ep(struct kref *kref)
363{
364 struct c4iw_ep *ep;
365
366 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530367 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000368 if (test_bit(QP_REFERENCED, &ep->com.flags))
369 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700370 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530371 if (ep->com.remote_addr.ss_family == AF_INET6) {
372 struct sockaddr_in6 *sin6 =
373 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600374 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530375
376 cxgb4_clip_release(
377 ep->com.dev->rdev.lldi.ports[0],
378 (const u32 *)&sin6->sin6_addr.s6_addr,
379 1);
380 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700381 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
382 dst_release(ep->dst);
383 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530384 if (ep->mpa_skb)
385 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700386 }
387 kfree(ep);
388}
389
390static void release_ep_resources(struct c4iw_ep *ep)
391{
392 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530393
394 /*
395 * If we have a hwtid, then remove it from the idr table
396 * so lookups will no longer find this endpoint. Otherwise
397 * we have a race where one thread finds the ep ptr just
398 * before the other thread is freeing the ep memory.
399 */
400 if (ep->hwtid != -1)
401 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700402 c4iw_put_ep(&ep->com);
403}
404
Steve Wisecfdda9d2010-04-21 15:30:06 -0700405static int status2errno(int status)
406{
407 switch (status) {
408 case CPL_ERR_NONE:
409 return 0;
410 case CPL_ERR_CONN_RESET:
411 return -ECONNRESET;
412 case CPL_ERR_ARP_MISS:
413 return -EHOSTUNREACH;
414 case CPL_ERR_CONN_TIMEDOUT:
415 return -ETIMEDOUT;
416 case CPL_ERR_TCAM_FULL:
417 return -ENOMEM;
418 case CPL_ERR_CONN_EXIST:
419 return -EADDRINUSE;
420 default:
421 return -EIO;
422 }
423}
424
425/*
426 * Try and reuse skbs already allocated...
427 */
428static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
429{
430 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
431 skb_trim(skb, 0);
432 skb_get(skb);
433 skb_reset_transport_header(skb);
434 } else {
435 skb = alloc_skb(len, gfp);
436 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530437 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700438 return skb;
439}
440
Vipul Pandya830662f2013-07-04 16:10:47 +0530441static struct net_device *get_real_dev(struct net_device *egress_dev)
442{
Steve Wise11b8e222014-05-16 12:42:46 -0500443 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530444}
445
446static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
447{
448 int i;
449
450 egress_dev = get_real_dev(egress_dev);
451 for (i = 0; i < dev->rdev.lldi.nports; i++)
452 if (dev->rdev.lldi.ports[i] == egress_dev)
453 return 1;
454 return 0;
455}
456
457static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
458 __u8 *peer_ip, __be16 local_port,
459 __be16 peer_port, u8 tos,
460 __u32 sin6_scope_id)
461{
462 struct dst_entry *dst = NULL;
463
464 if (IS_ENABLED(CONFIG_IPV6)) {
465 struct flowi6 fl6;
466
467 memset(&fl6, 0, sizeof(fl6));
468 memcpy(&fl6.daddr, peer_ip, 16);
469 memcpy(&fl6.saddr, local_ip, 16);
470 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
471 fl6.flowi6_oif = sin6_scope_id;
472 dst = ip6_route_output(&init_net, NULL, &fl6);
473 if (!dst)
474 goto out;
475 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
476 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
477 dst_release(dst);
478 dst = NULL;
479 }
480 }
481
482out:
483 return dst;
484}
485
486static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700487 __be32 peer_ip, __be16 local_port,
488 __be16 peer_port, u8 tos)
489{
490 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700491 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530492 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700493
David S. Miller31e4543d2011-05-03 20:25:42 -0700494 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500495 peer_port, local_port, IPPROTO_TCP,
496 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800497 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700498 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530499 n = dst_neigh_lookup(&rt->dst, &peer_ip);
500 if (!n)
501 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530502 if (!our_interface(dev, n->dev) &&
503 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530504 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530505 dst_release(&rt->dst);
506 return NULL;
507 }
508 neigh_release(n);
509 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700510}
511
512static void arp_failure_discard(void *handle, struct sk_buff *skb)
513{
Hariprasad S9dec9002016-05-05 01:27:29 +0530514 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700515 kfree_skb(skb);
516}
517
Hariprasad S64bec742016-05-06 22:18:10 +0530518static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
519{
520 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
521}
522
Hariprasad S9dec9002016-05-05 01:27:29 +0530523enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530524 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530525 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530526 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530527};
528
529static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
530{
531 struct c4iw_ep *ep;
532
533 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
534 release_ep_resources(ep);
535 return 0;
536}
537
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530538static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
539{
540 struct c4iw_ep *ep;
541
542 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
543 c4iw_put_ep(&ep->parent_ep->com);
544 release_ep_resources(ep);
545 return 0;
546}
547
Hariprasad S9dec9002016-05-05 01:27:29 +0530548/*
549 * Fake up a special CPL opcode and call sched() so process_work() will call
550 * _put_ep_safe() in a safe context to free the ep resources. This is needed
551 * because ARP error handlers are called in an ATOMIC context, and
552 * _c4iw_free_ep() needs to block.
553 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530554static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
555 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530556{
557 struct cpl_act_establish *rpl = cplhdr(skb);
558
559 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530560 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530561
562 /*
563 * Save ep in the skb->cb area, after where sched() will save the dev
564 * ptr.
565 */
566 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
567 sched(ep->com.dev, skb);
568}
569
570/* Handle an ARP failure for an accept */
571static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
572{
573 struct c4iw_ep *ep = handle;
574
575 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
576 ep->hwtid);
577
578 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530579 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530580}
581
Steve Wisecfdda9d2010-04-21 15:30:06 -0700582/*
583 * Handle an ARP failure for an active open.
584 */
585static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
586{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530587 struct c4iw_ep *ep = handle;
588
Masanari Iidae3d132d2015-10-16 21:14:29 +0900589 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530590 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530591 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530592 if (ep->com.remote_addr.ss_family == AF_INET6) {
593 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600594 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530595 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
596 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
597 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530598 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
599 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530600 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700601}
602
603/*
604 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
605 * and send it along.
606 */
607static void abort_arp_failure(void *handle, struct sk_buff *skb)
608{
Hariprasad S761e19a2016-05-06 22:18:02 +0530609 int ret;
610 struct c4iw_ep *ep = handle;
611 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700612 struct cpl_abort_req *req = cplhdr(skb);
613
614 PDBG("%s rdev %p\n", __func__, rdev);
615 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530616 ret = c4iw_ofld_send(rdev, skb);
617 if (ret) {
618 __state_set(&ep->com, DEAD);
619 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
620 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700621}
622
Hariprasad Sfef44222016-05-05 01:27:33 +0530623static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700624{
625 unsigned int flowclen = 80;
626 struct fw_flowc_wr *flowc;
627 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530628 u16 vlan = ep->l2t->vlan;
629 int nparams;
630
631 if (vlan == CPL_L2T_VLAN_NONE)
632 nparams = 8;
633 else
634 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700635
636 skb = get_skb(skb, flowclen, GFP_KERNEL);
637 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
638
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530639 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530640 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530641 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
642 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700643
644 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530645 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530646 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700647 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
648 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
649 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
650 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
651 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
652 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
653 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
654 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
655 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
656 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
657 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530658 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700659 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
660 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530661 if (nparams == 9) {
662 u16 pri;
663
664 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
665 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
666 flowc->mnemval[8].val = cpu_to_be32(pri);
667 } else {
668 /* Pad WR to 16 byte boundary */
669 flowc->mnemval[8].mnemonic = 0;
670 flowc->mnemval[8].val = 0;
671 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700672 for (i = 0; i < 9; i++) {
673 flowc->mnemval[i].r4[0] = 0;
674 flowc->mnemval[i].r4[1] = 0;
675 flowc->mnemval[i].r4[2] = 0;
676 }
677
678 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530679 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700680}
681
682static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
683{
684 struct cpl_close_con_req *req;
685 struct sk_buff *skb;
686 int wrlen = roundup(sizeof *req, 16);
687
688 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
689 skb = get_skb(NULL, wrlen, gfp);
690 if (!skb) {
691 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
692 return -ENOMEM;
693 }
694 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
695 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
696 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
697 memset(req, 0, wrlen);
698 INIT_TP_WR(req, ep->hwtid);
699 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
700 ep->hwtid));
701 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
702}
703
704static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
705{
706 struct cpl_abort_req *req;
707 int wrlen = roundup(sizeof *req, 16);
708
709 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
710 skb = get_skb(skb, wrlen, gfp);
711 if (!skb) {
712 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
713 __func__);
714 return -ENOMEM;
715 }
716 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530717 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700718 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
719 memset(req, 0, wrlen);
720 INIT_TP_WR(req, ep->hwtid);
721 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
722 req->cmd = CPL_ABORT_SEND_RST;
723 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
724}
725
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530726static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530727 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530728{
Hariprasad S04524a42014-09-24 03:53:41 +0530729 unsigned short hdr_size = (ipv6 ?
730 sizeof(struct ipv6hdr) :
731 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530732 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530733 (use_ts ?
734 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530735 unsigned short data_size = mtu - hdr_size;
736
737 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
738}
739
Steve Wisecfdda9d2010-04-21 15:30:06 -0700740static int send_connect(struct c4iw_ep *ep)
741{
Hariprasad S963cab52015-09-23 17:19:27 +0530742 struct cpl_act_open_req *req = NULL;
743 struct cpl_t5_act_open_req *t5req = NULL;
744 struct cpl_t6_act_open_req *t6req = NULL;
745 struct cpl_act_open_req6 *req6 = NULL;
746 struct cpl_t5_act_open_req6 *t5req6 = NULL;
747 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700748 struct sk_buff *skb;
749 u64 opt0;
750 u32 opt2;
751 unsigned int mtu_idx;
752 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530753 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500754 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600755 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500756 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600757 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500758 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600759 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500760 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600761 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530762 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530763 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
764 u32 isn = (prandom_u32() & ~7UL) - 1;
765
766 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
767 case CHELSIO_T4:
768 sizev4 = sizeof(struct cpl_act_open_req);
769 sizev6 = sizeof(struct cpl_act_open_req6);
770 break;
771 case CHELSIO_T5:
772 sizev4 = sizeof(struct cpl_t5_act_open_req);
773 sizev6 = sizeof(struct cpl_t5_act_open_req6);
774 break;
775 case CHELSIO_T6:
776 sizev4 = sizeof(struct cpl_t6_act_open_req);
777 sizev6 = sizeof(struct cpl_t6_act_open_req6);
778 break;
779 default:
780 pr_err("T%d Chip is not supported\n",
781 CHELSIO_CHIP_VERSION(adapter_type));
782 return -EINVAL;
783 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530784
785 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
786 roundup(sizev4, 16) :
787 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700788
789 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
790
791 skb = get_skb(NULL, wrlen, GFP_KERNEL);
792 if (!skb) {
793 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
794 __func__);
795 return -ENOMEM;
796 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000797 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700798
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530799 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530800 enable_tcp_timestamps,
801 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700802 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530803
804 /*
805 * Specify the largest window that will fit in opt0. The
806 * remainder will be specified in the rx_data_ack.
807 */
808 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800809 if (win > RCV_BUFSIZ_M)
810 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530811
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800812 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800813 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800814 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800815 WND_SCALE_V(wscale) |
816 MSS_IDX_V(mtu_idx) |
817 L2T_IDX_V(ep->l2t->idx) |
818 TX_CHAN_V(ep->tx_chan) |
819 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530820 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800821 ULP_MODE_V(ULP_MODE_TCPDDP) |
822 RCV_BUFSIZ_V(win);
823 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800824 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800825 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700826 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800827 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700828 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800829 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700830 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800831 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530832 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
833 if (peer2peer)
834 isn += 4;
835
Anish Bhattd7990b02014-11-12 17:15:57 -0800836 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530837 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530838 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500839 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530840
841 if (ep->com.remote_addr.ss_family == AF_INET6)
842 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
843 (const u32 *)&la6->sin6_addr.s6_addr, 1);
844
Hariprasad S5dab6d32014-06-23 19:12:36 +0530845 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700846
Hariprasad S963cab52015-09-23 17:19:27 +0530847 if (ep->com.remote_addr.ss_family == AF_INET) {
848 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
849 case CHELSIO_T4:
850 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530851 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530852 break;
853 case CHELSIO_T5:
854 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
855 wrlen);
856 INIT_TP_WR(t5req, 0);
857 req = (struct cpl_act_open_req *)t5req;
858 break;
859 case CHELSIO_T6:
860 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
861 wrlen);
862 INIT_TP_WR(t6req, 0);
863 req = (struct cpl_act_open_req *)t6req;
864 t5req = (struct cpl_t5_act_open_req *)t6req;
865 break;
866 default:
867 pr_err("T%d Chip is not supported\n",
868 CHELSIO_CHIP_VERSION(adapter_type));
869 ret = -EINVAL;
870 goto clip_release;
871 }
872
873 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
874 ((ep->rss_qid<<14) | ep->atid)));
875 req->local_port = la->sin_port;
876 req->peer_port = ra->sin_port;
877 req->local_ip = la->sin_addr.s_addr;
878 req->peer_ip = ra->sin_addr.s_addr;
879 req->opt0 = cpu_to_be64(opt0);
880
881 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530882 req->params = cpu_to_be32(cxgb4_select_ntuple(
883 ep->com.dev->rdev.lldi.ports[0],
884 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530885 req->opt2 = cpu_to_be32(opt2);
886 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530887 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
888 cxgb4_select_ntuple(
889 ep->com.dev->rdev.lldi.ports[0],
890 ep->l2t)));
891 t5req->rsvd = cpu_to_be32(isn);
892 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
893 t5req->opt2 = cpu_to_be32(opt2);
894 }
895 } else {
896 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
897 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530898 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530899 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530900 break;
901 case CHELSIO_T5:
902 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
903 wrlen);
904 INIT_TP_WR(t5req6, 0);
905 req6 = (struct cpl_act_open_req6 *)t5req6;
906 break;
907 case CHELSIO_T6:
908 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
909 wrlen);
910 INIT_TP_WR(t6req6, 0);
911 req6 = (struct cpl_act_open_req6 *)t6req6;
912 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
913 break;
914 default:
915 pr_err("T%d Chip is not supported\n",
916 CHELSIO_CHIP_VERSION(adapter_type));
917 ret = -EINVAL;
918 goto clip_release;
919 }
920
921 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
922 ((ep->rss_qid<<14)|ep->atid)));
923 req6->local_port = la6->sin6_port;
924 req6->peer_port = ra6->sin6_port;
925 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
926 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
927 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
928 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
929 req6->opt0 = cpu_to_be64(opt0);
930
931 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530932 req6->params = cpu_to_be32(cxgb4_select_ntuple(
933 ep->com.dev->rdev.lldi.ports[0],
934 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530935 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530936 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530937 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
938 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530939 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530940 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530941 t5req6->rsvd = cpu_to_be32(isn);
942 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
943 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530944 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000945 }
946
Vipul Pandya793dad92012-12-10 09:30:56 +0000947 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530948 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530949clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530950 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
951 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
952 (const u32 *)&la6->sin6_addr.s6_addr, 1);
953 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954}
955
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530956static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
957 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700958{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530959 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700960 struct fw_ofld_tx_data_wr *req;
961 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530962 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700963
964 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
965
966 BUG_ON(skb_cloned(skb));
967
968 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530969 if (mpa_rev_to_use == 2)
970 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700971 wrlen = roundup(mpalen + sizeof *req, 16);
972 skb = get_skb(skb, wrlen, GFP_KERNEL);
973 if (!skb) {
974 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530975 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700976 }
977 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
978
979 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
980 memset(req, 0, wrlen);
981 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530982 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
983 FW_WR_COMPL_F |
984 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700985 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530986 FW_WR_FLOWID_V(ep->hwtid) |
987 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700988 req->plen = cpu_to_be32(mpalen);
989 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530990 FW_OFLD_TX_DATA_WR_FLUSH_F |
991 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700992
993 mpa = (struct mpa_message *)(req + 1);
994 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
995 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530996 (markers_enabled ? MPA_MARKERS : 0) |
997 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700998 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530999 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301000 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301001 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301002 ep->retry_with_mpa_v1 = 0;
1003 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001004
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301005 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001006 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1007 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301008 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1009 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301010 mpa_v2_params.ird = htons((u16)ep->ird);
1011 mpa_v2_params.ord = htons((u16)ep->ord);
1012
1013 if (peer2peer) {
1014 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1015 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1016 mpa_v2_params.ord |=
1017 htons(MPA_V2_RDMA_WRITE_RTR);
1018 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1019 mpa_v2_params.ord |=
1020 htons(MPA_V2_RDMA_READ_RTR);
1021 }
1022 memcpy(mpa->private_data, &mpa_v2_params,
1023 sizeof(struct mpa_v2_conn_params));
1024
1025 if (ep->plen)
1026 memcpy(mpa->private_data +
1027 sizeof(struct mpa_v2_conn_params),
1028 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1029 } else
1030 if (ep->plen)
1031 memcpy(mpa->private_data,
1032 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001033
1034 /*
1035 * Reference the mpa skb. This ensures the data area
1036 * will remain in memory until the hw acks the tx.
1037 * Function fw4_ack() will deref it.
1038 */
1039 skb_get(skb);
1040 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1041 BUG_ON(ep->mpa_skb);
1042 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301043 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1044 if (ret)
1045 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001046 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301047 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001048 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301049 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301050 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001051}
1052
1053static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1054{
1055 int mpalen, wrlen;
1056 struct fw_ofld_tx_data_wr *req;
1057 struct mpa_message *mpa;
1058 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301059 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060
1061 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1062
1063 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301064 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1065 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001066 wrlen = roundup(mpalen + sizeof *req, 16);
1067
1068 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1069 if (!skb) {
1070 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1071 return -ENOMEM;
1072 }
1073 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1074
1075 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1076 memset(req, 0, wrlen);
1077 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301078 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1079 FW_WR_COMPL_F |
1080 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301082 FW_WR_FLOWID_V(ep->hwtid) |
1083 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001084 req->plen = cpu_to_be32(mpalen);
1085 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301086 FW_OFLD_TX_DATA_WR_FLUSH_F |
1087 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088
1089 mpa = (struct mpa_message *)(req + 1);
1090 memset(mpa, 0, sizeof(*mpa));
1091 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1092 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001093 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301095
1096 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1097 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001098 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1099 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301100 mpa_v2_params.ird = htons(((u16)ep->ird) |
1101 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1102 0));
1103 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1104 (p2p_type ==
1105 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1106 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1107 FW_RI_INIT_P2PTYPE_READ_REQ ?
1108 MPA_V2_RDMA_READ_RTR : 0) : 0));
1109 memcpy(mpa->private_data, &mpa_v2_params,
1110 sizeof(struct mpa_v2_conn_params));
1111
1112 if (ep->plen)
1113 memcpy(mpa->private_data +
1114 sizeof(struct mpa_v2_conn_params), pdata, plen);
1115 } else
1116 if (plen)
1117 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001118
1119 /*
1120 * Reference the mpa skb again. This ensures the data area
1121 * will remain in memory until the hw acks the tx.
1122 * Function fw4_ack() will deref it.
1123 */
1124 skb_get(skb);
1125 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301126 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001127 BUG_ON(ep->mpa_skb);
1128 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301129 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001130 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1131}
1132
1133static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1134{
1135 int mpalen, wrlen;
1136 struct fw_ofld_tx_data_wr *req;
1137 struct mpa_message *mpa;
1138 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301139 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001140
1141 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1142
1143 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301144 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1145 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001146 wrlen = roundup(mpalen + sizeof *req, 16);
1147
1148 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1149 if (!skb) {
1150 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1151 return -ENOMEM;
1152 }
1153 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1154
1155 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1156 memset(req, 0, wrlen);
1157 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301158 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1159 FW_WR_COMPL_F |
1160 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301162 FW_WR_FLOWID_V(ep->hwtid) |
1163 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001164 req->plen = cpu_to_be32(mpalen);
1165 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301166 FW_OFLD_TX_DATA_WR_FLUSH_F |
1167 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001168
1169 mpa = (struct mpa_message *)(req + 1);
1170 memset(mpa, 0, sizeof(*mpa));
1171 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1172 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1173 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301174 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301176
1177 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1178 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001179 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1180 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301181 mpa_v2_params.ird = htons((u16)ep->ird);
1182 mpa_v2_params.ord = htons((u16)ep->ord);
1183 if (peer2peer && (ep->mpa_attr.p2p_type !=
1184 FW_RI_INIT_P2PTYPE_DISABLED)) {
1185 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1186
1187 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1188 mpa_v2_params.ord |=
1189 htons(MPA_V2_RDMA_WRITE_RTR);
1190 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1191 mpa_v2_params.ord |=
1192 htons(MPA_V2_RDMA_READ_RTR);
1193 }
1194
1195 memcpy(mpa->private_data, &mpa_v2_params,
1196 sizeof(struct mpa_v2_conn_params));
1197
1198 if (ep->plen)
1199 memcpy(mpa->private_data +
1200 sizeof(struct mpa_v2_conn_params), pdata, plen);
1201 } else
1202 if (plen)
1203 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001204
1205 /*
1206 * Reference the mpa skb. This ensures the data area
1207 * will remain in memory until the hw acks the tx.
1208 * Function fw4_ack() will deref it.
1209 */
1210 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301211 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301213 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301214 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001215 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1216}
1217
1218static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1219{
1220 struct c4iw_ep *ep;
1221 struct cpl_act_establish *req = cplhdr(skb);
1222 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001223 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001224 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301225 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001226
1227 ep = lookup_atid(t, atid);
1228
1229 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1230 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1231
Steve Wisea7db89e2014-03-21 20:40:35 +05301232 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001233 dst_confirm(ep->dst);
1234
1235 /* setup the hwtid for this connection */
1236 ep->hwtid = tid;
1237 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301238 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001239
1240 ep->snd_seq = be32_to_cpu(req->snd_isn);
1241 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1242
1243 set_emss(ep, ntohs(req->tcp_opt));
1244
1245 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001246 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001247 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001248 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001249
1250 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301251 ret = send_flowc(ep, NULL);
1252 if (ret)
1253 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301254 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301255 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301256 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301257 ret = send_mpa_req(ep, skb, mpa_rev);
1258 if (ret)
1259 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301260 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001261 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301262err:
1263 mutex_unlock(&ep->com.mutex);
1264 connect_reply_upcall(ep, -ENOMEM);
1265 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1266 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001267}
1268
Steve Wisebe13b2d2014-03-21 20:40:33 +05301269static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001270{
1271 struct iw_cm_event event;
1272
1273 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1274 memset(&event, 0, sizeof(event));
1275 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301276 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001277 if (ep->com.cm_id) {
1278 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1279 ep, ep->com.cm_id, ep->hwtid);
1280 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301281 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001282 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001283 }
1284}
1285
Steve Wisecfdda9d2010-04-21 15:30:06 -07001286static void peer_close_upcall(struct c4iw_ep *ep)
1287{
1288 struct iw_cm_event event;
1289
1290 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1291 memset(&event, 0, sizeof(event));
1292 event.event = IW_CM_EVENT_DISCONNECT;
1293 if (ep->com.cm_id) {
1294 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1295 ep, ep->com.cm_id, ep->hwtid);
1296 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001297 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 }
1299}
1300
1301static void peer_abort_upcall(struct c4iw_ep *ep)
1302{
1303 struct iw_cm_event event;
1304
1305 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1306 memset(&event, 0, sizeof(event));
1307 event.event = IW_CM_EVENT_CLOSE;
1308 event.status = -ECONNRESET;
1309 if (ep->com.cm_id) {
1310 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1311 ep->com.cm_id, ep->hwtid);
1312 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301313 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001314 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315 }
1316}
1317
1318static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1319{
1320 struct iw_cm_event event;
1321
1322 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1323 memset(&event, 0, sizeof(event));
1324 event.event = IW_CM_EVENT_CONNECT_REPLY;
1325 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301326 memcpy(&event.local_addr, &ep->com.local_addr,
1327 sizeof(ep->com.local_addr));
1328 memcpy(&event.remote_addr, &ep->com.remote_addr,
1329 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001330
1331 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301332 if (!ep->tried_with_mpa_v1) {
1333 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301334 event.ord = ep->ird;
1335 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301336 event.private_data_len = ep->plen -
1337 sizeof(struct mpa_v2_conn_params);
1338 event.private_data = ep->mpa_pkt +
1339 sizeof(struct mpa_message) +
1340 sizeof(struct mpa_v2_conn_params);
1341 } else {
1342 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301343 event.ord = cur_max_read_depth(ep->com.dev);
1344 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301345 event.private_data_len = ep->plen;
1346 event.private_data = ep->mpa_pkt +
1347 sizeof(struct mpa_message);
1348 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001349 }
Roland Dreier85963e42010-07-19 13:13:09 -07001350
1351 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1352 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001353 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001354 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1355
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301356 if (status < 0)
1357 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001358}
1359
Steve Wisebe13b2d2014-03-21 20:40:33 +05301360static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001361{
1362 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301363 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001364
1365 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1366 memset(&event, 0, sizeof(event));
1367 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301368 memcpy(&event.local_addr, &ep->com.local_addr,
1369 sizeof(ep->com.local_addr));
1370 memcpy(&event.remote_addr, &ep->com.remote_addr,
1371 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001372 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301373 if (!ep->tried_with_mpa_v1) {
1374 /* this means MPA_v2 is used */
1375 event.ord = ep->ord;
1376 event.ird = ep->ird;
1377 event.private_data_len = ep->plen -
1378 sizeof(struct mpa_v2_conn_params);
1379 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1380 sizeof(struct mpa_v2_conn_params);
1381 } else {
1382 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301383 event.ord = cur_max_read_depth(ep->com.dev);
1384 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301385 event.private_data_len = ep->plen;
1386 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1387 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301388 c4iw_get_ep(&ep->com);
1389 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1390 &event);
1391 if (ret)
1392 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001393 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001394 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301395 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001396}
1397
1398static void established_upcall(struct c4iw_ep *ep)
1399{
1400 struct iw_cm_event event;
1401
1402 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1403 memset(&event, 0, sizeof(event));
1404 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301405 event.ird = ep->ord;
1406 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001407 if (ep->com.cm_id) {
1408 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1409 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001410 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001411 }
1412}
1413
1414static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1415{
1416 struct cpl_rx_data_ack *req;
1417 struct sk_buff *skb;
1418 int wrlen = roundup(sizeof *req, 16);
1419
1420 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1421 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1422 if (!skb) {
1423 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1424 return 0;
1425 }
1426
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301427 /*
1428 * If we couldn't specify the entire rcv window at connection setup
1429 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1430 * then add the overage in to the credits returned.
1431 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001432 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1433 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301434
Steve Wisecfdda9d2010-04-21 15:30:06 -07001435 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1436 memset(req, 0, wrlen);
1437 INIT_TP_WR(req, ep->hwtid);
1438 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1439 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001440 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301441 RX_DACK_CHANGE_F |
1442 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001443 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1445 return credits;
1446}
1447
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301448#define RELAXED_IRD_NEGOTIATION 1
1449
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301450/*
1451 * process_mpa_reply - process streaming mode MPA reply
1452 *
1453 * Returns:
1454 *
1455 * 0 upon success indicating a connect request was delivered to the ULP
1456 * or the mpa request is incomplete but valid so far.
1457 *
1458 * 1 if a failure requires the caller to close the connection.
1459 *
1460 * 2 if a failure requires the caller to abort the connection.
1461 */
Steve Wisecc18b932014-04-24 14:31:53 -05001462static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001463{
1464 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301465 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001466 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301467 u16 resp_ird, resp_ord;
1468 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469 struct c4iw_qp_attributes attrs;
1470 enum c4iw_qp_attr_mask mask;
1471 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001472 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473
1474 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1475
1476 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 * If we get more than the supported amount of private data
1478 * then we must fail this connection.
1479 */
1480 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1481 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301482 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483 }
1484
1485 /*
1486 * copy the new data into our accumulation buffer.
1487 */
1488 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1489 skb->len);
1490 ep->mpa_pkt_len += skb->len;
1491
1492 /*
1493 * if we don't even have the mpa message, then bail.
1494 */
1495 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001496 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001497 mpa = (struct mpa_message *) ep->mpa_pkt;
1498
1499 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301500 if (mpa->revision > mpa_rev) {
1501 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1502 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001503 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301504 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 }
1506 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1507 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301508 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001509 }
1510
1511 plen = ntohs(mpa->private_data_size);
1512
1513 /*
1514 * Fail if there's too much private data.
1515 */
1516 if (plen > MPA_MAX_PRIVATE_DATA) {
1517 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301518 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001519 }
1520
1521 /*
1522 * If plen does not account for pkt size
1523 */
1524 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1525 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301526 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001527 }
1528
1529 ep->plen = (u8) plen;
1530
1531 /*
1532 * If we don't have all the pdata yet, then bail.
1533 * We'll continue process when more data arrives.
1534 */
1535 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001536 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001537
1538 if (mpa->flags & MPA_REJECT) {
1539 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301540 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001541 }
1542
1543 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301544 * Stop mpa timer. If it expired, then
1545 * we ignore the MPA reply. process_timeout()
1546 * will abort the connection.
1547 */
1548 if (stop_ep_timer(ep))
1549 return 0;
1550
1551 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552 * If we get here we have accumulated the entire mpa
1553 * start reply message including private data. And
1554 * the MPA header is valid.
1555 */
Steve Wisec529fb52014-03-21 20:40:37 +05301556 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001557 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1558 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1559 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301560 ep->mpa_attr.version = mpa->revision;
1561 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1562
1563 if (mpa->revision == 2) {
1564 ep->mpa_attr.enhanced_rdma_conn =
1565 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1566 if (ep->mpa_attr.enhanced_rdma_conn) {
1567 mpa_v2_params = (struct mpa_v2_conn_params *)
1568 (ep->mpa_pkt + sizeof(*mpa));
1569 resp_ird = ntohs(mpa_v2_params->ird) &
1570 MPA_V2_IRD_ORD_MASK;
1571 resp_ord = ntohs(mpa_v2_params->ord) &
1572 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301573 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1574 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301575
1576 /*
1577 * This is a double-check. Ideally, below checks are
1578 * not required since ird/ord stuff has been taken
1579 * care of in c4iw_accept_cr
1580 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301581 if (ep->ird < resp_ord) {
1582 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1583 ep->com.dev->rdev.lldi.max_ordird_qp)
1584 ep->ird = resp_ord;
1585 else
1586 insuff_ird = 1;
1587 } else if (ep->ird > resp_ord) {
1588 ep->ird = resp_ord;
1589 }
1590 if (ep->ord > resp_ird) {
1591 if (RELAXED_IRD_NEGOTIATION)
1592 ep->ord = resp_ird;
1593 else
1594 insuff_ird = 1;
1595 }
1596 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597 err = -ENOMEM;
1598 ep->ird = resp_ord;
1599 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301600 }
1601
1602 if (ntohs(mpa_v2_params->ird) &
1603 MPA_V2_PEER2PEER_MODEL) {
1604 if (ntohs(mpa_v2_params->ord) &
1605 MPA_V2_RDMA_WRITE_RTR)
1606 ep->mpa_attr.p2p_type =
1607 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1608 else if (ntohs(mpa_v2_params->ord) &
1609 MPA_V2_RDMA_READ_RTR)
1610 ep->mpa_attr.p2p_type =
1611 FW_RI_INIT_P2PTYPE_READ_REQ;
1612 }
1613 }
1614 } else if (mpa->revision == 1)
1615 if (peer2peer)
1616 ep->mpa_attr.p2p_type = p2p_type;
1617
Steve Wisecfdda9d2010-04-21 15:30:06 -07001618 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1620 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1621 ep->mpa_attr.recv_marker_enabled,
1622 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1623 ep->mpa_attr.p2p_type, p2p_type);
1624
1625 /*
1626 * If responder's RTR does not match with that of initiator, assign
1627 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1628 * generated when moving QP to RTS state.
1629 * A TERM message will be sent after QP has moved to RTS state
1630 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001631 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301632 (ep->mpa_attr.p2p_type != p2p_type)) {
1633 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1634 rtr_mismatch = 1;
1635 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001636
1637 attrs.mpa_attr = ep->mpa_attr;
1638 attrs.max_ird = ep->ird;
1639 attrs.max_ord = ep->ord;
1640 attrs.llp_stream_handle = ep;
1641 attrs.next_state = C4IW_QP_STATE_RTS;
1642
1643 mask = C4IW_QP_ATTR_NEXT_STATE |
1644 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1645 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1646
1647 /* bind QP and TID with INIT_WR */
1648 err = c4iw_modify_qp(ep->com.qp->rhp,
1649 ep->com.qp, mask, &attrs, 1);
1650 if (err)
1651 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301652
1653 /*
1654 * If responder's RTR requirement did not match with what initiator
1655 * supports, generate TERM message
1656 */
1657 if (rtr_mismatch) {
1658 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1659 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1660 attrs.ecode = MPA_NOMATCH_RTR;
1661 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001662 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301663 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001664 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301665 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001666 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301667 goto out;
1668 }
1669
1670 /*
1671 * Generate TERM if initiator IRD is not sufficient for responder
1672 * provided ORD. Currently, we do the same behaviour even when
1673 * responder provided IRD is also not sufficient as regards to
1674 * initiator ORD.
1675 */
1676 if (insuff_ird) {
1677 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1678 __func__);
1679 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1680 attrs.ecode = MPA_INSUFF_IRD;
1681 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001682 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301683 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001684 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301685 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001686 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301687 goto out;
1688 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001689 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301690err_stop_timer:
1691 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001692err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301693 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001694out:
1695 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001696 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697}
1698
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301699/*
1700 * process_mpa_request - process streaming mode MPA request
1701 *
1702 * Returns:
1703 *
1704 * 0 upon success indicating a connect request was delivered to the ULP
1705 * or the mpa request is incomplete but valid so far.
1706 *
1707 * 1 if a failure requires the caller to close the connection.
1708 *
1709 * 2 if a failure requires the caller to abort the connection.
1710 */
1711static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001712{
1713 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301714 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001715 u16 plen;
1716
1717 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1718
Steve Wisecfdda9d2010-04-21 15:30:06 -07001719 /*
1720 * If we get more than the supported amount of private data
1721 * then we must fail this connection.
1722 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301723 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1724 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001725
1726 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1727
1728 /*
1729 * Copy the new data into our accumulation buffer.
1730 */
1731 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1732 skb->len);
1733 ep->mpa_pkt_len += skb->len;
1734
1735 /*
1736 * If we don't even have the mpa message, then bail.
1737 * We'll continue process when more data arrives.
1738 */
1739 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301740 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001741
1742 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001743 mpa = (struct mpa_message *) ep->mpa_pkt;
1744
1745 /*
1746 * Validate MPA Header.
1747 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301748 if (mpa->revision > mpa_rev) {
1749 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1750 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301751 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001752 }
1753
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301754 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1755 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001756
1757 plen = ntohs(mpa->private_data_size);
1758
1759 /*
1760 * Fail if there's too much private data.
1761 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301762 if (plen > MPA_MAX_PRIVATE_DATA)
1763 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001764
1765 /*
1766 * If plen does not account for pkt size
1767 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301768 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1769 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001770 ep->plen = (u8) plen;
1771
1772 /*
1773 * If we don't have all the pdata yet, then bail.
1774 */
1775 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301776 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777
1778 /*
1779 * If we get here we have accumulated the entire mpa
1780 * start reply message including private data.
1781 */
1782 ep->mpa_attr.initiator = 0;
1783 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1784 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1785 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301786 ep->mpa_attr.version = mpa->revision;
1787 if (mpa->revision == 1)
1788 ep->tried_with_mpa_v1 = 1;
1789 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1790
1791 if (mpa->revision == 2) {
1792 ep->mpa_attr.enhanced_rdma_conn =
1793 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1794 if (ep->mpa_attr.enhanced_rdma_conn) {
1795 mpa_v2_params = (struct mpa_v2_conn_params *)
1796 (ep->mpa_pkt + sizeof(*mpa));
1797 ep->ird = ntohs(mpa_v2_params->ird) &
1798 MPA_V2_IRD_ORD_MASK;
1799 ep->ord = ntohs(mpa_v2_params->ord) &
1800 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301801 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1802 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301803 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1804 if (peer2peer) {
1805 if (ntohs(mpa_v2_params->ord) &
1806 MPA_V2_RDMA_WRITE_RTR)
1807 ep->mpa_attr.p2p_type =
1808 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1809 else if (ntohs(mpa_v2_params->ord) &
1810 MPA_V2_RDMA_READ_RTR)
1811 ep->mpa_attr.p2p_type =
1812 FW_RI_INIT_P2PTYPE_READ_REQ;
1813 }
1814 }
1815 } else if (mpa->revision == 1)
1816 if (peer2peer)
1817 ep->mpa_attr.p2p_type = p2p_type;
1818
Steve Wisecfdda9d2010-04-21 15:30:06 -07001819 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1820 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1821 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1822 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1823 ep->mpa_attr.p2p_type);
1824
Hariprasad Se4b76a22016-05-06 22:17:59 +05301825 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001826
Hariprasad Se4b76a22016-05-06 22:17:59 +05301827 /* drive upcall */
1828 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1829 if (ep->parent_ep->com.state != DEAD) {
1830 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301831 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301832 } else {
1833 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301834 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301835 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301836 return 0;
1837
1838err_unlock_parent:
1839 mutex_unlock(&ep->parent_ep->com.mutex);
1840 goto err_out;
1841err_stop_timer:
1842 (void)stop_ep_timer(ep);
1843err_out:
1844 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845}
1846
1847static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1848{
1849 struct c4iw_ep *ep;
1850 struct cpl_rx_data *hdr = cplhdr(skb);
1851 unsigned int dlen = ntohs(hdr->len);
1852 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001853 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001854 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855
Hariprasad S944661d2016-05-06 22:18:03 +05301856 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301857 if (!ep)
1858 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001859 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1860 skb_pull(skb, sizeof(*hdr));
1861 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301862 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001863
Steve Wisecfdda9d2010-04-21 15:30:06 -07001864 /* update RX credits */
1865 update_rx_credits(ep, dlen);
1866
Steve Wisec529fb52014-03-21 20:40:37 +05301867 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001868 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001869 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001870 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001871 break;
1872 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001873 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301874 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001875 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001876 case FPDU_MODE: {
1877 struct c4iw_qp_attributes attrs;
1878 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001879 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001880 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001881 " qpid %u ep %p state %d tid %u status %d\n",
1882 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301883 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301884 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001885 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001886 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1887 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001888 break;
1889 }
Vipul Pandya15579672013-01-07 13:11:52 +00001890 default:
1891 break;
1892 }
Steve Wisec529fb52014-03-21 20:40:37 +05301893 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001894 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301895 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301896 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001897 return 0;
1898}
1899
1900static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1901{
1902 struct c4iw_ep *ep;
1903 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001904 int release = 0;
1905 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001906
Hariprasad S944661d2016-05-06 22:18:03 +05301907 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301908 if (!ep) {
1909 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1910 return 0;
1911 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001912 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001913 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001914 switch (ep->com.state) {
1915 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001916 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001917 __state_set(&ep->com, DEAD);
1918 release = 1;
1919 break;
1920 default:
1921 printk(KERN_ERR "%s ep %p state %d\n",
1922 __func__, ep, ep->com.state);
1923 break;
1924 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001925 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001926
1927 if (release)
1928 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301929 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001930 return 0;
1931}
1932
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301933static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001934{
1935 struct sk_buff *skb;
1936 struct fw_ofld_connection_wr *req;
1937 unsigned int mtu_idx;
1938 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301939 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301940 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001941
1942 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1943 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1944 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001945 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301946 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301947 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1948 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001949 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001950 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301951 req->le.lport = sin->sin_port;
1952 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001953 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301954 req->le.pport = sin->sin_port;
1955 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001956 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301957 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1958 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001959 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301960 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001961 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001962 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301963 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301964 enable_tcp_timestamps,
1965 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001966 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301967
1968 /*
1969 * Specify the largest window that will fit in opt0. The
1970 * remainder will be specified in the rx_data_ack.
1971 */
1972 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001973 if (win > RCV_BUFSIZ_M)
1974 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301975
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001976 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1977 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001978 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001979 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001980 WND_SCALE_V(wscale) |
1981 MSS_IDX_V(mtu_idx) |
1982 L2T_IDX_V(ep->l2t->idx) |
1983 TX_CHAN_V(ep->tx_chan) |
1984 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301985 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001986 ULP_MODE_V(ULP_MODE_TCPDDP) |
1987 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001988 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1989 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001990 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001991 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001992 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001993 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001994 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001995 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001996 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001997 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001998 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1999 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2000 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00002001 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2002 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302003 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002004}
2005
Steve Wisecfdda9d2010-04-21 15:30:06 -07002006/*
2007 * Return whether a failed active open has allocated a TID
2008 */
2009static inline int act_open_has_tid(int status)
2010{
2011 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
2012 status != CPL_ERR_ARP_MISS;
2013}
2014
Steve Wise7a2cea22014-03-14 21:52:07 +05302015/* Returns whether a CPL status conveys negative advice.
2016 */
2017static int is_neg_adv(unsigned int status)
2018{
2019 return status == CPL_ERR_RTX_NEG_ADVICE ||
2020 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2021 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2022}
2023
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302024static char *neg_adv_str(unsigned int status)
2025{
2026 switch (status) {
2027 case CPL_ERR_RTX_NEG_ADVICE:
2028 return "Retransmit timeout";
2029 case CPL_ERR_PERSIST_NEG_ADVICE:
2030 return "Persist timeout";
2031 case CPL_ERR_KEEPALV_NEG_ADVICE:
2032 return "Keepalive timeout";
2033 default:
2034 return "Unknown";
2035 }
2036}
2037
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302038static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2039{
2040 ep->snd_win = snd_win;
2041 ep->rcv_win = rcv_win;
2042 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2043}
2044
Vipul Pandya793dad92012-12-10 09:30:56 +00002045#define ACT_OPEN_RETRY_COUNT 2
2046
Vipul Pandya830662f2013-07-04 16:10:47 +05302047static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2048 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302049 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302050{
2051 struct neighbour *n;
2052 int err, step;
2053 struct net_device *pdev;
2054
2055 n = dst_neigh_lookup(dst, peer_ip);
2056 if (!n)
2057 return -ENODEV;
2058
2059 rcu_read_lock();
2060 err = -ENOMEM;
2061 if (n->dev->flags & IFF_LOOPBACK) {
2062 if (iptype == 4)
2063 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2064 else if (IS_ENABLED(CONFIG_IPV6))
2065 for_each_netdev(&init_net, pdev) {
2066 if (ipv6_chk_addr(&init_net,
2067 (struct in6_addr *)peer_ip,
2068 pdev, 1))
2069 break;
2070 }
2071 else
2072 pdev = NULL;
2073
2074 if (!pdev) {
2075 err = -ENODEV;
2076 goto out;
2077 }
2078 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302079 n, pdev, rt_tos2priority(tos));
Steve Wise609e9412016-09-01 06:43:46 -07002080 if (!ep->l2t) {
2081 dev_put(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302082 goto out;
Steve Wise609e9412016-09-01 06:43:46 -07002083 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 ep->mtu = pdev->mtu;
2085 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302086 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2087 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 step = cdev->rdev.lldi.ntxq /
2089 cdev->rdev.lldi.nchan;
2090 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2091 step = cdev->rdev.lldi.nrxq /
2092 cdev->rdev.lldi.nchan;
2093 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2094 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2095 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302096 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302097 dev_put(pdev);
2098 } else {
2099 pdev = get_real_dev(n->dev);
2100 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2101 n, pdev, 0);
2102 if (!ep->l2t)
2103 goto out;
2104 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002105 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302106 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2107 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302108 step = cdev->rdev.lldi.ntxq /
2109 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002110 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2111 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302112 step = cdev->rdev.lldi.nrxq /
2113 cdev->rdev.lldi.nchan;
2114 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002115 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302116 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302117
2118 if (clear_mpa_v1) {
2119 ep->retry_with_mpa_v1 = 0;
2120 ep->tried_with_mpa_v1 = 0;
2121 }
2122 }
2123 err = 0;
2124out:
2125 rcu_read_unlock();
2126
2127 neigh_release(n);
2128
2129 return err;
2130}
2131
Vipul Pandya793dad92012-12-10 09:30:56 +00002132static int c4iw_reconnect(struct c4iw_ep *ep)
2133{
2134 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302135 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002136 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302137 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002138 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302139 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002140 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302141 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002142 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302143 int iptype;
2144 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002145
2146 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2147 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302148 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002149
2150 /*
2151 * Allocate an active TID to initiate a TCP connection.
2152 */
2153 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2154 if (ep->atid == -1) {
2155 pr_err("%s - cannot alloc atid.\n", __func__);
2156 err = -ENOMEM;
2157 goto fail2;
2158 }
2159 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2160
2161 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002162 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302163 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2164 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302165 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302166 iptype = 4;
2167 ra = (__u8 *)&raddr->sin_addr;
2168 } else {
2169 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2170 raddr6->sin6_addr.s6_addr,
2171 laddr6->sin6_port, raddr6->sin6_port, 0,
2172 raddr6->sin6_scope_id);
2173 iptype = 6;
2174 ra = (__u8 *)&raddr6->sin6_addr;
2175 }
2176 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002177 pr_err("%s - cannot find route.\n", __func__);
2178 err = -EHOSTUNREACH;
2179 goto fail3;
2180 }
Hariprasad S963cab52015-09-23 17:19:27 +05302181 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302182 ep->com.dev->rdev.lldi.adapter_type,
2183 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302184 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002185 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002186 goto fail4;
2187 }
2188
2189 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2190 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2191 ep->l2t->idx);
2192
2193 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302194 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002195
2196 /* send connect request to rnic */
2197 err = send_connect(ep);
2198 if (!err)
2199 goto out;
2200
2201 cxgb4_l2t_release(ep->l2t);
2202fail4:
2203 dst_release(ep->dst);
2204fail3:
2205 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2206 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2207fail2:
2208 /*
2209 * remember to send notification to upper layer.
2210 * We are in here so the upper layer is not aware that this is
2211 * re-connect attempt and so, upper layer is still waiting for
2212 * response of 1st connect request.
2213 */
2214 connect_reply_upcall(ep, -ECONNRESET);
2215 c4iw_put_ep(&ep->com);
2216out:
2217 return err;
2218}
2219
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2221{
2222 struct c4iw_ep *ep;
2223 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002224 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2225 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002226 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002227 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302228 struct sockaddr_in *la;
2229 struct sockaddr_in *ra;
2230 struct sockaddr_in6 *la6;
2231 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302232 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002233
2234 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002235 la = (struct sockaddr_in *)&ep->com.local_addr;
2236 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2237 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2238 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002239
2240 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2241 status, status2errno(status));
2242
Steve Wise7a2cea22014-03-14 21:52:07 +05302243 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302244 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2245 __func__, atid, status, neg_adv_str(status));
2246 ep->stats.connect_neg_adv++;
2247 mutex_lock(&dev->rdev.stats.lock);
2248 dev->rdev.stats.neg_adv++;
2249 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250 return 0;
2251 }
2252
Vipul Pandya793dad92012-12-10 09:30:56 +00002253 set_bit(ACT_OPEN_RPL, &ep->com.history);
2254
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302255 /*
2256 * Log interesting failures.
2257 */
2258 switch (status) {
2259 case CPL_ERR_CONN_RESET:
2260 case CPL_ERR_CONN_TIMEDOUT:
2261 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002262 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302263 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002264 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302265 mutex_unlock(&dev->rdev.stats.lock);
2266 if (ep->com.local_addr.ss_family == AF_INET &&
2267 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302268 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2269 ntohl(rpl->atid_status))));
2270 if (ret)
2271 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002272 return 0;
2273 }
2274 break;
2275 case CPL_ERR_CONN_EXIST:
2276 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2277 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302278 if (ep->com.remote_addr.ss_family == AF_INET6) {
2279 struct sockaddr_in6 *sin6 =
2280 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002281 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302282 cxgb4_clip_release(
2283 ep->com.dev->rdev.lldi.ports[0],
2284 (const u32 *)
2285 &sin6->sin6_addr.s6_addr, 1);
2286 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002287 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2288 atid);
2289 cxgb4_free_atid(t, atid);
2290 dst_release(ep->dst);
2291 cxgb4_l2t_release(ep->l2t);
2292 c4iw_reconnect(ep);
2293 return 0;
2294 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002295 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302296 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302297 if (ep->com.local_addr.ss_family == AF_INET) {
2298 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2299 atid, status, status2errno(status),
2300 &la->sin_addr.s_addr, ntohs(la->sin_port),
2301 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2302 } else {
2303 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2304 atid, status, status2errno(status),
2305 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2306 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2307 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302308 break;
2309 }
2310
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302311fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002312 connect_reply_upcall(ep, status2errno(status));
2313 state_set(&ep->com, DEAD);
2314
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302315 if (ep->com.remote_addr.ss_family == AF_INET6) {
2316 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002317 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302318 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2319 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2320 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 if (status && act_open_has_tid(status))
2322 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2323
Vipul Pandya793dad92012-12-10 09:30:56 +00002324 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325 cxgb4_free_atid(t, atid);
2326 dst_release(ep->dst);
2327 cxgb4_l2t_release(ep->l2t);
2328 c4iw_put_ep(&ep->com);
2329
2330 return 0;
2331}
2332
2333static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2334{
2335 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302337 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002338
2339 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002340 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2341 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002342 }
2343 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2344 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002345 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302346 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002347out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348 return 0;
2349}
2350
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2352{
2353 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002354 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302355 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002356
2357 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002358 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302359 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360 return 0;
2361}
2362
Hariprasad S9dec9002016-05-05 01:27:29 +05302363static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2364 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002365{
2366 struct cpl_pass_accept_rpl *rpl;
2367 unsigned int mtu_idx;
2368 u64 opt0;
2369 u32 opt2;
2370 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302371 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302372 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302373 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002374
2375 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2376 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302377
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302379 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302380 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302381 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2382 rpl5 = (void *)rpl;
2383 INIT_TP_WR(rpl5, ep->hwtid);
2384 } else {
2385 skb_trim(skb, sizeof(*rpl));
2386 INIT_TP_WR(rpl, ep->hwtid);
2387 }
2388 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2389 ep->hwtid));
2390
2391 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302392 enable_tcp_timestamps && req->tcpopt.tstamp,
2393 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002394 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302395
2396 /*
2397 * Specify the largest window that will fit in opt0. The
2398 * remainder will be specified in the rx_data_ack.
2399 */
2400 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002401 if (win > RCV_BUFSIZ_M)
2402 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002403 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002404 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002405 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002406 WND_SCALE_V(wscale) |
2407 MSS_IDX_V(mtu_idx) |
2408 L2T_IDX_V(ep->l2t->idx) |
2409 TX_CHAN_V(ep->tx_chan) |
2410 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002411 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002412 ULP_MODE_V(ULP_MODE_TCPDDP) |
2413 RCV_BUFSIZ_V(win);
2414 opt2 = RX_CHANNEL_V(0) |
2415 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416
2417 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002418 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002420 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002422 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002423 if (enable_ecn) {
2424 const struct tcphdr *tcph;
2425 u32 hlen = ntohl(req->hdr_len);
2426
Hariprasad S963cab52015-09-23 17:19:27 +05302427 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2428 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2429 IP_HDR_LEN_G(hlen);
2430 else
2431 tcph = (const void *)(req + 1) +
2432 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002433 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002434 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002435 }
Hariprasad S963cab52015-09-23 17:19:27 +05302436 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302437 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002438 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302439 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302440 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302441 rpl5 = (void *)rpl;
2442 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2443 if (peer2peer)
2444 isn += 4;
2445 rpl5->iss = cpu_to_be32(isn);
2446 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002447 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448
Steve Wisecfdda9d2010-04-21 15:30:06 -07002449 rpl->opt0 = cpu_to_be64(opt0);
2450 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002451 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302452 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453
Hariprasad S9dec9002016-05-05 01:27:29 +05302454 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455}
2456
Vipul Pandya830662f2013-07-04 16:10:47 +05302457static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002458{
Vipul Pandya830662f2013-07-04 16:10:47 +05302459 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002460 BUG_ON(skb_cloned(skb));
2461 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 release_tid(&dev->rdev, hwtid, skb);
2463 return;
2464}
2465
Hariprasad S963cab52015-09-23 17:19:27 +05302466static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2467 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002468 __be16 *local_port, __be16 *peer_port)
2469{
Hariprasad S963cab52015-09-23 17:19:27 +05302470 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2471 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2472 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2473 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2474 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2475 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002476 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302477 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002478 struct tcphdr *tcp = (struct tcphdr *)
2479 ((u8 *)(req + 1) + eth_len + ip_len);
2480
Vipul Pandya830662f2013-07-04 16:10:47 +05302481 if (ip->version == 4) {
2482 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2483 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2484 ntohs(tcp->dest));
2485 *iptype = 4;
2486 memcpy(peer_ip, &ip->saddr, 4);
2487 memcpy(local_ip, &ip->daddr, 4);
2488 } else {
2489 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2490 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2491 ntohs(tcp->dest));
2492 *iptype = 6;
2493 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2494 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2495 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002496 *peer_port = tcp->source;
2497 *local_port = tcp->dest;
2498
2499 return;
2500}
2501
2502static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2503{
Vipul Pandya793dad92012-12-10 09:30:56 +00002504 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002505 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002506 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 struct tid_info *t = dev->rdev.lldi.tids;
2508 unsigned int hwtid = GET_TID(req);
2509 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302510 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002511 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302512 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002513 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002514 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302515 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302516 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302517 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518
Hariprasad Sf86fac72016-05-06 22:18:07 +05302519 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002520 if (!parent_ep) {
2521 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2522 goto reject;
2523 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002524
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302526 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 goto reject;
2528 }
2529
Hariprasad S963cab52015-09-23 17:19:27 +05302530 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2531 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302532
Steve Wisecfdda9d2010-04-21 15:30:06 -07002533 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302534 if (iptype == 4) {
2535 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2536 , __func__, parent_ep, hwtid,
2537 local_ip, peer_ip, ntohs(local_port),
2538 ntohs(peer_port), peer_mss);
2539 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2540 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302541 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302542 } else {
2543 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2544 , __func__, parent_ep, hwtid,
2545 local_ip, peer_ip, ntohs(local_port),
2546 ntohs(peer_port), peer_mss);
2547 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002548 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302549 ((struct sockaddr_in6 *)
2550 &parent_ep->com.local_addr)->sin6_scope_id);
2551 }
2552 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2554 __func__);
2555 goto reject;
2556 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002557
2558 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2559 if (!child_ep) {
2560 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2561 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 dst_release(dst);
2563 goto reject;
2564 }
David Miller3786cf12011-12-02 16:52:31 +00002565
Hariprasad S963cab52015-09-23 17:19:27 +05302566 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302567 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002568 if (err) {
2569 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2570 __func__);
2571 dst_release(dst);
2572 kfree(child_ep);
2573 goto reject;
2574 }
2575
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302576 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2577 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2578 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2579 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002580
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581 state_set(&child_ep->com, CONNECTING);
2582 child_ep->com.dev = dev;
2583 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002584
Vipul Pandya830662f2013-07-04 16:10:47 +05302585 if (iptype == 4) {
2586 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002587 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002588
Vipul Pandya830662f2013-07-04 16:10:47 +05302589 sin->sin_family = PF_INET;
2590 sin->sin_port = local_port;
2591 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002592
2593 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2594 sin->sin_family = PF_INET;
2595 sin->sin_port = ((struct sockaddr_in *)
2596 &parent_ep->com.local_addr)->sin_port;
2597 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2598
Steve Wise170003c2016-02-26 09:18:03 -06002599 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302600 sin->sin_family = PF_INET;
2601 sin->sin_port = peer_port;
2602 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2603 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002604 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302605 sin6->sin6_family = PF_INET6;
2606 sin6->sin6_port = local_port;
2607 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002608
2609 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2610 sin6->sin6_family = PF_INET6;
2611 sin6->sin6_port = ((struct sockaddr_in6 *)
2612 &parent_ep->com.local_addr)->sin6_port;
2613 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2614
Steve Wise170003c2016-02-26 09:18:03 -06002615 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302616 sin6->sin6_family = PF_INET6;
2617 sin6->sin6_port = peer_port;
2618 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2619 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002620
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621 c4iw_get_ep(&parent_ep->com);
2622 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302623 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 child_ep->dst = dst;
2625 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626
2627 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002628 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629
2630 init_timer(&child_ep->timer);
2631 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302632 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302633 if (accept_cr(child_ep, skb, req)) {
2634 c4iw_put_ep(&parent_ep->com);
2635 release_ep_resources(child_ep);
2636 } else {
2637 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2638 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302639 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002640 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302641 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2642 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2643 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 goto out;
2645reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302646 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302647 if (parent_ep)
2648 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002649out:
2650 return 0;
2651}
2652
2653static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2654{
2655 struct c4iw_ep *ep;
2656 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302658 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659
Hariprasad S944661d2016-05-06 22:18:03 +05302660 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2662 ep->snd_seq = be32_to_cpu(req->snd_isn);
2663 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2664
Vipul Pandya1cab7752012-12-10 09:30:55 +00002665 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2666 ntohs(req->tcp_opt));
2667
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 set_emss(ep, ntohs(req->tcp_opt));
2669
2670 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302671 mutex_lock(&ep->com.mutex);
2672 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002674 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302675 ret = send_flowc(ep, skb);
2676 mutex_unlock(&ep->com.mutex);
2677 if (ret)
2678 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302679 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680
2681 return 0;
2682}
2683
2684static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2685{
2686 struct cpl_peer_close *hdr = cplhdr(skb);
2687 struct c4iw_ep *ep;
2688 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689 int disconnect = 1;
2690 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002692 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693
Hariprasad S944661d2016-05-06 22:18:03 +05302694 ep = get_ep_from_tid(dev, tid);
2695 if (!ep)
2696 return 0;
2697
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2699 dst_confirm(ep->dst);
2700
Vipul Pandya793dad92012-12-10 09:30:56 +00002701 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002702 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703 switch (ep->com.state) {
2704 case MPA_REQ_WAIT:
2705 __state_set(&ep->com, CLOSING);
2706 break;
2707 case MPA_REQ_SENT:
2708 __state_set(&ep->com, CLOSING);
2709 connect_reply_upcall(ep, -ECONNRESET);
2710 break;
2711 case MPA_REQ_RCVD:
2712
2713 /*
2714 * We're gonna mark this puppy DEAD, but keep
2715 * the reference on it until the ULP accepts or
2716 * rejects the CR. Also wake up anyone waiting
2717 * in rdma connection migration (see c4iw_accept_cr()).
2718 */
2719 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002721 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 break;
2723 case MPA_REP_SENT:
2724 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002726 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727 break;
2728 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002729 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002731 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002732 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002733 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002734 if (ret != -ECONNRESET) {
2735 peer_close_upcall(ep);
2736 disconnect = 1;
2737 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 break;
2739 case ABORTING:
2740 disconnect = 0;
2741 break;
2742 case CLOSING:
2743 __state_set(&ep->com, MORIBUND);
2744 disconnect = 0;
2745 break;
2746 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002747 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748 if (ep->com.cm_id && ep->com.qp) {
2749 attrs.next_state = C4IW_QP_STATE_IDLE;
2750 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2751 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2752 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302753 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 __state_set(&ep->com, DEAD);
2755 release = 1;
2756 disconnect = 0;
2757 break;
2758 case DEAD:
2759 disconnect = 0;
2760 break;
2761 default:
2762 BUG_ON(1);
2763 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002764 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002765 if (disconnect)
2766 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2767 if (release)
2768 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302769 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770 return 0;
2771}
2772
Steve Wisecfdda9d2010-04-21 15:30:06 -07002773static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2774{
2775 struct cpl_abort_req_rss *req = cplhdr(skb);
2776 struct c4iw_ep *ep;
2777 struct cpl_abort_rpl *rpl;
2778 struct sk_buff *rpl_skb;
2779 struct c4iw_qp_attributes attrs;
2780 int ret;
2781 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002782 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783
Hariprasad S944661d2016-05-06 22:18:03 +05302784 ep = get_ep_from_tid(dev, tid);
2785 if (!ep)
2786 return 0;
2787
Steve Wise7a2cea22014-03-14 21:52:07 +05302788 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302789 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2790 __func__, ep->hwtid, req->status,
2791 neg_adv_str(req->status));
2792 ep->stats.abort_neg_adv++;
2793 mutex_lock(&dev->rdev.stats.lock);
2794 dev->rdev.stats.neg_adv++;
2795 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302796 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002797 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2799 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002800 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002801
2802 /*
2803 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302804 * However, this is not needed if com state is just
2805 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002806 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302807 if (ep->com.state != MPA_REQ_SENT)
2808 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002809
2810 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002811 switch (ep->com.state) {
2812 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302813 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 break;
2815 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002816 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002817 break;
2818 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002819 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002820 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302821 connect_reply_upcall(ep, -ECONNRESET);
2822 else {
2823 /*
2824 * we just don't send notification upwards because we
2825 * want to retry with mpa_v1 without upper layers even
2826 * knowing it.
2827 *
2828 * do some housekeeping so as to re-initiate the
2829 * connection
2830 */
2831 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2832 mpa_rev);
2833 ep->retry_with_mpa_v1 = 1;
2834 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002835 break;
2836 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 break;
2838 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 break;
2840 case MORIBUND:
2841 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002842 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 /*FALLTHROUGH*/
2844 case FPDU_MODE:
2845 if (ep->com.cm_id && ep->com.qp) {
2846 attrs.next_state = C4IW_QP_STATE_ERROR;
2847 ret = c4iw_modify_qp(ep->com.qp->rhp,
2848 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2849 &attrs, 1);
2850 if (ret)
2851 printk(KERN_ERR MOD
2852 "%s - qp <- error failed!\n",
2853 __func__);
2854 }
2855 peer_abort_upcall(ep);
2856 break;
2857 case ABORTING:
2858 break;
2859 case DEAD:
2860 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002861 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302862 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863 default:
2864 BUG_ON(1);
2865 break;
2866 }
2867 dst_confirm(ep->dst);
2868 if (ep->com.state != ABORTING) {
2869 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302870 /* we don't release if we want to retry with mpa_v1 */
2871 if (!ep->retry_with_mpa_v1)
2872 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002873 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002874 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002875
2876 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2877 if (!rpl_skb) {
2878 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2879 __func__);
2880 release = 1;
2881 goto out;
2882 }
2883 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2884 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2885 INIT_TP_WR(rpl, ep->hwtid);
2886 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2887 rpl->cmd = CPL_ABORT_NO_RST;
2888 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2889out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002890 if (release)
2891 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002892 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302893 if (ep->com.remote_addr.ss_family == AF_INET6) {
2894 struct sockaddr_in6 *sin6 =
2895 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002896 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302897 cxgb4_clip_release(
2898 ep->com.dev->rdev.lldi.ports[0],
2899 (const u32 *)&sin6->sin6_addr.s6_addr,
2900 1);
2901 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002902 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302903 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2904 dst_release(ep->dst);
2905 cxgb4_l2t_release(ep->l2t);
2906 c4iw_reconnect(ep);
2907 }
2908
Hariprasad S944661d2016-05-06 22:18:03 +05302909deref_ep:
2910 c4iw_put_ep(&ep->com);
2911 /* Dereferencing ep, referenced in peer_abort_intr() */
2912 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913 return 0;
2914}
2915
2916static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2917{
2918 struct c4iw_ep *ep;
2919 struct c4iw_qp_attributes attrs;
2920 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002922 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923
Hariprasad S944661d2016-05-06 22:18:03 +05302924 ep = get_ep_from_tid(dev, tid);
2925 if (!ep)
2926 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002927
2928 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2929 BUG_ON(!ep);
2930
2931 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002932 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302933 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 switch (ep->com.state) {
2935 case CLOSING:
2936 __state_set(&ep->com, MORIBUND);
2937 break;
2938 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002939 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002940 if ((ep->com.cm_id) && (ep->com.qp)) {
2941 attrs.next_state = C4IW_QP_STATE_IDLE;
2942 c4iw_modify_qp(ep->com.qp->rhp,
2943 ep->com.qp,
2944 C4IW_QP_ATTR_NEXT_STATE,
2945 &attrs, 1);
2946 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302947 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 __state_set(&ep->com, DEAD);
2949 release = 1;
2950 break;
2951 case ABORTING:
2952 case DEAD:
2953 break;
2954 default:
2955 BUG_ON(1);
2956 break;
2957 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002958 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 if (release)
2960 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302961 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 return 0;
2963}
2964
2965static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2966{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002967 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002968 unsigned int tid = GET_TID(rpl);
2969 struct c4iw_ep *ep;
2970 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971
Hariprasad S944661d2016-05-06 22:18:03 +05302972 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002973 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974
Steve Wise30c95c22011-05-09 22:06:22 -07002975 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002976 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2977 ep->com.qp->wq.sq.qid);
2978 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2979 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2980 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2981 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002982 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302983 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002984
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985 return 0;
2986}
2987
2988/*
2989 * Upcall from the adapter indicating data has been transmitted.
2990 * For us its just the single MPA request or reply. We can now free
2991 * the skb holding the mpa message.
2992 */
2993static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2994{
2995 struct c4iw_ep *ep;
2996 struct cpl_fw4_ack *hdr = cplhdr(skb);
2997 u8 credits = hdr->credits;
2998 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999
3000
Hariprasad S944661d2016-05-06 22:18:03 +05303001 ep = get_ep_from_tid(dev, tid);
3002 if (!ep)
3003 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003004 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
3005 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07003006 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3007 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05303008 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 }
3010
3011 dst_confirm(ep->dst);
3012 if (ep->mpa_skb) {
3013 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3014 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3015 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
3016 kfree_skb(ep->mpa_skb);
3017 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303018 mutex_lock(&ep->com.mutex);
3019 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3020 stop_ep_timer(ep);
3021 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022 }
Hariprasad S944661d2016-05-06 22:18:03 +05303023out:
3024 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003025 return 0;
3026}
3027
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3029{
Steve Wisea7db89e2014-03-21 20:40:35 +05303030 int err = 0;
3031 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 struct c4iw_ep *ep = to_ep(cm_id);
3033 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3034
Steve Wisea7db89e2014-03-21 20:40:35 +05303035 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303036 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303037 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038 c4iw_put_ep(&ep->com);
3039 return -ECONNRESET;
3040 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003041 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303043 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 else {
3045 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303046 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003047 }
Steve Wisea7db89e2014-03-21 20:40:35 +05303048 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303049 if (disconnect) {
3050 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303051 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05303052 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003053 c4iw_put_ep(&ep->com);
3054 return 0;
3055}
3056
3057int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3058{
3059 int err;
3060 struct c4iw_qp_attributes attrs;
3061 enum c4iw_qp_attr_mask mask;
3062 struct c4iw_ep *ep = to_ep(cm_id);
3063 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3064 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303065 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003066
3067 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303068
3069 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303070 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003071 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303072 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003073 }
3074
Steve Wisecfdda9d2010-04-21 15:30:06 -07003075 BUG_ON(!qp);
3076
Vipul Pandya793dad92012-12-10 09:30:56 +00003077 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303078 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3079 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003080 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303081 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082 }
3083
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303084 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3085 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303086 if (RELAXED_IRD_NEGOTIATION) {
3087 ep->ord = ep->ird;
3088 } else {
3089 ep->ird = conn_param->ird;
3090 ep->ord = conn_param->ord;
3091 send_mpa_reject(ep, conn_param->private_data,
3092 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303093 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303094 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303095 }
3096 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303097 if (conn_param->ird < ep->ord) {
3098 if (RELAXED_IRD_NEGOTIATION &&
3099 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3100 conn_param->ird = ep->ord;
3101 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303102 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303103 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303104 }
3105 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303106 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003107 ep->ird = conn_param->ird;
3108 ep->ord = conn_param->ord;
3109
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303110 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303111 if (peer2peer && ep->ird == 0)
3112 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303113 } else {
3114 if (peer2peer &&
3115 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303116 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303117 ep->ird = 1;
3118 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003119
3120 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3121
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303122 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303123 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303124 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003125 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303126
Steve Wisecfdda9d2010-04-21 15:30:06 -07003127 /* bind QP to EP and move to RTS */
3128 attrs.mpa_attr = ep->mpa_attr;
3129 attrs.max_ird = ep->ird;
3130 attrs.max_ord = ep->ord;
3131 attrs.llp_stream_handle = ep;
3132 attrs.next_state = C4IW_QP_STATE_RTS;
3133
3134 /* bind QP and TID with INIT_WR */
3135 mask = C4IW_QP_ATTR_NEXT_STATE |
3136 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3137 C4IW_QP_ATTR_MPA_ATTR |
3138 C4IW_QP_ATTR_MAX_IRD |
3139 C4IW_QP_ATTR_MAX_ORD;
3140
3141 err = c4iw_modify_qp(ep->com.qp->rhp,
3142 ep->com.qp, mask, &attrs, 1);
3143 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303144 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303145
3146 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003147 err = send_mpa_reply(ep, conn_param->private_data,
3148 conn_param->private_data_len);
3149 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303150 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003151
Steve Wisea7db89e2014-03-21 20:40:35 +05303152 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303154 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003155 c4iw_put_ep(&ep->com);
3156 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303157err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303158 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303159err_abort:
3160 abort = 1;
3161err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303162 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303163 if (abort)
3164 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003165 c4iw_put_ep(&ep->com);
3166 return err;
3167}
3168
Vipul Pandya830662f2013-07-04 16:10:47 +05303169static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3170{
3171 struct in_device *ind;
3172 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003173 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3174 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303175
3176 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3177 if (!ind)
3178 return -EADDRNOTAVAIL;
3179 for_primary_ifa(ind) {
3180 laddr->sin_addr.s_addr = ifa->ifa_address;
3181 raddr->sin_addr.s_addr = ifa->ifa_address;
3182 found = 1;
3183 break;
3184 }
3185 endfor_ifa(ind);
3186 in_dev_put(ind);
3187 return found ? 0 : -EADDRNOTAVAIL;
3188}
3189
3190static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3191 unsigned char banned_flags)
3192{
3193 struct inet6_dev *idev;
3194 int err = -EADDRNOTAVAIL;
3195
3196 rcu_read_lock();
3197 idev = __in6_dev_get(dev);
3198 if (idev != NULL) {
3199 struct inet6_ifaddr *ifp;
3200
3201 read_lock_bh(&idev->lock);
3202 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3203 if (ifp->scope == IFA_LINK &&
3204 !(ifp->flags & banned_flags)) {
3205 memcpy(addr, &ifp->addr, 16);
3206 err = 0;
3207 break;
3208 }
3209 }
3210 read_unlock_bh(&idev->lock);
3211 }
3212 rcu_read_unlock();
3213 return err;
3214}
3215
3216static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3217{
3218 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003219 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3220 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303221
Nicholas Krause54b9a962015-08-26 23:00:59 -04003222 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303223 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3224 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3225 return 0;
3226 }
3227 return -EADDRNOTAVAIL;
3228}
3229
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3231{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3233 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003234 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003235 struct sockaddr_in *laddr;
3236 struct sockaddr_in *raddr;
3237 struct sockaddr_in6 *laddr6;
3238 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303239 __u8 *ra;
3240 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003241
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303242 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3243 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003244 err = -EINVAL;
3245 goto out;
3246 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003247 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3248 if (!ep) {
3249 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3250 err = -ENOMEM;
3251 goto out;
3252 }
3253 init_timer(&ep->timer);
3254 ep->plen = conn_param->private_data_len;
3255 if (ep->plen)
3256 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3257 conn_param->private_data, ep->plen);
3258 ep->ird = conn_param->ird;
3259 ep->ord = conn_param->ord;
3260
3261 if (peer2peer && ep->ord == 0)
3262 ep->ord = 1;
3263
Steve Wisecfdda9d2010-04-21 15:30:06 -07003264 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303265 ref_cm_id(&ep->com);
3266 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003267 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303268 if (!ep->com.qp) {
3269 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3270 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003271 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303272 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003273 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003274 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3275 ep->com.qp, cm_id);
3276
3277 /*
3278 * Allocate an active TID to initiate a TCP connection.
3279 */
3280 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3281 if (ep->atid == -1) {
3282 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3283 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003284 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003285 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003286 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003287
Steve Wise170003c2016-02-26 09:18:03 -06003288 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003289 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003290 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003291 sizeof(ep->com.remote_addr));
3292
Steve Wise170003c2016-02-26 09:18:03 -06003293 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3294 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3295 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3296 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003297
Steve Wise170003c2016-02-26 09:18:03 -06003298 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303299 iptype = 4;
3300 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003301
Vipul Pandya830662f2013-07-04 16:10:47 +05303302 /*
3303 * Handle loopback requests to INADDR_ANY.
3304 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003305 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303306 err = pick_local_ipaddrs(dev, cm_id);
3307 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003308 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303309 }
3310
3311 /* find a route */
3312 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3313 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3314 ra, ntohs(raddr->sin_port));
3315 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3316 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303317 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303318 } else {
3319 iptype = 6;
3320 ra = (__u8 *)&raddr6->sin6_addr;
3321
3322 /*
3323 * Handle loopback requests to INADDR_ANY.
3324 */
3325 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3326 err = pick_local_ip6addrs(dev, cm_id);
3327 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003328 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303329 }
3330
3331 /* find a route */
3332 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3333 __func__, laddr6->sin6_addr.s6_addr,
3334 ntohs(laddr6->sin6_port),
3335 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3336 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3337 raddr6->sin6_addr.s6_addr,
3338 laddr6->sin6_port, raddr6->sin6_port, 0,
3339 raddr6->sin6_scope_id);
3340 }
3341 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003342 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3343 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003344 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003345 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003346
Hariprasad S963cab52015-09-23 17:19:27 +05303347 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303348 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003349 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003350 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003351 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003352 }
3353
3354 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3355 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3356 ep->l2t->idx);
3357
3358 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303359 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003360
3361 /* send connect request to rnic */
3362 err = send_connect(ep);
3363 if (!err)
3364 goto out;
3365
3366 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003367fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003368 dst_release(ep->dst);
3369fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003370 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003371 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003372fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303373 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374 c4iw_put_ep(&ep->com);
3375out:
3376 return err;
3377}
3378
Vipul Pandya830662f2013-07-04 16:10:47 +05303379static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3380{
3381 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003382 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003383 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303384
Hariprasad S28de1f72016-01-13 10:03:14 +05303385 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3386 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3387 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3388 if (err)
3389 return err;
3390 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303391 c4iw_init_wr_wait(&ep->com.wr_wait);
3392 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3393 ep->stid, &sin6->sin6_addr,
3394 sin6->sin6_port,
3395 ep->com.dev->rdev.lldi.rxq_ids[0]);
3396 if (!err)
3397 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3398 &ep->com.wr_wait,
3399 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303400 else if (err > 0)
3401 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303402 if (err) {
3403 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3404 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303405 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3406 err, ep->stid,
3407 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303408 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303409 return err;
3410}
3411
3412static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3413{
3414 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003415 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003416 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303417
3418 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3419 do {
3420 err = cxgb4_create_server_filter(
3421 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3422 sin->sin_addr.s_addr, sin->sin_port, 0,
3423 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3424 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303425 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3426 err = -EIO;
3427 break;
3428 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303429 set_current_state(TASK_UNINTERRUPTIBLE);
3430 schedule_timeout(usecs_to_jiffies(100));
3431 }
3432 } while (err == -EBUSY);
3433 } else {
3434 c4iw_init_wr_wait(&ep->com.wr_wait);
3435 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3436 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3437 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3438 if (!err)
3439 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3440 &ep->com.wr_wait,
3441 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303442 else if (err > 0)
3443 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303444 }
3445 if (err)
3446 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3447 , err, ep->stid,
3448 &sin->sin_addr, ntohs(sin->sin_port));
3449 return err;
3450}
3451
Steve Wisecfdda9d2010-04-21 15:30:06 -07003452int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3453{
3454 int err = 0;
3455 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3456 struct c4iw_listen_ep *ep;
3457
Steve Wisecfdda9d2010-04-21 15:30:06 -07003458 might_sleep();
3459
3460 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3461 if (!ep) {
3462 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3463 err = -ENOMEM;
3464 goto fail1;
3465 }
3466 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003467 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303468 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003469 ep->com.dev = dev;
3470 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003471 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303472 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003473
3474 /*
3475 * Allocate a server TID.
3476 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303477 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3478 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303479 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003480 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003481 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303482 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003483 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003484
Steve Wisecfdda9d2010-04-21 15:30:06 -07003485 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003486 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003487 err = -ENOMEM;
3488 goto fail2;
3489 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003490 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003491
Steve Wise170003c2016-02-26 09:18:03 -06003492 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3493 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003494
Steve Wisecfdda9d2010-04-21 15:30:06 -07003495 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303496 if (ep->com.local_addr.ss_family == AF_INET)
3497 err = create_server4(dev, ep);
3498 else
3499 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003500 if (!err) {
3501 cm_id->provider_data = ep;
3502 goto out;
3503 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003504
Vipul Pandya830662f2013-07-04 16:10:47 +05303505 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3506 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003507fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303508 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509 c4iw_put_ep(&ep->com);
3510fail1:
3511out:
3512 return err;
3513}
3514
3515int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3516{
3517 int err;
3518 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3519
3520 PDBG("%s ep %p\n", __func__, ep);
3521
3522 might_sleep();
3523 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303524 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3525 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003526 err = cxgb4_remove_server_filter(
3527 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3528 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3529 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303530 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003531 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303532 err = cxgb4_remove_server(
3533 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3534 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003535 if (err)
3536 goto done;
3537 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3538 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003539 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303540 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3541 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003542 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003543 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303544 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3545 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003546done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303547 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003548 c4iw_put_ep(&ep->com);
3549 return err;
3550}
3551
3552int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3553{
3554 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003555 int close = 0;
3556 int fatal = 0;
3557 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003558
Steve Wise2f5b48c2010-09-10 11:15:36 -05003559 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003560
3561 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3562 states[ep->com.state], abrupt);
3563
Hariprasad S6e410d82016-05-05 01:27:31 +05303564 /*
3565 * Ref the ep here in case we have fatal errors causing the
3566 * ep to be released and freed.
3567 */
3568 c4iw_get_ep(&ep->com);
3569
Steve Wisecfdda9d2010-04-21 15:30:06 -07003570 rdev = &ep->com.dev->rdev;
3571 if (c4iw_fatal_error(rdev)) {
3572 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303573 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003574 ep->com.state = DEAD;
3575 }
3576 switch (ep->com.state) {
3577 case MPA_REQ_WAIT:
3578 case MPA_REQ_SENT:
3579 case MPA_REQ_RCVD:
3580 case MPA_REP_SENT:
3581 case FPDU_MODE:
3582 close = 1;
3583 if (abrupt)
3584 ep->com.state = ABORTING;
3585 else {
3586 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003587 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003588 }
3589 set_bit(CLOSE_SENT, &ep->com.flags);
3590 break;
3591 case CLOSING:
3592 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3593 close = 1;
3594 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003595 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003596 ep->com.state = ABORTING;
3597 } else
3598 ep->com.state = MORIBUND;
3599 }
3600 break;
3601 case MORIBUND:
3602 case ABORTING:
3603 case DEAD:
3604 PDBG("%s ignoring disconnect ep %p state %u\n",
3605 __func__, ep, ep->com.state);
3606 break;
3607 default:
3608 BUG();
3609 break;
3610 }
3611
Steve Wisecfdda9d2010-04-21 15:30:06 -07003612 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003613 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003614 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303615 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003616 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003617 } else {
3618 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003619 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003620 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303621 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303622 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303623 if (!abrupt) {
3624 stop_ep_timer(ep);
3625 close_complete_upcall(ep, -EIO);
3626 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303627 if (ep->com.qp) {
3628 struct c4iw_qp_attributes attrs;
3629
3630 attrs.next_state = C4IW_QP_STATE_ERROR;
3631 ret = c4iw_modify_qp(ep->com.qp->rhp,
3632 ep->com.qp,
3633 C4IW_QP_ATTR_NEXT_STATE,
3634 &attrs, 1);
3635 if (ret)
3636 pr_err(MOD
3637 "%s - qp <- error failed!\n",
3638 __func__);
3639 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003640 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003642 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003643 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303644 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003645 if (fatal)
3646 release_ep_resources(ep);
3647 return ret;
3648}
3649
Vipul Pandya1cab7752012-12-10 09:30:55 +00003650static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3651 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3652{
3653 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003654 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003655
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003656 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3657 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003658 if (!ep)
3659 return;
3660
3661 switch (req->retval) {
3662 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003663 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3664 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3665 send_fw_act_open_req(ep, atid);
3666 return;
3667 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003668 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003669 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3670 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3671 send_fw_act_open_req(ep, atid);
3672 return;
3673 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003674 break;
3675 default:
3676 pr_info("%s unexpected ofld conn wr retval %d\n",
3677 __func__, req->retval);
3678 break;
3679 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003680 pr_err("active ofld_connect_wr failure %d atid %d\n",
3681 req->retval, atid);
3682 mutex_lock(&dev->rdev.stats.lock);
3683 dev->rdev.stats.act_ofld_conn_fails++;
3684 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003685 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003686 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303687 if (ep->com.remote_addr.ss_family == AF_INET6) {
3688 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003689 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303690 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3691 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3692 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003693 remove_handle(dev, &dev->atid_idr, atid);
3694 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3695 dst_release(ep->dst);
3696 cxgb4_l2t_release(ep->l2t);
3697 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003698}
3699
3700static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3701 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3702{
3703 struct sk_buff *rpl_skb;
3704 struct cpl_pass_accept_req *cpl;
3705 int ret;
3706
Paul Bolle710a3112013-02-05 20:51:30 +00003707 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003708 BUG_ON(!rpl_skb);
3709 if (req->retval) {
3710 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003711 mutex_lock(&dev->rdev.stats.lock);
3712 dev->rdev.stats.pas_ofld_conn_fails++;
3713 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003714 kfree_skb(rpl_skb);
3715 } else {
3716 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3717 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003718 (__force u32) htonl(
3719 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003720 ret = pass_accept_req(dev, rpl_skb);
3721 if (!ret)
3722 kfree_skb(rpl_skb);
3723 }
3724 return;
3725}
3726
3727static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003728{
3729 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3731
3732 switch (rpl->type) {
3733 case FW6_TYPE_CQE:
3734 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3735 break;
3736 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3737 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3738 switch (req->t_state) {
3739 case TCP_SYN_SENT:
3740 active_ofld_conn_reply(dev, skb, req);
3741 break;
3742 case TCP_SYN_RECV:
3743 passive_ofld_conn_reply(dev, skb, req);
3744 break;
3745 default:
3746 pr_err("%s unexpected ofld conn wr state %d\n",
3747 __func__, req->t_state);
3748 break;
3749 }
3750 break;
3751 }
3752 return 0;
3753}
3754
3755static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3756{
Hariprasad S963cab52015-09-23 17:19:27 +05303757 __be32 l2info;
3758 __be16 hdr_len, vlantag, len;
3759 u16 eth_hdr_len;
3760 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003761 u8 intf;
3762 struct cpl_rx_pkt *cpl = cplhdr(skb);
3763 struct cpl_pass_accept_req *req;
3764 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003765 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303766 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003767
Vipul Pandyaf079af72013-03-14 05:08:58 +00003768 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303770 vlantag = cpl->vlan;
3771 len = cpl->len;
3772 l2info = cpl->l2info;
3773 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003774 intf = cpl->iff;
3775
3776 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3777
3778 /*
3779 * We need to parse the TCP options from SYN packet.
3780 * to generate cpl_pass_accept_req.
3781 */
3782 memset(&tmp_opt, 0, sizeof(tmp_opt));
3783 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003784 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003785
3786 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3787 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303788 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3789 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303790 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303791 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303792 type = dev->rdev.lldi.adapter_type;
3793 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3794 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3795 req->hdr_len =
3796 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3797 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3798 eth_hdr_len = is_t4(type) ?
3799 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3800 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3801 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3802 IP_HDR_LEN_V(ip_hdr_len) |
3803 ETH_HDR_LEN_V(eth_hdr_len));
3804 } else { /* T6 and later */
3805 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3806 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3807 T6_IP_HDR_LEN_V(ip_hdr_len) |
3808 T6_ETH_HDR_LEN_V(eth_hdr_len));
3809 }
3810 req->vlan = vlantag;
3811 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003812 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3813 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3815 if (tmp_opt.wscale_ok)
3816 req->tcpopt.wsf = tmp_opt.snd_wscale;
3817 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3818 if (tmp_opt.sack_ok)
3819 req->tcpopt.sack = 1;
3820 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3821 return;
3822}
3823
3824static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3825 __be32 laddr, __be16 lport,
3826 __be32 raddr, __be16 rport,
3827 u32 rcv_isn, u32 filter, u16 window,
3828 u32 rss_qid, u8 port_id)
3829{
3830 struct sk_buff *req_skb;
3831 struct fw_ofld_connection_wr *req;
3832 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303833 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003834
3835 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3836 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3837 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003838 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303839 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303840 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003841 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003842 req->le.lport = lport;
3843 req->le.pport = rport;
3844 req->le.u.ipv4.lip = laddr;
3845 req->le.u.ipv4.pip = raddr;
3846 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3847 req->tcb.rcv_adv = htons(window);
3848 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303849 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3850 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3851 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003852 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003853
3854 /*
3855 * We store the qid in opt2 which will be used by the firmware
3856 * to send us the wr response.
3857 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003858 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003859
3860 /*
3861 * We initialize the MSS index in TCB to 0xF.
3862 * So that when driver sends cpl_pass_accept_rpl
3863 * TCB picks up the correct value. If this was 0
3864 * TP will ignore any value > 0 for MSS index.
3865 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003866 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303867 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003868
3869 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303870 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3871 if (ret < 0) {
3872 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3873 ret);
3874 kfree_skb(skb);
3875 kfree_skb(req_skb);
3876 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003877}
3878
3879/*
3880 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3881 * messages when a filter is being used instead of server to
3882 * redirect a syn packet. When packets hit filter they are redirected
3883 * to the offload queue and driver tries to establish the connection
3884 * using firmware work request.
3885 */
3886static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3887{
3888 int stid;
3889 unsigned int filter;
3890 struct ethhdr *eh = NULL;
3891 struct vlan_ethhdr *vlan_eh = NULL;
3892 struct iphdr *iph;
3893 struct tcphdr *tcph;
3894 struct rss_header *rss = (void *)skb->data;
3895 struct cpl_rx_pkt *cpl = (void *)skb->data;
3896 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3897 struct l2t_entry *e;
3898 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303899 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003900 u16 window;
3901 struct port_info *pi;
3902 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003903 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003904 int step;
3905 u32 tx_chan;
3906 struct neighbour *neigh;
3907
3908 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003909 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003910 goto reject;
3911
3912 /*
3913 * Drop all packets which did not hit the filter.
3914 * Unlikely to happen.
3915 */
3916 if (!(rss->filter_hit && rss->filter_tid))
3917 goto reject;
3918
3919 /*
3920 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3921 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303922 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003923
Hariprasad Sf86fac72016-05-06 22:18:07 +05303924 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003925 if (!lep) {
3926 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3927 goto reject;
3928 }
3929
Hariprasad S963cab52015-09-23 17:19:27 +05303930 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3931 case CHELSIO_T4:
3932 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3933 break;
3934 case CHELSIO_T5:
3935 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3936 break;
3937 case CHELSIO_T6:
3938 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3939 break;
3940 default:
3941 pr_err("T%d Chip is not supported\n",
3942 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3943 goto reject;
3944 }
3945
Vipul Pandyaf079af72013-03-14 05:08:58 +00003946 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003947 eh = (struct ethhdr *)(req + 1);
3948 iph = (struct iphdr *)(eh + 1);
3949 } else {
3950 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3951 iph = (struct iphdr *)(vlan_eh + 1);
3952 skb->vlan_tci = ntohs(cpl->vlan);
3953 }
3954
3955 if (iph->version != 0x4)
3956 goto reject;
3957
3958 tcph = (struct tcphdr *)(iph + 1);
3959 skb_set_network_header(skb, (void *)iph - (void *)rss);
3960 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3961 skb_get(skb);
3962
3963 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3964 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3965 ntohs(tcph->source), iph->tos);
3966
Vipul Pandya830662f2013-07-04 16:10:47 +05303967 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3968 iph->tos);
3969 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003970 pr_err("%s - failed to find dst entry!\n",
3971 __func__);
3972 goto reject;
3973 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003974 neigh = dst_neigh_lookup_skb(dst, skb);
3975
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003976 if (!neigh) {
3977 pr_err("%s - failed to allocate neigh!\n",
3978 __func__);
3979 goto free_dst;
3980 }
3981
Vipul Pandya1cab7752012-12-10 09:30:55 +00003982 if (neigh->dev->flags & IFF_LOOPBACK) {
3983 pdev = ip_dev_find(&init_net, iph->daddr);
3984 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3985 pdev, 0);
3986 pi = (struct port_info *)netdev_priv(pdev);
3987 tx_chan = cxgb4_port_chan(pdev);
3988 dev_put(pdev);
3989 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303990 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003991 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303992 pdev, 0);
3993 pi = (struct port_info *)netdev_priv(pdev);
3994 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003995 }
Steve Wiseebf00062014-03-19 17:44:40 +05303996 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003997 if (!e) {
3998 pr_err("%s - failed to allocate l2t entry!\n",
3999 __func__);
4000 goto free_dst;
4001 }
4002
4003 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4004 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00004005 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004006
4007 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05304008 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4009 dev->rdev.lldi.ports[0],
4010 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004011
4012 /*
4013 * Synthesize the cpl_pass_accept_req. We have everything except the
4014 * TID. Once firmware sends a reply with TID we update the TID field
4015 * in cpl and pass it through the regular cpl_pass_accept_req path.
4016 */
4017 build_cpl_pass_accept_req(skb, stid, iph->tos);
4018 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4019 tcph->source, ntohl(tcph->seq), filter, window,
4020 rss_qid, pi->port_id);
4021 cxgb4_l2t_release(e);
4022free_dst:
4023 dst_release(dst);
4024reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304025 if (lep)
4026 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004027 return 0;
4028}
4029
Steve Wisecfdda9d2010-04-21 15:30:06 -07004030/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004031 * These are the real handlers that are called from a
4032 * work queue.
4033 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304034static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004035 [CPL_ACT_ESTABLISH] = act_establish,
4036 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4037 [CPL_RX_DATA] = rx_data,
4038 [CPL_ABORT_RPL_RSS] = abort_rpl,
4039 [CPL_ABORT_RPL] = abort_rpl,
4040 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4041 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4042 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4043 [CPL_PASS_ESTABLISH] = pass_establish,
4044 [CPL_PEER_CLOSE] = peer_close,
4045 [CPL_ABORT_REQ_RSS] = peer_abort,
4046 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4047 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004048 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004049 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304050 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304051 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4052 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004053};
4054
4055static void process_timeout(struct c4iw_ep *ep)
4056{
4057 struct c4iw_qp_attributes attrs;
4058 int abort = 1;
4059
Steve Wise2f5b48c2010-09-10 11:15:36 -05004060 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004061 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4062 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004063 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004064 switch (ep->com.state) {
4065 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004066 connect_reply_upcall(ep, -ETIMEDOUT);
4067 break;
4068 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304069 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304070 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304071 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004072 break;
4073 case CLOSING:
4074 case MORIBUND:
4075 if (ep->com.cm_id && ep->com.qp) {
4076 attrs.next_state = C4IW_QP_STATE_ERROR;
4077 c4iw_modify_qp(ep->com.qp->rhp,
4078 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4079 &attrs, 1);
4080 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304081 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004082 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004083 case ABORTING:
4084 case DEAD:
4085
4086 /*
4087 * These states are expected if the ep timed out at the same
4088 * time as another thread was calling stop_ep_timer().
4089 * So we silently do nothing for these states.
4090 */
4091 abort = 0;
4092 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004093 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004094 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004096 abort = 0;
4097 }
Steve Wisecc18b932014-04-24 14:31:53 -05004098 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304099 if (abort)
4100 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004101 c4iw_put_ep(&ep->com);
4102}
4103
4104static void process_timedout_eps(void)
4105{
4106 struct c4iw_ep *ep;
4107
4108 spin_lock_irq(&timeout_lock);
4109 while (!list_empty(&timeout_list)) {
4110 struct list_head *tmp;
4111
4112 tmp = timeout_list.next;
4113 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004114 tmp->next = NULL;
4115 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004116 spin_unlock_irq(&timeout_lock);
4117 ep = list_entry(tmp, struct c4iw_ep, entry);
4118 process_timeout(ep);
4119 spin_lock_irq(&timeout_lock);
4120 }
4121 spin_unlock_irq(&timeout_lock);
4122}
4123
4124static void process_work(struct work_struct *work)
4125{
4126 struct sk_buff *skb = NULL;
4127 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004128 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004129 unsigned int opcode;
4130 int ret;
4131
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004132 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004133 while ((skb = skb_dequeue(&rxq))) {
4134 rpl = cplhdr(skb);
4135 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4136 opcode = rpl->ot.opcode;
4137
4138 BUG_ON(!work_handlers[opcode]);
4139 ret = work_handlers[opcode](dev, skb);
4140 if (!ret)
4141 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004142 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004143 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004144}
4145
4146static DECLARE_WORK(skb_work, process_work);
4147
4148static void ep_timeout(unsigned long arg)
4149{
4150 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004151 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004152
4153 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004154 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004155 /*
4156 * Only insert if it is not already on the list.
4157 */
4158 if (!ep->entry.next) {
4159 list_add_tail(&ep->entry, &timeout_list);
4160 kickit = 1;
4161 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004162 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004163 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004164 if (kickit)
4165 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004166}
4167
4168/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004169 * All the CM events are handled on a work queue to have a safe context.
4170 */
4171static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4172{
4173
4174 /*
4175 * Save dev in the skb->cb area.
4176 */
4177 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4178
4179 /*
4180 * Queue the skb and schedule the worker thread.
4181 */
4182 skb_queue_tail(&rxq, skb);
4183 queue_work(workq, &skb_work);
4184 return 0;
4185}
4186
4187static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4188{
4189 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4190
4191 if (rpl->status != CPL_ERR_NONE) {
4192 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4193 "for tid %u\n", rpl->status, GET_TID(rpl));
4194 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004195 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004196 return 0;
4197}
4198
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004199static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4200{
4201 struct cpl_fw6_msg *rpl = cplhdr(skb);
4202 struct c4iw_wr_wait *wr_waitp;
4203 int ret;
4204
4205 PDBG("%s type %u\n", __func__, rpl->type);
4206
4207 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004208 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004209 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004210 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004211 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004212 if (wr_waitp)
4213 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004214 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004215 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004216 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004217 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004218 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004219 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004220 default:
4221 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4222 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004223 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004224 break;
4225 }
4226 return 0;
4227}
4228
Steve Wise8da7e7a2011-06-14 20:59:27 +00004229static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4230{
4231 struct cpl_abort_req_rss *req = cplhdr(skb);
4232 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004233 unsigned int tid = GET_TID(req);
4234
Hariprasad S944661d2016-05-06 22:18:03 +05304235 ep = get_ep_from_tid(dev, tid);
4236 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004237 if (!ep) {
4238 printk(KERN_WARNING MOD
4239 "Abort on non-existent endpoint, tid %d\n", tid);
4240 kfree_skb(skb);
4241 return 0;
4242 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304243 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304244 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4245 __func__, ep->hwtid, req->status,
4246 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304247 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004248 }
4249 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4250 ep->com.state);
4251
Hariprasad S093108c2016-05-06 22:18:09 +05304252 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304253out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004254 sched(dev, skb);
4255 return 0;
4256}
4257
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004258/*
4259 * Most upcalls from the T4 Core go to sched() to
4260 * schedule the processing on a work queue.
4261 */
4262c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4263 [CPL_ACT_ESTABLISH] = sched,
4264 [CPL_ACT_OPEN_RPL] = sched,
4265 [CPL_RX_DATA] = sched,
4266 [CPL_ABORT_RPL_RSS] = sched,
4267 [CPL_ABORT_RPL] = sched,
4268 [CPL_PASS_OPEN_RPL] = sched,
4269 [CPL_CLOSE_LISTSRV_RPL] = sched,
4270 [CPL_PASS_ACCEPT_REQ] = sched,
4271 [CPL_PASS_ESTABLISH] = sched,
4272 [CPL_PEER_CLOSE] = sched,
4273 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004274 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004275 [CPL_RDMA_TERMINATE] = sched,
4276 [CPL_FW4_ACK] = sched,
4277 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004278 [CPL_FW6_MSG] = fw6_msg,
4279 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004280};
4281
Steve Wisecfdda9d2010-04-21 15:30:06 -07004282int __init c4iw_cm_init(void)
4283{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004284 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004285 skb_queue_head_init(&rxq);
4286
4287 workq = create_singlethread_workqueue("iw_cxgb4");
4288 if (!workq)
4289 return -ENOMEM;
4290
Steve Wisecfdda9d2010-04-21 15:30:06 -07004291 return 0;
4292}
4293
Steve Wise46c13762014-06-20 14:26:25 -05004294void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004295{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004296 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004297 flush_workqueue(workq);
4298 destroy_workqueue(workq);
4299}