blob: 9398143d7c5e93a01d5b35c67ae0fdd4e0126483 [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
Varun Prakash85e42b02016-09-13 21:23:56 +053052#include <libcxgb_cm.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070053#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053054#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070055
56static char *states[] = {
57 "idle",
58 "listen",
59 "connecting",
60 "mpa_wait_req",
61 "mpa_req_sent",
62 "mpa_req_rcvd",
63 "mpa_rep_sent",
64 "fpdu_mode",
65 "aborting",
66 "closing",
67 "moribund",
68 "dead",
69 NULL,
70};
71
Vipul Pandya5be78ee2012-12-10 09:30:54 +000072static int nocong;
73module_param(nocong, int, 0644);
74MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
75
76static int enable_ecn;
77module_param(enable_ecn, int, 0644);
78MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
79
Steve Wiseb52fe092011-03-11 22:30:01 +000080static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000081module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000082MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000083
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053084uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070085module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053086MODULE_PARM_DESC(c4iw_max_read_depth,
87 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070088
Steve Wisecfdda9d2010-04-21 15:30:06 -070089static int enable_tcp_timestamps;
90module_param(enable_tcp_timestamps, int, 0644);
91MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
92
93static int enable_tcp_sack;
94module_param(enable_tcp_sack, int, 0644);
95MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
96
97static int enable_tcp_window_scaling = 1;
98module_param(enable_tcp_window_scaling, int, 0644);
99MODULE_PARM_DESC(enable_tcp_window_scaling,
100 "Enable tcp window scaling (default=1)");
101
102int c4iw_debug;
103module_param(c4iw_debug, int, 0644);
104MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
105
Steve Wisedf2d5132014-03-19 17:44:44 +0530106static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700107module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530108MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700109
110static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
111module_param(p2p_type, int, 0644);
112MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
113 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
114
115static int ep_timeout_secs = 60;
116module_param(ep_timeout_secs, int, 0644);
117MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
118 "in seconds (default=60)");
119
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530120static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700121module_param(mpa_rev, int, 0644);
122MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530123 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530124 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700125
126static int markers_enabled;
127module_param(markers_enabled, int, 0644);
128MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
129
130static int crc_enabled = 1;
131module_param(crc_enabled, int, 0644);
132MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
133
134static int rcv_win = 256 * 1024;
135module_param(rcv_win, int, 0644);
136MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
137
Steve Wise98ae68b2010-09-10 11:15:41 -0500138static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700139module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500140MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700143
144static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700145
146static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
147static void ep_timeout(unsigned long arg);
148static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530149static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700151static LIST_HEAD(timeout_list);
152static spinlock_t timeout_lock;
153
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530154static void deref_cm_id(struct c4iw_ep_common *epc)
155{
156 epc->cm_id->rem_ref(epc->cm_id);
157 epc->cm_id = NULL;
158 set_bit(CM_ID_DEREFED, &epc->history);
159}
160
161static void ref_cm_id(struct c4iw_ep_common *epc)
162{
163 set_bit(CM_ID_REFED, &epc->history);
164 epc->cm_id->add_ref(epc->cm_id);
165}
166
Vipul Pandya325abea2013-01-07 13:11:53 +0000167static void deref_qp(struct c4iw_ep *ep)
168{
169 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
170 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530171 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000172}
173
174static void ref_qp(struct c4iw_ep *ep)
175{
176 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530177 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000178 c4iw_qp_add_ref(&ep->com.qp->ibqp);
179}
180
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181static void start_ep_timer(struct c4iw_ep *ep)
182{
183 PDBG("%s ep %p\n", __func__, ep);
184 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000185 pr_err("%s timer already started! ep %p\n",
186 __func__, ep);
187 return;
188 }
189 clear_bit(TIMEOUT, &ep->com.flags);
190 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700191 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
192 ep->timer.data = (unsigned long)ep;
193 ep->timer.function = ep_timeout;
194 add_timer(&ep->timer);
195}
196
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500197static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700198{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000199 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700200 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500201 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000202 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500203 return 0;
204 }
205 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700206}
207
208static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
209 struct l2t_entry *l2e)
210{
211 int error = 0;
212
213 if (c4iw_fatal_error(rdev)) {
214 kfree_skb(skb);
215 PDBG("%s - device in error state - dropping\n", __func__);
216 return -EIO;
217 }
218 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
219 if (error < 0)
220 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530221 else if (error == NET_XMIT_DROP)
222 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500223 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700224}
225
226int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
227{
228 int error = 0;
229
230 if (c4iw_fatal_error(rdev)) {
231 kfree_skb(skb);
232 PDBG("%s - device in error state - dropping\n", __func__);
233 return -EIO;
234 }
235 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
236 if (error < 0)
237 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500238 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700239}
240
241static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
242{
Varun Prakasha1a23452016-09-13 21:24:02 +0530243 u32 len = roundup(sizeof(struct cpl_tid_release), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700244
Varun Prakasha1a23452016-09-13 21:24:02 +0530245 skb = get_skb(skb, len, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700246 if (!skb)
247 return;
Varun Prakasha1a23452016-09-13 21:24:02 +0530248
249 cxgb_mk_tid_release(skb, len, hwtid, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700250 c4iw_ofld_send(rdev, skb);
251 return;
252}
253
254static void set_emss(struct c4iw_ep *ep, u16 opt)
255{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800256 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530257 ((AF_INET == ep->com.remote_addr.ss_family) ?
258 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
259 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700260 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800261 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530262 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 if (ep->emss < 128)
264 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530265 if (ep->emss & 7)
266 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800267 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
268 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700269 ep->mss, ep->emss);
270}
271
272static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
273{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700274 enum c4iw_ep_state state;
275
Steve Wise2f5b48c2010-09-10 11:15:36 -0500276 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700277 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500278 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279 return state;
280}
281
282static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
283{
284 epc->state = new;
285}
286
287static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
288{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500289 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700290 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
291 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500292 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700293 return;
294}
295
Hariprasad S4a740832016-06-10 01:05:15 +0530296static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
297{
298 struct sk_buff *skb;
299 unsigned int i;
300 size_t len;
301
302 len = roundup(sizeof(union cpl_wr_size), 16);
303 for (i = 0; i < size; i++) {
304 skb = alloc_skb(len, GFP_KERNEL);
305 if (!skb)
306 goto fail;
307 skb_queue_tail(ep_skb_list, skb);
308 }
309 return 0;
310fail:
311 skb_queue_purge(ep_skb_list);
312 return -ENOMEM;
313}
314
Steve Wisecfdda9d2010-04-21 15:30:06 -0700315static void *alloc_ep(int size, gfp_t gfp)
316{
317 struct c4iw_ep_common *epc;
318
319 epc = kzalloc(size, gfp);
320 if (epc) {
321 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500322 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500323 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700324 }
325 PDBG("%s alloc ep %p\n", __func__, epc);
326 return epc;
327}
328
Hariprasad S944661d2016-05-06 22:18:03 +0530329static void remove_ep_tid(struct c4iw_ep *ep)
330{
331 unsigned long flags;
332
333 spin_lock_irqsave(&ep->com.dev->lock, flags);
334 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
Steve Wise37eb8162016-09-01 06:44:52 -0700335 if (idr_is_empty(&ep->com.dev->hwtid_idr))
336 wake_up(&ep->com.dev->wait);
Hariprasad S944661d2016-05-06 22:18:03 +0530337 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
338}
339
340static void insert_ep_tid(struct c4iw_ep *ep)
341{
342 unsigned long flags;
343
344 spin_lock_irqsave(&ep->com.dev->lock, flags);
345 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
346 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
347}
348
349/*
350 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
351 */
352static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
353{
354 struct c4iw_ep *ep;
355 unsigned long flags;
356
357 spin_lock_irqsave(&dev->lock, flags);
358 ep = idr_find(&dev->hwtid_idr, tid);
359 if (ep)
360 c4iw_get_ep(&ep->com);
361 spin_unlock_irqrestore(&dev->lock, flags);
362 return ep;
363}
364
Hariprasad Sf86fac72016-05-06 22:18:07 +0530365/*
366 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
367 */
368static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
369 unsigned int stid)
370{
371 struct c4iw_listen_ep *ep;
372 unsigned long flags;
373
374 spin_lock_irqsave(&dev->lock, flags);
375 ep = idr_find(&dev->stid_idr, stid);
376 if (ep)
377 c4iw_get_ep(&ep->com);
378 spin_unlock_irqrestore(&dev->lock, flags);
379 return ep;
380}
381
Steve Wisecfdda9d2010-04-21 15:30:06 -0700382void _c4iw_free_ep(struct kref *kref)
383{
384 struct c4iw_ep *ep;
385
386 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530387 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000388 if (test_bit(QP_REFERENCED, &ep->com.flags))
389 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700390 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530391 if (ep->com.remote_addr.ss_family == AF_INET6) {
392 struct sockaddr_in6 *sin6 =
393 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600394 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530395
396 cxgb4_clip_release(
397 ep->com.dev->rdev.lldi.ports[0],
398 (const u32 *)&sin6->sin6_addr.s6_addr,
399 1);
400 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700401 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
402 dst_release(ep->dst);
403 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530404 if (ep->mpa_skb)
405 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700406 }
Hariprasad S4a740832016-06-10 01:05:15 +0530407 if (!skb_queue_empty(&ep->com.ep_skb_list))
408 skb_queue_purge(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700409 kfree(ep);
410}
411
412static void release_ep_resources(struct c4iw_ep *ep)
413{
414 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530415
416 /*
417 * If we have a hwtid, then remove it from the idr table
418 * so lookups will no longer find this endpoint. Otherwise
419 * we have a race where one thread finds the ep ptr just
420 * before the other thread is freeing the ep memory.
421 */
422 if (ep->hwtid != -1)
423 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700424 c4iw_put_ep(&ep->com);
425}
426
Steve Wisecfdda9d2010-04-21 15:30:06 -0700427static int status2errno(int status)
428{
429 switch (status) {
430 case CPL_ERR_NONE:
431 return 0;
432 case CPL_ERR_CONN_RESET:
433 return -ECONNRESET;
434 case CPL_ERR_ARP_MISS:
435 return -EHOSTUNREACH;
436 case CPL_ERR_CONN_TIMEDOUT:
437 return -ETIMEDOUT;
438 case CPL_ERR_TCAM_FULL:
439 return -ENOMEM;
440 case CPL_ERR_CONN_EXIST:
441 return -EADDRINUSE;
442 default:
443 return -EIO;
444 }
445}
446
447/*
448 * Try and reuse skbs already allocated...
449 */
450static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
451{
452 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
453 skb_trim(skb, 0);
454 skb_get(skb);
455 skb_reset_transport_header(skb);
456 } else {
457 skb = alloc_skb(len, gfp);
458 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530459 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700460 return skb;
461}
462
Vipul Pandya830662f2013-07-04 16:10:47 +0530463static struct net_device *get_real_dev(struct net_device *egress_dev)
464{
Steve Wise11b8e222014-05-16 12:42:46 -0500465 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530466}
467
Steve Wisecfdda9d2010-04-21 15:30:06 -0700468static void arp_failure_discard(void *handle, struct sk_buff *skb)
469{
Hariprasad S9dec9002016-05-05 01:27:29 +0530470 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700471 kfree_skb(skb);
472}
473
Hariprasad S64bec742016-05-06 22:18:10 +0530474static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
475{
476 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
477}
478
Hariprasad S9dec9002016-05-05 01:27:29 +0530479enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530480 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530481 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530482 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530483};
484
485static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
486{
487 struct c4iw_ep *ep;
488
489 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
490 release_ep_resources(ep);
491 return 0;
492}
493
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530494static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
495{
496 struct c4iw_ep *ep;
497
498 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
499 c4iw_put_ep(&ep->parent_ep->com);
500 release_ep_resources(ep);
501 return 0;
502}
503
Hariprasad S9dec9002016-05-05 01:27:29 +0530504/*
505 * Fake up a special CPL opcode and call sched() so process_work() will call
506 * _put_ep_safe() in a safe context to free the ep resources. This is needed
507 * because ARP error handlers are called in an ATOMIC context, and
508 * _c4iw_free_ep() needs to block.
509 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530510static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
511 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530512{
513 struct cpl_act_establish *rpl = cplhdr(skb);
514
515 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530516 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530517
518 /*
519 * Save ep in the skb->cb area, after where sched() will save the dev
520 * ptr.
521 */
522 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
523 sched(ep->com.dev, skb);
524}
525
526/* Handle an ARP failure for an accept */
527static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
528{
529 struct c4iw_ep *ep = handle;
530
531 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
532 ep->hwtid);
533
534 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530535 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530536}
537
Steve Wisecfdda9d2010-04-21 15:30:06 -0700538/*
539 * Handle an ARP failure for an active open.
540 */
541static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
542{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530543 struct c4iw_ep *ep = handle;
544
Masanari Iidae3d132d2015-10-16 21:14:29 +0900545 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530546 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530547 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530548 if (ep->com.remote_addr.ss_family == AF_INET6) {
549 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600550 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530551 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
552 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
553 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530554 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
555 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530556 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557}
558
559/*
560 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
561 * and send it along.
562 */
563static void abort_arp_failure(void *handle, struct sk_buff *skb)
564{
Hariprasad S761e19a2016-05-06 22:18:02 +0530565 int ret;
566 struct c4iw_ep *ep = handle;
567 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700568 struct cpl_abort_req *req = cplhdr(skb);
569
570 PDBG("%s rdev %p\n", __func__, rdev);
571 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530572 ret = c4iw_ofld_send(rdev, skb);
573 if (ret) {
574 __state_set(&ep->com, DEAD);
575 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
576 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577}
578
Hariprasad S4a740832016-06-10 01:05:15 +0530579static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700580{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530582 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700583 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530584 u16 vlan = ep->l2t->vlan;
585 int nparams;
586
Hariprasad S4a740832016-06-10 01:05:15 +0530587 if (WARN_ON(!skb))
588 return -ENOMEM;
589
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530590 if (vlan == CPL_L2T_VLAN_NONE)
591 nparams = 8;
592 else
593 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700594
Hariprasad S4a740832016-06-10 01:05:15 +0530595 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530597 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530598 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530599 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530600 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700601
602 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530603 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530604 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700605 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
606 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
607 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
608 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
609 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
610 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
611 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
612 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
613 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
614 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
615 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530616 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700617 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
618 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530619 if (nparams == 9) {
620 u16 pri;
621
622 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
623 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
624 flowc->mnemval[8].val = cpu_to_be32(pri);
625 } else {
626 /* Pad WR to 16 byte boundary */
627 flowc->mnemval[8].mnemonic = 0;
628 flowc->mnemval[8].val = 0;
629 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700630 for (i = 0; i < 9; i++) {
631 flowc->mnemval[i].r4[0] = 0;
632 flowc->mnemval[i].r4[1] = 0;
633 flowc->mnemval[i].r4[2] = 0;
634 }
635
636 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530637 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700638}
639
Hariprasad S4a740832016-06-10 01:05:15 +0530640static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641{
Hariprasad S4a740832016-06-10 01:05:15 +0530642 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Varun Prakash29fb6f42016-09-13 21:24:03 +0530643 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700644
645 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530646 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700647 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530648
Varun Prakash29fb6f42016-09-13 21:24:03 +0530649 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
650 NULL, arp_failure_discard);
651
Steve Wisecfdda9d2010-04-21 15:30:06 -0700652 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
653}
654
Hariprasad S4a740832016-06-10 01:05:15 +0530655static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700656{
Varun Prakasha7e1a972016-09-13 21:24:04 +0530657 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530658 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700659
660 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530661 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700662 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530663
Varun Prakasha7e1a972016-09-13 21:24:04 +0530664 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
665 ep, abort_arp_failure);
666
Hariprasad S4a740832016-06-10 01:05:15 +0530667 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668}
669
670static int send_connect(struct c4iw_ep *ep)
671{
Hariprasad S963cab52015-09-23 17:19:27 +0530672 struct cpl_act_open_req *req = NULL;
673 struct cpl_t5_act_open_req *t5req = NULL;
674 struct cpl_t6_act_open_req *t6req = NULL;
675 struct cpl_act_open_req6 *req6 = NULL;
676 struct cpl_t5_act_open_req6 *t5req6 = NULL;
677 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700678 struct sk_buff *skb;
679 u64 opt0;
680 u32 opt2;
681 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530682 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530683 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500684 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600685 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500686 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600687 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500688 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600689 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500690 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600691 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530692 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530693 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
694 u32 isn = (prandom_u32() & ~7UL) - 1;
695
696 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
697 case CHELSIO_T4:
698 sizev4 = sizeof(struct cpl_act_open_req);
699 sizev6 = sizeof(struct cpl_act_open_req6);
700 break;
701 case CHELSIO_T5:
702 sizev4 = sizeof(struct cpl_t5_act_open_req);
703 sizev6 = sizeof(struct cpl_t5_act_open_req6);
704 break;
705 case CHELSIO_T6:
706 sizev4 = sizeof(struct cpl_t6_act_open_req);
707 sizev6 = sizeof(struct cpl_t6_act_open_req6);
708 break;
709 default:
710 pr_err("T%d Chip is not supported\n",
711 CHELSIO_CHIP_VERSION(adapter_type));
712 return -EINVAL;
713 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530714
715 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
716 roundup(sizev4, 16) :
717 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700718
719 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
720
721 skb = get_skb(NULL, wrlen, GFP_KERNEL);
722 if (!skb) {
723 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
724 __func__);
725 return -ENOMEM;
726 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000727 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700728
Varun Prakash44c6d062016-09-13 21:24:00 +0530729 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
730 enable_tcp_timestamps,
731 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530732 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530733
734 /*
735 * Specify the largest window that will fit in opt0. The
736 * remainder will be specified in the rx_data_ack.
737 */
738 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800739 if (win > RCV_BUFSIZ_M)
740 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530741
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800742 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800743 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800744 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800745 WND_SCALE_V(wscale) |
746 MSS_IDX_V(mtu_idx) |
747 L2T_IDX_V(ep->l2t->idx) |
748 TX_CHAN_V(ep->tx_chan) |
749 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530750 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800751 ULP_MODE_V(ULP_MODE_TCPDDP) |
752 RCV_BUFSIZ_V(win);
753 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800754 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800755 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800757 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700758 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800759 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700760 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800761 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530762 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
763 if (peer2peer)
764 isn += 4;
765
Anish Bhattd7990b02014-11-12 17:15:57 -0800766 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530767 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530768 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500769 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530770
771 if (ep->com.remote_addr.ss_family == AF_INET6)
772 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
773 (const u32 *)&la6->sin6_addr.s6_addr, 1);
774
Hariprasad S5dab6d32014-06-23 19:12:36 +0530775 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700776
Hariprasad S963cab52015-09-23 17:19:27 +0530777 if (ep->com.remote_addr.ss_family == AF_INET) {
778 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
779 case CHELSIO_T4:
780 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530781 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530782 break;
783 case CHELSIO_T5:
784 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
785 wrlen);
786 INIT_TP_WR(t5req, 0);
787 req = (struct cpl_act_open_req *)t5req;
788 break;
789 case CHELSIO_T6:
790 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
791 wrlen);
792 INIT_TP_WR(t6req, 0);
793 req = (struct cpl_act_open_req *)t6req;
794 t5req = (struct cpl_t5_act_open_req *)t6req;
795 break;
796 default:
797 pr_err("T%d Chip is not supported\n",
798 CHELSIO_CHIP_VERSION(adapter_type));
799 ret = -EINVAL;
800 goto clip_release;
801 }
802
803 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
804 ((ep->rss_qid<<14) | ep->atid)));
805 req->local_port = la->sin_port;
806 req->peer_port = ra->sin_port;
807 req->local_ip = la->sin_addr.s_addr;
808 req->peer_ip = ra->sin_addr.s_addr;
809 req->opt0 = cpu_to_be64(opt0);
810
811 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530812 req->params = cpu_to_be32(cxgb4_select_ntuple(
813 ep->com.dev->rdev.lldi.ports[0],
814 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530815 req->opt2 = cpu_to_be32(opt2);
816 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530817 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
818 cxgb4_select_ntuple(
819 ep->com.dev->rdev.lldi.ports[0],
820 ep->l2t)));
821 t5req->rsvd = cpu_to_be32(isn);
822 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
823 t5req->opt2 = cpu_to_be32(opt2);
824 }
825 } else {
826 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
827 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530828 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530829 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530830 break;
831 case CHELSIO_T5:
832 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
833 wrlen);
834 INIT_TP_WR(t5req6, 0);
835 req6 = (struct cpl_act_open_req6 *)t5req6;
836 break;
837 case CHELSIO_T6:
838 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
839 wrlen);
840 INIT_TP_WR(t6req6, 0);
841 req6 = (struct cpl_act_open_req6 *)t6req6;
842 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
843 break;
844 default:
845 pr_err("T%d Chip is not supported\n",
846 CHELSIO_CHIP_VERSION(adapter_type));
847 ret = -EINVAL;
848 goto clip_release;
849 }
850
851 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
852 ((ep->rss_qid<<14)|ep->atid)));
853 req6->local_port = la6->sin6_port;
854 req6->peer_port = ra6->sin6_port;
855 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
856 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
857 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
858 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
859 req6->opt0 = cpu_to_be64(opt0);
860
861 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530862 req6->params = cpu_to_be32(cxgb4_select_ntuple(
863 ep->com.dev->rdev.lldi.ports[0],
864 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530865 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530866 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530867 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
868 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530869 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530870 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530871 t5req6->rsvd = cpu_to_be32(isn);
872 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
873 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530874 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000875 }
876
Vipul Pandya793dad92012-12-10 09:30:56 +0000877 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530878 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530879clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530880 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
881 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
882 (const u32 *)&la6->sin6_addr.s6_addr, 1);
883 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700884}
885
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530886static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
887 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530889 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700890 struct fw_ofld_tx_data_wr *req;
891 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530892 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700893
894 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
895
896 BUG_ON(skb_cloned(skb));
897
898 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530899 if (mpa_rev_to_use == 2)
900 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700901 wrlen = roundup(mpalen + sizeof *req, 16);
902 skb = get_skb(skb, wrlen, GFP_KERNEL);
903 if (!skb) {
904 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530905 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700906 }
907 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
908
909 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
910 memset(req, 0, wrlen);
911 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530912 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
913 FW_WR_COMPL_F |
914 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700915 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530916 FW_WR_FLOWID_V(ep->hwtid) |
917 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700918 req->plen = cpu_to_be32(mpalen);
919 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530920 FW_OFLD_TX_DATA_WR_FLUSH_F |
921 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700922
923 mpa = (struct mpa_message *)(req + 1);
924 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530925
926 mpa->flags = 0;
927 if (crc_enabled)
928 mpa->flags |= MPA_CRC;
929 if (markers_enabled) {
930 mpa->flags |= MPA_MARKERS;
931 ep->mpa_attr.recv_marker_enabled = 1;
932 } else {
933 ep->mpa_attr.recv_marker_enabled = 0;
934 }
935 if (mpa_rev_to_use == 2)
936 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
937
Steve Wisecfdda9d2010-04-21 15:30:06 -0700938 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530939 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530940 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530941 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530942 ep->retry_with_mpa_v1 = 0;
943 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700944
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530945 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700946 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
947 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530948 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
949 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530950 mpa_v2_params.ird = htons((u16)ep->ird);
951 mpa_v2_params.ord = htons((u16)ep->ord);
952
953 if (peer2peer) {
954 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
955 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
956 mpa_v2_params.ord |=
957 htons(MPA_V2_RDMA_WRITE_RTR);
958 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
959 mpa_v2_params.ord |=
960 htons(MPA_V2_RDMA_READ_RTR);
961 }
962 memcpy(mpa->private_data, &mpa_v2_params,
963 sizeof(struct mpa_v2_conn_params));
964
965 if (ep->plen)
966 memcpy(mpa->private_data +
967 sizeof(struct mpa_v2_conn_params),
968 ep->mpa_pkt + sizeof(*mpa), ep->plen);
969 } else
970 if (ep->plen)
971 memcpy(mpa->private_data,
972 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700973
974 /*
975 * Reference the mpa skb. This ensures the data area
976 * will remain in memory until the hw acks the tx.
977 * Function fw4_ack() will deref it.
978 */
979 skb_get(skb);
980 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
981 BUG_ON(ep->mpa_skb);
982 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530983 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
984 if (ret)
985 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700986 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530987 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700988 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530989 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530990 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700991}
992
993static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
994{
995 int mpalen, wrlen;
996 struct fw_ofld_tx_data_wr *req;
997 struct mpa_message *mpa;
998 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530999 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001000
1001 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1002
1003 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301004 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1005 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001006 wrlen = roundup(mpalen + sizeof *req, 16);
1007
1008 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1009 if (!skb) {
1010 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1011 return -ENOMEM;
1012 }
1013 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1014
1015 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1016 memset(req, 0, wrlen);
1017 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301018 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1019 FW_WR_COMPL_F |
1020 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001021 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301022 FW_WR_FLOWID_V(ep->hwtid) |
1023 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024 req->plen = cpu_to_be32(mpalen);
1025 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301026 FW_OFLD_TX_DATA_WR_FLUSH_F |
1027 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001028
1029 mpa = (struct mpa_message *)(req + 1);
1030 memset(mpa, 0, sizeof(*mpa));
1031 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1032 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001033 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001034 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301035
1036 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1037 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001038 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1039 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301040 mpa_v2_params.ird = htons(((u16)ep->ird) |
1041 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1042 0));
1043 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1044 (p2p_type ==
1045 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1046 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1047 FW_RI_INIT_P2PTYPE_READ_REQ ?
1048 MPA_V2_RDMA_READ_RTR : 0) : 0));
1049 memcpy(mpa->private_data, &mpa_v2_params,
1050 sizeof(struct mpa_v2_conn_params));
1051
1052 if (ep->plen)
1053 memcpy(mpa->private_data +
1054 sizeof(struct mpa_v2_conn_params), pdata, plen);
1055 } else
1056 if (plen)
1057 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001058
1059 /*
1060 * Reference the mpa skb again. This ensures the data area
1061 * will remain in memory until the hw acks the tx.
1062 * Function fw4_ack() will deref it.
1063 */
1064 skb_get(skb);
1065 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301066 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067 BUG_ON(ep->mpa_skb);
1068 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301069 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1071}
1072
1073static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1074{
1075 int mpalen, wrlen;
1076 struct fw_ofld_tx_data_wr *req;
1077 struct mpa_message *mpa;
1078 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301079 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080
1081 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1082
1083 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301084 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1085 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001086 wrlen = roundup(mpalen + sizeof *req, 16);
1087
1088 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1089 if (!skb) {
1090 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1091 return -ENOMEM;
1092 }
1093 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1094
1095 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1096 memset(req, 0, wrlen);
1097 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301098 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1099 FW_WR_COMPL_F |
1100 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001101 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301102 FW_WR_FLOWID_V(ep->hwtid) |
1103 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 req->plen = cpu_to_be32(mpalen);
1105 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301106 FW_OFLD_TX_DATA_WR_FLUSH_F |
1107 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001108
1109 mpa = (struct mpa_message *)(req + 1);
1110 memset(mpa, 0, sizeof(*mpa));
1111 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301112 mpa->flags = 0;
1113 if (ep->mpa_attr.crc_enabled)
1114 mpa->flags |= MPA_CRC;
1115 if (ep->mpa_attr.recv_marker_enabled)
1116 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301117 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001118 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301119
1120 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1121 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001122 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1123 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301124 mpa_v2_params.ird = htons((u16)ep->ird);
1125 mpa_v2_params.ord = htons((u16)ep->ord);
1126 if (peer2peer && (ep->mpa_attr.p2p_type !=
1127 FW_RI_INIT_P2PTYPE_DISABLED)) {
1128 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1129
1130 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1131 mpa_v2_params.ord |=
1132 htons(MPA_V2_RDMA_WRITE_RTR);
1133 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1134 mpa_v2_params.ord |=
1135 htons(MPA_V2_RDMA_READ_RTR);
1136 }
1137
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. 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);
Hariprasad S64bec742016-05-06 22:18:10 +05301154 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301156 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301157 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1159}
1160
1161static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1162{
1163 struct c4iw_ep *ep;
1164 struct cpl_act_establish *req = cplhdr(skb);
1165 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001166 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001167 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301168 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169
1170 ep = lookup_atid(t, atid);
1171
1172 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1173 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1174
Steve Wisea7db89e2014-03-21 20:40:35 +05301175 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001176 dst_confirm(ep->dst);
1177
1178 /* setup the hwtid for this connection */
1179 ep->hwtid = tid;
1180 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301181 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182
1183 ep->snd_seq = be32_to_cpu(req->snd_isn);
1184 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1185
1186 set_emss(ep, ntohs(req->tcp_opt));
1187
1188 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001189 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001190 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001191 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001192
1193 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301194 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301195 if (ret)
1196 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301197 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301198 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301199 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301200 ret = send_mpa_req(ep, skb, mpa_rev);
1201 if (ret)
1202 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301203 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001204 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301205err:
1206 mutex_unlock(&ep->com.mutex);
1207 connect_reply_upcall(ep, -ENOMEM);
1208 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1209 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001210}
1211
Steve Wisebe13b2d2014-03-21 20:40:33 +05301212static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001213{
1214 struct iw_cm_event event;
1215
1216 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1217 memset(&event, 0, sizeof(event));
1218 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301219 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001220 if (ep->com.cm_id) {
1221 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1222 ep, ep->com.cm_id, ep->hwtid);
1223 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301224 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001225 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001226 }
1227}
1228
Steve Wisecfdda9d2010-04-21 15:30:06 -07001229static void peer_close_upcall(struct c4iw_ep *ep)
1230{
1231 struct iw_cm_event event;
1232
1233 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1234 memset(&event, 0, sizeof(event));
1235 event.event = IW_CM_EVENT_DISCONNECT;
1236 if (ep->com.cm_id) {
1237 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1238 ep, ep->com.cm_id, ep->hwtid);
1239 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001240 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001241 }
1242}
1243
1244static void peer_abort_upcall(struct c4iw_ep *ep)
1245{
1246 struct iw_cm_event event;
1247
1248 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1249 memset(&event, 0, sizeof(event));
1250 event.event = IW_CM_EVENT_CLOSE;
1251 event.status = -ECONNRESET;
1252 if (ep->com.cm_id) {
1253 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1254 ep->com.cm_id, ep->hwtid);
1255 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301256 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001257 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001258 }
1259}
1260
1261static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1262{
1263 struct iw_cm_event event;
1264
1265 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1266 memset(&event, 0, sizeof(event));
1267 event.event = IW_CM_EVENT_CONNECT_REPLY;
1268 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301269 memcpy(&event.local_addr, &ep->com.local_addr,
1270 sizeof(ep->com.local_addr));
1271 memcpy(&event.remote_addr, &ep->com.remote_addr,
1272 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001273
1274 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301275 if (!ep->tried_with_mpa_v1) {
1276 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301277 event.ord = ep->ird;
1278 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301279 event.private_data_len = ep->plen -
1280 sizeof(struct mpa_v2_conn_params);
1281 event.private_data = ep->mpa_pkt +
1282 sizeof(struct mpa_message) +
1283 sizeof(struct mpa_v2_conn_params);
1284 } else {
1285 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301286 event.ord = cur_max_read_depth(ep->com.dev);
1287 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301288 event.private_data_len = ep->plen;
1289 event.private_data = ep->mpa_pkt +
1290 sizeof(struct mpa_message);
1291 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001292 }
Roland Dreier85963e42010-07-19 13:13:09 -07001293
1294 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1295 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001296 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001297 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1298
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301299 if (status < 0)
1300 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001301}
1302
Steve Wisebe13b2d2014-03-21 20:40:33 +05301303static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304{
1305 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301306 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001307
1308 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1309 memset(&event, 0, sizeof(event));
1310 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301311 memcpy(&event.local_addr, &ep->com.local_addr,
1312 sizeof(ep->com.local_addr));
1313 memcpy(&event.remote_addr, &ep->com.remote_addr,
1314 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301316 if (!ep->tried_with_mpa_v1) {
1317 /* this means MPA_v2 is used */
1318 event.ord = ep->ord;
1319 event.ird = ep->ird;
1320 event.private_data_len = ep->plen -
1321 sizeof(struct mpa_v2_conn_params);
1322 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1323 sizeof(struct mpa_v2_conn_params);
1324 } else {
1325 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301326 event.ord = cur_max_read_depth(ep->com.dev);
1327 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301328 event.private_data_len = ep->plen;
1329 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1330 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301331 c4iw_get_ep(&ep->com);
1332 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1333 &event);
1334 if (ret)
1335 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001336 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301338 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001339}
1340
1341static void established_upcall(struct c4iw_ep *ep)
1342{
1343 struct iw_cm_event event;
1344
1345 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1346 memset(&event, 0, sizeof(event));
1347 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301348 event.ird = ep->ord;
1349 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001350 if (ep->com.cm_id) {
1351 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1352 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001353 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001354 }
1355}
1356
1357static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1358{
Steve Wisecfdda9d2010-04-21 15:30:06 -07001359 struct sk_buff *skb;
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301360 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1361 u32 credit_dack;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362
1363 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1364 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1365 if (!skb) {
1366 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1367 return 0;
1368 }
1369
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301370 /*
1371 * If we couldn't specify the entire rcv window at connection setup
1372 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1373 * then add the overage in to the credits returned.
1374 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001375 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1376 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301377
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301378 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1379 RX_DACK_MODE_V(dack_mode);
1380
1381 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1382 credit_dack);
1383
Steve Wisecfdda9d2010-04-21 15:30:06 -07001384 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1385 return credits;
1386}
1387
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301388#define RELAXED_IRD_NEGOTIATION 1
1389
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301390/*
1391 * process_mpa_reply - process streaming mode MPA reply
1392 *
1393 * Returns:
1394 *
1395 * 0 upon success indicating a connect request was delivered to the ULP
1396 * or the mpa request is incomplete but valid so far.
1397 *
1398 * 1 if a failure requires the caller to close the connection.
1399 *
1400 * 2 if a failure requires the caller to abort the connection.
1401 */
Steve Wisecc18b932014-04-24 14:31:53 -05001402static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403{
1404 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301405 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001406 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301407 u16 resp_ird, resp_ord;
1408 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 struct c4iw_qp_attributes attrs;
1410 enum c4iw_qp_attr_mask mask;
1411 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001412 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001413
1414 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1415
1416 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001417 * If we get more than the supported amount of private data
1418 * then we must fail this connection.
1419 */
1420 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1421 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301422 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001423 }
1424
1425 /*
1426 * copy the new data into our accumulation buffer.
1427 */
1428 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1429 skb->len);
1430 ep->mpa_pkt_len += skb->len;
1431
1432 /*
1433 * if we don't even have the mpa message, then bail.
1434 */
1435 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001436 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437 mpa = (struct mpa_message *) ep->mpa_pkt;
1438
1439 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301440 if (mpa->revision > mpa_rev) {
1441 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1442 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001443 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301444 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001445 }
1446 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1447 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301448 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001449 }
1450
1451 plen = ntohs(mpa->private_data_size);
1452
1453 /*
1454 * Fail if there's too much private data.
1455 */
1456 if (plen > MPA_MAX_PRIVATE_DATA) {
1457 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301458 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459 }
1460
1461 /*
1462 * If plen does not account for pkt size
1463 */
1464 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1465 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301466 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467 }
1468
1469 ep->plen = (u8) plen;
1470
1471 /*
1472 * If we don't have all the pdata yet, then bail.
1473 * We'll continue process when more data arrives.
1474 */
1475 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001476 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477
1478 if (mpa->flags & MPA_REJECT) {
1479 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301480 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001481 }
1482
1483 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301484 * Stop mpa timer. If it expired, then
1485 * we ignore the MPA reply. process_timeout()
1486 * will abort the connection.
1487 */
1488 if (stop_ep_timer(ep))
1489 return 0;
1490
1491 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001492 * If we get here we have accumulated the entire mpa
1493 * start reply message including private data. And
1494 * the MPA header is valid.
1495 */
Steve Wisec529fb52014-03-21 20:40:37 +05301496 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001497 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001498 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301499 ep->mpa_attr.version = mpa->revision;
1500 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1501
1502 if (mpa->revision == 2) {
1503 ep->mpa_attr.enhanced_rdma_conn =
1504 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1505 if (ep->mpa_attr.enhanced_rdma_conn) {
1506 mpa_v2_params = (struct mpa_v2_conn_params *)
1507 (ep->mpa_pkt + sizeof(*mpa));
1508 resp_ird = ntohs(mpa_v2_params->ird) &
1509 MPA_V2_IRD_ORD_MASK;
1510 resp_ord = ntohs(mpa_v2_params->ord) &
1511 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301512 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1513 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301514
1515 /*
1516 * This is a double-check. Ideally, below checks are
1517 * not required since ird/ord stuff has been taken
1518 * care of in c4iw_accept_cr
1519 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301520 if (ep->ird < resp_ord) {
1521 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1522 ep->com.dev->rdev.lldi.max_ordird_qp)
1523 ep->ird = resp_ord;
1524 else
1525 insuff_ird = 1;
1526 } else if (ep->ird > resp_ord) {
1527 ep->ird = resp_ord;
1528 }
1529 if (ep->ord > resp_ird) {
1530 if (RELAXED_IRD_NEGOTIATION)
1531 ep->ord = resp_ird;
1532 else
1533 insuff_ird = 1;
1534 }
1535 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301536 err = -ENOMEM;
1537 ep->ird = resp_ord;
1538 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301539 }
1540
1541 if (ntohs(mpa_v2_params->ird) &
1542 MPA_V2_PEER2PEER_MODEL) {
1543 if (ntohs(mpa_v2_params->ord) &
1544 MPA_V2_RDMA_WRITE_RTR)
1545 ep->mpa_attr.p2p_type =
1546 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1547 else if (ntohs(mpa_v2_params->ord) &
1548 MPA_V2_RDMA_READ_RTR)
1549 ep->mpa_attr.p2p_type =
1550 FW_RI_INIT_P2PTYPE_READ_REQ;
1551 }
1552 }
1553 } else if (mpa->revision == 1)
1554 if (peer2peer)
1555 ep->mpa_attr.p2p_type = p2p_type;
1556
Steve Wisecfdda9d2010-04-21 15:30:06 -07001557 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301558 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1559 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1560 ep->mpa_attr.recv_marker_enabled,
1561 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1562 ep->mpa_attr.p2p_type, p2p_type);
1563
1564 /*
1565 * If responder's RTR does not match with that of initiator, assign
1566 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1567 * generated when moving QP to RTS state.
1568 * A TERM message will be sent after QP has moved to RTS state
1569 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001570 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301571 (ep->mpa_attr.p2p_type != p2p_type)) {
1572 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1573 rtr_mismatch = 1;
1574 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001575
1576 attrs.mpa_attr = ep->mpa_attr;
1577 attrs.max_ird = ep->ird;
1578 attrs.max_ord = ep->ord;
1579 attrs.llp_stream_handle = ep;
1580 attrs.next_state = C4IW_QP_STATE_RTS;
1581
1582 mask = C4IW_QP_ATTR_NEXT_STATE |
1583 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1584 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1585
1586 /* bind QP and TID with INIT_WR */
1587 err = c4iw_modify_qp(ep->com.qp->rhp,
1588 ep->com.qp, mask, &attrs, 1);
1589 if (err)
1590 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301591
1592 /*
1593 * If responder's RTR requirement did not match with what initiator
1594 * supports, generate TERM message
1595 */
1596 if (rtr_mismatch) {
1597 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1598 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1599 attrs.ecode = MPA_NOMATCH_RTR;
1600 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001601 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301602 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001603 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301604 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001605 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301606 goto out;
1607 }
1608
1609 /*
1610 * Generate TERM if initiator IRD is not sufficient for responder
1611 * provided ORD. Currently, we do the same behaviour even when
1612 * responder provided IRD is also not sufficient as regards to
1613 * initiator ORD.
1614 */
1615 if (insuff_ird) {
1616 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1617 __func__);
1618 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1619 attrs.ecode = MPA_INSUFF_IRD;
1620 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001621 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301622 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001623 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301624 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001625 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301626 goto out;
1627 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001628 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301629err_stop_timer:
1630 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001631err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301632 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001633out:
1634 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001635 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001636}
1637
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301638/*
1639 * process_mpa_request - process streaming mode MPA request
1640 *
1641 * Returns:
1642 *
1643 * 0 upon success indicating a connect request was delivered to the ULP
1644 * or the mpa request is incomplete but valid so far.
1645 *
1646 * 1 if a failure requires the caller to close the connection.
1647 *
1648 * 2 if a failure requires the caller to abort the connection.
1649 */
1650static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001651{
1652 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301653 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001654 u16 plen;
1655
1656 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1657
Steve Wisecfdda9d2010-04-21 15:30:06 -07001658 /*
1659 * If we get more than the supported amount of private data
1660 * then we must fail this connection.
1661 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301662 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1663 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664
1665 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1666
1667 /*
1668 * Copy the new data into our accumulation buffer.
1669 */
1670 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1671 skb->len);
1672 ep->mpa_pkt_len += skb->len;
1673
1674 /*
1675 * If we don't even have the mpa message, then bail.
1676 * We'll continue process when more data arrives.
1677 */
1678 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301679 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001680
1681 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682 mpa = (struct mpa_message *) ep->mpa_pkt;
1683
1684 /*
1685 * Validate MPA Header.
1686 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301687 if (mpa->revision > mpa_rev) {
1688 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1689 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301690 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691 }
1692
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301693 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1694 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001695
1696 plen = ntohs(mpa->private_data_size);
1697
1698 /*
1699 * Fail if there's too much private data.
1700 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301701 if (plen > MPA_MAX_PRIVATE_DATA)
1702 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001703
1704 /*
1705 * If plen does not account for pkt size
1706 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301707 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1708 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709 ep->plen = (u8) plen;
1710
1711 /*
1712 * If we don't have all the pdata yet, then bail.
1713 */
1714 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301715 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716
1717 /*
1718 * If we get here we have accumulated the entire mpa
1719 * start reply message including private data.
1720 */
1721 ep->mpa_attr.initiator = 0;
1722 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1723 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1724 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301725 ep->mpa_attr.version = mpa->revision;
1726 if (mpa->revision == 1)
1727 ep->tried_with_mpa_v1 = 1;
1728 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1729
1730 if (mpa->revision == 2) {
1731 ep->mpa_attr.enhanced_rdma_conn =
1732 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1733 if (ep->mpa_attr.enhanced_rdma_conn) {
1734 mpa_v2_params = (struct mpa_v2_conn_params *)
1735 (ep->mpa_pkt + sizeof(*mpa));
1736 ep->ird = ntohs(mpa_v2_params->ird) &
1737 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001738 ep->ird = min_t(u32, ep->ird,
1739 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301740 ep->ord = ntohs(mpa_v2_params->ord) &
1741 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001742 ep->ord = min_t(u32, ep->ord,
1743 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301744 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1745 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301746 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1747 if (peer2peer) {
1748 if (ntohs(mpa_v2_params->ord) &
1749 MPA_V2_RDMA_WRITE_RTR)
1750 ep->mpa_attr.p2p_type =
1751 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1752 else if (ntohs(mpa_v2_params->ord) &
1753 MPA_V2_RDMA_READ_RTR)
1754 ep->mpa_attr.p2p_type =
1755 FW_RI_INIT_P2PTYPE_READ_REQ;
1756 }
1757 }
1758 } else if (mpa->revision == 1)
1759 if (peer2peer)
1760 ep->mpa_attr.p2p_type = p2p_type;
1761
Steve Wisecfdda9d2010-04-21 15:30:06 -07001762 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1763 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1764 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1765 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1766 ep->mpa_attr.p2p_type);
1767
Hariprasad Se4b76a22016-05-06 22:17:59 +05301768 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001769
Hariprasad Se4b76a22016-05-06 22:17:59 +05301770 /* drive upcall */
1771 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1772 if (ep->parent_ep->com.state != DEAD) {
1773 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301774 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301775 } else {
1776 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301777 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301778 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301779 return 0;
1780
1781err_unlock_parent:
1782 mutex_unlock(&ep->parent_ep->com.mutex);
1783 goto err_out;
1784err_stop_timer:
1785 (void)stop_ep_timer(ep);
1786err_out:
1787 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788}
1789
1790static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1791{
1792 struct c4iw_ep *ep;
1793 struct cpl_rx_data *hdr = cplhdr(skb);
1794 unsigned int dlen = ntohs(hdr->len);
1795 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001796 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001797 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001798
Hariprasad S944661d2016-05-06 22:18:03 +05301799 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301800 if (!ep)
1801 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1803 skb_pull(skb, sizeof(*hdr));
1804 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301805 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001806
Steve Wisec529fb52014-03-21 20:40:37 +05301807 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001808 case MPA_REQ_SENT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001809 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001810 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001811 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812 break;
1813 case MPA_REQ_WAIT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001814 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001815 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301816 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001818 case FPDU_MODE: {
1819 struct c4iw_qp_attributes attrs;
Steve Wise3bcf96e2016-12-22 07:40:37 -08001820
1821 update_rx_credits(ep, dlen);
Vipul Pandya15579672013-01-07 13:11:52 +00001822 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001823 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001824 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001825 " qpid %u ep %p state %d tid %u status %d\n",
1826 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301827 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301828 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001829 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001830 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1831 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001832 break;
1833 }
Vipul Pandya15579672013-01-07 13:11:52 +00001834 default:
1835 break;
1836 }
Steve Wisec529fb52014-03-21 20:40:37 +05301837 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001838 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301839 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301840 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001841 return 0;
1842}
1843
1844static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1845{
1846 struct c4iw_ep *ep;
1847 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001848 int release = 0;
1849 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001850
Hariprasad S944661d2016-05-06 22:18:03 +05301851 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301852 if (!ep) {
1853 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1854 return 0;
1855 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001856 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001857 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858 switch (ep->com.state) {
1859 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001860 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001861 __state_set(&ep->com, DEAD);
1862 release = 1;
1863 break;
1864 default:
1865 printk(KERN_ERR "%s ep %p state %d\n",
1866 __func__, ep, ep->com.state);
1867 break;
1868 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001869 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001870
1871 if (release)
1872 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301873 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001874 return 0;
1875}
1876
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301877static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001878{
1879 struct sk_buff *skb;
1880 struct fw_ofld_connection_wr *req;
1881 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301882 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301883 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301884 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001885
1886 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1887 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1888 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001889 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301890 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301891 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1892 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001893 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001894 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301895 req->le.lport = sin->sin_port;
1896 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001897 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301898 req->le.pport = sin->sin_port;
1899 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301901 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1902 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001903 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301904 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001905 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001906 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301907 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1908 enable_tcp_timestamps,
1909 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301910 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301911
1912 /*
1913 * Specify the largest window that will fit in opt0. The
1914 * remainder will be specified in the rx_data_ack.
1915 */
1916 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001917 if (win > RCV_BUFSIZ_M)
1918 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301919
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001920 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1921 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001922 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001923 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001924 WND_SCALE_V(wscale) |
1925 MSS_IDX_V(mtu_idx) |
1926 L2T_IDX_V(ep->l2t->idx) |
1927 TX_CHAN_V(ep->tx_chan) |
1928 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301929 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001930 ULP_MODE_V(ULP_MODE_TCPDDP) |
1931 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001932 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1933 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001934 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001935 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001936 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001937 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001938 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001939 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001940 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001941 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001942 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1943 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1944 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001945 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1946 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301947 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001948}
1949
Steve Wisecfdda9d2010-04-21 15:30:06 -07001950/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301951 * Some of the error codes above implicitly indicate that there is no TID
1952 * allocated with the result of an ACT_OPEN. We use this predicate to make
1953 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001954 */
1955static inline int act_open_has_tid(int status)
1956{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301957 return (status != CPL_ERR_TCAM_PARITY &&
1958 status != CPL_ERR_TCAM_MISS &&
1959 status != CPL_ERR_TCAM_FULL &&
1960 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1961 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962}
1963
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301964static char *neg_adv_str(unsigned int status)
1965{
1966 switch (status) {
1967 case CPL_ERR_RTX_NEG_ADVICE:
1968 return "Retransmit timeout";
1969 case CPL_ERR_PERSIST_NEG_ADVICE:
1970 return "Persist timeout";
1971 case CPL_ERR_KEEPALV_NEG_ADVICE:
1972 return "Keepalive timeout";
1973 default:
1974 return "Unknown";
1975 }
1976}
1977
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301978static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1979{
1980 ep->snd_win = snd_win;
1981 ep->rcv_win = rcv_win;
1982 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1983}
1984
Vipul Pandya793dad92012-12-10 09:30:56 +00001985#define ACT_OPEN_RETRY_COUNT 2
1986
Vipul Pandya830662f2013-07-04 16:10:47 +05301987static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1988 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301989 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301990{
1991 struct neighbour *n;
1992 int err, step;
1993 struct net_device *pdev;
1994
1995 n = dst_neigh_lookup(dst, peer_ip);
1996 if (!n)
1997 return -ENODEV;
1998
1999 rcu_read_lock();
2000 err = -ENOMEM;
2001 if (n->dev->flags & IFF_LOOPBACK) {
2002 if (iptype == 4)
2003 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2004 else if (IS_ENABLED(CONFIG_IPV6))
2005 for_each_netdev(&init_net, pdev) {
2006 if (ipv6_chk_addr(&init_net,
2007 (struct in6_addr *)peer_ip,
2008 pdev, 1))
2009 break;
2010 }
2011 else
2012 pdev = NULL;
2013
2014 if (!pdev) {
2015 err = -ENODEV;
2016 goto out;
2017 }
2018 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302019 n, pdev, rt_tos2priority(tos));
Steve Wise609e9412016-09-01 06:43:46 -07002020 if (!ep->l2t) {
2021 dev_put(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302022 goto out;
Steve Wise609e9412016-09-01 06:43:46 -07002023 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302024 ep->mtu = pdev->mtu;
2025 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302026 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2027 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302028 step = cdev->rdev.lldi.ntxq /
2029 cdev->rdev.lldi.nchan;
2030 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2031 step = cdev->rdev.lldi.nrxq /
2032 cdev->rdev.lldi.nchan;
2033 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2034 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2035 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302036 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302037 dev_put(pdev);
2038 } else {
2039 pdev = get_real_dev(n->dev);
2040 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2041 n, pdev, 0);
2042 if (!ep->l2t)
2043 goto out;
2044 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002045 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302046 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2047 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302048 step = cdev->rdev.lldi.ntxq /
2049 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002050 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2051 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302052 step = cdev->rdev.lldi.nrxq /
2053 cdev->rdev.lldi.nchan;
2054 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002055 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302056 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302057
2058 if (clear_mpa_v1) {
2059 ep->retry_with_mpa_v1 = 0;
2060 ep->tried_with_mpa_v1 = 0;
2061 }
2062 }
2063 err = 0;
2064out:
2065 rcu_read_unlock();
2066
2067 neigh_release(n);
2068
2069 return err;
2070}
2071
Vipul Pandya793dad92012-12-10 09:30:56 +00002072static int c4iw_reconnect(struct c4iw_ep *ep)
2073{
2074 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302075 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302076 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002077 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302078 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002079 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302080 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002081 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302082 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002083 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302084 int iptype;
2085 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002086
2087 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2088 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302089 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002090
Hariprasad S4a740832016-06-10 01:05:15 +05302091 /* When MPA revision is different on nodes, the node with MPA_rev=2
2092 * tries to reconnect with MPA_rev 1 for the same EP through
2093 * c4iw_reconnect(), where the same EP is assigned with new tid for
2094 * further connection establishment. As we are using the same EP pointer
2095 * for reconnect, few skbs are used during the previous c4iw_connect(),
2096 * which leaves the EP with inadequate skbs for further
2097 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2098 * skb_list() during peer_abort(). Allocate skbs which is already used.
2099 */
2100 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2101 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2102 err = -ENOMEM;
2103 goto fail1;
2104 }
2105
Vipul Pandya793dad92012-12-10 09:30:56 +00002106 /*
2107 * Allocate an active TID to initiate a TCP connection.
2108 */
2109 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2110 if (ep->atid == -1) {
2111 pr_err("%s - cannot alloc atid.\n", __func__);
2112 err = -ENOMEM;
2113 goto fail2;
2114 }
2115 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2116
2117 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002118 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302119 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2120 laddr->sin_addr.s_addr,
2121 raddr->sin_addr.s_addr,
2122 laddr->sin_port,
2123 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302124 iptype = 4;
2125 ra = (__u8 *)&raddr->sin_addr;
2126 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302127 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2128 get_real_dev,
2129 laddr6->sin6_addr.s6_addr,
2130 raddr6->sin6_addr.s6_addr,
2131 laddr6->sin6_port,
2132 raddr6->sin6_port, 0,
2133 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302134 iptype = 6;
2135 ra = (__u8 *)&raddr6->sin6_addr;
2136 }
2137 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002138 pr_err("%s - cannot find route.\n", __func__);
2139 err = -EHOSTUNREACH;
2140 goto fail3;
2141 }
Hariprasad S963cab52015-09-23 17:19:27 +05302142 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302143 ep->com.dev->rdev.lldi.adapter_type,
2144 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302145 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002146 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002147 goto fail4;
2148 }
2149
2150 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2151 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2152 ep->l2t->idx);
2153
2154 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302155 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002156
2157 /* send connect request to rnic */
2158 err = send_connect(ep);
2159 if (!err)
2160 goto out;
2161
2162 cxgb4_l2t_release(ep->l2t);
2163fail4:
2164 dst_release(ep->dst);
2165fail3:
2166 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2167 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2168fail2:
2169 /*
2170 * remember to send notification to upper layer.
2171 * We are in here so the upper layer is not aware that this is
2172 * re-connect attempt and so, upper layer is still waiting for
2173 * response of 1st connect request.
2174 */
2175 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302176fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002177 c4iw_put_ep(&ep->com);
2178out:
2179 return err;
2180}
2181
Steve Wisecfdda9d2010-04-21 15:30:06 -07002182static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2183{
2184 struct c4iw_ep *ep;
2185 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002186 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2187 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002188 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002189 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302190 struct sockaddr_in *la;
2191 struct sockaddr_in *ra;
2192 struct sockaddr_in6 *la6;
2193 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302194 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002195
2196 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002197 la = (struct sockaddr_in *)&ep->com.local_addr;
2198 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2199 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2200 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002201
2202 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2203 status, status2errno(status));
2204
Varun Prakashb65eef02016-09-13 21:23:59 +05302205 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302206 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2207 __func__, atid, status, neg_adv_str(status));
2208 ep->stats.connect_neg_adv++;
2209 mutex_lock(&dev->rdev.stats.lock);
2210 dev->rdev.stats.neg_adv++;
2211 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002212 return 0;
2213 }
2214
Vipul Pandya793dad92012-12-10 09:30:56 +00002215 set_bit(ACT_OPEN_RPL, &ep->com.history);
2216
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302217 /*
2218 * Log interesting failures.
2219 */
2220 switch (status) {
2221 case CPL_ERR_CONN_RESET:
2222 case CPL_ERR_CONN_TIMEDOUT:
2223 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002224 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302225 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002226 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302227 mutex_unlock(&dev->rdev.stats.lock);
2228 if (ep->com.local_addr.ss_family == AF_INET &&
2229 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302230 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2231 ntohl(rpl->atid_status))));
2232 if (ret)
2233 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002234 return 0;
2235 }
2236 break;
2237 case CPL_ERR_CONN_EXIST:
2238 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2239 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302240 if (ep->com.remote_addr.ss_family == AF_INET6) {
2241 struct sockaddr_in6 *sin6 =
2242 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002243 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302244 cxgb4_clip_release(
2245 ep->com.dev->rdev.lldi.ports[0],
2246 (const u32 *)
2247 &sin6->sin6_addr.s6_addr, 1);
2248 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002249 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2250 atid);
2251 cxgb4_free_atid(t, atid);
2252 dst_release(ep->dst);
2253 cxgb4_l2t_release(ep->l2t);
2254 c4iw_reconnect(ep);
2255 return 0;
2256 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002257 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302258 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302259 if (ep->com.local_addr.ss_family == AF_INET) {
2260 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2261 atid, status, status2errno(status),
2262 &la->sin_addr.s_addr, ntohs(la->sin_port),
2263 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2264 } else {
2265 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2266 atid, status, status2errno(status),
2267 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2268 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2269 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302270 break;
2271 }
2272
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302273fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002274 connect_reply_upcall(ep, status2errno(status));
2275 state_set(&ep->com, DEAD);
2276
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302277 if (ep->com.remote_addr.ss_family == AF_INET6) {
2278 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002279 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302280 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2281 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2282 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002283 if (status && act_open_has_tid(status))
2284 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2285
Vipul Pandya793dad92012-12-10 09:30:56 +00002286 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002287 cxgb4_free_atid(t, atid);
2288 dst_release(ep->dst);
2289 cxgb4_l2t_release(ep->l2t);
2290 c4iw_put_ep(&ep->com);
2291
2292 return 0;
2293}
2294
2295static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2296{
2297 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002298 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302299 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002300
2301 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002302 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2303 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304 }
2305 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2306 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002307 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302308 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002309out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002310 return 0;
2311}
2312
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2314{
2315 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302317 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318
2319 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002320 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302321 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002322 return 0;
2323}
2324
Hariprasad S9dec9002016-05-05 01:27:29 +05302325static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2326 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327{
2328 struct cpl_pass_accept_rpl *rpl;
2329 unsigned int mtu_idx;
2330 u64 opt0;
2331 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302332 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302333 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302334 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302335 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336
2337 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2338 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302339
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302341 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302342 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302343 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2344 rpl5 = (void *)rpl;
2345 INIT_TP_WR(rpl5, ep->hwtid);
2346 } else {
2347 skb_trim(skb, sizeof(*rpl));
2348 INIT_TP_WR(rpl, ep->hwtid);
2349 }
2350 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2351 ep->hwtid));
2352
Varun Prakash44c6d062016-09-13 21:24:00 +05302353 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2354 enable_tcp_timestamps && req->tcpopt.tstamp,
2355 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302356 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302357
2358 /*
2359 * Specify the largest window that will fit in opt0. The
2360 * remainder will be specified in the rx_data_ack.
2361 */
2362 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002363 if (win > RCV_BUFSIZ_M)
2364 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002365 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002366 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002367 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002368 WND_SCALE_V(wscale) |
2369 MSS_IDX_V(mtu_idx) |
2370 L2T_IDX_V(ep->l2t->idx) |
2371 TX_CHAN_V(ep->tx_chan) |
2372 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002373 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002374 ULP_MODE_V(ULP_MODE_TCPDDP) |
2375 RCV_BUFSIZ_V(win);
2376 opt2 = RX_CHANNEL_V(0) |
2377 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378
2379 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002380 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002381 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002382 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002384 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002385 if (enable_ecn) {
2386 const struct tcphdr *tcph;
2387 u32 hlen = ntohl(req->hdr_len);
2388
Hariprasad S963cab52015-09-23 17:19:27 +05302389 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2390 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2391 IP_HDR_LEN_G(hlen);
2392 else
2393 tcph = (const void *)(req + 1) +
2394 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002395 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002396 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002397 }
Hariprasad S963cab52015-09-23 17:19:27 +05302398 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302399 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002400 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302401 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302402 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302403 rpl5 = (void *)rpl;
2404 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2405 if (peer2peer)
2406 isn += 4;
2407 rpl5->iss = cpu_to_be32(isn);
2408 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002409 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411 rpl->opt0 = cpu_to_be64(opt0);
2412 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002413 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302414 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415
Hariprasad S9dec9002016-05-05 01:27:29 +05302416 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002417}
2418
Vipul Pandya830662f2013-07-04 16:10:47 +05302419static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420{
Vipul Pandya830662f2013-07-04 16:10:47 +05302421 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002422 BUG_ON(skb_cloned(skb));
2423 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002424 release_tid(&dev->rdev, hwtid, skb);
2425 return;
2426}
2427
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2429{
Vipul Pandya793dad92012-12-10 09:30:56 +00002430 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002431 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002432 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433 struct tid_info *t = dev->rdev.lldi.tids;
2434 unsigned int hwtid = GET_TID(req);
2435 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302436 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302438 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002439 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002440 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302441 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302442 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302443 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002444
Hariprasad Sf86fac72016-05-06 22:18:07 +05302445 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002446 if (!parent_ep) {
2447 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2448 goto reject;
2449 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002450
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302452 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 goto reject;
2454 }
2455
Varun Prakash85e42b02016-09-13 21:23:56 +05302456 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2457 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302458
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302460 if (iptype == 4) {
2461 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2462 , __func__, parent_ep, hwtid,
2463 local_ip, peer_ip, ntohs(local_port),
2464 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302465 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2466 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2467 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302468 } else {
2469 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2470 , __func__, parent_ep, hwtid,
2471 local_ip, peer_ip, ntohs(local_port),
2472 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302473 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2474 local_ip, peer_ip, local_port, peer_port,
2475 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2476 ((struct sockaddr_in6 *)
2477 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302478 }
2479 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2481 __func__);
2482 goto reject;
2483 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484
2485 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2486 if (!child_ep) {
2487 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2488 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002489 dst_release(dst);
2490 goto reject;
2491 }
David Miller3786cf12011-12-02 16:52:31 +00002492
Hariprasad S963cab52015-09-23 17:19:27 +05302493 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302494 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002495 if (err) {
2496 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2497 __func__);
2498 dst_release(dst);
2499 kfree(child_ep);
2500 goto reject;
2501 }
2502
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302503 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2504 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2505 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2506 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002507
Hariprasad S4a740832016-06-10 01:05:15 +05302508 skb_queue_head_init(&child_ep->com.ep_skb_list);
2509 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2510 goto fail;
2511
Steve Wisecfdda9d2010-04-21 15:30:06 -07002512 state_set(&child_ep->com, CONNECTING);
2513 child_ep->com.dev = dev;
2514 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002515
Vipul Pandya830662f2013-07-04 16:10:47 +05302516 if (iptype == 4) {
2517 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002518 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002519
Vipul Pandya830662f2013-07-04 16:10:47 +05302520 sin->sin_family = PF_INET;
2521 sin->sin_port = local_port;
2522 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002523
2524 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2525 sin->sin_family = PF_INET;
2526 sin->sin_port = ((struct sockaddr_in *)
2527 &parent_ep->com.local_addr)->sin_port;
2528 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2529
Steve Wise170003c2016-02-26 09:18:03 -06002530 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302531 sin->sin_family = PF_INET;
2532 sin->sin_port = peer_port;
2533 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2534 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002535 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302536 sin6->sin6_family = PF_INET6;
2537 sin6->sin6_port = local_port;
2538 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002539
2540 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2541 sin6->sin6_family = PF_INET6;
2542 sin6->sin6_port = ((struct sockaddr_in6 *)
2543 &parent_ep->com.local_addr)->sin6_port;
2544 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2545
Steve Wise170003c2016-02-26 09:18:03 -06002546 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302547 sin6->sin6_family = PF_INET6;
2548 sin6->sin6_port = peer_port;
2549 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2550 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002551
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552 c4iw_get_ep(&parent_ep->com);
2553 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302554 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 child_ep->dst = dst;
2556 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002557
2558 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002559 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560
2561 init_timer(&child_ep->timer);
2562 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302563 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302564 if (accept_cr(child_ep, skb, req)) {
2565 c4iw_put_ep(&parent_ep->com);
2566 release_ep_resources(child_ep);
2567 } else {
2568 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2569 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302570 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002571 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302572 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2573 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2574 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002575 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302576fail:
2577 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302579 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302580 if (parent_ep)
2581 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582out:
2583 return 0;
2584}
2585
2586static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2587{
2588 struct c4iw_ep *ep;
2589 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002590 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302591 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002592
Hariprasad S944661d2016-05-06 22:18:03 +05302593 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002594 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2595 ep->snd_seq = be32_to_cpu(req->snd_isn);
2596 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2597
Vipul Pandya1cab7752012-12-10 09:30:55 +00002598 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2599 ntohs(req->tcp_opt));
2600
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 set_emss(ep, ntohs(req->tcp_opt));
2602
2603 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302604 mutex_lock(&ep->com.mutex);
2605 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002606 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002607 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302608 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302609 mutex_unlock(&ep->com.mutex);
2610 if (ret)
2611 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302612 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613
2614 return 0;
2615}
2616
2617static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2618{
2619 struct cpl_peer_close *hdr = cplhdr(skb);
2620 struct c4iw_ep *ep;
2621 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622 int disconnect = 1;
2623 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002625 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626
Hariprasad S944661d2016-05-06 22:18:03 +05302627 ep = get_ep_from_tid(dev, tid);
2628 if (!ep)
2629 return 0;
2630
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2632 dst_confirm(ep->dst);
2633
Vipul Pandya793dad92012-12-10 09:30:56 +00002634 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002635 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636 switch (ep->com.state) {
2637 case MPA_REQ_WAIT:
2638 __state_set(&ep->com, CLOSING);
2639 break;
2640 case MPA_REQ_SENT:
2641 __state_set(&ep->com, CLOSING);
2642 connect_reply_upcall(ep, -ECONNRESET);
2643 break;
2644 case MPA_REQ_RCVD:
2645
2646 /*
2647 * We're gonna mark this puppy DEAD, but keep
2648 * the reference on it until the ULP accepts or
2649 * rejects the CR. Also wake up anyone waiting
2650 * in rdma connection migration (see c4iw_accept_cr()).
2651 */
2652 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002654 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 break;
2656 case MPA_REP_SENT:
2657 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002659 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002660 break;
2661 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002662 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002664 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002665 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002666 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002667 if (ret != -ECONNRESET) {
2668 peer_close_upcall(ep);
2669 disconnect = 1;
2670 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002671 break;
2672 case ABORTING:
2673 disconnect = 0;
2674 break;
2675 case CLOSING:
2676 __state_set(&ep->com, MORIBUND);
2677 disconnect = 0;
2678 break;
2679 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002680 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 if (ep->com.cm_id && ep->com.qp) {
2682 attrs.next_state = C4IW_QP_STATE_IDLE;
2683 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2684 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2685 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302686 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687 __state_set(&ep->com, DEAD);
2688 release = 1;
2689 disconnect = 0;
2690 break;
2691 case DEAD:
2692 disconnect = 0;
2693 break;
2694 default:
2695 BUG_ON(1);
2696 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002697 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698 if (disconnect)
2699 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2700 if (release)
2701 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302702 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703 return 0;
2704}
2705
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2707{
2708 struct cpl_abort_req_rss *req = cplhdr(skb);
2709 struct c4iw_ep *ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002710 struct sk_buff *rpl_skb;
2711 struct c4iw_qp_attributes attrs;
2712 int ret;
2713 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 unsigned int tid = GET_TID(req);
Varun Prakash052f4732016-09-13 21:24:05 +05302715 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002716
Hariprasad S944661d2016-05-06 22:18:03 +05302717 ep = get_ep_from_tid(dev, tid);
2718 if (!ep)
2719 return 0;
2720
Varun Prakashb65eef02016-09-13 21:23:59 +05302721 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302722 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2723 __func__, ep->hwtid, req->status,
2724 neg_adv_str(req->status));
2725 ep->stats.abort_neg_adv++;
2726 mutex_lock(&dev->rdev.stats.lock);
2727 dev->rdev.stats.neg_adv++;
2728 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302729 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002730 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002731 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2732 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002733 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002734
2735 /*
2736 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302737 * However, this is not needed if com state is just
2738 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002739 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302740 if (ep->com.state != MPA_REQ_SENT)
2741 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002742
2743 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002744 switch (ep->com.state) {
2745 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302746 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002747 break;
2748 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002749 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 break;
2751 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002752 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002753 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302754 connect_reply_upcall(ep, -ECONNRESET);
2755 else {
2756 /*
2757 * we just don't send notification upwards because we
2758 * want to retry with mpa_v1 without upper layers even
2759 * knowing it.
2760 *
2761 * do some housekeeping so as to re-initiate the
2762 * connection
2763 */
2764 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2765 mpa_rev);
2766 ep->retry_with_mpa_v1 = 1;
2767 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002768 break;
2769 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002770 break;
2771 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 break;
2773 case MORIBUND:
2774 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002775 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002776 /*FALLTHROUGH*/
2777 case FPDU_MODE:
2778 if (ep->com.cm_id && ep->com.qp) {
2779 attrs.next_state = C4IW_QP_STATE_ERROR;
2780 ret = c4iw_modify_qp(ep->com.qp->rhp,
2781 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2782 &attrs, 1);
2783 if (ret)
2784 printk(KERN_ERR MOD
2785 "%s - qp <- error failed!\n",
2786 __func__);
2787 }
2788 peer_abort_upcall(ep);
2789 break;
2790 case ABORTING:
2791 break;
2792 case DEAD:
2793 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002794 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302795 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002796 default:
2797 BUG_ON(1);
2798 break;
2799 }
2800 dst_confirm(ep->dst);
2801 if (ep->com.state != ABORTING) {
2802 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302803 /* we don't release if we want to retry with mpa_v1 */
2804 if (!ep->retry_with_mpa_v1)
2805 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002807 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002808
Hariprasad S4a740832016-06-10 01:05:15 +05302809 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2810 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002811 release = 1;
2812 goto out;
2813 }
Varun Prakash052f4732016-09-13 21:24:05 +05302814
2815 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2816
Steve Wisecfdda9d2010-04-21 15:30:06 -07002817 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2818out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002819 if (release)
2820 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002821 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302822 if (ep->com.remote_addr.ss_family == AF_INET6) {
2823 struct sockaddr_in6 *sin6 =
2824 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002825 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302826 cxgb4_clip_release(
2827 ep->com.dev->rdev.lldi.ports[0],
2828 (const u32 *)&sin6->sin6_addr.s6_addr,
2829 1);
2830 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002831 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302832 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2833 dst_release(ep->dst);
2834 cxgb4_l2t_release(ep->l2t);
2835 c4iw_reconnect(ep);
2836 }
2837
Hariprasad S944661d2016-05-06 22:18:03 +05302838deref_ep:
2839 c4iw_put_ep(&ep->com);
2840 /* Dereferencing ep, referenced in peer_abort_intr() */
2841 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002842 return 0;
2843}
2844
2845static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2846{
2847 struct c4iw_ep *ep;
2848 struct c4iw_qp_attributes attrs;
2849 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002850 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002851 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002852
Hariprasad S944661d2016-05-06 22:18:03 +05302853 ep = get_ep_from_tid(dev, tid);
2854 if (!ep)
2855 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002856
2857 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2858 BUG_ON(!ep);
2859
2860 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002861 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302862 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863 switch (ep->com.state) {
2864 case CLOSING:
2865 __state_set(&ep->com, MORIBUND);
2866 break;
2867 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002868 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002869 if ((ep->com.cm_id) && (ep->com.qp)) {
2870 attrs.next_state = C4IW_QP_STATE_IDLE;
2871 c4iw_modify_qp(ep->com.qp->rhp,
2872 ep->com.qp,
2873 C4IW_QP_ATTR_NEXT_STATE,
2874 &attrs, 1);
2875 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302876 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877 __state_set(&ep->com, DEAD);
2878 release = 1;
2879 break;
2880 case ABORTING:
2881 case DEAD:
2882 break;
2883 default:
2884 BUG_ON(1);
2885 break;
2886 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002887 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002888 if (release)
2889 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302890 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002891 return 0;
2892}
2893
2894static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2895{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002896 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002897 unsigned int tid = GET_TID(rpl);
2898 struct c4iw_ep *ep;
2899 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900
Hariprasad S944661d2016-05-06 22:18:03 +05302901 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002902 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002903
Steve Wise30c95c22011-05-09 22:06:22 -07002904 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002905 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2906 ep->com.qp->wq.sq.qid);
2907 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2908 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2909 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2910 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002911 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302912 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913
Steve Wisecfdda9d2010-04-21 15:30:06 -07002914 return 0;
2915}
2916
2917/*
2918 * Upcall from the adapter indicating data has been transmitted.
2919 * For us its just the single MPA request or reply. We can now free
2920 * the skb holding the mpa message.
2921 */
2922static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2923{
2924 struct c4iw_ep *ep;
2925 struct cpl_fw4_ack *hdr = cplhdr(skb);
2926 u8 credits = hdr->credits;
2927 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002928
2929
Hariprasad S944661d2016-05-06 22:18:03 +05302930 ep = get_ep_from_tid(dev, tid);
2931 if (!ep)
2932 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2934 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002935 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2936 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302937 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938 }
2939
2940 dst_confirm(ep->dst);
2941 if (ep->mpa_skb) {
2942 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2943 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2944 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002945 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 kfree_skb(ep->mpa_skb);
2947 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302948 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2949 stop_ep_timer(ep);
2950 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951 }
Hariprasad S944661d2016-05-06 22:18:03 +05302952out:
2953 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002954 return 0;
2955}
2956
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2958{
Hariprasad Sbce28412016-06-10 01:05:13 +05302959 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002960 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302961
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2963
Steve Wisea7db89e2014-03-21 20:40:35 +05302964 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302965 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302966 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967 c4iw_put_ep(&ep->com);
2968 return -ECONNRESET;
2969 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002970 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302972 abort = 1;
2973 else
2974 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302975 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302976
2977 stop_ep_timer(ep);
2978 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002979 c4iw_put_ep(&ep->com);
2980 return 0;
2981}
2982
2983int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2984{
2985 int err;
2986 struct c4iw_qp_attributes attrs;
2987 enum c4iw_qp_attr_mask mask;
2988 struct c4iw_ep *ep = to_ep(cm_id);
2989 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2990 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302991 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992
2993 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302994
2995 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302996 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002997 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302998 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999 }
3000
Steve Wisecfdda9d2010-04-21 15:30:06 -07003001 BUG_ON(!qp);
3002
Vipul Pandya793dad92012-12-10 09:30:56 +00003003 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303004 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3005 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303007 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003008 }
3009
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303010 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3011 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303012 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003013 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303014 } else {
3015 ep->ird = conn_param->ird;
3016 ep->ord = conn_param->ord;
3017 send_mpa_reject(ep, conn_param->private_data,
3018 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303019 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303020 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303021 }
3022 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303023 if (conn_param->ird < ep->ord) {
3024 if (RELAXED_IRD_NEGOTIATION &&
3025 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3026 conn_param->ird = ep->ord;
3027 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303028 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303029 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303030 }
3031 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303032 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003033 ep->ird = conn_param->ird;
3034 ep->ord = conn_param->ord;
3035
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303036 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303037 if (peer2peer && ep->ird == 0)
3038 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303039 } else {
3040 if (peer2peer &&
3041 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303042 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303043 ep->ird = 1;
3044 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003045
3046 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3047
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303048 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303049 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303050 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003051 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303052
Steve Wisecfdda9d2010-04-21 15:30:06 -07003053 /* bind QP to EP and move to RTS */
3054 attrs.mpa_attr = ep->mpa_attr;
3055 attrs.max_ird = ep->ird;
3056 attrs.max_ord = ep->ord;
3057 attrs.llp_stream_handle = ep;
3058 attrs.next_state = C4IW_QP_STATE_RTS;
3059
3060 /* bind QP and TID with INIT_WR */
3061 mask = C4IW_QP_ATTR_NEXT_STATE |
3062 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3063 C4IW_QP_ATTR_MPA_ATTR |
3064 C4IW_QP_ATTR_MAX_IRD |
3065 C4IW_QP_ATTR_MAX_ORD;
3066
3067 err = c4iw_modify_qp(ep->com.qp->rhp,
3068 ep->com.qp, mask, &attrs, 1);
3069 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303070 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303071
3072 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003073 err = send_mpa_reply(ep, conn_param->private_data,
3074 conn_param->private_data_len);
3075 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303076 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003077
Steve Wisea7db89e2014-03-21 20:40:35 +05303078 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003079 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303080 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003081 c4iw_put_ep(&ep->com);
3082 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303083err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303084 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303085err_abort:
3086 abort = 1;
3087err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303088 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303089 if (abort)
3090 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003091 c4iw_put_ep(&ep->com);
3092 return err;
3093}
3094
Vipul Pandya830662f2013-07-04 16:10:47 +05303095static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3096{
3097 struct in_device *ind;
3098 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003099 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3100 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303101
3102 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3103 if (!ind)
3104 return -EADDRNOTAVAIL;
3105 for_primary_ifa(ind) {
3106 laddr->sin_addr.s_addr = ifa->ifa_address;
3107 raddr->sin_addr.s_addr = ifa->ifa_address;
3108 found = 1;
3109 break;
3110 }
3111 endfor_ifa(ind);
3112 in_dev_put(ind);
3113 return found ? 0 : -EADDRNOTAVAIL;
3114}
3115
3116static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3117 unsigned char banned_flags)
3118{
3119 struct inet6_dev *idev;
3120 int err = -EADDRNOTAVAIL;
3121
3122 rcu_read_lock();
3123 idev = __in6_dev_get(dev);
3124 if (idev != NULL) {
3125 struct inet6_ifaddr *ifp;
3126
3127 read_lock_bh(&idev->lock);
3128 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3129 if (ifp->scope == IFA_LINK &&
3130 !(ifp->flags & banned_flags)) {
3131 memcpy(addr, &ifp->addr, 16);
3132 err = 0;
3133 break;
3134 }
3135 }
3136 read_unlock_bh(&idev->lock);
3137 }
3138 rcu_read_unlock();
3139 return err;
3140}
3141
3142static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3143{
3144 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003145 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3146 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303147
Nicholas Krause54b9a962015-08-26 23:00:59 -04003148 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303149 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3150 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3151 return 0;
3152 }
3153 return -EADDRNOTAVAIL;
3154}
3155
Steve Wisecfdda9d2010-04-21 15:30:06 -07003156int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3157{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003158 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3159 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003160 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003161 struct sockaddr_in *laddr;
3162 struct sockaddr_in *raddr;
3163 struct sockaddr_in6 *laddr6;
3164 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303165 __u8 *ra;
3166 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003167
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303168 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3169 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003170 err = -EINVAL;
3171 goto out;
3172 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003173 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3174 if (!ep) {
3175 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3176 err = -ENOMEM;
3177 goto out;
3178 }
Hariprasad S4a740832016-06-10 01:05:15 +05303179
3180 skb_queue_head_init(&ep->com.ep_skb_list);
3181 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3182 err = -ENOMEM;
3183 goto fail1;
3184 }
3185
Steve Wisecfdda9d2010-04-21 15:30:06 -07003186 init_timer(&ep->timer);
3187 ep->plen = conn_param->private_data_len;
3188 if (ep->plen)
3189 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3190 conn_param->private_data, ep->plen);
3191 ep->ird = conn_param->ird;
3192 ep->ord = conn_param->ord;
3193
3194 if (peer2peer && ep->ord == 0)
3195 ep->ord = 1;
3196
Steve Wisecfdda9d2010-04-21 15:30:06 -07003197 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303198 ref_cm_id(&ep->com);
3199 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003200 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303201 if (!ep->com.qp) {
3202 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3203 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303204 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303205 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003206 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003207 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3208 ep->com.qp, cm_id);
3209
3210 /*
3211 * Allocate an active TID to initiate a TCP connection.
3212 */
3213 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3214 if (ep->atid == -1) {
3215 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3216 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303217 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003218 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003219 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003220
Steve Wise170003c2016-02-26 09:18:03 -06003221 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003222 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003223 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003224 sizeof(ep->com.remote_addr));
3225
Steve Wise170003c2016-02-26 09:18:03 -06003226 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3227 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3228 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3229 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003230
Steve Wise170003c2016-02-26 09:18:03 -06003231 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303232 iptype = 4;
3233 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003234
Vipul Pandya830662f2013-07-04 16:10:47 +05303235 /*
3236 * Handle loopback requests to INADDR_ANY.
3237 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003238 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303239 err = pick_local_ipaddrs(dev, cm_id);
3240 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303241 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303242 }
3243
3244 /* find a route */
3245 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3246 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3247 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303248 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3249 laddr->sin_addr.s_addr,
3250 raddr->sin_addr.s_addr,
3251 laddr->sin_port,
3252 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303253 } else {
3254 iptype = 6;
3255 ra = (__u8 *)&raddr6->sin6_addr;
3256
3257 /*
3258 * Handle loopback requests to INADDR_ANY.
3259 */
3260 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3261 err = pick_local_ip6addrs(dev, cm_id);
3262 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303263 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303264 }
3265
3266 /* find a route */
3267 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3268 __func__, laddr6->sin6_addr.s6_addr,
3269 ntohs(laddr6->sin6_port),
3270 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303271 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3272 laddr6->sin6_addr.s6_addr,
3273 raddr6->sin6_addr.s6_addr,
3274 laddr6->sin6_port,
3275 raddr6->sin6_port, 0,
3276 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303277 }
3278 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003279 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3280 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303281 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003282 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003283
Hariprasad S963cab52015-09-23 17:19:27 +05303284 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303285 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003286 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003287 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303288 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003289 }
3290
3291 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3292 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3293 ep->l2t->idx);
3294
3295 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303296 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297
3298 /* send connect request to rnic */
3299 err = send_connect(ep);
3300 if (!err)
3301 goto out;
3302
3303 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303304fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003305 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303306fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003307 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003308 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303309fail2:
3310 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303311 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303312fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003313 c4iw_put_ep(&ep->com);
3314out:
3315 return err;
3316}
3317
Vipul Pandya830662f2013-07-04 16:10:47 +05303318static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3319{
3320 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003321 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003322 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303323
Hariprasad S28de1f72016-01-13 10:03:14 +05303324 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3325 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3326 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3327 if (err)
3328 return err;
3329 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303330 c4iw_init_wr_wait(&ep->com.wr_wait);
3331 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3332 ep->stid, &sin6->sin6_addr,
3333 sin6->sin6_port,
3334 ep->com.dev->rdev.lldi.rxq_ids[0]);
3335 if (!err)
3336 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3337 &ep->com.wr_wait,
3338 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303339 else if (err > 0)
3340 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303341 if (err) {
3342 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3343 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303344 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3345 err, ep->stid,
3346 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303347 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303348 return err;
3349}
3350
3351static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3352{
3353 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003354 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003355 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303356
3357 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3358 do {
3359 err = cxgb4_create_server_filter(
3360 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3361 sin->sin_addr.s_addr, sin->sin_port, 0,
3362 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3363 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303364 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3365 err = -EIO;
3366 break;
3367 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303368 set_current_state(TASK_UNINTERRUPTIBLE);
3369 schedule_timeout(usecs_to_jiffies(100));
3370 }
3371 } while (err == -EBUSY);
3372 } else {
3373 c4iw_init_wr_wait(&ep->com.wr_wait);
3374 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3375 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3376 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3377 if (!err)
3378 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3379 &ep->com.wr_wait,
3380 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303381 else if (err > 0)
3382 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303383 }
3384 if (err)
3385 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3386 , err, ep->stid,
3387 &sin->sin_addr, ntohs(sin->sin_port));
3388 return err;
3389}
3390
Steve Wisecfdda9d2010-04-21 15:30:06 -07003391int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3392{
3393 int err = 0;
3394 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3395 struct c4iw_listen_ep *ep;
3396
Steve Wisecfdda9d2010-04-21 15:30:06 -07003397 might_sleep();
3398
3399 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3400 if (!ep) {
3401 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3402 err = -ENOMEM;
3403 goto fail1;
3404 }
Hariprasad S4a740832016-06-10 01:05:15 +05303405 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003406 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003407 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303408 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003409 ep->com.dev = dev;
3410 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003411 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303412 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003413
3414 /*
3415 * Allocate a server TID.
3416 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303417 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3418 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303419 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003420 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003421 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303422 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003423 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003424
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003426 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003427 err = -ENOMEM;
3428 goto fail2;
3429 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003430 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003431
Steve Wise170003c2016-02-26 09:18:03 -06003432 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3433 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003434
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303436 if (ep->com.local_addr.ss_family == AF_INET)
3437 err = create_server4(dev, ep);
3438 else
3439 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003440 if (!err) {
3441 cm_id->provider_data = ep;
3442 goto out;
3443 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003444
Vipul Pandya830662f2013-07-04 16:10:47 +05303445 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3446 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003447fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303448 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003449 c4iw_put_ep(&ep->com);
3450fail1:
3451out:
3452 return err;
3453}
3454
3455int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3456{
3457 int err;
3458 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3459
3460 PDBG("%s ep %p\n", __func__, ep);
3461
3462 might_sleep();
3463 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303464 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3465 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003466 err = cxgb4_remove_server_filter(
3467 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3468 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3469 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303470 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003471 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303472 err = cxgb4_remove_server(
3473 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3474 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003475 if (err)
3476 goto done;
3477 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3478 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003479 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303480 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3481 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003482 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003483 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303484 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3485 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003486done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303487 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003488 c4iw_put_ep(&ep->com);
3489 return err;
3490}
3491
3492int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3493{
3494 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003495 int close = 0;
3496 int fatal = 0;
3497 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498
Steve Wise2f5b48c2010-09-10 11:15:36 -05003499 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003500
3501 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3502 states[ep->com.state], abrupt);
3503
Hariprasad S6e410d82016-05-05 01:27:31 +05303504 /*
3505 * Ref the ep here in case we have fatal errors causing the
3506 * ep to be released and freed.
3507 */
3508 c4iw_get_ep(&ep->com);
3509
Steve Wisecfdda9d2010-04-21 15:30:06 -07003510 rdev = &ep->com.dev->rdev;
3511 if (c4iw_fatal_error(rdev)) {
3512 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303513 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003514 ep->com.state = DEAD;
3515 }
3516 switch (ep->com.state) {
3517 case MPA_REQ_WAIT:
3518 case MPA_REQ_SENT:
3519 case MPA_REQ_RCVD:
3520 case MPA_REP_SENT:
3521 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303522 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003523 close = 1;
3524 if (abrupt)
3525 ep->com.state = ABORTING;
3526 else {
3527 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003528
3529 /*
3530 * if we close before we see the fw4_ack() then we fix
3531 * up the timer state since we're reusing it.
3532 */
3533 if (ep->mpa_skb &&
3534 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3535 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3536 stop_ep_timer(ep);
3537 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003538 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003539 }
3540 set_bit(CLOSE_SENT, &ep->com.flags);
3541 break;
3542 case CLOSING:
3543 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3544 close = 1;
3545 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003546 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003547 ep->com.state = ABORTING;
3548 } else
3549 ep->com.state = MORIBUND;
3550 }
3551 break;
3552 case MORIBUND:
3553 case ABORTING:
3554 case DEAD:
3555 PDBG("%s ignoring disconnect ep %p state %u\n",
3556 __func__, ep, ep->com.state);
3557 break;
3558 default:
3559 BUG();
3560 break;
3561 }
3562
Steve Wisecfdda9d2010-04-21 15:30:06 -07003563 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003564 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003565 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303566 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303567 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003568 } else {
3569 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303570 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003571 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303572 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303573 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303574 if (!abrupt) {
3575 stop_ep_timer(ep);
3576 close_complete_upcall(ep, -EIO);
3577 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303578 if (ep->com.qp) {
3579 struct c4iw_qp_attributes attrs;
3580
3581 attrs.next_state = C4IW_QP_STATE_ERROR;
3582 ret = c4iw_modify_qp(ep->com.qp->rhp,
3583 ep->com.qp,
3584 C4IW_QP_ATTR_NEXT_STATE,
3585 &attrs, 1);
3586 if (ret)
3587 pr_err(MOD
3588 "%s - qp <- error failed!\n",
3589 __func__);
3590 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003591 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303592 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003593 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003594 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303595 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003596 if (fatal)
3597 release_ep_resources(ep);
3598 return ret;
3599}
3600
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3602 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3603{
3604 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003605 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003606
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003607 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3608 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003609 if (!ep)
3610 return;
3611
3612 switch (req->retval) {
3613 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003614 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3615 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3616 send_fw_act_open_req(ep, atid);
3617 return;
3618 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003620 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3621 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3622 send_fw_act_open_req(ep, atid);
3623 return;
3624 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003625 break;
3626 default:
3627 pr_info("%s unexpected ofld conn wr retval %d\n",
3628 __func__, req->retval);
3629 break;
3630 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003631 pr_err("active ofld_connect_wr failure %d atid %d\n",
3632 req->retval, atid);
3633 mutex_lock(&dev->rdev.stats.lock);
3634 dev->rdev.stats.act_ofld_conn_fails++;
3635 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003636 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003637 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303638 if (ep->com.remote_addr.ss_family == AF_INET6) {
3639 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003640 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303641 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3642 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3643 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003644 remove_handle(dev, &dev->atid_idr, atid);
3645 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3646 dst_release(ep->dst);
3647 cxgb4_l2t_release(ep->l2t);
3648 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003649}
3650
3651static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3652 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3653{
3654 struct sk_buff *rpl_skb;
3655 struct cpl_pass_accept_req *cpl;
3656 int ret;
3657
Paul Bolle710a3112013-02-05 20:51:30 +00003658 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003659 BUG_ON(!rpl_skb);
3660 if (req->retval) {
3661 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003662 mutex_lock(&dev->rdev.stats.lock);
3663 dev->rdev.stats.pas_ofld_conn_fails++;
3664 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003665 kfree_skb(rpl_skb);
3666 } else {
3667 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3668 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003669 (__force u32) htonl(
3670 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 ret = pass_accept_req(dev, rpl_skb);
3672 if (!ret)
3673 kfree_skb(rpl_skb);
3674 }
3675 return;
3676}
3677
3678static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003679{
3680 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003681 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3682
3683 switch (rpl->type) {
3684 case FW6_TYPE_CQE:
3685 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3686 break;
3687 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3688 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3689 switch (req->t_state) {
3690 case TCP_SYN_SENT:
3691 active_ofld_conn_reply(dev, skb, req);
3692 break;
3693 case TCP_SYN_RECV:
3694 passive_ofld_conn_reply(dev, skb, req);
3695 break;
3696 default:
3697 pr_err("%s unexpected ofld conn wr state %d\n",
3698 __func__, req->t_state);
3699 break;
3700 }
3701 break;
3702 }
3703 return 0;
3704}
3705
3706static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3707{
Hariprasad S963cab52015-09-23 17:19:27 +05303708 __be32 l2info;
3709 __be16 hdr_len, vlantag, len;
3710 u16 eth_hdr_len;
3711 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003712 u8 intf;
3713 struct cpl_rx_pkt *cpl = cplhdr(skb);
3714 struct cpl_pass_accept_req *req;
3715 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003716 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303717 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003718
Vipul Pandyaf079af72013-03-14 05:08:58 +00003719 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003720 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303721 vlantag = cpl->vlan;
3722 len = cpl->len;
3723 l2info = cpl->l2info;
3724 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003725 intf = cpl->iff;
3726
3727 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3728
3729 /*
3730 * We need to parse the TCP options from SYN packet.
3731 * to generate cpl_pass_accept_req.
3732 */
3733 memset(&tmp_opt, 0, sizeof(tmp_opt));
3734 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003735 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003736
3737 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3738 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303739 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3740 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303741 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303742 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303743 type = dev->rdev.lldi.adapter_type;
3744 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3745 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3746 req->hdr_len =
3747 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3748 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3749 eth_hdr_len = is_t4(type) ?
3750 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3751 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3752 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3753 IP_HDR_LEN_V(ip_hdr_len) |
3754 ETH_HDR_LEN_V(eth_hdr_len));
3755 } else { /* T6 and later */
3756 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3757 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3758 T6_IP_HDR_LEN_V(ip_hdr_len) |
3759 T6_ETH_HDR_LEN_V(eth_hdr_len));
3760 }
3761 req->vlan = vlantag;
3762 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003763 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3764 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003765 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3766 if (tmp_opt.wscale_ok)
3767 req->tcpopt.wsf = tmp_opt.snd_wscale;
3768 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3769 if (tmp_opt.sack_ok)
3770 req->tcpopt.sack = 1;
3771 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3772 return;
3773}
3774
3775static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3776 __be32 laddr, __be16 lport,
3777 __be32 raddr, __be16 rport,
3778 u32 rcv_isn, u32 filter, u16 window,
3779 u32 rss_qid, u8 port_id)
3780{
3781 struct sk_buff *req_skb;
3782 struct fw_ofld_connection_wr *req;
3783 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303784 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003785
3786 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3787 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3788 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003789 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303790 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303791 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003792 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003793 req->le.lport = lport;
3794 req->le.pport = rport;
3795 req->le.u.ipv4.lip = laddr;
3796 req->le.u.ipv4.pip = raddr;
3797 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3798 req->tcb.rcv_adv = htons(window);
3799 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303800 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3801 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3802 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003803 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003804
3805 /*
3806 * We store the qid in opt2 which will be used by the firmware
3807 * to send us the wr response.
3808 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003809 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003810
3811 /*
3812 * We initialize the MSS index in TCB to 0xF.
3813 * So that when driver sends cpl_pass_accept_rpl
3814 * TCB picks up the correct value. If this was 0
3815 * TP will ignore any value > 0 for MSS index.
3816 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003817 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303818 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003819
3820 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303821 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3822 if (ret < 0) {
3823 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3824 ret);
3825 kfree_skb(skb);
3826 kfree_skb(req_skb);
3827 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003828}
3829
3830/*
3831 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3832 * messages when a filter is being used instead of server to
3833 * redirect a syn packet. When packets hit filter they are redirected
3834 * to the offload queue and driver tries to establish the connection
3835 * using firmware work request.
3836 */
3837static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3838{
3839 int stid;
3840 unsigned int filter;
3841 struct ethhdr *eh = NULL;
3842 struct vlan_ethhdr *vlan_eh = NULL;
3843 struct iphdr *iph;
3844 struct tcphdr *tcph;
3845 struct rss_header *rss = (void *)skb->data;
3846 struct cpl_rx_pkt *cpl = (void *)skb->data;
3847 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3848 struct l2t_entry *e;
3849 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303850 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003851 u16 window;
3852 struct port_info *pi;
3853 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003854 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003855 int step;
3856 u32 tx_chan;
3857 struct neighbour *neigh;
3858
3859 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003860 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003861 goto reject;
3862
3863 /*
3864 * Drop all packets which did not hit the filter.
3865 * Unlikely to happen.
3866 */
3867 if (!(rss->filter_hit && rss->filter_tid))
3868 goto reject;
3869
3870 /*
3871 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3872 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303873 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003874
Hariprasad Sf86fac72016-05-06 22:18:07 +05303875 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003876 if (!lep) {
3877 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3878 goto reject;
3879 }
3880
Hariprasad S963cab52015-09-23 17:19:27 +05303881 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3882 case CHELSIO_T4:
3883 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3884 break;
3885 case CHELSIO_T5:
3886 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3887 break;
3888 case CHELSIO_T6:
3889 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3890 break;
3891 default:
3892 pr_err("T%d Chip is not supported\n",
3893 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3894 goto reject;
3895 }
3896
Vipul Pandyaf079af72013-03-14 05:08:58 +00003897 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003898 eh = (struct ethhdr *)(req + 1);
3899 iph = (struct iphdr *)(eh + 1);
3900 } else {
3901 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3902 iph = (struct iphdr *)(vlan_eh + 1);
3903 skb->vlan_tci = ntohs(cpl->vlan);
3904 }
3905
3906 if (iph->version != 0x4)
3907 goto reject;
3908
3909 tcph = (struct tcphdr *)(iph + 1);
3910 skb_set_network_header(skb, (void *)iph - (void *)rss);
3911 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3912 skb_get(skb);
3913
3914 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3915 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3916 ntohs(tcph->source), iph->tos);
3917
Varun Prakash804c2f32016-09-13 21:23:57 +05303918 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3919 iph->daddr, iph->saddr, tcph->dest,
3920 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303921 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003922 pr_err("%s - failed to find dst entry!\n",
3923 __func__);
3924 goto reject;
3925 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003926 neigh = dst_neigh_lookup_skb(dst, skb);
3927
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003928 if (!neigh) {
3929 pr_err("%s - failed to allocate neigh!\n",
3930 __func__);
3931 goto free_dst;
3932 }
3933
Vipul Pandya1cab7752012-12-10 09:30:55 +00003934 if (neigh->dev->flags & IFF_LOOPBACK) {
3935 pdev = ip_dev_find(&init_net, iph->daddr);
3936 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3937 pdev, 0);
3938 pi = (struct port_info *)netdev_priv(pdev);
3939 tx_chan = cxgb4_port_chan(pdev);
3940 dev_put(pdev);
3941 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303942 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003943 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303944 pdev, 0);
3945 pi = (struct port_info *)netdev_priv(pdev);
3946 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003947 }
Steve Wiseebf00062014-03-19 17:44:40 +05303948 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003949 if (!e) {
3950 pr_err("%s - failed to allocate l2t entry!\n",
3951 __func__);
3952 goto free_dst;
3953 }
3954
3955 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3956 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003957 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003958
3959 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303960 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3961 dev->rdev.lldi.ports[0],
3962 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003963
3964 /*
3965 * Synthesize the cpl_pass_accept_req. We have everything except the
3966 * TID. Once firmware sends a reply with TID we update the TID field
3967 * in cpl and pass it through the regular cpl_pass_accept_req path.
3968 */
3969 build_cpl_pass_accept_req(skb, stid, iph->tos);
3970 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3971 tcph->source, ntohl(tcph->seq), filter, window,
3972 rss_qid, pi->port_id);
3973 cxgb4_l2t_release(e);
3974free_dst:
3975 dst_release(dst);
3976reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303977 if (lep)
3978 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003979 return 0;
3980}
3981
Steve Wisecfdda9d2010-04-21 15:30:06 -07003982/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003983 * These are the real handlers that are called from a
3984 * work queue.
3985 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303986static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003987 [CPL_ACT_ESTABLISH] = act_establish,
3988 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3989 [CPL_RX_DATA] = rx_data,
3990 [CPL_ABORT_RPL_RSS] = abort_rpl,
3991 [CPL_ABORT_RPL] = abort_rpl,
3992 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3993 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3994 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3995 [CPL_PASS_ESTABLISH] = pass_establish,
3996 [CPL_PEER_CLOSE] = peer_close,
3997 [CPL_ABORT_REQ_RSS] = peer_abort,
3998 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3999 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004000 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004001 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304002 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304003 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4004 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004005};
4006
4007static void process_timeout(struct c4iw_ep *ep)
4008{
4009 struct c4iw_qp_attributes attrs;
4010 int abort = 1;
4011
Steve Wise2f5b48c2010-09-10 11:15:36 -05004012 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004013 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4014 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004015 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004016 switch (ep->com.state) {
4017 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004018 connect_reply_upcall(ep, -ETIMEDOUT);
4019 break;
4020 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304021 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304022 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304023 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004024 break;
4025 case CLOSING:
4026 case MORIBUND:
4027 if (ep->com.cm_id && ep->com.qp) {
4028 attrs.next_state = C4IW_QP_STATE_ERROR;
4029 c4iw_modify_qp(ep->com.qp->rhp,
4030 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4031 &attrs, 1);
4032 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304033 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004034 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004035 case ABORTING:
4036 case DEAD:
4037
4038 /*
4039 * These states are expected if the ep timed out at the same
4040 * time as another thread was calling stop_ep_timer().
4041 * So we silently do nothing for these states.
4042 */
4043 abort = 0;
4044 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004045 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004046 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004047 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004048 abort = 0;
4049 }
Steve Wisecc18b932014-04-24 14:31:53 -05004050 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304051 if (abort)
4052 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004053 c4iw_put_ep(&ep->com);
4054}
4055
4056static void process_timedout_eps(void)
4057{
4058 struct c4iw_ep *ep;
4059
4060 spin_lock_irq(&timeout_lock);
4061 while (!list_empty(&timeout_list)) {
4062 struct list_head *tmp;
4063
4064 tmp = timeout_list.next;
4065 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004066 tmp->next = NULL;
4067 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004068 spin_unlock_irq(&timeout_lock);
4069 ep = list_entry(tmp, struct c4iw_ep, entry);
4070 process_timeout(ep);
4071 spin_lock_irq(&timeout_lock);
4072 }
4073 spin_unlock_irq(&timeout_lock);
4074}
4075
4076static void process_work(struct work_struct *work)
4077{
4078 struct sk_buff *skb = NULL;
4079 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004080 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004081 unsigned int opcode;
4082 int ret;
4083
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004084 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004085 while ((skb = skb_dequeue(&rxq))) {
4086 rpl = cplhdr(skb);
4087 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4088 opcode = rpl->ot.opcode;
4089
4090 BUG_ON(!work_handlers[opcode]);
4091 ret = work_handlers[opcode](dev, skb);
4092 if (!ret)
4093 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004094 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004096}
4097
4098static DECLARE_WORK(skb_work, process_work);
4099
4100static void ep_timeout(unsigned long arg)
4101{
4102 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004103 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004104
4105 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004106 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004107 /*
4108 * Only insert if it is not already on the list.
4109 */
4110 if (!ep->entry.next) {
4111 list_add_tail(&ep->entry, &timeout_list);
4112 kickit = 1;
4113 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004114 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004115 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004116 if (kickit)
4117 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004118}
4119
4120/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004121 * All the CM events are handled on a work queue to have a safe context.
4122 */
4123static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4124{
4125
4126 /*
4127 * Save dev in the skb->cb area.
4128 */
4129 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4130
4131 /*
4132 * Queue the skb and schedule the worker thread.
4133 */
4134 skb_queue_tail(&rxq, skb);
4135 queue_work(workq, &skb_work);
4136 return 0;
4137}
4138
4139static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4140{
4141 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4142
4143 if (rpl->status != CPL_ERR_NONE) {
4144 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4145 "for tid %u\n", rpl->status, GET_TID(rpl));
4146 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004147 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004148 return 0;
4149}
4150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004151static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4152{
4153 struct cpl_fw6_msg *rpl = cplhdr(skb);
4154 struct c4iw_wr_wait *wr_waitp;
4155 int ret;
4156
4157 PDBG("%s type %u\n", __func__, rpl->type);
4158
4159 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004160 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004161 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004162 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004163 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004164 if (wr_waitp)
4165 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004166 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004167 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004168 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004169 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004170 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004171 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004172 default:
4173 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4174 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004175 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004176 break;
4177 }
4178 return 0;
4179}
4180
Steve Wise8da7e7a2011-06-14 20:59:27 +00004181static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4182{
4183 struct cpl_abort_req_rss *req = cplhdr(skb);
4184 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004185 unsigned int tid = GET_TID(req);
4186
Hariprasad S944661d2016-05-06 22:18:03 +05304187 ep = get_ep_from_tid(dev, tid);
4188 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004189 if (!ep) {
4190 printk(KERN_WARNING MOD
4191 "Abort on non-existent endpoint, tid %d\n", tid);
4192 kfree_skb(skb);
4193 return 0;
4194 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304195 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304196 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4197 __func__, ep->hwtid, req->status,
4198 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304199 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004200 }
4201 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4202 ep->com.state);
4203
Hariprasad S093108c2016-05-06 22:18:09 +05304204 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304205out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004206 sched(dev, skb);
4207 return 0;
4208}
4209
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004210/*
4211 * Most upcalls from the T4 Core go to sched() to
4212 * schedule the processing on a work queue.
4213 */
4214c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4215 [CPL_ACT_ESTABLISH] = sched,
4216 [CPL_ACT_OPEN_RPL] = sched,
4217 [CPL_RX_DATA] = sched,
4218 [CPL_ABORT_RPL_RSS] = sched,
4219 [CPL_ABORT_RPL] = sched,
4220 [CPL_PASS_OPEN_RPL] = sched,
4221 [CPL_CLOSE_LISTSRV_RPL] = sched,
4222 [CPL_PASS_ACCEPT_REQ] = sched,
4223 [CPL_PASS_ESTABLISH] = sched,
4224 [CPL_PEER_CLOSE] = sched,
4225 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004226 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004227 [CPL_RDMA_TERMINATE] = sched,
4228 [CPL_FW4_ACK] = sched,
4229 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004230 [CPL_FW6_MSG] = fw6_msg,
4231 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004232};
4233
Steve Wisecfdda9d2010-04-21 15:30:06 -07004234int __init c4iw_cm_init(void)
4235{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004236 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004237 skb_queue_head_init(&rxq);
4238
Bhaktipriya Shridhar52ee1a02016-08-15 23:39:14 +05304239 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004240 if (!workq)
4241 return -ENOMEM;
4242
Steve Wisecfdda9d2010-04-21 15:30:06 -07004243 return 0;
4244}
4245
Steve Wise46c13762014-06-20 14:26:25 -05004246void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004247{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004248 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004249 flush_workqueue(workq);
4250 destroy_workqueue(workq);
4251}