blob: b6a953aed7e83d6058164ca66af2516ab0981e23 [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
Hariprasad S4a740832016-06-10 01:05:15 +0530297static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
298{
299 struct sk_buff *skb;
300 unsigned int i;
301 size_t len;
302
303 len = roundup(sizeof(union cpl_wr_size), 16);
304 for (i = 0; i < size; i++) {
305 skb = alloc_skb(len, GFP_KERNEL);
306 if (!skb)
307 goto fail;
308 skb_queue_tail(ep_skb_list, skb);
309 }
310 return 0;
311fail:
312 skb_queue_purge(ep_skb_list);
313 return -ENOMEM;
314}
315
Steve Wisecfdda9d2010-04-21 15:30:06 -0700316static void *alloc_ep(int size, gfp_t gfp)
317{
318 struct c4iw_ep_common *epc;
319
320 epc = kzalloc(size, gfp);
321 if (epc) {
322 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500323 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500324 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700325 }
326 PDBG("%s alloc ep %p\n", __func__, epc);
327 return epc;
328}
329
Hariprasad S944661d2016-05-06 22:18:03 +0530330static void remove_ep_tid(struct c4iw_ep *ep)
331{
332 unsigned long flags;
333
334 spin_lock_irqsave(&ep->com.dev->lock, flags);
335 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
336 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
337}
338
339static void insert_ep_tid(struct c4iw_ep *ep)
340{
341 unsigned long flags;
342
343 spin_lock_irqsave(&ep->com.dev->lock, flags);
344 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
345 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
346}
347
348/*
349 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
350 */
351static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
352{
353 struct c4iw_ep *ep;
354 unsigned long flags;
355
356 spin_lock_irqsave(&dev->lock, flags);
357 ep = idr_find(&dev->hwtid_idr, tid);
358 if (ep)
359 c4iw_get_ep(&ep->com);
360 spin_unlock_irqrestore(&dev->lock, flags);
361 return ep;
362}
363
Hariprasad Sf86fac72016-05-06 22:18:07 +0530364/*
365 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
366 */
367static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
368 unsigned int stid)
369{
370 struct c4iw_listen_ep *ep;
371 unsigned long flags;
372
373 spin_lock_irqsave(&dev->lock, flags);
374 ep = idr_find(&dev->stid_idr, stid);
375 if (ep)
376 c4iw_get_ep(&ep->com);
377 spin_unlock_irqrestore(&dev->lock, flags);
378 return ep;
379}
380
Steve Wisecfdda9d2010-04-21 15:30:06 -0700381void _c4iw_free_ep(struct kref *kref)
382{
383 struct c4iw_ep *ep;
384
385 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530386 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000387 if (test_bit(QP_REFERENCED, &ep->com.flags))
388 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700389 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530390 if (ep->com.remote_addr.ss_family == AF_INET6) {
391 struct sockaddr_in6 *sin6 =
392 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600393 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530394
395 cxgb4_clip_release(
396 ep->com.dev->rdev.lldi.ports[0],
397 (const u32 *)&sin6->sin6_addr.s6_addr,
398 1);
399 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700400 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
401 dst_release(ep->dst);
402 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530403 if (ep->mpa_skb)
404 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700405 }
Hariprasad S4a740832016-06-10 01:05:15 +0530406 if (!skb_queue_empty(&ep->com.ep_skb_list))
407 skb_queue_purge(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700408 kfree(ep);
409}
410
411static void release_ep_resources(struct c4iw_ep *ep)
412{
413 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530414
415 /*
416 * If we have a hwtid, then remove it from the idr table
417 * so lookups will no longer find this endpoint. Otherwise
418 * we have a race where one thread finds the ep ptr just
419 * before the other thread is freeing the ep memory.
420 */
421 if (ep->hwtid != -1)
422 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700423 c4iw_put_ep(&ep->com);
424}
425
Steve Wisecfdda9d2010-04-21 15:30:06 -0700426static int status2errno(int status)
427{
428 switch (status) {
429 case CPL_ERR_NONE:
430 return 0;
431 case CPL_ERR_CONN_RESET:
432 return -ECONNRESET;
433 case CPL_ERR_ARP_MISS:
434 return -EHOSTUNREACH;
435 case CPL_ERR_CONN_TIMEDOUT:
436 return -ETIMEDOUT;
437 case CPL_ERR_TCAM_FULL:
438 return -ENOMEM;
439 case CPL_ERR_CONN_EXIST:
440 return -EADDRINUSE;
441 default:
442 return -EIO;
443 }
444}
445
446/*
447 * Try and reuse skbs already allocated...
448 */
449static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
450{
451 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
452 skb_trim(skb, 0);
453 skb_get(skb);
454 skb_reset_transport_header(skb);
455 } else {
456 skb = alloc_skb(len, gfp);
457 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530458 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700459 return skb;
460}
461
Vipul Pandya830662f2013-07-04 16:10:47 +0530462static struct net_device *get_real_dev(struct net_device *egress_dev)
463{
Steve Wise11b8e222014-05-16 12:42:46 -0500464 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530465}
466
467static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
468{
469 int i;
470
471 egress_dev = get_real_dev(egress_dev);
472 for (i = 0; i < dev->rdev.lldi.nports; i++)
473 if (dev->rdev.lldi.ports[i] == egress_dev)
474 return 1;
475 return 0;
476}
477
478static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
479 __u8 *peer_ip, __be16 local_port,
480 __be16 peer_port, u8 tos,
481 __u32 sin6_scope_id)
482{
483 struct dst_entry *dst = NULL;
484
485 if (IS_ENABLED(CONFIG_IPV6)) {
486 struct flowi6 fl6;
487
488 memset(&fl6, 0, sizeof(fl6));
489 memcpy(&fl6.daddr, peer_ip, 16);
490 memcpy(&fl6.saddr, local_ip, 16);
491 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
492 fl6.flowi6_oif = sin6_scope_id;
493 dst = ip6_route_output(&init_net, NULL, &fl6);
494 if (!dst)
495 goto out;
496 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
497 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
498 dst_release(dst);
499 dst = NULL;
500 }
501 }
502
503out:
504 return dst;
505}
506
507static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700508 __be32 peer_ip, __be16 local_port,
509 __be16 peer_port, u8 tos)
510{
511 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700512 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530513 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700514
David S. Miller31e4543d2011-05-03 20:25:42 -0700515 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500516 peer_port, local_port, IPPROTO_TCP,
517 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800518 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700519 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530520 n = dst_neigh_lookup(&rt->dst, &peer_ip);
521 if (!n)
522 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530523 if (!our_interface(dev, n->dev) &&
524 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530525 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530526 dst_release(&rt->dst);
527 return NULL;
528 }
529 neigh_release(n);
530 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700531}
532
533static void arp_failure_discard(void *handle, struct sk_buff *skb)
534{
Hariprasad S9dec9002016-05-05 01:27:29 +0530535 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700536 kfree_skb(skb);
537}
538
Hariprasad S64bec742016-05-06 22:18:10 +0530539static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
540{
541 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
542}
543
Hariprasad S9dec9002016-05-05 01:27:29 +0530544enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530545 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530546 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530547 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530548};
549
550static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
551{
552 struct c4iw_ep *ep;
553
554 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
555 release_ep_resources(ep);
556 return 0;
557}
558
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530559static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
560{
561 struct c4iw_ep *ep;
562
563 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
564 c4iw_put_ep(&ep->parent_ep->com);
565 release_ep_resources(ep);
566 return 0;
567}
568
Hariprasad S9dec9002016-05-05 01:27:29 +0530569/*
570 * Fake up a special CPL opcode and call sched() so process_work() will call
571 * _put_ep_safe() in a safe context to free the ep resources. This is needed
572 * because ARP error handlers are called in an ATOMIC context, and
573 * _c4iw_free_ep() needs to block.
574 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530575static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
576 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530577{
578 struct cpl_act_establish *rpl = cplhdr(skb);
579
580 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530581 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530582
583 /*
584 * Save ep in the skb->cb area, after where sched() will save the dev
585 * ptr.
586 */
587 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
588 sched(ep->com.dev, skb);
589}
590
591/* Handle an ARP failure for an accept */
592static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
593{
594 struct c4iw_ep *ep = handle;
595
596 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
597 ep->hwtid);
598
599 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530600 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530601}
602
Steve Wisecfdda9d2010-04-21 15:30:06 -0700603/*
604 * Handle an ARP failure for an active open.
605 */
606static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
607{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530608 struct c4iw_ep *ep = handle;
609
Masanari Iidae3d132d2015-10-16 21:14:29 +0900610 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530611 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530612 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530613 if (ep->com.remote_addr.ss_family == AF_INET6) {
614 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600615 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530616 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
617 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
618 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530619 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
620 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530621 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700622}
623
624/*
625 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
626 * and send it along.
627 */
628static void abort_arp_failure(void *handle, struct sk_buff *skb)
629{
Hariprasad S761e19a2016-05-06 22:18:02 +0530630 int ret;
631 struct c4iw_ep *ep = handle;
632 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700633 struct cpl_abort_req *req = cplhdr(skb);
634
635 PDBG("%s rdev %p\n", __func__, rdev);
636 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530637 ret = c4iw_ofld_send(rdev, skb);
638 if (ret) {
639 __state_set(&ep->com, DEAD);
640 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642}
643
Hariprasad S4a740832016-06-10 01:05:15 +0530644static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700646 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530647 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530649 u16 vlan = ep->l2t->vlan;
650 int nparams;
651
Hariprasad S4a740832016-06-10 01:05:15 +0530652 if (WARN_ON(!skb))
653 return -ENOMEM;
654
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530655 if (vlan == CPL_L2T_VLAN_NONE)
656 nparams = 8;
657 else
658 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700659
Hariprasad S4a740832016-06-10 01:05:15 +0530660 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530662 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530663 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530664 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530665 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666
667 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530668 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530669 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700670 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
671 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
672 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
673 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
674 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
675 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
676 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
677 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
678 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
679 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
680 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530681 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700682 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
683 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530684 if (nparams == 9) {
685 u16 pri;
686
687 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
688 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
689 flowc->mnemval[8].val = cpu_to_be32(pri);
690 } else {
691 /* Pad WR to 16 byte boundary */
692 flowc->mnemval[8].mnemonic = 0;
693 flowc->mnemval[8].val = 0;
694 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700695 for (i = 0; i < 9; i++) {
696 flowc->mnemval[i].r4[0] = 0;
697 flowc->mnemval[i].r4[1] = 0;
698 flowc->mnemval[i].r4[2] = 0;
699 }
700
701 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530702 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700703}
704
Hariprasad S4a740832016-06-10 01:05:15 +0530705static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700706{
707 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530708 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700709 int wrlen = roundup(sizeof *req, 16);
710
711 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530712 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700713 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530714
Steve Wisecfdda9d2010-04-21 15:30:06 -0700715 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
716 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
717 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
718 memset(req, 0, wrlen);
719 INIT_TP_WR(req, ep->hwtid);
720 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
721 ep->hwtid));
722 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
723}
724
Hariprasad S4a740832016-06-10 01:05:15 +0530725static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726{
727 struct cpl_abort_req *req;
728 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530729 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700730
731 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530732 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700733 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530734
735 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
736 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
737 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700738 memset(req, 0, wrlen);
739 INIT_TP_WR(req, ep->hwtid);
740 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
741 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530742 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700743}
744
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530745static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530746 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530747{
Hariprasad S04524a42014-09-24 03:53:41 +0530748 unsigned short hdr_size = (ipv6 ?
749 sizeof(struct ipv6hdr) :
750 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530751 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530752 (use_ts ?
753 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530754 unsigned short data_size = mtu - hdr_size;
755
756 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
757}
758
Steve Wisecfdda9d2010-04-21 15:30:06 -0700759static int send_connect(struct c4iw_ep *ep)
760{
Hariprasad S963cab52015-09-23 17:19:27 +0530761 struct cpl_act_open_req *req = NULL;
762 struct cpl_t5_act_open_req *t5req = NULL;
763 struct cpl_t6_act_open_req *t6req = NULL;
764 struct cpl_act_open_req6 *req6 = NULL;
765 struct cpl_t5_act_open_req6 *t5req6 = NULL;
766 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700767 struct sk_buff *skb;
768 u64 opt0;
769 u32 opt2;
770 unsigned int mtu_idx;
771 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530772 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500773 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600774 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500775 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600776 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500777 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600778 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500779 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600780 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530781 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530782 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
783 u32 isn = (prandom_u32() & ~7UL) - 1;
784
785 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
786 case CHELSIO_T4:
787 sizev4 = sizeof(struct cpl_act_open_req);
788 sizev6 = sizeof(struct cpl_act_open_req6);
789 break;
790 case CHELSIO_T5:
791 sizev4 = sizeof(struct cpl_t5_act_open_req);
792 sizev6 = sizeof(struct cpl_t5_act_open_req6);
793 break;
794 case CHELSIO_T6:
795 sizev4 = sizeof(struct cpl_t6_act_open_req);
796 sizev6 = sizeof(struct cpl_t6_act_open_req6);
797 break;
798 default:
799 pr_err("T%d Chip is not supported\n",
800 CHELSIO_CHIP_VERSION(adapter_type));
801 return -EINVAL;
802 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530803
804 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
805 roundup(sizev4, 16) :
806 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700807
808 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
809
810 skb = get_skb(NULL, wrlen, GFP_KERNEL);
811 if (!skb) {
812 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
813 __func__);
814 return -ENOMEM;
815 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000816 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700817
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530818 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530819 enable_tcp_timestamps,
820 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700821 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530822
823 /*
824 * Specify the largest window that will fit in opt0. The
825 * remainder will be specified in the rx_data_ack.
826 */
827 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800828 if (win > RCV_BUFSIZ_M)
829 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530830
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800831 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800832 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800833 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800834 WND_SCALE_V(wscale) |
835 MSS_IDX_V(mtu_idx) |
836 L2T_IDX_V(ep->l2t->idx) |
837 TX_CHAN_V(ep->tx_chan) |
838 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530839 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800840 ULP_MODE_V(ULP_MODE_TCPDDP) |
841 RCV_BUFSIZ_V(win);
842 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800843 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800844 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700845 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800846 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700847 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800848 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700849 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800850 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530851 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
852 if (peer2peer)
853 isn += 4;
854
Anish Bhattd7990b02014-11-12 17:15:57 -0800855 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530856 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530857 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500858 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530859
860 if (ep->com.remote_addr.ss_family == AF_INET6)
861 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
862 (const u32 *)&la6->sin6_addr.s6_addr, 1);
863
Hariprasad S5dab6d32014-06-23 19:12:36 +0530864 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700865
Hariprasad S963cab52015-09-23 17:19:27 +0530866 if (ep->com.remote_addr.ss_family == AF_INET) {
867 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
868 case CHELSIO_T4:
869 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530870 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530871 break;
872 case CHELSIO_T5:
873 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
874 wrlen);
875 INIT_TP_WR(t5req, 0);
876 req = (struct cpl_act_open_req *)t5req;
877 break;
878 case CHELSIO_T6:
879 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
880 wrlen);
881 INIT_TP_WR(t6req, 0);
882 req = (struct cpl_act_open_req *)t6req;
883 t5req = (struct cpl_t5_act_open_req *)t6req;
884 break;
885 default:
886 pr_err("T%d Chip is not supported\n",
887 CHELSIO_CHIP_VERSION(adapter_type));
888 ret = -EINVAL;
889 goto clip_release;
890 }
891
892 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
893 ((ep->rss_qid<<14) | ep->atid)));
894 req->local_port = la->sin_port;
895 req->peer_port = ra->sin_port;
896 req->local_ip = la->sin_addr.s_addr;
897 req->peer_ip = ra->sin_addr.s_addr;
898 req->opt0 = cpu_to_be64(opt0);
899
900 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530901 req->params = cpu_to_be32(cxgb4_select_ntuple(
902 ep->com.dev->rdev.lldi.ports[0],
903 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530904 req->opt2 = cpu_to_be32(opt2);
905 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530906 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
907 cxgb4_select_ntuple(
908 ep->com.dev->rdev.lldi.ports[0],
909 ep->l2t)));
910 t5req->rsvd = cpu_to_be32(isn);
911 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
912 t5req->opt2 = cpu_to_be32(opt2);
913 }
914 } else {
915 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
916 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530917 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530918 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530919 break;
920 case CHELSIO_T5:
921 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
922 wrlen);
923 INIT_TP_WR(t5req6, 0);
924 req6 = (struct cpl_act_open_req6 *)t5req6;
925 break;
926 case CHELSIO_T6:
927 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
928 wrlen);
929 INIT_TP_WR(t6req6, 0);
930 req6 = (struct cpl_act_open_req6 *)t6req6;
931 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
932 break;
933 default:
934 pr_err("T%d Chip is not supported\n",
935 CHELSIO_CHIP_VERSION(adapter_type));
936 ret = -EINVAL;
937 goto clip_release;
938 }
939
940 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
941 ((ep->rss_qid<<14)|ep->atid)));
942 req6->local_port = la6->sin6_port;
943 req6->peer_port = ra6->sin6_port;
944 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
945 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
946 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
947 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
948 req6->opt0 = cpu_to_be64(opt0);
949
950 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530951 req6->params = cpu_to_be32(cxgb4_select_ntuple(
952 ep->com.dev->rdev.lldi.ports[0],
953 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530954 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530955 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530956 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
957 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530958 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530959 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530960 t5req6->rsvd = cpu_to_be32(isn);
961 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
962 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530963 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000964 }
965
Vipul Pandya793dad92012-12-10 09:30:56 +0000966 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530967 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530968clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530969 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
970 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
971 (const u32 *)&la6->sin6_addr.s6_addr, 1);
972 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700973}
974
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530975static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
976 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700977{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530978 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979 struct fw_ofld_tx_data_wr *req;
980 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530981 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982
983 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
984
985 BUG_ON(skb_cloned(skb));
986
987 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530988 if (mpa_rev_to_use == 2)
989 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700990 wrlen = roundup(mpalen + sizeof *req, 16);
991 skb = get_skb(skb, wrlen, GFP_KERNEL);
992 if (!skb) {
993 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530994 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700995 }
996 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
997
998 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
999 memset(req, 0, wrlen);
1000 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301001 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1002 FW_WR_COMPL_F |
1003 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001004 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301005 FW_WR_FLOWID_V(ep->hwtid) |
1006 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001007 req->plen = cpu_to_be32(mpalen);
1008 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301009 FW_OFLD_TX_DATA_WR_FLUSH_F |
1010 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011
1012 mpa = (struct mpa_message *)(req + 1);
1013 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301014
1015 mpa->flags = 0;
1016 if (crc_enabled)
1017 mpa->flags |= MPA_CRC;
1018 if (markers_enabled) {
1019 mpa->flags |= MPA_MARKERS;
1020 ep->mpa_attr.recv_marker_enabled = 1;
1021 } else {
1022 ep->mpa_attr.recv_marker_enabled = 0;
1023 }
1024 if (mpa_rev_to_use == 2)
1025 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1026
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301028 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301029 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301030 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301031 ep->retry_with_mpa_v1 = 0;
1032 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001033
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301034 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001035 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1036 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301037 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1038 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301039 mpa_v2_params.ird = htons((u16)ep->ird);
1040 mpa_v2_params.ord = htons((u16)ep->ord);
1041
1042 if (peer2peer) {
1043 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1044 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1045 mpa_v2_params.ord |=
1046 htons(MPA_V2_RDMA_WRITE_RTR);
1047 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1048 mpa_v2_params.ord |=
1049 htons(MPA_V2_RDMA_READ_RTR);
1050 }
1051 memcpy(mpa->private_data, &mpa_v2_params,
1052 sizeof(struct mpa_v2_conn_params));
1053
1054 if (ep->plen)
1055 memcpy(mpa->private_data +
1056 sizeof(struct mpa_v2_conn_params),
1057 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1058 } else
1059 if (ep->plen)
1060 memcpy(mpa->private_data,
1061 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001062
1063 /*
1064 * Reference the mpa skb. This ensures the data area
1065 * will remain in memory until the hw acks the tx.
1066 * Function fw4_ack() will deref it.
1067 */
1068 skb_get(skb);
1069 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1070 BUG_ON(ep->mpa_skb);
1071 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301072 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1073 if (ret)
1074 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001075 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301076 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001077 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301078 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301079 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080}
1081
1082static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1083{
1084 int mpalen, wrlen;
1085 struct fw_ofld_tx_data_wr *req;
1086 struct mpa_message *mpa;
1087 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301088 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089
1090 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1091
1092 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301093 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1094 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001095 wrlen = roundup(mpalen + sizeof *req, 16);
1096
1097 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1098 if (!skb) {
1099 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1100 return -ENOMEM;
1101 }
1102 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1103
1104 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1105 memset(req, 0, wrlen);
1106 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301107 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1108 FW_WR_COMPL_F |
1109 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001110 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301111 FW_WR_FLOWID_V(ep->hwtid) |
1112 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001113 req->plen = cpu_to_be32(mpalen);
1114 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301115 FW_OFLD_TX_DATA_WR_FLUSH_F |
1116 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001117
1118 mpa = (struct mpa_message *)(req + 1);
1119 memset(mpa, 0, sizeof(*mpa));
1120 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1121 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001122 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301124
1125 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1126 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001127 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1128 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301129 mpa_v2_params.ird = htons(((u16)ep->ird) |
1130 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1131 0));
1132 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1133 (p2p_type ==
1134 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1135 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1136 FW_RI_INIT_P2PTYPE_READ_REQ ?
1137 MPA_V2_RDMA_READ_RTR : 0) : 0));
1138 memcpy(mpa->private_data, &mpa_v2_params,
1139 sizeof(struct mpa_v2_conn_params));
1140
1141 if (ep->plen)
1142 memcpy(mpa->private_data +
1143 sizeof(struct mpa_v2_conn_params), pdata, plen);
1144 } else
1145 if (plen)
1146 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001147
1148 /*
1149 * Reference the mpa skb again. This ensures the data area
1150 * will remain in memory until the hw acks the tx.
1151 * Function fw4_ack() will deref it.
1152 */
1153 skb_get(skb);
1154 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301155 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001156 BUG_ON(ep->mpa_skb);
1157 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301158 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001159 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1160}
1161
1162static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1163{
1164 int mpalen, wrlen;
1165 struct fw_ofld_tx_data_wr *req;
1166 struct mpa_message *mpa;
1167 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301168 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169
1170 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1171
1172 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301173 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1174 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175 wrlen = roundup(mpalen + sizeof *req, 16);
1176
1177 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1178 if (!skb) {
1179 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1180 return -ENOMEM;
1181 }
1182 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1183
1184 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1185 memset(req, 0, wrlen);
1186 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301187 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1188 FW_WR_COMPL_F |
1189 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001190 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301191 FW_WR_FLOWID_V(ep->hwtid) |
1192 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193 req->plen = cpu_to_be32(mpalen);
1194 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301195 FW_OFLD_TX_DATA_WR_FLUSH_F |
1196 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001197
1198 mpa = (struct mpa_message *)(req + 1);
1199 memset(mpa, 0, sizeof(*mpa));
1200 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301201 mpa->flags = 0;
1202 if (ep->mpa_attr.crc_enabled)
1203 mpa->flags |= MPA_CRC;
1204 if (ep->mpa_attr.recv_marker_enabled)
1205 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301206 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001207 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301208
1209 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1210 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001211 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1212 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301213 mpa_v2_params.ird = htons((u16)ep->ird);
1214 mpa_v2_params.ord = htons((u16)ep->ord);
1215 if (peer2peer && (ep->mpa_attr.p2p_type !=
1216 FW_RI_INIT_P2PTYPE_DISABLED)) {
1217 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1218
1219 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1220 mpa_v2_params.ord |=
1221 htons(MPA_V2_RDMA_WRITE_RTR);
1222 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1223 mpa_v2_params.ord |=
1224 htons(MPA_V2_RDMA_READ_RTR);
1225 }
1226
1227 memcpy(mpa->private_data, &mpa_v2_params,
1228 sizeof(struct mpa_v2_conn_params));
1229
1230 if (ep->plen)
1231 memcpy(mpa->private_data +
1232 sizeof(struct mpa_v2_conn_params), pdata, plen);
1233 } else
1234 if (plen)
1235 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001236
1237 /*
1238 * Reference the mpa skb. This ensures the data area
1239 * will remain in memory until the hw acks the tx.
1240 * Function fw4_ack() will deref it.
1241 */
1242 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301243 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001244 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301245 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301246 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001247 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1248}
1249
1250static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1251{
1252 struct c4iw_ep *ep;
1253 struct cpl_act_establish *req = cplhdr(skb);
1254 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001255 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301257 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001258
1259 ep = lookup_atid(t, atid);
1260
1261 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1262 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1263
Steve Wisea7db89e2014-03-21 20:40:35 +05301264 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001265 dst_confirm(ep->dst);
1266
1267 /* setup the hwtid for this connection */
1268 ep->hwtid = tid;
1269 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301270 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271
1272 ep->snd_seq = be32_to_cpu(req->snd_isn);
1273 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1274
1275 set_emss(ep, ntohs(req->tcp_opt));
1276
1277 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001278 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001279 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001280 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001281
1282 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301283 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301284 if (ret)
1285 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301286 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301287 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301288 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301289 ret = send_mpa_req(ep, skb, mpa_rev);
1290 if (ret)
1291 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301292 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301294err:
1295 mutex_unlock(&ep->com.mutex);
1296 connect_reply_upcall(ep, -ENOMEM);
1297 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1298 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001299}
1300
Steve Wisebe13b2d2014-03-21 20:40:33 +05301301static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001302{
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;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301308 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001309 if (ep->com.cm_id) {
1310 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1311 ep, 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(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315 }
1316}
1317
Steve Wisecfdda9d2010-04-21 15:30:06 -07001318static void peer_close_upcall(struct c4iw_ep *ep)
1319{
1320 struct iw_cm_event event;
1321
1322 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1323 memset(&event, 0, sizeof(event));
1324 event.event = IW_CM_EVENT_DISCONNECT;
1325 if (ep->com.cm_id) {
1326 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1327 ep, ep->com.cm_id, ep->hwtid);
1328 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001329 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001330 }
1331}
1332
1333static void peer_abort_upcall(struct c4iw_ep *ep)
1334{
1335 struct iw_cm_event event;
1336
1337 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1338 memset(&event, 0, sizeof(event));
1339 event.event = IW_CM_EVENT_CLOSE;
1340 event.status = -ECONNRESET;
1341 if (ep->com.cm_id) {
1342 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1343 ep->com.cm_id, ep->hwtid);
1344 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301345 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001346 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001347 }
1348}
1349
1350static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1351{
1352 struct iw_cm_event event;
1353
1354 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1355 memset(&event, 0, sizeof(event));
1356 event.event = IW_CM_EVENT_CONNECT_REPLY;
1357 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301358 memcpy(&event.local_addr, &ep->com.local_addr,
1359 sizeof(ep->com.local_addr));
1360 memcpy(&event.remote_addr, &ep->com.remote_addr,
1361 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362
1363 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301364 if (!ep->tried_with_mpa_v1) {
1365 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301366 event.ord = ep->ird;
1367 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301368 event.private_data_len = ep->plen -
1369 sizeof(struct mpa_v2_conn_params);
1370 event.private_data = ep->mpa_pkt +
1371 sizeof(struct mpa_message) +
1372 sizeof(struct mpa_v2_conn_params);
1373 } else {
1374 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301375 event.ord = cur_max_read_depth(ep->com.dev);
1376 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301377 event.private_data_len = ep->plen;
1378 event.private_data = ep->mpa_pkt +
1379 sizeof(struct mpa_message);
1380 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001381 }
Roland Dreier85963e42010-07-19 13:13:09 -07001382
1383 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1384 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001385 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001386 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1387
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301388 if (status < 0)
1389 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001390}
1391
Steve Wisebe13b2d2014-03-21 20:40:33 +05301392static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001393{
1394 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301395 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001396
1397 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1398 memset(&event, 0, sizeof(event));
1399 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301400 memcpy(&event.local_addr, &ep->com.local_addr,
1401 sizeof(ep->com.local_addr));
1402 memcpy(&event.remote_addr, &ep->com.remote_addr,
1403 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301405 if (!ep->tried_with_mpa_v1) {
1406 /* this means MPA_v2 is used */
1407 event.ord = ep->ord;
1408 event.ird = ep->ird;
1409 event.private_data_len = ep->plen -
1410 sizeof(struct mpa_v2_conn_params);
1411 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1412 sizeof(struct mpa_v2_conn_params);
1413 } else {
1414 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301415 event.ord = cur_max_read_depth(ep->com.dev);
1416 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301417 event.private_data_len = ep->plen;
1418 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1419 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301420 c4iw_get_ep(&ep->com);
1421 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1422 &event);
1423 if (ret)
1424 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001425 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001426 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301427 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001428}
1429
1430static void established_upcall(struct c4iw_ep *ep)
1431{
1432 struct iw_cm_event event;
1433
1434 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1435 memset(&event, 0, sizeof(event));
1436 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301437 event.ird = ep->ord;
1438 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439 if (ep->com.cm_id) {
1440 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1441 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001442 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001443 }
1444}
1445
1446static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1447{
1448 struct cpl_rx_data_ack *req;
1449 struct sk_buff *skb;
1450 int wrlen = roundup(sizeof *req, 16);
1451
1452 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1453 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1454 if (!skb) {
1455 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1456 return 0;
1457 }
1458
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301459 /*
1460 * If we couldn't specify the entire rcv window at connection setup
1461 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1462 * then add the overage in to the credits returned.
1463 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001464 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1465 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301466
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1468 memset(req, 0, wrlen);
1469 INIT_TP_WR(req, ep->hwtid);
1470 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1471 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001472 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301473 RX_DACK_CHANGE_F |
1474 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001475 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001476 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1477 return credits;
1478}
1479
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301480#define RELAXED_IRD_NEGOTIATION 1
1481
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301482/*
1483 * process_mpa_reply - process streaming mode MPA reply
1484 *
1485 * Returns:
1486 *
1487 * 0 upon success indicating a connect request was delivered to the ULP
1488 * or the mpa request is incomplete but valid so far.
1489 *
1490 * 1 if a failure requires the caller to close the connection.
1491 *
1492 * 2 if a failure requires the caller to abort the connection.
1493 */
Steve Wisecc18b932014-04-24 14:31:53 -05001494static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001495{
1496 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301497 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001498 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301499 u16 resp_ird, resp_ord;
1500 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001501 struct c4iw_qp_attributes attrs;
1502 enum c4iw_qp_attr_mask mask;
1503 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001504 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505
1506 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1507
1508 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001509 * If we get more than the supported amount of private data
1510 * then we must fail this connection.
1511 */
1512 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1513 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301514 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001515 }
1516
1517 /*
1518 * copy the new data into our accumulation buffer.
1519 */
1520 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1521 skb->len);
1522 ep->mpa_pkt_len += skb->len;
1523
1524 /*
1525 * if we don't even have the mpa message, then bail.
1526 */
1527 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001528 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001529 mpa = (struct mpa_message *) ep->mpa_pkt;
1530
1531 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301532 if (mpa->revision > mpa_rev) {
1533 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1534 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001535 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301536 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001537 }
1538 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1539 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301540 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001541 }
1542
1543 plen = ntohs(mpa->private_data_size);
1544
1545 /*
1546 * Fail if there's too much private data.
1547 */
1548 if (plen > MPA_MAX_PRIVATE_DATA) {
1549 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301550 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001551 }
1552
1553 /*
1554 * If plen does not account for pkt size
1555 */
1556 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1557 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301558 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001559 }
1560
1561 ep->plen = (u8) plen;
1562
1563 /*
1564 * If we don't have all the pdata yet, then bail.
1565 * We'll continue process when more data arrives.
1566 */
1567 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001568 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001569
1570 if (mpa->flags & MPA_REJECT) {
1571 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301572 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001573 }
1574
1575 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301576 * Stop mpa timer. If it expired, then
1577 * we ignore the MPA reply. process_timeout()
1578 * will abort the connection.
1579 */
1580 if (stop_ep_timer(ep))
1581 return 0;
1582
1583 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001584 * If we get here we have accumulated the entire mpa
1585 * start reply message including private data. And
1586 * the MPA header is valid.
1587 */
Steve Wisec529fb52014-03-21 20:40:37 +05301588 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001589 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001590 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301591 ep->mpa_attr.version = mpa->revision;
1592 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1593
1594 if (mpa->revision == 2) {
1595 ep->mpa_attr.enhanced_rdma_conn =
1596 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1597 if (ep->mpa_attr.enhanced_rdma_conn) {
1598 mpa_v2_params = (struct mpa_v2_conn_params *)
1599 (ep->mpa_pkt + sizeof(*mpa));
1600 resp_ird = ntohs(mpa_v2_params->ird) &
1601 MPA_V2_IRD_ORD_MASK;
1602 resp_ord = ntohs(mpa_v2_params->ord) &
1603 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301604 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1605 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301606
1607 /*
1608 * This is a double-check. Ideally, below checks are
1609 * not required since ird/ord stuff has been taken
1610 * care of in c4iw_accept_cr
1611 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301612 if (ep->ird < resp_ord) {
1613 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1614 ep->com.dev->rdev.lldi.max_ordird_qp)
1615 ep->ird = resp_ord;
1616 else
1617 insuff_ird = 1;
1618 } else if (ep->ird > resp_ord) {
1619 ep->ird = resp_ord;
1620 }
1621 if (ep->ord > resp_ird) {
1622 if (RELAXED_IRD_NEGOTIATION)
1623 ep->ord = resp_ird;
1624 else
1625 insuff_ird = 1;
1626 }
1627 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301628 err = -ENOMEM;
1629 ep->ird = resp_ord;
1630 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301631 }
1632
1633 if (ntohs(mpa_v2_params->ird) &
1634 MPA_V2_PEER2PEER_MODEL) {
1635 if (ntohs(mpa_v2_params->ord) &
1636 MPA_V2_RDMA_WRITE_RTR)
1637 ep->mpa_attr.p2p_type =
1638 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1639 else if (ntohs(mpa_v2_params->ord) &
1640 MPA_V2_RDMA_READ_RTR)
1641 ep->mpa_attr.p2p_type =
1642 FW_RI_INIT_P2PTYPE_READ_REQ;
1643 }
1644 }
1645 } else if (mpa->revision == 1)
1646 if (peer2peer)
1647 ep->mpa_attr.p2p_type = p2p_type;
1648
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301650 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1651 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1652 ep->mpa_attr.recv_marker_enabled,
1653 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1654 ep->mpa_attr.p2p_type, p2p_type);
1655
1656 /*
1657 * If responder's RTR does not match with that of initiator, assign
1658 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1659 * generated when moving QP to RTS state.
1660 * A TERM message will be sent after QP has moved to RTS state
1661 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001662 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301663 (ep->mpa_attr.p2p_type != p2p_type)) {
1664 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1665 rtr_mismatch = 1;
1666 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001667
1668 attrs.mpa_attr = ep->mpa_attr;
1669 attrs.max_ird = ep->ird;
1670 attrs.max_ord = ep->ord;
1671 attrs.llp_stream_handle = ep;
1672 attrs.next_state = C4IW_QP_STATE_RTS;
1673
1674 mask = C4IW_QP_ATTR_NEXT_STATE |
1675 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1676 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1677
1678 /* bind QP and TID with INIT_WR */
1679 err = c4iw_modify_qp(ep->com.qp->rhp,
1680 ep->com.qp, mask, &attrs, 1);
1681 if (err)
1682 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301683
1684 /*
1685 * If responder's RTR requirement did not match with what initiator
1686 * supports, generate TERM message
1687 */
1688 if (rtr_mismatch) {
1689 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1690 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1691 attrs.ecode = MPA_NOMATCH_RTR;
1692 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001693 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301694 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001695 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301696 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001697 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301698 goto out;
1699 }
1700
1701 /*
1702 * Generate TERM if initiator IRD is not sufficient for responder
1703 * provided ORD. Currently, we do the same behaviour even when
1704 * responder provided IRD is also not sufficient as regards to
1705 * initiator ORD.
1706 */
1707 if (insuff_ird) {
1708 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1709 __func__);
1710 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1711 attrs.ecode = MPA_INSUFF_IRD;
1712 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001713 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301714 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001715 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301716 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001717 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301718 goto out;
1719 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001720 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301721err_stop_timer:
1722 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001723err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301724 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001725out:
1726 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001727 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001728}
1729
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301730/*
1731 * process_mpa_request - process streaming mode MPA request
1732 *
1733 * Returns:
1734 *
1735 * 0 upon success indicating a connect request was delivered to the ULP
1736 * or the mpa request is incomplete but valid so far.
1737 *
1738 * 1 if a failure requires the caller to close the connection.
1739 *
1740 * 2 if a failure requires the caller to abort the connection.
1741 */
1742static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001743{
1744 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301745 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001746 u16 plen;
1747
1748 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1749
Steve Wisecfdda9d2010-04-21 15:30:06 -07001750 /*
1751 * If we get more than the supported amount of private data
1752 * then we must fail this connection.
1753 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301754 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1755 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001756
1757 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1758
1759 /*
1760 * Copy the new data into our accumulation buffer.
1761 */
1762 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1763 skb->len);
1764 ep->mpa_pkt_len += skb->len;
1765
1766 /*
1767 * If we don't even have the mpa message, then bail.
1768 * We'll continue process when more data arrives.
1769 */
1770 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301771 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001772
1773 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001774 mpa = (struct mpa_message *) ep->mpa_pkt;
1775
1776 /*
1777 * Validate MPA Header.
1778 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301779 if (mpa->revision > mpa_rev) {
1780 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1781 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301782 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001783 }
1784
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301785 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1786 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001787
1788 plen = ntohs(mpa->private_data_size);
1789
1790 /*
1791 * Fail if there's too much private data.
1792 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301793 if (plen > MPA_MAX_PRIVATE_DATA)
1794 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001795
1796 /*
1797 * If plen does not account for pkt size
1798 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301799 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1800 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801 ep->plen = (u8) plen;
1802
1803 /*
1804 * If we don't have all the pdata yet, then bail.
1805 */
1806 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301807 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001808
1809 /*
1810 * If we get here we have accumulated the entire mpa
1811 * start reply message including private data.
1812 */
1813 ep->mpa_attr.initiator = 0;
1814 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1815 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1816 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301817 ep->mpa_attr.version = mpa->revision;
1818 if (mpa->revision == 1)
1819 ep->tried_with_mpa_v1 = 1;
1820 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1821
1822 if (mpa->revision == 2) {
1823 ep->mpa_attr.enhanced_rdma_conn =
1824 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1825 if (ep->mpa_attr.enhanced_rdma_conn) {
1826 mpa_v2_params = (struct mpa_v2_conn_params *)
1827 (ep->mpa_pkt + sizeof(*mpa));
1828 ep->ird = ntohs(mpa_v2_params->ird) &
1829 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001830 ep->ird = min_t(u32, ep->ird,
1831 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301832 ep->ord = ntohs(mpa_v2_params->ord) &
1833 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001834 ep->ord = min_t(u32, ep->ord,
1835 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301836 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1837 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301838 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1839 if (peer2peer) {
1840 if (ntohs(mpa_v2_params->ord) &
1841 MPA_V2_RDMA_WRITE_RTR)
1842 ep->mpa_attr.p2p_type =
1843 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1844 else if (ntohs(mpa_v2_params->ord) &
1845 MPA_V2_RDMA_READ_RTR)
1846 ep->mpa_attr.p2p_type =
1847 FW_RI_INIT_P2PTYPE_READ_REQ;
1848 }
1849 }
1850 } else if (mpa->revision == 1)
1851 if (peer2peer)
1852 ep->mpa_attr.p2p_type = p2p_type;
1853
Steve Wisecfdda9d2010-04-21 15:30:06 -07001854 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1855 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1856 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1857 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1858 ep->mpa_attr.p2p_type);
1859
Hariprasad Se4b76a22016-05-06 22:17:59 +05301860 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001861
Hariprasad Se4b76a22016-05-06 22:17:59 +05301862 /* drive upcall */
1863 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1864 if (ep->parent_ep->com.state != DEAD) {
1865 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301866 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301867 } else {
1868 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301869 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301870 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301871 return 0;
1872
1873err_unlock_parent:
1874 mutex_unlock(&ep->parent_ep->com.mutex);
1875 goto err_out;
1876err_stop_timer:
1877 (void)stop_ep_timer(ep);
1878err_out:
1879 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001880}
1881
1882static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1883{
1884 struct c4iw_ep *ep;
1885 struct cpl_rx_data *hdr = cplhdr(skb);
1886 unsigned int dlen = ntohs(hdr->len);
1887 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001888 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001889 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001890
Hariprasad S944661d2016-05-06 22:18:03 +05301891 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301892 if (!ep)
1893 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001894 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1895 skb_pull(skb, sizeof(*hdr));
1896 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301897 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001898
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899 /* update RX credits */
1900 update_rx_credits(ep, dlen);
1901
Steve Wisec529fb52014-03-21 20:40:37 +05301902 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001903 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001904 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001905 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001906 break;
1907 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001908 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301909 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001910 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001911 case FPDU_MODE: {
1912 struct c4iw_qp_attributes attrs;
1913 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001914 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001915 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001916 " qpid %u ep %p state %d tid %u status %d\n",
1917 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301918 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301919 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001920 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001921 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1922 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001923 break;
1924 }
Vipul Pandya15579672013-01-07 13:11:52 +00001925 default:
1926 break;
1927 }
Steve Wisec529fb52014-03-21 20:40:37 +05301928 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001929 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301930 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301931 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001932 return 0;
1933}
1934
1935static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1936{
1937 struct c4iw_ep *ep;
1938 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001939 int release = 0;
1940 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001941
Hariprasad S944661d2016-05-06 22:18:03 +05301942 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301943 if (!ep) {
1944 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1945 return 0;
1946 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001947 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001948 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001949 switch (ep->com.state) {
1950 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001951 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001952 __state_set(&ep->com, DEAD);
1953 release = 1;
1954 break;
1955 default:
1956 printk(KERN_ERR "%s ep %p state %d\n",
1957 __func__, ep, ep->com.state);
1958 break;
1959 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001960 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001961
1962 if (release)
1963 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301964 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001965 return 0;
1966}
1967
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301968static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001969{
1970 struct sk_buff *skb;
1971 struct fw_ofld_connection_wr *req;
1972 unsigned int mtu_idx;
1973 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301974 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301975 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001976
1977 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1978 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1979 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001980 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301981 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301982 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1983 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001984 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001985 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301986 req->le.lport = sin->sin_port;
1987 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001988 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301989 req->le.pport = sin->sin_port;
1990 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001991 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301992 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1993 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001994 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301995 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001996 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001997 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301998 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301999 enable_tcp_timestamps,
2000 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002001 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302002
2003 /*
2004 * Specify the largest window that will fit in opt0. The
2005 * remainder will be specified in the rx_data_ack.
2006 */
2007 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002008 if (win > RCV_BUFSIZ_M)
2009 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302010
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002011 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
2012 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002013 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002014 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002015 WND_SCALE_V(wscale) |
2016 MSS_IDX_V(mtu_idx) |
2017 L2T_IDX_V(ep->l2t->idx) |
2018 TX_CHAN_V(ep->tx_chan) |
2019 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302020 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002021 ULP_MODE_V(ULP_MODE_TCPDDP) |
2022 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002023 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
2024 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002025 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002026 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002027 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002028 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002029 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002030 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002031 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002032 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002033 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
2034 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2035 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00002036 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2037 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302038 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002039}
2040
Steve Wisecfdda9d2010-04-21 15:30:06 -07002041/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05302042 * Some of the error codes above implicitly indicate that there is no TID
2043 * allocated with the result of an ACT_OPEN. We use this predicate to make
2044 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07002045 */
2046static inline int act_open_has_tid(int status)
2047{
Hariprasad S4c72efe2016-06-10 01:05:14 +05302048 return (status != CPL_ERR_TCAM_PARITY &&
2049 status != CPL_ERR_TCAM_MISS &&
2050 status != CPL_ERR_TCAM_FULL &&
2051 status != CPL_ERR_CONN_EXIST_SYNRECV &&
2052 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002053}
2054
Steve Wise7a2cea22014-03-14 21:52:07 +05302055/* Returns whether a CPL status conveys negative advice.
2056 */
2057static int is_neg_adv(unsigned int status)
2058{
2059 return status == CPL_ERR_RTX_NEG_ADVICE ||
2060 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2061 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2062}
2063
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302064static char *neg_adv_str(unsigned int status)
2065{
2066 switch (status) {
2067 case CPL_ERR_RTX_NEG_ADVICE:
2068 return "Retransmit timeout";
2069 case CPL_ERR_PERSIST_NEG_ADVICE:
2070 return "Persist timeout";
2071 case CPL_ERR_KEEPALV_NEG_ADVICE:
2072 return "Keepalive timeout";
2073 default:
2074 return "Unknown";
2075 }
2076}
2077
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302078static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2079{
2080 ep->snd_win = snd_win;
2081 ep->rcv_win = rcv_win;
2082 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2083}
2084
Vipul Pandya793dad92012-12-10 09:30:56 +00002085#define ACT_OPEN_RETRY_COUNT 2
2086
Vipul Pandya830662f2013-07-04 16:10:47 +05302087static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2088 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302089 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302090{
2091 struct neighbour *n;
2092 int err, step;
2093 struct net_device *pdev;
2094
2095 n = dst_neigh_lookup(dst, peer_ip);
2096 if (!n)
2097 return -ENODEV;
2098
2099 rcu_read_lock();
2100 err = -ENOMEM;
2101 if (n->dev->flags & IFF_LOOPBACK) {
2102 if (iptype == 4)
2103 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2104 else if (IS_ENABLED(CONFIG_IPV6))
2105 for_each_netdev(&init_net, pdev) {
2106 if (ipv6_chk_addr(&init_net,
2107 (struct in6_addr *)peer_ip,
2108 pdev, 1))
2109 break;
2110 }
2111 else
2112 pdev = NULL;
2113
2114 if (!pdev) {
2115 err = -ENODEV;
2116 goto out;
2117 }
2118 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302119 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302120 if (!ep->l2t)
2121 goto out;
2122 ep->mtu = pdev->mtu;
2123 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302124 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2125 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302126 step = cdev->rdev.lldi.ntxq /
2127 cdev->rdev.lldi.nchan;
2128 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2129 step = cdev->rdev.lldi.nrxq /
2130 cdev->rdev.lldi.nchan;
2131 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2132 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2133 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302134 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302135 dev_put(pdev);
2136 } else {
2137 pdev = get_real_dev(n->dev);
2138 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2139 n, pdev, 0);
2140 if (!ep->l2t)
2141 goto out;
2142 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002143 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302144 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2145 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302146 step = cdev->rdev.lldi.ntxq /
2147 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002148 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2149 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302150 step = cdev->rdev.lldi.nrxq /
2151 cdev->rdev.lldi.nchan;
2152 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002153 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302154 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302155
2156 if (clear_mpa_v1) {
2157 ep->retry_with_mpa_v1 = 0;
2158 ep->tried_with_mpa_v1 = 0;
2159 }
2160 }
2161 err = 0;
2162out:
2163 rcu_read_unlock();
2164
2165 neigh_release(n);
2166
2167 return err;
2168}
2169
Vipul Pandya793dad92012-12-10 09:30:56 +00002170static int c4iw_reconnect(struct c4iw_ep *ep)
2171{
2172 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302173 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302174 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002175 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302176 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002177 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302178 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002179 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302180 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002181 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302182 int iptype;
2183 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002184
2185 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2186 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302187 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002188
Hariprasad S4a740832016-06-10 01:05:15 +05302189 /* When MPA revision is different on nodes, the node with MPA_rev=2
2190 * tries to reconnect with MPA_rev 1 for the same EP through
2191 * c4iw_reconnect(), where the same EP is assigned with new tid for
2192 * further connection establishment. As we are using the same EP pointer
2193 * for reconnect, few skbs are used during the previous c4iw_connect(),
2194 * which leaves the EP with inadequate skbs for further
2195 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2196 * skb_list() during peer_abort(). Allocate skbs which is already used.
2197 */
2198 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2199 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2200 err = -ENOMEM;
2201 goto fail1;
2202 }
2203
Vipul Pandya793dad92012-12-10 09:30:56 +00002204 /*
2205 * Allocate an active TID to initiate a TCP connection.
2206 */
2207 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2208 if (ep->atid == -1) {
2209 pr_err("%s - cannot alloc atid.\n", __func__);
2210 err = -ENOMEM;
2211 goto fail2;
2212 }
2213 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2214
2215 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002216 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302217 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2218 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302219 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302220 iptype = 4;
2221 ra = (__u8 *)&raddr->sin_addr;
2222 } else {
2223 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2224 raddr6->sin6_addr.s6_addr,
2225 laddr6->sin6_port, raddr6->sin6_port, 0,
2226 raddr6->sin6_scope_id);
2227 iptype = 6;
2228 ra = (__u8 *)&raddr6->sin6_addr;
2229 }
2230 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002231 pr_err("%s - cannot find route.\n", __func__);
2232 err = -EHOSTUNREACH;
2233 goto fail3;
2234 }
Hariprasad S963cab52015-09-23 17:19:27 +05302235 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302236 ep->com.dev->rdev.lldi.adapter_type,
2237 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302238 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002239 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002240 goto fail4;
2241 }
2242
2243 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2244 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2245 ep->l2t->idx);
2246
2247 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302248 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002249
2250 /* send connect request to rnic */
2251 err = send_connect(ep);
2252 if (!err)
2253 goto out;
2254
2255 cxgb4_l2t_release(ep->l2t);
2256fail4:
2257 dst_release(ep->dst);
2258fail3:
2259 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2260 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2261fail2:
2262 /*
2263 * remember to send notification to upper layer.
2264 * We are in here so the upper layer is not aware that this is
2265 * re-connect attempt and so, upper layer is still waiting for
2266 * response of 1st connect request.
2267 */
2268 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302269fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002270 c4iw_put_ep(&ep->com);
2271out:
2272 return err;
2273}
2274
Steve Wisecfdda9d2010-04-21 15:30:06 -07002275static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2276{
2277 struct c4iw_ep *ep;
2278 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002279 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2280 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002281 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002282 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302283 struct sockaddr_in *la;
2284 struct sockaddr_in *ra;
2285 struct sockaddr_in6 *la6;
2286 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302287 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002288
2289 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002290 la = (struct sockaddr_in *)&ep->com.local_addr;
2291 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2292 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2293 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002294
2295 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2296 status, status2errno(status));
2297
Steve Wise7a2cea22014-03-14 21:52:07 +05302298 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302299 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2300 __func__, atid, status, neg_adv_str(status));
2301 ep->stats.connect_neg_adv++;
2302 mutex_lock(&dev->rdev.stats.lock);
2303 dev->rdev.stats.neg_adv++;
2304 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002305 return 0;
2306 }
2307
Vipul Pandya793dad92012-12-10 09:30:56 +00002308 set_bit(ACT_OPEN_RPL, &ep->com.history);
2309
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302310 /*
2311 * Log interesting failures.
2312 */
2313 switch (status) {
2314 case CPL_ERR_CONN_RESET:
2315 case CPL_ERR_CONN_TIMEDOUT:
2316 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002317 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302318 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002319 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302320 mutex_unlock(&dev->rdev.stats.lock);
2321 if (ep->com.local_addr.ss_family == AF_INET &&
2322 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302323 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2324 ntohl(rpl->atid_status))));
2325 if (ret)
2326 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002327 return 0;
2328 }
2329 break;
2330 case CPL_ERR_CONN_EXIST:
2331 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2332 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302333 if (ep->com.remote_addr.ss_family == AF_INET6) {
2334 struct sockaddr_in6 *sin6 =
2335 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002336 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302337 cxgb4_clip_release(
2338 ep->com.dev->rdev.lldi.ports[0],
2339 (const u32 *)
2340 &sin6->sin6_addr.s6_addr, 1);
2341 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002342 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2343 atid);
2344 cxgb4_free_atid(t, atid);
2345 dst_release(ep->dst);
2346 cxgb4_l2t_release(ep->l2t);
2347 c4iw_reconnect(ep);
2348 return 0;
2349 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002350 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302351 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302352 if (ep->com.local_addr.ss_family == AF_INET) {
2353 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2354 atid, status, status2errno(status),
2355 &la->sin_addr.s_addr, ntohs(la->sin_port),
2356 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2357 } else {
2358 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2359 atid, status, status2errno(status),
2360 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2361 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2362 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302363 break;
2364 }
2365
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302366fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002367 connect_reply_upcall(ep, status2errno(status));
2368 state_set(&ep->com, DEAD);
2369
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302370 if (ep->com.remote_addr.ss_family == AF_INET6) {
2371 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002372 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302373 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2374 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2375 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 if (status && act_open_has_tid(status))
2377 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2378
Vipul Pandya793dad92012-12-10 09:30:56 +00002379 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 cxgb4_free_atid(t, atid);
2381 dst_release(ep->dst);
2382 cxgb4_l2t_release(ep->l2t);
2383 c4iw_put_ep(&ep->com);
2384
2385 return 0;
2386}
2387
2388static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2389{
2390 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302392 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393
2394 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002395 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2396 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002397 }
2398 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2399 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002400 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302401 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002402out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002403 return 0;
2404}
2405
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2407{
2408 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002409 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302410 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411
2412 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002413 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302414 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415 return 0;
2416}
2417
Hariprasad S9dec9002016-05-05 01:27:29 +05302418static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2419 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420{
2421 struct cpl_pass_accept_rpl *rpl;
2422 unsigned int mtu_idx;
2423 u64 opt0;
2424 u32 opt2;
2425 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302426 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302427 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302428 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429
2430 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2431 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302432
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302434 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302435 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302436 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2437 rpl5 = (void *)rpl;
2438 INIT_TP_WR(rpl5, ep->hwtid);
2439 } else {
2440 skb_trim(skb, sizeof(*rpl));
2441 INIT_TP_WR(rpl, ep->hwtid);
2442 }
2443 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2444 ep->hwtid));
2445
2446 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302447 enable_tcp_timestamps && req->tcpopt.tstamp,
2448 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002449 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302450
2451 /*
2452 * Specify the largest window that will fit in opt0. The
2453 * remainder will be specified in the rx_data_ack.
2454 */
2455 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002456 if (win > RCV_BUFSIZ_M)
2457 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002458 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002459 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002460 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002461 WND_SCALE_V(wscale) |
2462 MSS_IDX_V(mtu_idx) |
2463 L2T_IDX_V(ep->l2t->idx) |
2464 TX_CHAN_V(ep->tx_chan) |
2465 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002466 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002467 ULP_MODE_V(ULP_MODE_TCPDDP) |
2468 RCV_BUFSIZ_V(win);
2469 opt2 = RX_CHANNEL_V(0) |
2470 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002471
2472 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002473 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002474 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002475 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002476 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002477 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002478 if (enable_ecn) {
2479 const struct tcphdr *tcph;
2480 u32 hlen = ntohl(req->hdr_len);
2481
Hariprasad S963cab52015-09-23 17:19:27 +05302482 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2483 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2484 IP_HDR_LEN_G(hlen);
2485 else
2486 tcph = (const void *)(req + 1) +
2487 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002488 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002489 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002490 }
Hariprasad S963cab52015-09-23 17:19:27 +05302491 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302492 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002493 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302494 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302495 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302496 rpl5 = (void *)rpl;
2497 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2498 if (peer2peer)
2499 isn += 4;
2500 rpl5->iss = cpu_to_be32(isn);
2501 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002502 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002503
Steve Wisecfdda9d2010-04-21 15:30:06 -07002504 rpl->opt0 = cpu_to_be64(opt0);
2505 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002506 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302507 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002508
Hariprasad S9dec9002016-05-05 01:27:29 +05302509 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002510}
2511
Vipul Pandya830662f2013-07-04 16:10:47 +05302512static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002513{
Vipul Pandya830662f2013-07-04 16:10:47 +05302514 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 BUG_ON(skb_cloned(skb));
2516 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517 release_tid(&dev->rdev, hwtid, skb);
2518 return;
2519}
2520
Hariprasad S963cab52015-09-23 17:19:27 +05302521static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2522 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 __be16 *local_port, __be16 *peer_port)
2524{
Hariprasad S963cab52015-09-23 17:19:27 +05302525 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2526 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2527 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2528 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2529 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2530 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302532 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002533 struct tcphdr *tcp = (struct tcphdr *)
2534 ((u8 *)(req + 1) + eth_len + ip_len);
2535
Vipul Pandya830662f2013-07-04 16:10:47 +05302536 if (ip->version == 4) {
2537 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2538 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2539 ntohs(tcp->dest));
2540 *iptype = 4;
2541 memcpy(peer_ip, &ip->saddr, 4);
2542 memcpy(local_ip, &ip->daddr, 4);
2543 } else {
2544 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2545 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2546 ntohs(tcp->dest));
2547 *iptype = 6;
2548 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2549 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2550 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002551 *peer_port = tcp->source;
2552 *local_port = tcp->dest;
2553
2554 return;
2555}
2556
2557static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2558{
Vipul Pandya793dad92012-12-10 09:30:56 +00002559 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002561 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 struct tid_info *t = dev->rdev.lldi.tids;
2563 unsigned int hwtid = GET_TID(req);
2564 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302565 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002566 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302567 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002568 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002569 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302570 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302571 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302572 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002573
Hariprasad Sf86fac72016-05-06 22:18:07 +05302574 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002575 if (!parent_ep) {
2576 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2577 goto reject;
2578 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002579
Steve Wisecfdda9d2010-04-21 15:30:06 -07002580 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302581 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582 goto reject;
2583 }
2584
Hariprasad S963cab52015-09-23 17:19:27 +05302585 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2586 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302587
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302589 if (iptype == 4) {
2590 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2591 , __func__, parent_ep, hwtid,
2592 local_ip, peer_ip, ntohs(local_port),
2593 ntohs(peer_port), peer_mss);
2594 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2595 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302596 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302597 } else {
2598 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2599 , __func__, parent_ep, hwtid,
2600 local_ip, peer_ip, ntohs(local_port),
2601 ntohs(peer_port), peer_mss);
2602 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002603 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302604 ((struct sockaddr_in6 *)
2605 &parent_ep->com.local_addr)->sin6_scope_id);
2606 }
2607 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2609 __func__);
2610 goto reject;
2611 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612
2613 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2614 if (!child_ep) {
2615 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2616 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617 dst_release(dst);
2618 goto reject;
2619 }
David Miller3786cf12011-12-02 16:52:31 +00002620
Hariprasad S963cab52015-09-23 17:19:27 +05302621 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302622 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002623 if (err) {
2624 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2625 __func__);
2626 dst_release(dst);
2627 kfree(child_ep);
2628 goto reject;
2629 }
2630
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302631 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2632 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2633 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2634 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002635
Hariprasad S4a740832016-06-10 01:05:15 +05302636 skb_queue_head_init(&child_ep->com.ep_skb_list);
2637 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2638 goto fail;
2639
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 state_set(&child_ep->com, CONNECTING);
2641 child_ep->com.dev = dev;
2642 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002643
Vipul Pandya830662f2013-07-04 16:10:47 +05302644 if (iptype == 4) {
2645 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002646 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002647
Vipul Pandya830662f2013-07-04 16:10:47 +05302648 sin->sin_family = PF_INET;
2649 sin->sin_port = local_port;
2650 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002651
2652 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2653 sin->sin_family = PF_INET;
2654 sin->sin_port = ((struct sockaddr_in *)
2655 &parent_ep->com.local_addr)->sin_port;
2656 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2657
Steve Wise170003c2016-02-26 09:18:03 -06002658 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302659 sin->sin_family = PF_INET;
2660 sin->sin_port = peer_port;
2661 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2662 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002663 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302664 sin6->sin6_family = PF_INET6;
2665 sin6->sin6_port = local_port;
2666 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002667
2668 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2669 sin6->sin6_family = PF_INET6;
2670 sin6->sin6_port = ((struct sockaddr_in6 *)
2671 &parent_ep->com.local_addr)->sin6_port;
2672 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2673
Steve Wise170003c2016-02-26 09:18:03 -06002674 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302675 sin6->sin6_family = PF_INET6;
2676 sin6->sin6_port = peer_port;
2677 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2678 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002679
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 c4iw_get_ep(&parent_ep->com);
2681 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302682 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002683 child_ep->dst = dst;
2684 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685
2686 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002687 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688
2689 init_timer(&child_ep->timer);
2690 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302691 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302692 if (accept_cr(child_ep, skb, req)) {
2693 c4iw_put_ep(&parent_ep->com);
2694 release_ep_resources(child_ep);
2695 } else {
2696 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2697 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302698 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002699 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302700 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2701 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2702 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302704fail:
2705 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302707 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302708 if (parent_ep)
2709 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710out:
2711 return 0;
2712}
2713
2714static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2715{
2716 struct c4iw_ep *ep;
2717 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302719 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720
Hariprasad S944661d2016-05-06 22:18:03 +05302721 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2723 ep->snd_seq = be32_to_cpu(req->snd_isn);
2724 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2725
Vipul Pandya1cab7752012-12-10 09:30:55 +00002726 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2727 ntohs(req->tcp_opt));
2728
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 set_emss(ep, ntohs(req->tcp_opt));
2730
2731 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302732 mutex_lock(&ep->com.mutex);
2733 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002735 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302736 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302737 mutex_unlock(&ep->com.mutex);
2738 if (ret)
2739 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302740 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002741
2742 return 0;
2743}
2744
2745static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2746{
2747 struct cpl_peer_close *hdr = cplhdr(skb);
2748 struct c4iw_ep *ep;
2749 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 int disconnect = 1;
2751 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002753 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754
Hariprasad S944661d2016-05-06 22:18:03 +05302755 ep = get_ep_from_tid(dev, tid);
2756 if (!ep)
2757 return 0;
2758
Steve Wisecfdda9d2010-04-21 15:30:06 -07002759 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2760 dst_confirm(ep->dst);
2761
Vipul Pandya793dad92012-12-10 09:30:56 +00002762 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002763 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002764 switch (ep->com.state) {
2765 case MPA_REQ_WAIT:
2766 __state_set(&ep->com, CLOSING);
2767 break;
2768 case MPA_REQ_SENT:
2769 __state_set(&ep->com, CLOSING);
2770 connect_reply_upcall(ep, -ECONNRESET);
2771 break;
2772 case MPA_REQ_RCVD:
2773
2774 /*
2775 * We're gonna mark this puppy DEAD, but keep
2776 * the reference on it until the ULP accepts or
2777 * rejects the CR. Also wake up anyone waiting
2778 * in rdma connection migration (see c4iw_accept_cr()).
2779 */
2780 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002781 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002782 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783 break;
2784 case MPA_REP_SENT:
2785 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002786 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002787 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002788 break;
2789 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002790 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002792 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002793 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002794 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002795 if (ret != -ECONNRESET) {
2796 peer_close_upcall(ep);
2797 disconnect = 1;
2798 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 break;
2800 case ABORTING:
2801 disconnect = 0;
2802 break;
2803 case CLOSING:
2804 __state_set(&ep->com, MORIBUND);
2805 disconnect = 0;
2806 break;
2807 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002808 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 if (ep->com.cm_id && ep->com.qp) {
2810 attrs.next_state = C4IW_QP_STATE_IDLE;
2811 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2812 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2813 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302814 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002815 __state_set(&ep->com, DEAD);
2816 release = 1;
2817 disconnect = 0;
2818 break;
2819 case DEAD:
2820 disconnect = 0;
2821 break;
2822 default:
2823 BUG_ON(1);
2824 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002825 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826 if (disconnect)
2827 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2828 if (release)
2829 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302830 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002831 return 0;
2832}
2833
Steve Wisecfdda9d2010-04-21 15:30:06 -07002834static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2835{
2836 struct cpl_abort_req_rss *req = cplhdr(skb);
2837 struct c4iw_ep *ep;
2838 struct cpl_abort_rpl *rpl;
2839 struct sk_buff *rpl_skb;
2840 struct c4iw_qp_attributes attrs;
2841 int ret;
2842 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002844
Hariprasad S944661d2016-05-06 22:18:03 +05302845 ep = get_ep_from_tid(dev, tid);
2846 if (!ep)
2847 return 0;
2848
Steve Wise7a2cea22014-03-14 21:52:07 +05302849 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302850 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2851 __func__, ep->hwtid, req->status,
2852 neg_adv_str(req->status));
2853 ep->stats.abort_neg_adv++;
2854 mutex_lock(&dev->rdev.stats.lock);
2855 dev->rdev.stats.neg_adv++;
2856 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302857 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002859 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2860 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002861 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002862
2863 /*
2864 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302865 * However, this is not needed if com state is just
2866 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002867 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302868 if (ep->com.state != MPA_REQ_SENT)
2869 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002870
2871 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002872 switch (ep->com.state) {
2873 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302874 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002875 break;
2876 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002877 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002878 break;
2879 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002880 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002881 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302882 connect_reply_upcall(ep, -ECONNRESET);
2883 else {
2884 /*
2885 * we just don't send notification upwards because we
2886 * want to retry with mpa_v1 without upper layers even
2887 * knowing it.
2888 *
2889 * do some housekeeping so as to re-initiate the
2890 * connection
2891 */
2892 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2893 mpa_rev);
2894 ep->retry_with_mpa_v1 = 1;
2895 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896 break;
2897 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002898 break;
2899 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900 break;
2901 case MORIBUND:
2902 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002903 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002904 /*FALLTHROUGH*/
2905 case FPDU_MODE:
2906 if (ep->com.cm_id && ep->com.qp) {
2907 attrs.next_state = C4IW_QP_STATE_ERROR;
2908 ret = c4iw_modify_qp(ep->com.qp->rhp,
2909 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2910 &attrs, 1);
2911 if (ret)
2912 printk(KERN_ERR MOD
2913 "%s - qp <- error failed!\n",
2914 __func__);
2915 }
2916 peer_abort_upcall(ep);
2917 break;
2918 case ABORTING:
2919 break;
2920 case DEAD:
2921 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002922 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302923 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 default:
2925 BUG_ON(1);
2926 break;
2927 }
2928 dst_confirm(ep->dst);
2929 if (ep->com.state != ABORTING) {
2930 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302931 /* we don't release if we want to retry with mpa_v1 */
2932 if (!ep->retry_with_mpa_v1)
2933 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002935 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936
Hariprasad S4a740832016-06-10 01:05:15 +05302937 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2938 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002939 release = 1;
2940 goto out;
2941 }
2942 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2943 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2944 INIT_TP_WR(rpl, ep->hwtid);
2945 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2946 rpl->cmd = CPL_ABORT_NO_RST;
2947 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2948out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 if (release)
2950 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002951 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302952 if (ep->com.remote_addr.ss_family == AF_INET6) {
2953 struct sockaddr_in6 *sin6 =
2954 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002955 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302956 cxgb4_clip_release(
2957 ep->com.dev->rdev.lldi.ports[0],
2958 (const u32 *)&sin6->sin6_addr.s6_addr,
2959 1);
2960 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002961 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302962 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2963 dst_release(ep->dst);
2964 cxgb4_l2t_release(ep->l2t);
2965 c4iw_reconnect(ep);
2966 }
2967
Hariprasad S944661d2016-05-06 22:18:03 +05302968deref_ep:
2969 c4iw_put_ep(&ep->com);
2970 /* Dereferencing ep, referenced in peer_abort_intr() */
2971 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 return 0;
2973}
2974
2975static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2976{
2977 struct c4iw_ep *ep;
2978 struct c4iw_qp_attributes attrs;
2979 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002980 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002982
Hariprasad S944661d2016-05-06 22:18:03 +05302983 ep = get_ep_from_tid(dev, tid);
2984 if (!ep)
2985 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986
2987 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2988 BUG_ON(!ep);
2989
2990 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002991 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302992 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002993 switch (ep->com.state) {
2994 case CLOSING:
2995 __state_set(&ep->com, MORIBUND);
2996 break;
2997 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002998 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999 if ((ep->com.cm_id) && (ep->com.qp)) {
3000 attrs.next_state = C4IW_QP_STATE_IDLE;
3001 c4iw_modify_qp(ep->com.qp->rhp,
3002 ep->com.qp,
3003 C4IW_QP_ATTR_NEXT_STATE,
3004 &attrs, 1);
3005 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05303006 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003007 __state_set(&ep->com, DEAD);
3008 release = 1;
3009 break;
3010 case ABORTING:
3011 case DEAD:
3012 break;
3013 default:
3014 BUG_ON(1);
3015 break;
3016 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05003017 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 if (release)
3019 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05303020 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003021 return 0;
3022}
3023
3024static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
3025{
Steve Wise0e42c1f2010-09-10 11:15:09 -05003026 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05003027 unsigned int tid = GET_TID(rpl);
3028 struct c4iw_ep *ep;
3029 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003030
Hariprasad S944661d2016-05-06 22:18:03 +05303031 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05003032 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003033
Steve Wise30c95c22011-05-09 22:06:22 -07003034 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05003035 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
3036 ep->com.qp->wq.sq.qid);
3037 attrs.next_state = C4IW_QP_STATE_TERMINATE;
3038 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
3039 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
3040 } else
Steve Wise30c95c22011-05-09 22:06:22 -07003041 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05303042 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043
Steve Wisecfdda9d2010-04-21 15:30:06 -07003044 return 0;
3045}
3046
3047/*
3048 * Upcall from the adapter indicating data has been transmitted.
3049 * For us its just the single MPA request or reply. We can now free
3050 * the skb holding the mpa message.
3051 */
3052static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
3053{
3054 struct c4iw_ep *ep;
3055 struct cpl_fw4_ack *hdr = cplhdr(skb);
3056 u8 credits = hdr->credits;
3057 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003058
3059
Hariprasad S944661d2016-05-06 22:18:03 +05303060 ep = get_ep_from_tid(dev, tid);
3061 if (!ep)
3062 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
3064 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07003065 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3066 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05303067 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 }
3069
3070 dst_confirm(ep->dst);
3071 if (ep->mpa_skb) {
3072 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3073 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3074 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07003075 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003076 kfree_skb(ep->mpa_skb);
3077 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303078 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3079 stop_ep_timer(ep);
3080 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003081 }
Hariprasad S944661d2016-05-06 22:18:03 +05303082out:
3083 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003084 return 0;
3085}
3086
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3088{
Hariprasad Sbce28412016-06-10 01:05:13 +05303089 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003090 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05303091
Steve Wisecfdda9d2010-04-21 15:30:06 -07003092 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3093
Steve Wisea7db89e2014-03-21 20:40:35 +05303094 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303095 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303096 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003097 c4iw_put_ep(&ep->com);
3098 return -ECONNRESET;
3099 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003100 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003101 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05303102 abort = 1;
3103 else
3104 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303105 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05303106
3107 stop_ep_timer(ep);
3108 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003109 c4iw_put_ep(&ep->com);
3110 return 0;
3111}
3112
3113int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3114{
3115 int err;
3116 struct c4iw_qp_attributes attrs;
3117 enum c4iw_qp_attr_mask mask;
3118 struct c4iw_ep *ep = to_ep(cm_id);
3119 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3120 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303121 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003122
3123 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303124
3125 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303126 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003127 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303128 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003129 }
3130
Steve Wisecfdda9d2010-04-21 15:30:06 -07003131 BUG_ON(!qp);
3132
Vipul Pandya793dad92012-12-10 09:30:56 +00003133 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303134 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3135 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003136 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303137 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003138 }
3139
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303140 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3141 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303142 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003143 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303144 } else {
3145 ep->ird = conn_param->ird;
3146 ep->ord = conn_param->ord;
3147 send_mpa_reject(ep, conn_param->private_data,
3148 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303149 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303150 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303151 }
3152 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303153 if (conn_param->ird < ep->ord) {
3154 if (RELAXED_IRD_NEGOTIATION &&
3155 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3156 conn_param->ird = ep->ord;
3157 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303158 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303159 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303160 }
3161 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303162 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003163 ep->ird = conn_param->ird;
3164 ep->ord = conn_param->ord;
3165
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303166 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303167 if (peer2peer && ep->ird == 0)
3168 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303169 } else {
3170 if (peer2peer &&
3171 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303172 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303173 ep->ird = 1;
3174 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003175
3176 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3177
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303178 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303179 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303180 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003181 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303182
Steve Wisecfdda9d2010-04-21 15:30:06 -07003183 /* bind QP to EP and move to RTS */
3184 attrs.mpa_attr = ep->mpa_attr;
3185 attrs.max_ird = ep->ird;
3186 attrs.max_ord = ep->ord;
3187 attrs.llp_stream_handle = ep;
3188 attrs.next_state = C4IW_QP_STATE_RTS;
3189
3190 /* bind QP and TID with INIT_WR */
3191 mask = C4IW_QP_ATTR_NEXT_STATE |
3192 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3193 C4IW_QP_ATTR_MPA_ATTR |
3194 C4IW_QP_ATTR_MAX_IRD |
3195 C4IW_QP_ATTR_MAX_ORD;
3196
3197 err = c4iw_modify_qp(ep->com.qp->rhp,
3198 ep->com.qp, mask, &attrs, 1);
3199 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303200 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303201
3202 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003203 err = send_mpa_reply(ep, conn_param->private_data,
3204 conn_param->private_data_len);
3205 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303206 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003207
Steve Wisea7db89e2014-03-21 20:40:35 +05303208 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003209 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303210 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211 c4iw_put_ep(&ep->com);
3212 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303213err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303214 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303215err_abort:
3216 abort = 1;
3217err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303218 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303219 if (abort)
3220 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003221 c4iw_put_ep(&ep->com);
3222 return err;
3223}
3224
Vipul Pandya830662f2013-07-04 16:10:47 +05303225static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3226{
3227 struct in_device *ind;
3228 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003229 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3230 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303231
3232 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3233 if (!ind)
3234 return -EADDRNOTAVAIL;
3235 for_primary_ifa(ind) {
3236 laddr->sin_addr.s_addr = ifa->ifa_address;
3237 raddr->sin_addr.s_addr = ifa->ifa_address;
3238 found = 1;
3239 break;
3240 }
3241 endfor_ifa(ind);
3242 in_dev_put(ind);
3243 return found ? 0 : -EADDRNOTAVAIL;
3244}
3245
3246static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3247 unsigned char banned_flags)
3248{
3249 struct inet6_dev *idev;
3250 int err = -EADDRNOTAVAIL;
3251
3252 rcu_read_lock();
3253 idev = __in6_dev_get(dev);
3254 if (idev != NULL) {
3255 struct inet6_ifaddr *ifp;
3256
3257 read_lock_bh(&idev->lock);
3258 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3259 if (ifp->scope == IFA_LINK &&
3260 !(ifp->flags & banned_flags)) {
3261 memcpy(addr, &ifp->addr, 16);
3262 err = 0;
3263 break;
3264 }
3265 }
3266 read_unlock_bh(&idev->lock);
3267 }
3268 rcu_read_unlock();
3269 return err;
3270}
3271
3272static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3273{
3274 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003275 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3276 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303277
Nicholas Krause54b9a962015-08-26 23:00:59 -04003278 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303279 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3280 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3281 return 0;
3282 }
3283 return -EADDRNOTAVAIL;
3284}
3285
Steve Wisecfdda9d2010-04-21 15:30:06 -07003286int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3287{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003288 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3289 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003290 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003291 struct sockaddr_in *laddr;
3292 struct sockaddr_in *raddr;
3293 struct sockaddr_in6 *laddr6;
3294 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303295 __u8 *ra;
3296 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303298 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3299 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003300 err = -EINVAL;
3301 goto out;
3302 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3304 if (!ep) {
3305 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3306 err = -ENOMEM;
3307 goto out;
3308 }
Hariprasad S4a740832016-06-10 01:05:15 +05303309
3310 skb_queue_head_init(&ep->com.ep_skb_list);
3311 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3312 err = -ENOMEM;
3313 goto fail1;
3314 }
3315
Steve Wisecfdda9d2010-04-21 15:30:06 -07003316 init_timer(&ep->timer);
3317 ep->plen = conn_param->private_data_len;
3318 if (ep->plen)
3319 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3320 conn_param->private_data, ep->plen);
3321 ep->ird = conn_param->ird;
3322 ep->ord = conn_param->ord;
3323
3324 if (peer2peer && ep->ord == 0)
3325 ep->ord = 1;
3326
Steve Wisecfdda9d2010-04-21 15:30:06 -07003327 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303328 ref_cm_id(&ep->com);
3329 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003330 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303331 if (!ep->com.qp) {
3332 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3333 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303334 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303335 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003336 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003337 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3338 ep->com.qp, cm_id);
3339
3340 /*
3341 * Allocate an active TID to initiate a TCP connection.
3342 */
3343 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3344 if (ep->atid == -1) {
3345 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3346 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303347 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003348 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003349 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003350
Steve Wise170003c2016-02-26 09:18:03 -06003351 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003352 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003353 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003354 sizeof(ep->com.remote_addr));
3355
Steve Wise170003c2016-02-26 09:18:03 -06003356 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3357 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3358 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3359 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003360
Steve Wise170003c2016-02-26 09:18:03 -06003361 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303362 iptype = 4;
3363 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003364
Vipul Pandya830662f2013-07-04 16:10:47 +05303365 /*
3366 * Handle loopback requests to INADDR_ANY.
3367 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003368 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303369 err = pick_local_ipaddrs(dev, cm_id);
3370 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303371 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303372 }
3373
3374 /* find a route */
3375 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3376 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3377 ra, ntohs(raddr->sin_port));
3378 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3379 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303380 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303381 } else {
3382 iptype = 6;
3383 ra = (__u8 *)&raddr6->sin6_addr;
3384
3385 /*
3386 * Handle loopback requests to INADDR_ANY.
3387 */
3388 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3389 err = pick_local_ip6addrs(dev, cm_id);
3390 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303391 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303392 }
3393
3394 /* find a route */
3395 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3396 __func__, laddr6->sin6_addr.s6_addr,
3397 ntohs(laddr6->sin6_port),
3398 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3399 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3400 raddr6->sin6_addr.s6_addr,
3401 laddr6->sin6_port, raddr6->sin6_port, 0,
3402 raddr6->sin6_scope_id);
3403 }
3404 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003405 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3406 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303407 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003408 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003409
Hariprasad S963cab52015-09-23 17:19:27 +05303410 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303411 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003412 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003413 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303414 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003415 }
3416
3417 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3418 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3419 ep->l2t->idx);
3420
3421 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303422 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423
3424 /* send connect request to rnic */
3425 err = send_connect(ep);
3426 if (!err)
3427 goto out;
3428
3429 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303430fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003431 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303432fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003433 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003434 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303435fail2:
3436 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303437 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303438fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003439 c4iw_put_ep(&ep->com);
3440out:
3441 return err;
3442}
3443
Vipul Pandya830662f2013-07-04 16:10:47 +05303444static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3445{
3446 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003447 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003448 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303449
Hariprasad S28de1f72016-01-13 10:03:14 +05303450 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3451 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3452 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3453 if (err)
3454 return err;
3455 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303456 c4iw_init_wr_wait(&ep->com.wr_wait);
3457 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3458 ep->stid, &sin6->sin6_addr,
3459 sin6->sin6_port,
3460 ep->com.dev->rdev.lldi.rxq_ids[0]);
3461 if (!err)
3462 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3463 &ep->com.wr_wait,
3464 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303465 else if (err > 0)
3466 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303467 if (err) {
3468 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3469 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303470 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3471 err, ep->stid,
3472 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303473 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303474 return err;
3475}
3476
3477static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3478{
3479 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003480 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003481 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303482
3483 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3484 do {
3485 err = cxgb4_create_server_filter(
3486 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3487 sin->sin_addr.s_addr, sin->sin_port, 0,
3488 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3489 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303490 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3491 err = -EIO;
3492 break;
3493 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303494 set_current_state(TASK_UNINTERRUPTIBLE);
3495 schedule_timeout(usecs_to_jiffies(100));
3496 }
3497 } while (err == -EBUSY);
3498 } else {
3499 c4iw_init_wr_wait(&ep->com.wr_wait);
3500 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3501 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3502 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3503 if (!err)
3504 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3505 &ep->com.wr_wait,
3506 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303507 else if (err > 0)
3508 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303509 }
3510 if (err)
3511 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3512 , err, ep->stid,
3513 &sin->sin_addr, ntohs(sin->sin_port));
3514 return err;
3515}
3516
Steve Wisecfdda9d2010-04-21 15:30:06 -07003517int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3518{
3519 int err = 0;
3520 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3521 struct c4iw_listen_ep *ep;
3522
Steve Wisecfdda9d2010-04-21 15:30:06 -07003523 might_sleep();
3524
3525 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3526 if (!ep) {
3527 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3528 err = -ENOMEM;
3529 goto fail1;
3530 }
Hariprasad S4a740832016-06-10 01:05:15 +05303531 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003532 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003533 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303534 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535 ep->com.dev = dev;
3536 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003537 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303538 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003539
3540 /*
3541 * Allocate a server TID.
3542 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303543 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3544 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303545 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003546 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003547 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303548 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003549 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003550
Steve Wisecfdda9d2010-04-21 15:30:06 -07003551 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003552 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003553 err = -ENOMEM;
3554 goto fail2;
3555 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003556 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003557
Steve Wise170003c2016-02-26 09:18:03 -06003558 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3559 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003560
Steve Wisecfdda9d2010-04-21 15:30:06 -07003561 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303562 if (ep->com.local_addr.ss_family == AF_INET)
3563 err = create_server4(dev, ep);
3564 else
3565 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003566 if (!err) {
3567 cm_id->provider_data = ep;
3568 goto out;
3569 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003570
Vipul Pandya830662f2013-07-04 16:10:47 +05303571 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3572 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003573fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303574 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003575 c4iw_put_ep(&ep->com);
3576fail1:
3577out:
3578 return err;
3579}
3580
3581int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3582{
3583 int err;
3584 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3585
3586 PDBG("%s ep %p\n", __func__, ep);
3587
3588 might_sleep();
3589 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303590 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3591 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003592 err = cxgb4_remove_server_filter(
3593 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3594 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3595 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303596 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003597 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303598 err = cxgb4_remove_server(
3599 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3600 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601 if (err)
3602 goto done;
3603 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3604 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003605 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303606 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3607 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003608 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003609 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303610 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3611 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003612done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303613 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003614 c4iw_put_ep(&ep->com);
3615 return err;
3616}
3617
3618int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3619{
3620 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003621 int close = 0;
3622 int fatal = 0;
3623 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003624
Steve Wise2f5b48c2010-09-10 11:15:36 -05003625 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003626
3627 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3628 states[ep->com.state], abrupt);
3629
Hariprasad S6e410d82016-05-05 01:27:31 +05303630 /*
3631 * Ref the ep here in case we have fatal errors causing the
3632 * ep to be released and freed.
3633 */
3634 c4iw_get_ep(&ep->com);
3635
Steve Wisecfdda9d2010-04-21 15:30:06 -07003636 rdev = &ep->com.dev->rdev;
3637 if (c4iw_fatal_error(rdev)) {
3638 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303639 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003640 ep->com.state = DEAD;
3641 }
3642 switch (ep->com.state) {
3643 case MPA_REQ_WAIT:
3644 case MPA_REQ_SENT:
3645 case MPA_REQ_RCVD:
3646 case MPA_REP_SENT:
3647 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303648 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003649 close = 1;
3650 if (abrupt)
3651 ep->com.state = ABORTING;
3652 else {
3653 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003654
3655 /*
3656 * if we close before we see the fw4_ack() then we fix
3657 * up the timer state since we're reusing it.
3658 */
3659 if (ep->mpa_skb &&
3660 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3661 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3662 stop_ep_timer(ep);
3663 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003664 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003665 }
3666 set_bit(CLOSE_SENT, &ep->com.flags);
3667 break;
3668 case CLOSING:
3669 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3670 close = 1;
3671 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003672 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003673 ep->com.state = ABORTING;
3674 } else
3675 ep->com.state = MORIBUND;
3676 }
3677 break;
3678 case MORIBUND:
3679 case ABORTING:
3680 case DEAD:
3681 PDBG("%s ignoring disconnect ep %p state %u\n",
3682 __func__, ep, ep->com.state);
3683 break;
3684 default:
3685 BUG();
3686 break;
3687 }
3688
Steve Wisecfdda9d2010-04-21 15:30:06 -07003689 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003690 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003691 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303692 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303693 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003694 } else {
3695 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303696 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003697 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303698 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303699 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303700 if (!abrupt) {
3701 stop_ep_timer(ep);
3702 close_complete_upcall(ep, -EIO);
3703 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303704 if (ep->com.qp) {
3705 struct c4iw_qp_attributes attrs;
3706
3707 attrs.next_state = C4IW_QP_STATE_ERROR;
3708 ret = c4iw_modify_qp(ep->com.qp->rhp,
3709 ep->com.qp,
3710 C4IW_QP_ATTR_NEXT_STATE,
3711 &attrs, 1);
3712 if (ret)
3713 pr_err(MOD
3714 "%s - qp <- error failed!\n",
3715 __func__);
3716 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003717 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303718 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003719 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003720 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303721 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003722 if (fatal)
3723 release_ep_resources(ep);
3724 return ret;
3725}
3726
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3728 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3729{
3730 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003731 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003733 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3734 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003735 if (!ep)
3736 return;
3737
3738 switch (req->retval) {
3739 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003740 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3741 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3742 send_fw_act_open_req(ep, atid);
3743 return;
3744 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003745 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003746 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3747 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3748 send_fw_act_open_req(ep, atid);
3749 return;
3750 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003751 break;
3752 default:
3753 pr_info("%s unexpected ofld conn wr retval %d\n",
3754 __func__, req->retval);
3755 break;
3756 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003757 pr_err("active ofld_connect_wr failure %d atid %d\n",
3758 req->retval, atid);
3759 mutex_lock(&dev->rdev.stats.lock);
3760 dev->rdev.stats.act_ofld_conn_fails++;
3761 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003763 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303764 if (ep->com.remote_addr.ss_family == AF_INET6) {
3765 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003766 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303767 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3768 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3769 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003770 remove_handle(dev, &dev->atid_idr, atid);
3771 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3772 dst_release(ep->dst);
3773 cxgb4_l2t_release(ep->l2t);
3774 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775}
3776
3777static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3778 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3779{
3780 struct sk_buff *rpl_skb;
3781 struct cpl_pass_accept_req *cpl;
3782 int ret;
3783
Paul Bolle710a3112013-02-05 20:51:30 +00003784 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003785 BUG_ON(!rpl_skb);
3786 if (req->retval) {
3787 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003788 mutex_lock(&dev->rdev.stats.lock);
3789 dev->rdev.stats.pas_ofld_conn_fails++;
3790 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003791 kfree_skb(rpl_skb);
3792 } else {
3793 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3794 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003795 (__force u32) htonl(
3796 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003797 ret = pass_accept_req(dev, rpl_skb);
3798 if (!ret)
3799 kfree_skb(rpl_skb);
3800 }
3801 return;
3802}
3803
3804static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003805{
3806 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003807 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3808
3809 switch (rpl->type) {
3810 case FW6_TYPE_CQE:
3811 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3812 break;
3813 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3814 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3815 switch (req->t_state) {
3816 case TCP_SYN_SENT:
3817 active_ofld_conn_reply(dev, skb, req);
3818 break;
3819 case TCP_SYN_RECV:
3820 passive_ofld_conn_reply(dev, skb, req);
3821 break;
3822 default:
3823 pr_err("%s unexpected ofld conn wr state %d\n",
3824 __func__, req->t_state);
3825 break;
3826 }
3827 break;
3828 }
3829 return 0;
3830}
3831
3832static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3833{
Hariprasad S963cab52015-09-23 17:19:27 +05303834 __be32 l2info;
3835 __be16 hdr_len, vlantag, len;
3836 u16 eth_hdr_len;
3837 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003838 u8 intf;
3839 struct cpl_rx_pkt *cpl = cplhdr(skb);
3840 struct cpl_pass_accept_req *req;
3841 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003842 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303843 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003844
Vipul Pandyaf079af72013-03-14 05:08:58 +00003845 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003846 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303847 vlantag = cpl->vlan;
3848 len = cpl->len;
3849 l2info = cpl->l2info;
3850 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003851 intf = cpl->iff;
3852
3853 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3854
3855 /*
3856 * We need to parse the TCP options from SYN packet.
3857 * to generate cpl_pass_accept_req.
3858 */
3859 memset(&tmp_opt, 0, sizeof(tmp_opt));
3860 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003861 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003862
3863 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3864 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303865 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3866 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303867 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303868 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303869 type = dev->rdev.lldi.adapter_type;
3870 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3871 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3872 req->hdr_len =
3873 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3874 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3875 eth_hdr_len = is_t4(type) ?
3876 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3877 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3878 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3879 IP_HDR_LEN_V(ip_hdr_len) |
3880 ETH_HDR_LEN_V(eth_hdr_len));
3881 } else { /* T6 and later */
3882 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3883 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3884 T6_IP_HDR_LEN_V(ip_hdr_len) |
3885 T6_ETH_HDR_LEN_V(eth_hdr_len));
3886 }
3887 req->vlan = vlantag;
3888 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003889 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3890 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003891 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3892 if (tmp_opt.wscale_ok)
3893 req->tcpopt.wsf = tmp_opt.snd_wscale;
3894 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3895 if (tmp_opt.sack_ok)
3896 req->tcpopt.sack = 1;
3897 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3898 return;
3899}
3900
3901static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3902 __be32 laddr, __be16 lport,
3903 __be32 raddr, __be16 rport,
3904 u32 rcv_isn, u32 filter, u16 window,
3905 u32 rss_qid, u8 port_id)
3906{
3907 struct sk_buff *req_skb;
3908 struct fw_ofld_connection_wr *req;
3909 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303910 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003911
3912 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3913 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3914 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003915 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303916 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303917 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003918 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003919 req->le.lport = lport;
3920 req->le.pport = rport;
3921 req->le.u.ipv4.lip = laddr;
3922 req->le.u.ipv4.pip = raddr;
3923 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3924 req->tcb.rcv_adv = htons(window);
3925 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303926 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3927 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3928 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003929 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003930
3931 /*
3932 * We store the qid in opt2 which will be used by the firmware
3933 * to send us the wr response.
3934 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003935 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003936
3937 /*
3938 * We initialize the MSS index in TCB to 0xF.
3939 * So that when driver sends cpl_pass_accept_rpl
3940 * TCB picks up the correct value. If this was 0
3941 * TP will ignore any value > 0 for MSS index.
3942 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003943 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303944 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003945
3946 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303947 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3948 if (ret < 0) {
3949 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3950 ret);
3951 kfree_skb(skb);
3952 kfree_skb(req_skb);
3953 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003954}
3955
3956/*
3957 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3958 * messages when a filter is being used instead of server to
3959 * redirect a syn packet. When packets hit filter they are redirected
3960 * to the offload queue and driver tries to establish the connection
3961 * using firmware work request.
3962 */
3963static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3964{
3965 int stid;
3966 unsigned int filter;
3967 struct ethhdr *eh = NULL;
3968 struct vlan_ethhdr *vlan_eh = NULL;
3969 struct iphdr *iph;
3970 struct tcphdr *tcph;
3971 struct rss_header *rss = (void *)skb->data;
3972 struct cpl_rx_pkt *cpl = (void *)skb->data;
3973 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3974 struct l2t_entry *e;
3975 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303976 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003977 u16 window;
3978 struct port_info *pi;
3979 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003980 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003981 int step;
3982 u32 tx_chan;
3983 struct neighbour *neigh;
3984
3985 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003986 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003987 goto reject;
3988
3989 /*
3990 * Drop all packets which did not hit the filter.
3991 * Unlikely to happen.
3992 */
3993 if (!(rss->filter_hit && rss->filter_tid))
3994 goto reject;
3995
3996 /*
3997 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3998 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303999 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004000
Hariprasad Sf86fac72016-05-06 22:18:07 +05304001 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004002 if (!lep) {
4003 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
4004 goto reject;
4005 }
4006
Hariprasad S963cab52015-09-23 17:19:27 +05304007 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
4008 case CHELSIO_T4:
4009 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4010 break;
4011 case CHELSIO_T5:
4012 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4013 break;
4014 case CHELSIO_T6:
4015 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
4016 break;
4017 default:
4018 pr_err("T%d Chip is not supported\n",
4019 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
4020 goto reject;
4021 }
4022
Vipul Pandyaf079af72013-03-14 05:08:58 +00004023 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00004024 eh = (struct ethhdr *)(req + 1);
4025 iph = (struct iphdr *)(eh + 1);
4026 } else {
4027 vlan_eh = (struct vlan_ethhdr *)(req + 1);
4028 iph = (struct iphdr *)(vlan_eh + 1);
4029 skb->vlan_tci = ntohs(cpl->vlan);
4030 }
4031
4032 if (iph->version != 0x4)
4033 goto reject;
4034
4035 tcph = (struct tcphdr *)(iph + 1);
4036 skb_set_network_header(skb, (void *)iph - (void *)rss);
4037 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
4038 skb_get(skb);
4039
4040 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
4041 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
4042 ntohs(tcph->source), iph->tos);
4043
Vipul Pandya830662f2013-07-04 16:10:47 +05304044 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
4045 iph->tos);
4046 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00004047 pr_err("%s - failed to find dst entry!\n",
4048 __func__);
4049 goto reject;
4050 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00004051 neigh = dst_neigh_lookup_skb(dst, skb);
4052
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00004053 if (!neigh) {
4054 pr_err("%s - failed to allocate neigh!\n",
4055 __func__);
4056 goto free_dst;
4057 }
4058
Vipul Pandya1cab7752012-12-10 09:30:55 +00004059 if (neigh->dev->flags & IFF_LOOPBACK) {
4060 pdev = ip_dev_find(&init_net, iph->daddr);
4061 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
4062 pdev, 0);
4063 pi = (struct port_info *)netdev_priv(pdev);
4064 tx_chan = cxgb4_port_chan(pdev);
4065 dev_put(pdev);
4066 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05304067 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004068 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05304069 pdev, 0);
4070 pi = (struct port_info *)netdev_priv(pdev);
4071 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004072 }
Steve Wiseebf00062014-03-19 17:44:40 +05304073 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004074 if (!e) {
4075 pr_err("%s - failed to allocate l2t entry!\n",
4076 __func__);
4077 goto free_dst;
4078 }
4079
4080 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4081 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00004082 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004083
4084 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05304085 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4086 dev->rdev.lldi.ports[0],
4087 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004088
4089 /*
4090 * Synthesize the cpl_pass_accept_req. We have everything except the
4091 * TID. Once firmware sends a reply with TID we update the TID field
4092 * in cpl and pass it through the regular cpl_pass_accept_req path.
4093 */
4094 build_cpl_pass_accept_req(skb, stid, iph->tos);
4095 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4096 tcph->source, ntohl(tcph->seq), filter, window,
4097 rss_qid, pi->port_id);
4098 cxgb4_l2t_release(e);
4099free_dst:
4100 dst_release(dst);
4101reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304102 if (lep)
4103 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004104 return 0;
4105}
4106
Steve Wisecfdda9d2010-04-21 15:30:06 -07004107/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004108 * These are the real handlers that are called from a
4109 * work queue.
4110 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304111static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004112 [CPL_ACT_ESTABLISH] = act_establish,
4113 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4114 [CPL_RX_DATA] = rx_data,
4115 [CPL_ABORT_RPL_RSS] = abort_rpl,
4116 [CPL_ABORT_RPL] = abort_rpl,
4117 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4118 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4119 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4120 [CPL_PASS_ESTABLISH] = pass_establish,
4121 [CPL_PEER_CLOSE] = peer_close,
4122 [CPL_ABORT_REQ_RSS] = peer_abort,
4123 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4124 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004125 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004126 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304127 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304128 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4129 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004130};
4131
4132static void process_timeout(struct c4iw_ep *ep)
4133{
4134 struct c4iw_qp_attributes attrs;
4135 int abort = 1;
4136
Steve Wise2f5b48c2010-09-10 11:15:36 -05004137 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004138 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4139 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004140 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004141 switch (ep->com.state) {
4142 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004143 connect_reply_upcall(ep, -ETIMEDOUT);
4144 break;
4145 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304146 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304147 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304148 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004149 break;
4150 case CLOSING:
4151 case MORIBUND:
4152 if (ep->com.cm_id && ep->com.qp) {
4153 attrs.next_state = C4IW_QP_STATE_ERROR;
4154 c4iw_modify_qp(ep->com.qp->rhp,
4155 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4156 &attrs, 1);
4157 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304158 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004159 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004160 case ABORTING:
4161 case DEAD:
4162
4163 /*
4164 * These states are expected if the ep timed out at the same
4165 * time as another thread was calling stop_ep_timer().
4166 * So we silently do nothing for these states.
4167 */
4168 abort = 0;
4169 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004170 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004171 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004172 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004173 abort = 0;
4174 }
Steve Wisecc18b932014-04-24 14:31:53 -05004175 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304176 if (abort)
4177 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004178 c4iw_put_ep(&ep->com);
4179}
4180
4181static void process_timedout_eps(void)
4182{
4183 struct c4iw_ep *ep;
4184
4185 spin_lock_irq(&timeout_lock);
4186 while (!list_empty(&timeout_list)) {
4187 struct list_head *tmp;
4188
4189 tmp = timeout_list.next;
4190 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004191 tmp->next = NULL;
4192 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004193 spin_unlock_irq(&timeout_lock);
4194 ep = list_entry(tmp, struct c4iw_ep, entry);
4195 process_timeout(ep);
4196 spin_lock_irq(&timeout_lock);
4197 }
4198 spin_unlock_irq(&timeout_lock);
4199}
4200
4201static void process_work(struct work_struct *work)
4202{
4203 struct sk_buff *skb = NULL;
4204 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004205 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004206 unsigned int opcode;
4207 int ret;
4208
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004209 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004210 while ((skb = skb_dequeue(&rxq))) {
4211 rpl = cplhdr(skb);
4212 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4213 opcode = rpl->ot.opcode;
4214
4215 BUG_ON(!work_handlers[opcode]);
4216 ret = work_handlers[opcode](dev, skb);
4217 if (!ret)
4218 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004219 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004220 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004221}
4222
4223static DECLARE_WORK(skb_work, process_work);
4224
4225static void ep_timeout(unsigned long arg)
4226{
4227 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004228 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004229
4230 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004231 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004232 /*
4233 * Only insert if it is not already on the list.
4234 */
4235 if (!ep->entry.next) {
4236 list_add_tail(&ep->entry, &timeout_list);
4237 kickit = 1;
4238 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004239 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004240 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004241 if (kickit)
4242 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004243}
4244
4245/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004246 * All the CM events are handled on a work queue to have a safe context.
4247 */
4248static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4249{
4250
4251 /*
4252 * Save dev in the skb->cb area.
4253 */
4254 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4255
4256 /*
4257 * Queue the skb and schedule the worker thread.
4258 */
4259 skb_queue_tail(&rxq, skb);
4260 queue_work(workq, &skb_work);
4261 return 0;
4262}
4263
4264static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4265{
4266 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4267
4268 if (rpl->status != CPL_ERR_NONE) {
4269 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4270 "for tid %u\n", rpl->status, GET_TID(rpl));
4271 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004272 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004273 return 0;
4274}
4275
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004276static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4277{
4278 struct cpl_fw6_msg *rpl = cplhdr(skb);
4279 struct c4iw_wr_wait *wr_waitp;
4280 int ret;
4281
4282 PDBG("%s type %u\n", __func__, rpl->type);
4283
4284 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004285 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004286 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004287 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004288 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004289 if (wr_waitp)
4290 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004291 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004292 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004293 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004294 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004295 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004296 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004297 default:
4298 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4299 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004300 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004301 break;
4302 }
4303 return 0;
4304}
4305
Steve Wise8da7e7a2011-06-14 20:59:27 +00004306static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4307{
4308 struct cpl_abort_req_rss *req = cplhdr(skb);
4309 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004310 unsigned int tid = GET_TID(req);
4311
Hariprasad S944661d2016-05-06 22:18:03 +05304312 ep = get_ep_from_tid(dev, tid);
4313 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004314 if (!ep) {
4315 printk(KERN_WARNING MOD
4316 "Abort on non-existent endpoint, tid %d\n", tid);
4317 kfree_skb(skb);
4318 return 0;
4319 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304320 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304321 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4322 __func__, ep->hwtid, req->status,
4323 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304324 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004325 }
4326 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4327 ep->com.state);
4328
Hariprasad S093108c2016-05-06 22:18:09 +05304329 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304330out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004331 sched(dev, skb);
4332 return 0;
4333}
4334
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004335/*
4336 * Most upcalls from the T4 Core go to sched() to
4337 * schedule the processing on a work queue.
4338 */
4339c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4340 [CPL_ACT_ESTABLISH] = sched,
4341 [CPL_ACT_OPEN_RPL] = sched,
4342 [CPL_RX_DATA] = sched,
4343 [CPL_ABORT_RPL_RSS] = sched,
4344 [CPL_ABORT_RPL] = sched,
4345 [CPL_PASS_OPEN_RPL] = sched,
4346 [CPL_CLOSE_LISTSRV_RPL] = sched,
4347 [CPL_PASS_ACCEPT_REQ] = sched,
4348 [CPL_PASS_ESTABLISH] = sched,
4349 [CPL_PEER_CLOSE] = sched,
4350 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004351 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004352 [CPL_RDMA_TERMINATE] = sched,
4353 [CPL_FW4_ACK] = sched,
4354 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004355 [CPL_FW6_MSG] = fw6_msg,
4356 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004357};
4358
Steve Wisecfdda9d2010-04-21 15:30:06 -07004359int __init c4iw_cm_init(void)
4360{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004361 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004362 skb_queue_head_init(&rxq);
4363
4364 workq = create_singlethread_workqueue("iw_cxgb4");
4365 if (!workq)
4366 return -ENOMEM;
4367
Steve Wisecfdda9d2010-04-21 15:30:06 -07004368 return 0;
4369}
4370
Steve Wise46c13762014-06-20 14:26:25 -05004371void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004372{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004373 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004374 flush_workqueue(workq);
4375 destroy_workqueue(workq);
4376}