blob: dd30aeed7e6967cbac9ac485b238b57d0afca384 [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{
Joe Perches700456b2017-02-09 14:23:50 -0800470 pr_err("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
Joe Perches700456b2017-02-09 14:23:50 -0800531 pr_err("ARP failure during accept - tid %u - dropping connection\n",
Hariprasad S9dec9002016-05-05 01:27:29 +0530532 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
Joe Perches700456b2017-02-09 14:23:50 -0800545 pr_err("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;
Ganesh Goudar192539f2017-01-31 12:00:09 +0530695 struct net_device *netdev;
696 u64 params;
697
698 netdev = ep->com.dev->rdev.lldi.ports[0];
Hariprasad S963cab52015-09-23 17:19:27 +0530699
700 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
701 case CHELSIO_T4:
702 sizev4 = sizeof(struct cpl_act_open_req);
703 sizev6 = sizeof(struct cpl_act_open_req6);
704 break;
705 case CHELSIO_T5:
706 sizev4 = sizeof(struct cpl_t5_act_open_req);
707 sizev6 = sizeof(struct cpl_t5_act_open_req6);
708 break;
709 case CHELSIO_T6:
710 sizev4 = sizeof(struct cpl_t6_act_open_req);
711 sizev6 = sizeof(struct cpl_t6_act_open_req6);
712 break;
713 default:
714 pr_err("T%d Chip is not supported\n",
715 CHELSIO_CHIP_VERSION(adapter_type));
716 return -EINVAL;
717 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530718
719 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
720 roundup(sizev4, 16) :
721 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700722
723 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
724
725 skb = get_skb(NULL, wrlen, GFP_KERNEL);
726 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -0800727 pr_err("%s - failed to alloc skb\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700728 return -ENOMEM;
729 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000730 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700731
Varun Prakash44c6d062016-09-13 21:24:00 +0530732 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
733 enable_tcp_timestamps,
734 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530735 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530736
737 /*
738 * Specify the largest window that will fit in opt0. The
739 * remainder will be specified in the rx_data_ack.
740 */
741 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800742 if (win > RCV_BUFSIZ_M)
743 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530744
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800745 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800746 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800747 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800748 WND_SCALE_V(wscale) |
749 MSS_IDX_V(mtu_idx) |
750 L2T_IDX_V(ep->l2t->idx) |
751 TX_CHAN_V(ep->tx_chan) |
752 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530753 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800754 ULP_MODE_V(ULP_MODE_TCPDDP) |
755 RCV_BUFSIZ_V(win);
756 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800757 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800758 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700759 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800760 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700761 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800762 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700763 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800764 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530765 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
766 if (peer2peer)
767 isn += 4;
768
Anish Bhattd7990b02014-11-12 17:15:57 -0800769 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530770 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530771 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500772 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530773
Ganesh Goudar192539f2017-01-31 12:00:09 +0530774 params = cxgb4_select_ntuple(netdev, ep->l2t);
775
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530776 if (ep->com.remote_addr.ss_family == AF_INET6)
777 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
778 (const u32 *)&la6->sin6_addr.s6_addr, 1);
779
Hariprasad S5dab6d32014-06-23 19:12:36 +0530780 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700781
Hariprasad S963cab52015-09-23 17:19:27 +0530782 if (ep->com.remote_addr.ss_family == AF_INET) {
783 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
784 case CHELSIO_T4:
785 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530786 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530787 break;
788 case CHELSIO_T5:
789 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
790 wrlen);
791 INIT_TP_WR(t5req, 0);
792 req = (struct cpl_act_open_req *)t5req;
793 break;
794 case CHELSIO_T6:
795 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
796 wrlen);
797 INIT_TP_WR(t6req, 0);
798 req = (struct cpl_act_open_req *)t6req;
799 t5req = (struct cpl_t5_act_open_req *)t6req;
800 break;
801 default:
802 pr_err("T%d Chip is not supported\n",
803 CHELSIO_CHIP_VERSION(adapter_type));
804 ret = -EINVAL;
805 goto clip_release;
806 }
807
808 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
809 ((ep->rss_qid<<14) | ep->atid)));
810 req->local_port = la->sin_port;
811 req->peer_port = ra->sin_port;
812 req->local_ip = la->sin_addr.s_addr;
813 req->peer_ip = ra->sin_addr.s_addr;
814 req->opt0 = cpu_to_be64(opt0);
815
816 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530817 req->params = cpu_to_be32(params);
Vipul Pandya830662f2013-07-04 16:10:47 +0530818 req->opt2 = cpu_to_be32(opt2);
819 } else {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530820 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
821 t5req->params =
822 cpu_to_be64(FILTER_TUPLE_V(params));
823 t5req->rsvd = cpu_to_be32(isn);
824 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
825 t5req->opt2 = cpu_to_be32(opt2);
826 } else {
827 t6req->params =
828 cpu_to_be64(FILTER_TUPLE_V(params));
829 t6req->rsvd = cpu_to_be32(isn);
830 PDBG("%s snd_isn %u\n", __func__, t6req->rsvd);
831 t6req->opt2 = cpu_to_be32(opt2);
832 }
Hariprasad S963cab52015-09-23 17:19:27 +0530833 }
834 } else {
835 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
836 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530837 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530838 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530839 break;
840 case CHELSIO_T5:
841 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
842 wrlen);
843 INIT_TP_WR(t5req6, 0);
844 req6 = (struct cpl_act_open_req6 *)t5req6;
845 break;
846 case CHELSIO_T6:
847 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
848 wrlen);
849 INIT_TP_WR(t6req6, 0);
850 req6 = (struct cpl_act_open_req6 *)t6req6;
851 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
852 break;
853 default:
854 pr_err("T%d Chip is not supported\n",
855 CHELSIO_CHIP_VERSION(adapter_type));
856 ret = -EINVAL;
857 goto clip_release;
858 }
859
860 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
861 ((ep->rss_qid<<14)|ep->atid)));
862 req6->local_port = la6->sin6_port;
863 req6->peer_port = ra6->sin6_port;
864 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
865 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
866 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
867 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
868 req6->opt0 = cpu_to_be64(opt0);
869
870 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530871 req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
872 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530873 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530874 } else {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530875 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
876 t5req6->params =
877 cpu_to_be64(FILTER_TUPLE_V(params));
878 t5req6->rsvd = cpu_to_be32(isn);
879 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
880 t5req6->opt2 = cpu_to_be32(opt2);
881 } else {
882 t6req6->params =
883 cpu_to_be64(FILTER_TUPLE_V(params));
884 t6req6->rsvd = cpu_to_be32(isn);
885 PDBG("%s snd_isn %u\n", __func__, t6req6->rsvd);
886 t6req6->opt2 = cpu_to_be32(opt2);
887 }
888
Vipul Pandya830662f2013-07-04 16:10:47 +0530889 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000890 }
891
Vipul Pandya793dad92012-12-10 09:30:56 +0000892 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530893 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530894clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530895 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
896 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
897 (const u32 *)&la6->sin6_addr.s6_addr, 1);
898 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700899}
900
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530901static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
902 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530904 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700905 struct fw_ofld_tx_data_wr *req;
906 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530907 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700908
909 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
910
911 BUG_ON(skb_cloned(skb));
912
913 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530914 if (mpa_rev_to_use == 2)
915 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700916 wrlen = roundup(mpalen + sizeof *req, 16);
917 skb = get_skb(skb, wrlen, GFP_KERNEL);
918 if (!skb) {
919 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530920 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700921 }
922 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
923
924 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
925 memset(req, 0, wrlen);
926 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530927 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
928 FW_WR_COMPL_F |
929 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530931 FW_WR_FLOWID_V(ep->hwtid) |
932 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700933 req->plen = cpu_to_be32(mpalen);
934 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530935 FW_OFLD_TX_DATA_WR_FLUSH_F |
936 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700937
938 mpa = (struct mpa_message *)(req + 1);
939 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530940
941 mpa->flags = 0;
942 if (crc_enabled)
943 mpa->flags |= MPA_CRC;
944 if (markers_enabled) {
945 mpa->flags |= MPA_MARKERS;
946 ep->mpa_attr.recv_marker_enabled = 1;
947 } else {
948 ep->mpa_attr.recv_marker_enabled = 0;
949 }
950 if (mpa_rev_to_use == 2)
951 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
952
Steve Wisecfdda9d2010-04-21 15:30:06 -0700953 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530954 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530955 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530956 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530957 ep->retry_with_mpa_v1 = 0;
958 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700959
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530960 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700961 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
962 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530963 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
964 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 mpa_v2_params.ird = htons((u16)ep->ird);
966 mpa_v2_params.ord = htons((u16)ep->ord);
967
968 if (peer2peer) {
969 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
970 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
971 mpa_v2_params.ord |=
972 htons(MPA_V2_RDMA_WRITE_RTR);
973 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
974 mpa_v2_params.ord |=
975 htons(MPA_V2_RDMA_READ_RTR);
976 }
977 memcpy(mpa->private_data, &mpa_v2_params,
978 sizeof(struct mpa_v2_conn_params));
979
980 if (ep->plen)
981 memcpy(mpa->private_data +
982 sizeof(struct mpa_v2_conn_params),
983 ep->mpa_pkt + sizeof(*mpa), ep->plen);
984 } else
985 if (ep->plen)
986 memcpy(mpa->private_data,
987 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700988
989 /*
990 * Reference the mpa skb. This ensures the data area
991 * will remain in memory until the hw acks the tx.
992 * Function fw4_ack() will deref it.
993 */
994 skb_get(skb);
995 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
996 BUG_ON(ep->mpa_skb);
997 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530998 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
999 if (ret)
1000 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001001 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301002 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001003 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301004 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301005 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001006}
1007
1008static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1009{
1010 int mpalen, wrlen;
1011 struct fw_ofld_tx_data_wr *req;
1012 struct mpa_message *mpa;
1013 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301014 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001015
1016 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1017
1018 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301019 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1020 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001021 wrlen = roundup(mpalen + sizeof *req, 16);
1022
1023 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1024 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001025 pr_err("%s - cannot alloc skb!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001026 return -ENOMEM;
1027 }
1028 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1029
1030 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1031 memset(req, 0, wrlen);
1032 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301033 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1034 FW_WR_COMPL_F |
1035 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001036 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301037 FW_WR_FLOWID_V(ep->hwtid) |
1038 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001039 req->plen = cpu_to_be32(mpalen);
1040 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301041 FW_OFLD_TX_DATA_WR_FLUSH_F |
1042 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001043
1044 mpa = (struct mpa_message *)(req + 1);
1045 memset(mpa, 0, sizeof(*mpa));
1046 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1047 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001048 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001049 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301050
1051 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1052 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001053 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1054 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301055 mpa_v2_params.ird = htons(((u16)ep->ird) |
1056 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1057 0));
1058 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1059 (p2p_type ==
1060 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1061 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1062 FW_RI_INIT_P2PTYPE_READ_REQ ?
1063 MPA_V2_RDMA_READ_RTR : 0) : 0));
1064 memcpy(mpa->private_data, &mpa_v2_params,
1065 sizeof(struct mpa_v2_conn_params));
1066
1067 if (ep->plen)
1068 memcpy(mpa->private_data +
1069 sizeof(struct mpa_v2_conn_params), pdata, plen);
1070 } else
1071 if (plen)
1072 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001073
1074 /*
1075 * Reference the mpa skb again. This ensures the data area
1076 * will remain in memory until the hw acks the tx.
1077 * Function fw4_ack() will deref it.
1078 */
1079 skb_get(skb);
1080 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301081 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001082 BUG_ON(ep->mpa_skb);
1083 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301084 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001085 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1086}
1087
1088static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1089{
1090 int mpalen, wrlen;
1091 struct fw_ofld_tx_data_wr *req;
1092 struct mpa_message *mpa;
1093 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301094 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001095
1096 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1097
1098 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301099 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1100 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001101 wrlen = roundup(mpalen + sizeof *req, 16);
1102
1103 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1104 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001105 pr_err("%s - cannot alloc skb!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001106 return -ENOMEM;
1107 }
1108 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1109
1110 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1111 memset(req, 0, wrlen);
1112 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301113 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1114 FW_WR_COMPL_F |
1115 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001116 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301117 FW_WR_FLOWID_V(ep->hwtid) |
1118 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001119 req->plen = cpu_to_be32(mpalen);
1120 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301121 FW_OFLD_TX_DATA_WR_FLUSH_F |
1122 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123
1124 mpa = (struct mpa_message *)(req + 1);
1125 memset(mpa, 0, sizeof(*mpa));
1126 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301127 mpa->flags = 0;
1128 if (ep->mpa_attr.crc_enabled)
1129 mpa->flags |= MPA_CRC;
1130 if (ep->mpa_attr.recv_marker_enabled)
1131 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301132 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001133 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301134
1135 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1136 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001137 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1138 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301139 mpa_v2_params.ird = htons((u16)ep->ird);
1140 mpa_v2_params.ord = htons((u16)ep->ord);
1141 if (peer2peer && (ep->mpa_attr.p2p_type !=
1142 FW_RI_INIT_P2PTYPE_DISABLED)) {
1143 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1144
1145 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1146 mpa_v2_params.ord |=
1147 htons(MPA_V2_RDMA_WRITE_RTR);
1148 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1149 mpa_v2_params.ord |=
1150 htons(MPA_V2_RDMA_READ_RTR);
1151 }
1152
1153 memcpy(mpa->private_data, &mpa_v2_params,
1154 sizeof(struct mpa_v2_conn_params));
1155
1156 if (ep->plen)
1157 memcpy(mpa->private_data +
1158 sizeof(struct mpa_v2_conn_params), pdata, plen);
1159 } else
1160 if (plen)
1161 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001162
1163 /*
1164 * Reference the mpa skb. This ensures the data area
1165 * will remain in memory until the hw acks the tx.
1166 * Function fw4_ack() will deref it.
1167 */
1168 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301169 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001170 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301171 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301172 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1174}
1175
1176static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1177{
1178 struct c4iw_ep *ep;
1179 struct cpl_act_establish *req = cplhdr(skb);
1180 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001181 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301183 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001184
1185 ep = lookup_atid(t, atid);
1186
1187 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1188 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1189
Steve Wisea7db89e2014-03-21 20:40:35 +05301190 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001191 dst_confirm(ep->dst);
1192
1193 /* setup the hwtid for this connection */
1194 ep->hwtid = tid;
1195 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301196 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001197
1198 ep->snd_seq = be32_to_cpu(req->snd_isn);
1199 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1200
1201 set_emss(ep, ntohs(req->tcp_opt));
1202
1203 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001204 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001205 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001206 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001207
1208 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301209 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301210 if (ret)
1211 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301212 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301213 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301214 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301215 ret = send_mpa_req(ep, skb, mpa_rev);
1216 if (ret)
1217 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301218 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001219 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301220err:
1221 mutex_unlock(&ep->com.mutex);
1222 connect_reply_upcall(ep, -ENOMEM);
1223 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1224 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001225}
1226
Steve Wisebe13b2d2014-03-21 20:40:33 +05301227static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001228{
1229 struct iw_cm_event event;
1230
1231 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1232 memset(&event, 0, sizeof(event));
1233 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301234 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235 if (ep->com.cm_id) {
1236 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1237 ep, ep->com.cm_id, ep->hwtid);
1238 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301239 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001240 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001241 }
1242}
1243
Steve Wisecfdda9d2010-04-21 15:30:06 -07001244static void peer_close_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_DISCONNECT;
1251 if (ep->com.cm_id) {
1252 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1253 ep, ep->com.cm_id, ep->hwtid);
1254 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001255 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 }
1257}
1258
1259static void peer_abort_upcall(struct c4iw_ep *ep)
1260{
1261 struct iw_cm_event event;
1262
1263 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1264 memset(&event, 0, sizeof(event));
1265 event.event = IW_CM_EVENT_CLOSE;
1266 event.status = -ECONNRESET;
1267 if (ep->com.cm_id) {
1268 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1269 ep->com.cm_id, ep->hwtid);
1270 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301271 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001272 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001273 }
1274}
1275
1276static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1277{
1278 struct iw_cm_event event;
1279
1280 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1281 memset(&event, 0, sizeof(event));
1282 event.event = IW_CM_EVENT_CONNECT_REPLY;
1283 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301284 memcpy(&event.local_addr, &ep->com.local_addr,
1285 sizeof(ep->com.local_addr));
1286 memcpy(&event.remote_addr, &ep->com.remote_addr,
1287 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001288
1289 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301290 if (!ep->tried_with_mpa_v1) {
1291 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301292 event.ord = ep->ird;
1293 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301294 event.private_data_len = ep->plen -
1295 sizeof(struct mpa_v2_conn_params);
1296 event.private_data = ep->mpa_pkt +
1297 sizeof(struct mpa_message) +
1298 sizeof(struct mpa_v2_conn_params);
1299 } else {
1300 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301301 event.ord = cur_max_read_depth(ep->com.dev);
1302 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301303 event.private_data_len = ep->plen;
1304 event.private_data = ep->mpa_pkt +
1305 sizeof(struct mpa_message);
1306 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001307 }
Roland Dreier85963e42010-07-19 13:13:09 -07001308
1309 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1310 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001311 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001312 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1313
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301314 if (status < 0)
1315 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001316}
1317
Steve Wisebe13b2d2014-03-21 20:40:33 +05301318static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001319{
1320 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301321 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001322
1323 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1324 memset(&event, 0, sizeof(event));
1325 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301326 memcpy(&event.local_addr, &ep->com.local_addr,
1327 sizeof(ep->com.local_addr));
1328 memcpy(&event.remote_addr, &ep->com.remote_addr,
1329 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001330 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301331 if (!ep->tried_with_mpa_v1) {
1332 /* this means MPA_v2 is used */
1333 event.ord = ep->ord;
1334 event.ird = ep->ird;
1335 event.private_data_len = ep->plen -
1336 sizeof(struct mpa_v2_conn_params);
1337 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1338 sizeof(struct mpa_v2_conn_params);
1339 } else {
1340 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301341 event.ord = cur_max_read_depth(ep->com.dev);
1342 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301343 event.private_data_len = ep->plen;
1344 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1345 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301346 c4iw_get_ep(&ep->com);
1347 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1348 &event);
1349 if (ret)
1350 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001351 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001352 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301353 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001354}
1355
1356static void established_upcall(struct c4iw_ep *ep)
1357{
1358 struct iw_cm_event event;
1359
1360 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1361 memset(&event, 0, sizeof(event));
1362 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301363 event.ird = ep->ord;
1364 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365 if (ep->com.cm_id) {
1366 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1367 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001368 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001369 }
1370}
1371
1372static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1373{
Steve Wisecfdda9d2010-04-21 15:30:06 -07001374 struct sk_buff *skb;
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301375 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1376 u32 credit_dack;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001377
1378 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1379 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1380 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001381 pr_err("update_rx_credits - cannot alloc skb!\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382 return 0;
1383 }
1384
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301385 /*
1386 * If we couldn't specify the entire rcv window at connection setup
1387 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1388 * then add the overage in to the credits returned.
1389 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001390 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1391 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301392
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301393 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1394 RX_DACK_MODE_V(dack_mode);
1395
1396 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1397 credit_dack);
1398
Steve Wisecfdda9d2010-04-21 15:30:06 -07001399 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1400 return credits;
1401}
1402
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301403#define RELAXED_IRD_NEGOTIATION 1
1404
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301405/*
1406 * process_mpa_reply - process streaming mode MPA reply
1407 *
1408 * Returns:
1409 *
1410 * 0 upon success indicating a connect request was delivered to the ULP
1411 * or the mpa request is incomplete but valid so far.
1412 *
1413 * 1 if a failure requires the caller to close the connection.
1414 *
1415 * 2 if a failure requires the caller to abort the connection.
1416 */
Steve Wisecc18b932014-04-24 14:31:53 -05001417static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001418{
1419 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301420 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001421 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301422 u16 resp_ird, resp_ord;
1423 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001424 struct c4iw_qp_attributes attrs;
1425 enum c4iw_qp_attr_mask mask;
1426 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001427 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001428
1429 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1430
1431 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001432 * If we get more than the supported amount of private data
1433 * then we must fail this connection.
1434 */
1435 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1436 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301437 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001438 }
1439
1440 /*
1441 * copy the new data into our accumulation buffer.
1442 */
1443 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1444 skb->len);
1445 ep->mpa_pkt_len += skb->len;
1446
1447 /*
1448 * if we don't even have the mpa message, then bail.
1449 */
1450 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001451 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001452 mpa = (struct mpa_message *) ep->mpa_pkt;
1453
1454 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301455 if (mpa->revision > mpa_rev) {
Joe Perches700456b2017-02-09 14:23:50 -08001456 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1457 __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001458 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301459 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001460 }
1461 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1462 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301463 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001464 }
1465
1466 plen = ntohs(mpa->private_data_size);
1467
1468 /*
1469 * Fail if there's too much private data.
1470 */
1471 if (plen > MPA_MAX_PRIVATE_DATA) {
1472 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301473 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001474 }
1475
1476 /*
1477 * If plen does not account for pkt size
1478 */
1479 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1480 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301481 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001482 }
1483
1484 ep->plen = (u8) plen;
1485
1486 /*
1487 * If we don't have all the pdata yet, then bail.
1488 * We'll continue process when more data arrives.
1489 */
1490 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001491 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001492
1493 if (mpa->flags & MPA_REJECT) {
1494 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301495 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001496 }
1497
1498 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301499 * Stop mpa timer. If it expired, then
1500 * we ignore the MPA reply. process_timeout()
1501 * will abort the connection.
1502 */
1503 if (stop_ep_timer(ep))
1504 return 0;
1505
1506 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001507 * If we get here we have accumulated the entire mpa
1508 * start reply message including private data. And
1509 * the MPA header is valid.
1510 */
Steve Wisec529fb52014-03-21 20:40:37 +05301511 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001512 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001513 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301514 ep->mpa_attr.version = mpa->revision;
1515 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1516
1517 if (mpa->revision == 2) {
1518 ep->mpa_attr.enhanced_rdma_conn =
1519 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1520 if (ep->mpa_attr.enhanced_rdma_conn) {
1521 mpa_v2_params = (struct mpa_v2_conn_params *)
1522 (ep->mpa_pkt + sizeof(*mpa));
1523 resp_ird = ntohs(mpa_v2_params->ird) &
1524 MPA_V2_IRD_ORD_MASK;
1525 resp_ord = ntohs(mpa_v2_params->ord) &
1526 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301527 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1528 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301529
1530 /*
1531 * This is a double-check. Ideally, below checks are
1532 * not required since ird/ord stuff has been taken
1533 * care of in c4iw_accept_cr
1534 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301535 if (ep->ird < resp_ord) {
1536 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1537 ep->com.dev->rdev.lldi.max_ordird_qp)
1538 ep->ird = resp_ord;
1539 else
1540 insuff_ird = 1;
1541 } else if (ep->ird > resp_ord) {
1542 ep->ird = resp_ord;
1543 }
1544 if (ep->ord > resp_ird) {
1545 if (RELAXED_IRD_NEGOTIATION)
1546 ep->ord = resp_ird;
1547 else
1548 insuff_ird = 1;
1549 }
1550 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301551 err = -ENOMEM;
1552 ep->ird = resp_ord;
1553 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301554 }
1555
1556 if (ntohs(mpa_v2_params->ird) &
1557 MPA_V2_PEER2PEER_MODEL) {
1558 if (ntohs(mpa_v2_params->ord) &
1559 MPA_V2_RDMA_WRITE_RTR)
1560 ep->mpa_attr.p2p_type =
1561 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1562 else if (ntohs(mpa_v2_params->ord) &
1563 MPA_V2_RDMA_READ_RTR)
1564 ep->mpa_attr.p2p_type =
1565 FW_RI_INIT_P2PTYPE_READ_REQ;
1566 }
1567 }
1568 } else if (mpa->revision == 1)
1569 if (peer2peer)
1570 ep->mpa_attr.p2p_type = p2p_type;
1571
Steve Wisecfdda9d2010-04-21 15:30:06 -07001572 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301573 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1574 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1575 ep->mpa_attr.recv_marker_enabled,
1576 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1577 ep->mpa_attr.p2p_type, p2p_type);
1578
1579 /*
1580 * If responder's RTR does not match with that of initiator, assign
1581 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1582 * generated when moving QP to RTS state.
1583 * A TERM message will be sent after QP has moved to RTS state
1584 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001585 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301586 (ep->mpa_attr.p2p_type != p2p_type)) {
1587 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1588 rtr_mismatch = 1;
1589 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001590
1591 attrs.mpa_attr = ep->mpa_attr;
1592 attrs.max_ird = ep->ird;
1593 attrs.max_ord = ep->ord;
1594 attrs.llp_stream_handle = ep;
1595 attrs.next_state = C4IW_QP_STATE_RTS;
1596
1597 mask = C4IW_QP_ATTR_NEXT_STATE |
1598 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1599 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1600
1601 /* bind QP and TID with INIT_WR */
1602 err = c4iw_modify_qp(ep->com.qp->rhp,
1603 ep->com.qp, mask, &attrs, 1);
1604 if (err)
1605 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301606
1607 /*
1608 * If responder's RTR requirement did not match with what initiator
1609 * supports, generate TERM message
1610 */
1611 if (rtr_mismatch) {
Joe Perches700456b2017-02-09 14:23:50 -08001612 pr_err("%s: RTR mismatch, sending TERM\n", __func__);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301613 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1614 attrs.ecode = MPA_NOMATCH_RTR;
1615 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001616 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301617 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001618 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001620 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301621 goto out;
1622 }
1623
1624 /*
1625 * Generate TERM if initiator IRD is not sufficient for responder
1626 * provided ORD. Currently, we do the same behaviour even when
1627 * responder provided IRD is also not sufficient as regards to
1628 * initiator ORD.
1629 */
1630 if (insuff_ird) {
Joe Perches700456b2017-02-09 14:23:50 -08001631 pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301632 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1633 attrs.ecode = MPA_INSUFF_IRD;
1634 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001635 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301636 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001637 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301638 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001639 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301640 goto out;
1641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001642 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301643err_stop_timer:
1644 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001645err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301646 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001647out:
1648 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001649 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001650}
1651
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301652/*
1653 * process_mpa_request - process streaming mode MPA request
1654 *
1655 * Returns:
1656 *
1657 * 0 upon success indicating a connect request was delivered to the ULP
1658 * or the mpa request is incomplete but valid so far.
1659 *
1660 * 1 if a failure requires the caller to close the connection.
1661 *
1662 * 2 if a failure requires the caller to abort the connection.
1663 */
1664static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665{
1666 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301667 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668 u16 plen;
1669
1670 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1671
Steve Wisecfdda9d2010-04-21 15:30:06 -07001672 /*
1673 * If we get more than the supported amount of private data
1674 * then we must fail this connection.
1675 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301676 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1677 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678
1679 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1680
1681 /*
1682 * Copy the new data into our accumulation buffer.
1683 */
1684 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1685 skb->len);
1686 ep->mpa_pkt_len += skb->len;
1687
1688 /*
1689 * If we don't even have the mpa message, then bail.
1690 * We'll continue process when more data arrives.
1691 */
1692 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301693 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001694
1695 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696 mpa = (struct mpa_message *) ep->mpa_pkt;
1697
1698 /*
1699 * Validate MPA Header.
1700 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301701 if (mpa->revision > mpa_rev) {
Joe Perches700456b2017-02-09 14:23:50 -08001702 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1703 __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301704 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001705 }
1706
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301707 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1708 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709
1710 plen = ntohs(mpa->private_data_size);
1711
1712 /*
1713 * Fail if there's too much private data.
1714 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301715 if (plen > MPA_MAX_PRIVATE_DATA)
1716 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001717
1718 /*
1719 * If plen does not account for pkt size
1720 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301721 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1722 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001723 ep->plen = (u8) plen;
1724
1725 /*
1726 * If we don't have all the pdata yet, then bail.
1727 */
1728 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301729 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001730
1731 /*
1732 * If we get here we have accumulated the entire mpa
1733 * start reply message including private data.
1734 */
1735 ep->mpa_attr.initiator = 0;
1736 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1737 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1738 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301739 ep->mpa_attr.version = mpa->revision;
1740 if (mpa->revision == 1)
1741 ep->tried_with_mpa_v1 = 1;
1742 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1743
1744 if (mpa->revision == 2) {
1745 ep->mpa_attr.enhanced_rdma_conn =
1746 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1747 if (ep->mpa_attr.enhanced_rdma_conn) {
1748 mpa_v2_params = (struct mpa_v2_conn_params *)
1749 (ep->mpa_pkt + sizeof(*mpa));
1750 ep->ird = ntohs(mpa_v2_params->ird) &
1751 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001752 ep->ird = min_t(u32, ep->ird,
1753 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301754 ep->ord = ntohs(mpa_v2_params->ord) &
1755 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001756 ep->ord = min_t(u32, ep->ord,
1757 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301758 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1759 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301760 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1761 if (peer2peer) {
1762 if (ntohs(mpa_v2_params->ord) &
1763 MPA_V2_RDMA_WRITE_RTR)
1764 ep->mpa_attr.p2p_type =
1765 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1766 else if (ntohs(mpa_v2_params->ord) &
1767 MPA_V2_RDMA_READ_RTR)
1768 ep->mpa_attr.p2p_type =
1769 FW_RI_INIT_P2PTYPE_READ_REQ;
1770 }
1771 }
1772 } else if (mpa->revision == 1)
1773 if (peer2peer)
1774 ep->mpa_attr.p2p_type = p2p_type;
1775
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1777 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1778 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1779 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1780 ep->mpa_attr.p2p_type);
1781
Hariprasad Se4b76a22016-05-06 22:17:59 +05301782 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001783
Hariprasad Se4b76a22016-05-06 22:17:59 +05301784 /* drive upcall */
1785 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1786 if (ep->parent_ep->com.state != DEAD) {
1787 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301788 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301789 } else {
1790 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301791 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301792 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301793 return 0;
1794
1795err_unlock_parent:
1796 mutex_unlock(&ep->parent_ep->com.mutex);
1797 goto err_out;
1798err_stop_timer:
1799 (void)stop_ep_timer(ep);
1800err_out:
1801 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802}
1803
1804static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1805{
1806 struct c4iw_ep *ep;
1807 struct cpl_rx_data *hdr = cplhdr(skb);
1808 unsigned int dlen = ntohs(hdr->len);
1809 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001810 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001811 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812
Hariprasad S944661d2016-05-06 22:18:03 +05301813 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301814 if (!ep)
1815 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001816 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1817 skb_pull(skb, sizeof(*hdr));
1818 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301819 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820
Steve Wisec529fb52014-03-21 20:40:37 +05301821 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001822 case MPA_REQ_SENT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001823 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001824 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001825 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001826 break;
1827 case MPA_REQ_WAIT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001828 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001829 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301830 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001832 case FPDU_MODE: {
1833 struct c4iw_qp_attributes attrs;
Steve Wise3bcf96e2016-12-22 07:40:37 -08001834
1835 update_rx_credits(ep, dlen);
Vipul Pandya15579672013-01-07 13:11:52 +00001836 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001837 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001838 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001839 " qpid %u ep %p state %d tid %u status %d\n",
1840 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301841 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301842 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001843 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001844 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1845 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001846 break;
1847 }
Vipul Pandya15579672013-01-07 13:11:52 +00001848 default:
1849 break;
1850 }
Steve Wisec529fb52014-03-21 20:40:37 +05301851 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001852 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301853 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301854 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855 return 0;
1856}
1857
1858static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1859{
1860 struct c4iw_ep *ep;
1861 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001862 int release = 0;
1863 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001864
Hariprasad S944661d2016-05-06 22:18:03 +05301865 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301866 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08001867 pr_warn("Abort rpl to freed endpoint\n");
Vipul Pandya49840372012-05-18 15:29:29 +05301868 return 0;
1869 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001870 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001871 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001872 switch (ep->com.state) {
1873 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001874 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001875 __state_set(&ep->com, DEAD);
1876 release = 1;
1877 break;
1878 default:
Joe Perches700456b2017-02-09 14:23:50 -08001879 pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001880 break;
1881 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001882 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001883
1884 if (release)
1885 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301886 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001887 return 0;
1888}
1889
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301890static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001891{
1892 struct sk_buff *skb;
1893 struct fw_ofld_connection_wr *req;
1894 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301895 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301896 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301897 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001898
1899 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1900 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1901 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001902 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301903 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301904 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1905 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001906 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001907 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301908 req->le.lport = sin->sin_port;
1909 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001910 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301911 req->le.pport = sin->sin_port;
1912 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001913 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301914 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1915 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001916 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301917 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001918 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001919 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301920 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1921 enable_tcp_timestamps,
1922 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301923 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301924
1925 /*
1926 * Specify the largest window that will fit in opt0. The
1927 * remainder will be specified in the rx_data_ack.
1928 */
1929 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001930 if (win > RCV_BUFSIZ_M)
1931 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301932
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001933 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1934 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001935 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001936 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001937 WND_SCALE_V(wscale) |
1938 MSS_IDX_V(mtu_idx) |
1939 L2T_IDX_V(ep->l2t->idx) |
1940 TX_CHAN_V(ep->tx_chan) |
1941 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301942 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001943 ULP_MODE_V(ULP_MODE_TCPDDP) |
1944 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001945 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1946 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001947 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001948 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001949 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001950 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001951 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001952 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001953 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001954 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001955 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1956 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1957 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001958 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1959 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301960 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001961}
1962
Steve Wisecfdda9d2010-04-21 15:30:06 -07001963/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301964 * Some of the error codes above implicitly indicate that there is no TID
1965 * allocated with the result of an ACT_OPEN. We use this predicate to make
1966 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001967 */
1968static inline int act_open_has_tid(int status)
1969{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301970 return (status != CPL_ERR_TCAM_PARITY &&
1971 status != CPL_ERR_TCAM_MISS &&
1972 status != CPL_ERR_TCAM_FULL &&
1973 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1974 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001975}
1976
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301977static char *neg_adv_str(unsigned int status)
1978{
1979 switch (status) {
1980 case CPL_ERR_RTX_NEG_ADVICE:
1981 return "Retransmit timeout";
1982 case CPL_ERR_PERSIST_NEG_ADVICE:
1983 return "Persist timeout";
1984 case CPL_ERR_KEEPALV_NEG_ADVICE:
1985 return "Keepalive timeout";
1986 default:
1987 return "Unknown";
1988 }
1989}
1990
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301991static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1992{
1993 ep->snd_win = snd_win;
1994 ep->rcv_win = rcv_win;
1995 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1996}
1997
Vipul Pandya793dad92012-12-10 09:30:56 +00001998#define ACT_OPEN_RETRY_COUNT 2
1999
Vipul Pandya830662f2013-07-04 16:10:47 +05302000static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2001 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302002 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302003{
2004 struct neighbour *n;
2005 int err, step;
2006 struct net_device *pdev;
2007
2008 n = dst_neigh_lookup(dst, peer_ip);
2009 if (!n)
2010 return -ENODEV;
2011
2012 rcu_read_lock();
2013 err = -ENOMEM;
2014 if (n->dev->flags & IFF_LOOPBACK) {
2015 if (iptype == 4)
2016 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2017 else if (IS_ENABLED(CONFIG_IPV6))
2018 for_each_netdev(&init_net, pdev) {
2019 if (ipv6_chk_addr(&init_net,
2020 (struct in6_addr *)peer_ip,
2021 pdev, 1))
2022 break;
2023 }
2024 else
2025 pdev = NULL;
2026
2027 if (!pdev) {
2028 err = -ENODEV;
2029 goto out;
2030 }
2031 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302032 n, pdev, rt_tos2priority(tos));
Steve Wise609e9412016-09-01 06:43:46 -07002033 if (!ep->l2t) {
2034 dev_put(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302035 goto out;
Steve Wise609e9412016-09-01 06:43:46 -07002036 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302037 ep->mtu = pdev->mtu;
2038 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302039 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2040 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302041 step = cdev->rdev.lldi.ntxq /
2042 cdev->rdev.lldi.nchan;
2043 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2044 step = cdev->rdev.lldi.nrxq /
2045 cdev->rdev.lldi.nchan;
2046 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2047 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2048 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302049 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302050 dev_put(pdev);
2051 } else {
2052 pdev = get_real_dev(n->dev);
2053 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2054 n, pdev, 0);
2055 if (!ep->l2t)
2056 goto out;
2057 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002058 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302059 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2060 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302061 step = cdev->rdev.lldi.ntxq /
2062 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002063 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2064 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302065 step = cdev->rdev.lldi.nrxq /
2066 cdev->rdev.lldi.nchan;
2067 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002068 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302069 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302070
2071 if (clear_mpa_v1) {
2072 ep->retry_with_mpa_v1 = 0;
2073 ep->tried_with_mpa_v1 = 0;
2074 }
2075 }
2076 err = 0;
2077out:
2078 rcu_read_unlock();
2079
2080 neigh_release(n);
2081
2082 return err;
2083}
2084
Vipul Pandya793dad92012-12-10 09:30:56 +00002085static int c4iw_reconnect(struct c4iw_ep *ep)
2086{
2087 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302088 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302089 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002090 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302091 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002092 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302093 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002094 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302095 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002096 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302097 int iptype;
2098 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002099
2100 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2101 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302102 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002103
Hariprasad S4a740832016-06-10 01:05:15 +05302104 /* When MPA revision is different on nodes, the node with MPA_rev=2
2105 * tries to reconnect with MPA_rev 1 for the same EP through
2106 * c4iw_reconnect(), where the same EP is assigned with new tid for
2107 * further connection establishment. As we are using the same EP pointer
2108 * for reconnect, few skbs are used during the previous c4iw_connect(),
2109 * which leaves the EP with inadequate skbs for further
2110 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2111 * skb_list() during peer_abort(). Allocate skbs which is already used.
2112 */
2113 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2114 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2115 err = -ENOMEM;
2116 goto fail1;
2117 }
2118
Vipul Pandya793dad92012-12-10 09:30:56 +00002119 /*
2120 * Allocate an active TID to initiate a TCP connection.
2121 */
2122 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2123 if (ep->atid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08002124 pr_err("%s - cannot alloc atid\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002125 err = -ENOMEM;
2126 goto fail2;
2127 }
2128 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2129
2130 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002131 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302132 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2133 laddr->sin_addr.s_addr,
2134 raddr->sin_addr.s_addr,
2135 laddr->sin_port,
2136 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302137 iptype = 4;
2138 ra = (__u8 *)&raddr->sin_addr;
2139 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302140 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2141 get_real_dev,
2142 laddr6->sin6_addr.s6_addr,
2143 raddr6->sin6_addr.s6_addr,
2144 laddr6->sin6_port,
2145 raddr6->sin6_port, 0,
2146 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302147 iptype = 6;
2148 ra = (__u8 *)&raddr6->sin6_addr;
2149 }
2150 if (!ep->dst) {
Joe Perches700456b2017-02-09 14:23:50 -08002151 pr_err("%s - cannot find route\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002152 err = -EHOSTUNREACH;
2153 goto fail3;
2154 }
Hariprasad S963cab52015-09-23 17:19:27 +05302155 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302156 ep->com.dev->rdev.lldi.adapter_type,
2157 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302158 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08002159 pr_err("%s - cannot alloc l2e\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002160 goto fail4;
2161 }
2162
2163 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2164 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2165 ep->l2t->idx);
2166
2167 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302168 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002169
2170 /* send connect request to rnic */
2171 err = send_connect(ep);
2172 if (!err)
2173 goto out;
2174
2175 cxgb4_l2t_release(ep->l2t);
2176fail4:
2177 dst_release(ep->dst);
2178fail3:
2179 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2180 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2181fail2:
2182 /*
2183 * remember to send notification to upper layer.
2184 * We are in here so the upper layer is not aware that this is
2185 * re-connect attempt and so, upper layer is still waiting for
2186 * response of 1st connect request.
2187 */
2188 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302189fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002190 c4iw_put_ep(&ep->com);
2191out:
2192 return err;
2193}
2194
Steve Wisecfdda9d2010-04-21 15:30:06 -07002195static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2196{
2197 struct c4iw_ep *ep;
2198 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002199 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2200 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002201 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002202 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302203 struct sockaddr_in *la;
2204 struct sockaddr_in *ra;
2205 struct sockaddr_in6 *la6;
2206 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302207 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002208
2209 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002210 la = (struct sockaddr_in *)&ep->com.local_addr;
2211 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2212 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2213 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002214
2215 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2216 status, status2errno(status));
2217
Varun Prakashb65eef02016-09-13 21:23:59 +05302218 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302219 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2220 __func__, atid, status, neg_adv_str(status));
2221 ep->stats.connect_neg_adv++;
2222 mutex_lock(&dev->rdev.stats.lock);
2223 dev->rdev.stats.neg_adv++;
2224 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002225 return 0;
2226 }
2227
Vipul Pandya793dad92012-12-10 09:30:56 +00002228 set_bit(ACT_OPEN_RPL, &ep->com.history);
2229
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302230 /*
2231 * Log interesting failures.
2232 */
2233 switch (status) {
2234 case CPL_ERR_CONN_RESET:
2235 case CPL_ERR_CONN_TIMEDOUT:
2236 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002237 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302238 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002239 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302240 mutex_unlock(&dev->rdev.stats.lock);
2241 if (ep->com.local_addr.ss_family == AF_INET &&
2242 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302243 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2244 ntohl(rpl->atid_status))));
2245 if (ret)
2246 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002247 return 0;
2248 }
2249 break;
2250 case CPL_ERR_CONN_EXIST:
2251 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2252 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302253 if (ep->com.remote_addr.ss_family == AF_INET6) {
2254 struct sockaddr_in6 *sin6 =
2255 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002256 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302257 cxgb4_clip_release(
2258 ep->com.dev->rdev.lldi.ports[0],
2259 (const u32 *)
2260 &sin6->sin6_addr.s6_addr, 1);
2261 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002262 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2263 atid);
2264 cxgb4_free_atid(t, atid);
2265 dst_release(ep->dst);
2266 cxgb4_l2t_release(ep->l2t);
2267 c4iw_reconnect(ep);
2268 return 0;
2269 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002270 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302271 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302272 if (ep->com.local_addr.ss_family == AF_INET) {
2273 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2274 atid, status, status2errno(status),
2275 &la->sin_addr.s_addr, ntohs(la->sin_port),
2276 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2277 } else {
2278 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2279 atid, status, status2errno(status),
2280 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2281 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2282 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302283 break;
2284 }
2285
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302286fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002287 connect_reply_upcall(ep, status2errno(status));
2288 state_set(&ep->com, DEAD);
2289
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302290 if (ep->com.remote_addr.ss_family == AF_INET6) {
2291 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002292 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302293 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2294 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2295 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002296 if (status && act_open_has_tid(status))
2297 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2298
Vipul Pandya793dad92012-12-10 09:30:56 +00002299 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002300 cxgb4_free_atid(t, atid);
2301 dst_release(ep->dst);
2302 cxgb4_l2t_release(ep->l2t);
2303 c4iw_put_ep(&ep->com);
2304
2305 return 0;
2306}
2307
2308static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2309{
2310 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302312 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313
2314 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002315 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2316 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317 }
2318 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2319 rpl->status, status2errno(rpl->status));
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);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002322out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323 return 0;
2324}
2325
Steve Wisecfdda9d2010-04-21 15:30:06 -07002326static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2327{
2328 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002329 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302330 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331
2332 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002333 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302334 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002335 return 0;
2336}
2337
Hariprasad S9dec9002016-05-05 01:27:29 +05302338static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2339 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340{
2341 struct cpl_pass_accept_rpl *rpl;
2342 unsigned int mtu_idx;
2343 u64 opt0;
2344 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302345 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302346 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302347 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302348 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349
2350 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2351 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302352
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302354 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302355 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302356 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2357 rpl5 = (void *)rpl;
2358 INIT_TP_WR(rpl5, ep->hwtid);
2359 } else {
2360 skb_trim(skb, sizeof(*rpl));
2361 INIT_TP_WR(rpl, ep->hwtid);
2362 }
2363 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2364 ep->hwtid));
2365
Varun Prakash44c6d062016-09-13 21:24:00 +05302366 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2367 enable_tcp_timestamps && req->tcpopt.tstamp,
2368 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302369 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302370
2371 /*
2372 * Specify the largest window that will fit in opt0. The
2373 * remainder will be specified in the rx_data_ack.
2374 */
2375 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002376 if (win > RCV_BUFSIZ_M)
2377 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002378 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002379 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002380 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002381 WND_SCALE_V(wscale) |
2382 MSS_IDX_V(mtu_idx) |
2383 L2T_IDX_V(ep->l2t->idx) |
2384 TX_CHAN_V(ep->tx_chan) |
2385 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002386 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002387 ULP_MODE_V(ULP_MODE_TCPDDP) |
2388 RCV_BUFSIZ_V(win);
2389 opt2 = RX_CHANNEL_V(0) |
2390 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391
2392 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002393 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002394 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002395 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002396 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002397 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002398 if (enable_ecn) {
2399 const struct tcphdr *tcph;
2400 u32 hlen = ntohl(req->hdr_len);
2401
Hariprasad S963cab52015-09-23 17:19:27 +05302402 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2403 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2404 IP_HDR_LEN_G(hlen);
2405 else
2406 tcph = (const void *)(req + 1) +
2407 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002408 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002409 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002410 }
Hariprasad S963cab52015-09-23 17:19:27 +05302411 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302412 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002413 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302414 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302415 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302416 rpl5 = (void *)rpl;
2417 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2418 if (peer2peer)
2419 isn += 4;
2420 rpl5->iss = cpu_to_be32(isn);
2421 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002422 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423
Steve Wisecfdda9d2010-04-21 15:30:06 -07002424 rpl->opt0 = cpu_to_be64(opt0);
2425 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002426 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302427 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428
Hariprasad S9dec9002016-05-05 01:27:29 +05302429 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430}
2431
Vipul Pandya830662f2013-07-04 16:10:47 +05302432static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433{
Vipul Pandya830662f2013-07-04 16:10:47 +05302434 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 BUG_ON(skb_cloned(skb));
2436 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437 release_tid(&dev->rdev, hwtid, skb);
2438 return;
2439}
2440
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2442{
Vipul Pandya793dad92012-12-10 09:30:56 +00002443 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002444 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002445 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002446 struct tid_info *t = dev->rdev.lldi.tids;
2447 unsigned int hwtid = GET_TID(req);
2448 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302451 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002452 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002453 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302454 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302455 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302456 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457
Hariprasad Sf86fac72016-05-06 22:18:07 +05302458 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002459 if (!parent_ep) {
2460 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2461 goto reject;
2462 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002463
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302465 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 goto reject;
2467 }
2468
Varun Prakash85e42b02016-09-13 21:23:56 +05302469 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2470 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302471
Steve Wisecfdda9d2010-04-21 15:30:06 -07002472 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302473 if (iptype == 4) {
2474 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2475 , __func__, parent_ep, hwtid,
2476 local_ip, peer_ip, ntohs(local_port),
2477 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302478 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2479 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2480 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302481 } else {
2482 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2483 , __func__, parent_ep, hwtid,
2484 local_ip, peer_ip, ntohs(local_port),
2485 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302486 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2487 local_ip, peer_ip, local_port, peer_port,
2488 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2489 ((struct sockaddr_in6 *)
2490 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302491 }
2492 if (!dst) {
Joe Perches700456b2017-02-09 14:23:50 -08002493 pr_err("%s - failed to find dst entry!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002494 goto reject;
2495 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002496
2497 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2498 if (!child_ep) {
Joe Perches700456b2017-02-09 14:23:50 -08002499 pr_err("%s - failed to allocate ep entry!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002500 dst_release(dst);
2501 goto reject;
2502 }
David Miller3786cf12011-12-02 16:52:31 +00002503
Hariprasad S963cab52015-09-23 17:19:27 +05302504 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302505 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002506 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08002507 pr_err("%s - failed to allocate l2t entry!\n", __func__);
David Miller3786cf12011-12-02 16:52:31 +00002508 dst_release(dst);
2509 kfree(child_ep);
2510 goto reject;
2511 }
2512
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302513 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2514 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2515 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2516 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002517
Hariprasad S4a740832016-06-10 01:05:15 +05302518 skb_queue_head_init(&child_ep->com.ep_skb_list);
2519 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2520 goto fail;
2521
Steve Wisecfdda9d2010-04-21 15:30:06 -07002522 state_set(&child_ep->com, CONNECTING);
2523 child_ep->com.dev = dev;
2524 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002525
Vipul Pandya830662f2013-07-04 16:10:47 +05302526 if (iptype == 4) {
2527 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002528 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002529
ssh10b462b062016-12-24 07:14:35 +05302530 sin->sin_family = AF_INET;
Vipul Pandya830662f2013-07-04 16:10:47 +05302531 sin->sin_port = local_port;
2532 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002533
2534 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
ssh10b462b062016-12-24 07:14:35 +05302535 sin->sin_family = AF_INET;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002536 sin->sin_port = ((struct sockaddr_in *)
2537 &parent_ep->com.local_addr)->sin_port;
2538 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2539
Steve Wise170003c2016-02-26 09:18:03 -06002540 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
ssh10b462b062016-12-24 07:14:35 +05302541 sin->sin_family = AF_INET;
Vipul Pandya830662f2013-07-04 16:10:47 +05302542 sin->sin_port = peer_port;
2543 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2544 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002545 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302546 sin6->sin6_family = PF_INET6;
2547 sin6->sin6_port = local_port;
2548 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002549
2550 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2551 sin6->sin6_family = PF_INET6;
2552 sin6->sin6_port = ((struct sockaddr_in6 *)
2553 &parent_ep->com.local_addr)->sin6_port;
2554 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2555
Steve Wise170003c2016-02-26 09:18:03 -06002556 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302557 sin6->sin6_family = PF_INET6;
2558 sin6->sin6_port = peer_port;
2559 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2560 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002561
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 c4iw_get_ep(&parent_ep->com);
2563 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302564 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565 child_ep->dst = dst;
2566 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567
2568 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002569 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570
2571 init_timer(&child_ep->timer);
2572 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302573 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302574 if (accept_cr(child_ep, skb, req)) {
2575 c4iw_put_ep(&parent_ep->com);
2576 release_ep_resources(child_ep);
2577 } else {
2578 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2579 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302580 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002581 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302582 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2583 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2584 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302586fail:
2587 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302589 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302590 if (parent_ep)
2591 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002592out:
2593 return 0;
2594}
2595
2596static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2597{
2598 struct c4iw_ep *ep;
2599 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302601 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602
Hariprasad S944661d2016-05-06 22:18:03 +05302603 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2605 ep->snd_seq = be32_to_cpu(req->snd_isn);
2606 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2607
Vipul Pandya1cab7752012-12-10 09:30:55 +00002608 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2609 ntohs(req->tcp_opt));
2610
Steve Wisecfdda9d2010-04-21 15:30:06 -07002611 set_emss(ep, ntohs(req->tcp_opt));
2612
2613 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302614 mutex_lock(&ep->com.mutex);
2615 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002617 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302618 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302619 mutex_unlock(&ep->com.mutex);
2620 if (ret)
2621 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302622 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623
2624 return 0;
2625}
2626
2627static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2628{
2629 struct cpl_peer_close *hdr = cplhdr(skb);
2630 struct c4iw_ep *ep;
2631 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002632 int disconnect = 1;
2633 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002635 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636
Hariprasad S944661d2016-05-06 22:18:03 +05302637 ep = get_ep_from_tid(dev, tid);
2638 if (!ep)
2639 return 0;
2640
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2642 dst_confirm(ep->dst);
2643
Vipul Pandya793dad92012-12-10 09:30:56 +00002644 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002645 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 switch (ep->com.state) {
2647 case MPA_REQ_WAIT:
2648 __state_set(&ep->com, CLOSING);
2649 break;
2650 case MPA_REQ_SENT:
2651 __state_set(&ep->com, CLOSING);
2652 connect_reply_upcall(ep, -ECONNRESET);
2653 break;
2654 case MPA_REQ_RCVD:
2655
2656 /*
2657 * We're gonna mark this puppy DEAD, but keep
2658 * the reference on it until the ULP accepts or
2659 * rejects the CR. Also wake up anyone waiting
2660 * in rdma connection migration (see c4iw_accept_cr()).
2661 */
2662 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002664 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665 break;
2666 case MPA_REP_SENT:
2667 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002669 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 break;
2671 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002672 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002674 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002675 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002676 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002677 if (ret != -ECONNRESET) {
2678 peer_close_upcall(ep);
2679 disconnect = 1;
2680 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 break;
2682 case ABORTING:
2683 disconnect = 0;
2684 break;
2685 case CLOSING:
2686 __state_set(&ep->com, MORIBUND);
2687 disconnect = 0;
2688 break;
2689 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002690 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 if (ep->com.cm_id && ep->com.qp) {
2692 attrs.next_state = C4IW_QP_STATE_IDLE;
2693 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2694 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2695 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302696 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 __state_set(&ep->com, DEAD);
2698 release = 1;
2699 disconnect = 0;
2700 break;
2701 case DEAD:
2702 disconnect = 0;
2703 break;
2704 default:
2705 BUG_ON(1);
2706 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002707 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708 if (disconnect)
2709 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2710 if (release)
2711 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302712 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002713 return 0;
2714}
2715
Steve Wisecfdda9d2010-04-21 15:30:06 -07002716static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2717{
2718 struct cpl_abort_req_rss *req = cplhdr(skb);
2719 struct c4iw_ep *ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 struct sk_buff *rpl_skb;
2721 struct c4iw_qp_attributes attrs;
2722 int ret;
2723 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724 unsigned int tid = GET_TID(req);
Varun Prakash052f4732016-09-13 21:24:05 +05302725 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002726
Hariprasad S944661d2016-05-06 22:18:03 +05302727 ep = get_ep_from_tid(dev, tid);
2728 if (!ep)
2729 return 0;
2730
Varun Prakashb65eef02016-09-13 21:23:59 +05302731 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302732 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2733 __func__, ep->hwtid, req->status,
2734 neg_adv_str(req->status));
2735 ep->stats.abort_neg_adv++;
2736 mutex_lock(&dev->rdev.stats.lock);
2737 dev->rdev.stats.neg_adv++;
2738 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302739 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002741 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2742 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002743 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002744
2745 /*
2746 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302747 * However, this is not needed if com state is just
2748 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002749 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302750 if (ep->com.state != MPA_REQ_SENT)
2751 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002752
2753 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 switch (ep->com.state) {
2755 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302756 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 break;
2758 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002759 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760 break;
2761 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002762 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002763 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302764 connect_reply_upcall(ep, -ECONNRESET);
2765 else {
2766 /*
2767 * we just don't send notification upwards because we
2768 * want to retry with mpa_v1 without upper layers even
2769 * knowing it.
2770 *
2771 * do some housekeeping so as to re-initiate the
2772 * connection
2773 */
2774 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2775 mpa_rev);
2776 ep->retry_with_mpa_v1 = 1;
2777 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778 break;
2779 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 break;
2781 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002782 break;
2783 case MORIBUND:
2784 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002785 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002786 /*FALLTHROUGH*/
2787 case FPDU_MODE:
2788 if (ep->com.cm_id && ep->com.qp) {
2789 attrs.next_state = C4IW_QP_STATE_ERROR;
2790 ret = c4iw_modify_qp(ep->com.qp->rhp,
2791 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2792 &attrs, 1);
2793 if (ret)
Joe Perches700456b2017-02-09 14:23:50 -08002794 pr_err("%s - qp <- error failed!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002795 }
2796 peer_abort_upcall(ep);
2797 break;
2798 case ABORTING:
2799 break;
2800 case DEAD:
2801 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002802 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302803 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002804 default:
2805 BUG_ON(1);
2806 break;
2807 }
2808 dst_confirm(ep->dst);
2809 if (ep->com.state != ABORTING) {
2810 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302811 /* we don't release if we want to retry with mpa_v1 */
2812 if (!ep->retry_with_mpa_v1)
2813 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002815 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816
Hariprasad S4a740832016-06-10 01:05:15 +05302817 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2818 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002819 release = 1;
2820 goto out;
2821 }
Varun Prakash052f4732016-09-13 21:24:05 +05302822
2823 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2824
Steve Wisecfdda9d2010-04-21 15:30:06 -07002825 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2826out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002827 if (release)
2828 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002829 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302830 if (ep->com.remote_addr.ss_family == AF_INET6) {
2831 struct sockaddr_in6 *sin6 =
2832 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002833 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302834 cxgb4_clip_release(
2835 ep->com.dev->rdev.lldi.ports[0],
2836 (const u32 *)&sin6->sin6_addr.s6_addr,
2837 1);
2838 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002839 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302840 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2841 dst_release(ep->dst);
2842 cxgb4_l2t_release(ep->l2t);
2843 c4iw_reconnect(ep);
2844 }
2845
Hariprasad S944661d2016-05-06 22:18:03 +05302846deref_ep:
2847 c4iw_put_ep(&ep->com);
2848 /* Dereferencing ep, referenced in peer_abort_intr() */
2849 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002850 return 0;
2851}
2852
2853static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2854{
2855 struct c4iw_ep *ep;
2856 struct c4iw_qp_attributes attrs;
2857 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002859 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860
Hariprasad S944661d2016-05-06 22:18:03 +05302861 ep = get_ep_from_tid(dev, tid);
2862 if (!ep)
2863 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002864
2865 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2866 BUG_ON(!ep);
2867
2868 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002869 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302870 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 switch (ep->com.state) {
2872 case CLOSING:
2873 __state_set(&ep->com, MORIBUND);
2874 break;
2875 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002876 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877 if ((ep->com.cm_id) && (ep->com.qp)) {
2878 attrs.next_state = C4IW_QP_STATE_IDLE;
2879 c4iw_modify_qp(ep->com.qp->rhp,
2880 ep->com.qp,
2881 C4IW_QP_ATTR_NEXT_STATE,
2882 &attrs, 1);
2883 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302884 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885 __state_set(&ep->com, DEAD);
2886 release = 1;
2887 break;
2888 case ABORTING:
2889 case DEAD:
2890 break;
2891 default:
2892 BUG_ON(1);
2893 break;
2894 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002895 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896 if (release)
2897 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302898 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002899 return 0;
2900}
2901
2902static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2903{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002904 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002905 unsigned int tid = GET_TID(rpl);
2906 struct c4iw_ep *ep;
2907 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002908
Hariprasad S944661d2016-05-06 22:18:03 +05302909 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002910 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002911
Steve Wise30c95c22011-05-09 22:06:22 -07002912 if (ep && ep->com.qp) {
Joe Perches700456b2017-02-09 14:23:50 -08002913 pr_warn("TERM received tid %u qpid %u\n",
2914 tid, ep->com.qp->wq.sq.qid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002915 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2916 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2917 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2918 } else
Joe Perches700456b2017-02-09 14:23:50 -08002919 pr_warn("TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302920 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921
Steve Wisecfdda9d2010-04-21 15:30:06 -07002922 return 0;
2923}
2924
2925/*
2926 * Upcall from the adapter indicating data has been transmitted.
2927 * For us its just the single MPA request or reply. We can now free
2928 * the skb holding the mpa message.
2929 */
2930static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2931{
2932 struct c4iw_ep *ep;
2933 struct cpl_fw4_ack *hdr = cplhdr(skb);
2934 u8 credits = hdr->credits;
2935 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936
2937
Hariprasad S944661d2016-05-06 22:18:03 +05302938 ep = get_ep_from_tid(dev, tid);
2939 if (!ep)
2940 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002941 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2942 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002943 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2944 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302945 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 }
2947
2948 dst_confirm(ep->dst);
2949 if (ep->mpa_skb) {
2950 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2951 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2952 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002953 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002954 kfree_skb(ep->mpa_skb);
2955 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302956 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2957 stop_ep_timer(ep);
2958 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 }
Hariprasad S944661d2016-05-06 22:18:03 +05302960out:
2961 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 return 0;
2963}
2964
Steve Wisecfdda9d2010-04-21 15:30:06 -07002965int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2966{
Hariprasad Sbce28412016-06-10 01:05:13 +05302967 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002968 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302969
Steve Wisecfdda9d2010-04-21 15:30:06 -07002970 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2971
Steve Wisea7db89e2014-03-21 20:40:35 +05302972 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302973 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302974 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975 c4iw_put_ep(&ep->com);
2976 return -ECONNRESET;
2977 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002978 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002979 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302980 abort = 1;
2981 else
2982 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302983 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302984
2985 stop_ep_timer(ep);
2986 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002987 c4iw_put_ep(&ep->com);
2988 return 0;
2989}
2990
2991int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2992{
2993 int err;
2994 struct c4iw_qp_attributes attrs;
2995 enum c4iw_qp_attr_mask mask;
2996 struct c4iw_ep *ep = to_ep(cm_id);
2997 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2998 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302999 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003000
3001 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303002
3003 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303004 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003005 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303006 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003007 }
3008
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 BUG_ON(!qp);
3010
Vipul Pandya793dad92012-12-10 09:30:56 +00003011 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303012 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3013 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303015 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003016 }
3017
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303018 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3019 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303020 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003021 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303022 } else {
3023 ep->ird = conn_param->ird;
3024 ep->ord = conn_param->ord;
3025 send_mpa_reject(ep, conn_param->private_data,
3026 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303028 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303029 }
3030 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303031 if (conn_param->ird < ep->ord) {
3032 if (RELAXED_IRD_NEGOTIATION &&
3033 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3034 conn_param->ird = ep->ord;
3035 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303036 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303037 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303038 }
3039 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303040 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003041 ep->ird = conn_param->ird;
3042 ep->ord = conn_param->ord;
3043
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303044 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303045 if (peer2peer && ep->ird == 0)
3046 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303047 } else {
3048 if (peer2peer &&
3049 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303050 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303051 ep->ird = 1;
3052 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003053
3054 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3055
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303056 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303057 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303058 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003059 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303060
Steve Wisecfdda9d2010-04-21 15:30:06 -07003061 /* bind QP to EP and move to RTS */
3062 attrs.mpa_attr = ep->mpa_attr;
3063 attrs.max_ird = ep->ird;
3064 attrs.max_ord = ep->ord;
3065 attrs.llp_stream_handle = ep;
3066 attrs.next_state = C4IW_QP_STATE_RTS;
3067
3068 /* bind QP and TID with INIT_WR */
3069 mask = C4IW_QP_ATTR_NEXT_STATE |
3070 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3071 C4IW_QP_ATTR_MPA_ATTR |
3072 C4IW_QP_ATTR_MAX_IRD |
3073 C4IW_QP_ATTR_MAX_ORD;
3074
3075 err = c4iw_modify_qp(ep->com.qp->rhp,
3076 ep->com.qp, mask, &attrs, 1);
3077 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303078 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303079
3080 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003081 err = send_mpa_reply(ep, conn_param->private_data,
3082 conn_param->private_data_len);
3083 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303084 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003085
Steve Wisea7db89e2014-03-21 20:40:35 +05303086 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303088 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003089 c4iw_put_ep(&ep->com);
3090 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303091err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303092 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303093err_abort:
3094 abort = 1;
3095err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303096 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303097 if (abort)
3098 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003099 c4iw_put_ep(&ep->com);
3100 return err;
3101}
3102
Vipul Pandya830662f2013-07-04 16:10:47 +05303103static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3104{
3105 struct in_device *ind;
3106 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003107 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3108 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303109
3110 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3111 if (!ind)
3112 return -EADDRNOTAVAIL;
3113 for_primary_ifa(ind) {
3114 laddr->sin_addr.s_addr = ifa->ifa_address;
3115 raddr->sin_addr.s_addr = ifa->ifa_address;
3116 found = 1;
3117 break;
3118 }
3119 endfor_ifa(ind);
3120 in_dev_put(ind);
3121 return found ? 0 : -EADDRNOTAVAIL;
3122}
3123
3124static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3125 unsigned char banned_flags)
3126{
3127 struct inet6_dev *idev;
3128 int err = -EADDRNOTAVAIL;
3129
3130 rcu_read_lock();
3131 idev = __in6_dev_get(dev);
3132 if (idev != NULL) {
3133 struct inet6_ifaddr *ifp;
3134
3135 read_lock_bh(&idev->lock);
3136 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3137 if (ifp->scope == IFA_LINK &&
3138 !(ifp->flags & banned_flags)) {
3139 memcpy(addr, &ifp->addr, 16);
3140 err = 0;
3141 break;
3142 }
3143 }
3144 read_unlock_bh(&idev->lock);
3145 }
3146 rcu_read_unlock();
3147 return err;
3148}
3149
3150static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3151{
3152 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003153 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3154 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303155
Nicholas Krause54b9a962015-08-26 23:00:59 -04003156 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303157 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3158 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3159 return 0;
3160 }
3161 return -EADDRNOTAVAIL;
3162}
3163
Steve Wisecfdda9d2010-04-21 15:30:06 -07003164int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3165{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003166 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3167 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003168 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003169 struct sockaddr_in *laddr;
3170 struct sockaddr_in *raddr;
3171 struct sockaddr_in6 *laddr6;
3172 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303173 __u8 *ra;
3174 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003175
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303176 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3177 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003178 err = -EINVAL;
3179 goto out;
3180 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003181 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3182 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08003183 pr_err("%s - cannot alloc ep\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003184 err = -ENOMEM;
3185 goto out;
3186 }
Hariprasad S4a740832016-06-10 01:05:15 +05303187
3188 skb_queue_head_init(&ep->com.ep_skb_list);
3189 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3190 err = -ENOMEM;
3191 goto fail1;
3192 }
3193
Steve Wisecfdda9d2010-04-21 15:30:06 -07003194 init_timer(&ep->timer);
3195 ep->plen = conn_param->private_data_len;
3196 if (ep->plen)
3197 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3198 conn_param->private_data, ep->plen);
3199 ep->ird = conn_param->ird;
3200 ep->ord = conn_param->ord;
3201
3202 if (peer2peer && ep->ord == 0)
3203 ep->ord = 1;
3204
Steve Wisecfdda9d2010-04-21 15:30:06 -07003205 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303206 ref_cm_id(&ep->com);
3207 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003208 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303209 if (!ep->com.qp) {
3210 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3211 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303212 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303213 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003214 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003215 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3216 ep->com.qp, cm_id);
3217
3218 /*
3219 * Allocate an active TID to initiate a TCP connection.
3220 */
3221 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3222 if (ep->atid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08003223 pr_err("%s - cannot alloc atid\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003224 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303225 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003226 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003227 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003228
Steve Wise170003c2016-02-26 09:18:03 -06003229 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003230 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003231 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003232 sizeof(ep->com.remote_addr));
3233
Steve Wise170003c2016-02-26 09:18:03 -06003234 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3235 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3236 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3237 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003238
Steve Wise170003c2016-02-26 09:18:03 -06003239 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303240 iptype = 4;
3241 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003242
Vipul Pandya830662f2013-07-04 16:10:47 +05303243 /*
3244 * Handle loopback requests to INADDR_ANY.
3245 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003246 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303247 err = pick_local_ipaddrs(dev, cm_id);
3248 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303249 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303250 }
3251
3252 /* find a route */
3253 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3254 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3255 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303256 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3257 laddr->sin_addr.s_addr,
3258 raddr->sin_addr.s_addr,
3259 laddr->sin_port,
3260 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303261 } else {
3262 iptype = 6;
3263 ra = (__u8 *)&raddr6->sin6_addr;
3264
3265 /*
3266 * Handle loopback requests to INADDR_ANY.
3267 */
3268 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3269 err = pick_local_ip6addrs(dev, cm_id);
3270 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303271 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303272 }
3273
3274 /* find a route */
3275 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3276 __func__, laddr6->sin6_addr.s6_addr,
3277 ntohs(laddr6->sin6_port),
3278 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303279 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3280 laddr6->sin6_addr.s6_addr,
3281 raddr6->sin6_addr.s6_addr,
3282 laddr6->sin6_port,
3283 raddr6->sin6_port, 0,
3284 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303285 }
3286 if (!ep->dst) {
Joe Perches700456b2017-02-09 14:23:50 -08003287 pr_err("%s - cannot find route\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003288 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303289 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003290 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291
Hariprasad S963cab52015-09-23 17:19:27 +05303292 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303293 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003294 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08003295 pr_err("%s - cannot alloc l2e\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303296 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297 }
3298
3299 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3300 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3301 ep->l2t->idx);
3302
3303 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303304 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305
3306 /* send connect request to rnic */
3307 err = send_connect(ep);
3308 if (!err)
3309 goto out;
3310
3311 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303312fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003313 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303314fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003315 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003316 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303317fail2:
3318 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303319 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303320fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003321 c4iw_put_ep(&ep->com);
3322out:
3323 return err;
3324}
3325
Vipul Pandya830662f2013-07-04 16:10:47 +05303326static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3327{
3328 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003329 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003330 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303331
Hariprasad S28de1f72016-01-13 10:03:14 +05303332 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3333 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3334 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3335 if (err)
3336 return err;
3337 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303338 c4iw_init_wr_wait(&ep->com.wr_wait);
3339 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3340 ep->stid, &sin6->sin6_addr,
3341 sin6->sin6_port,
3342 ep->com.dev->rdev.lldi.rxq_ids[0]);
3343 if (!err)
3344 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3345 &ep->com.wr_wait,
3346 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303347 else if (err > 0)
3348 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303349 if (err) {
3350 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3351 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303352 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3353 err, ep->stid,
3354 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303355 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303356 return err;
3357}
3358
3359static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3360{
3361 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003362 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003363 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303364
3365 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3366 do {
3367 err = cxgb4_create_server_filter(
3368 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3369 sin->sin_addr.s_addr, sin->sin_port, 0,
3370 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3371 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303372 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3373 err = -EIO;
3374 break;
3375 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303376 set_current_state(TASK_UNINTERRUPTIBLE);
3377 schedule_timeout(usecs_to_jiffies(100));
3378 }
3379 } while (err == -EBUSY);
3380 } else {
3381 c4iw_init_wr_wait(&ep->com.wr_wait);
3382 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3383 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3384 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3385 if (!err)
3386 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3387 &ep->com.wr_wait,
3388 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303389 else if (err > 0)
3390 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303391 }
3392 if (err)
3393 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3394 , err, ep->stid,
3395 &sin->sin_addr, ntohs(sin->sin_port));
3396 return err;
3397}
3398
Steve Wisecfdda9d2010-04-21 15:30:06 -07003399int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3400{
3401 int err = 0;
3402 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3403 struct c4iw_listen_ep *ep;
3404
Steve Wisecfdda9d2010-04-21 15:30:06 -07003405 might_sleep();
3406
3407 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3408 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08003409 pr_err("%s - cannot alloc ep\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003410 err = -ENOMEM;
3411 goto fail1;
3412 }
Hariprasad S4a740832016-06-10 01:05:15 +05303413 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003414 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003415 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303416 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003417 ep->com.dev = dev;
3418 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003419 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303420 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003421
3422 /*
3423 * Allocate a server TID.
3424 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303425 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3426 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303427 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003428 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003429 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303430 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003431 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003432
Steve Wisecfdda9d2010-04-21 15:30:06 -07003433 if (ep->stid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08003434 pr_err("%s - cannot alloc stid\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435 err = -ENOMEM;
3436 goto fail2;
3437 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003438 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003439
Steve Wise170003c2016-02-26 09:18:03 -06003440 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3441 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003442
Steve Wisecfdda9d2010-04-21 15:30:06 -07003443 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303444 if (ep->com.local_addr.ss_family == AF_INET)
3445 err = create_server4(dev, ep);
3446 else
3447 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003448 if (!err) {
3449 cm_id->provider_data = ep;
3450 goto out;
3451 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003452
Vipul Pandya830662f2013-07-04 16:10:47 +05303453 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3454 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003455fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303456 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003457 c4iw_put_ep(&ep->com);
3458fail1:
3459out:
3460 return err;
3461}
3462
3463int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3464{
3465 int err;
3466 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3467
3468 PDBG("%s ep %p\n", __func__, ep);
3469
3470 might_sleep();
3471 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303472 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3473 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003474 err = cxgb4_remove_server_filter(
3475 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3476 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3477 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303478 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003479 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303480 err = cxgb4_remove_server(
3481 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3482 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003483 if (err)
3484 goto done;
3485 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3486 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003487 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303488 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3489 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003490 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003491 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303492 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3493 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003494done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303495 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003496 c4iw_put_ep(&ep->com);
3497 return err;
3498}
3499
3500int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3501{
3502 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003503 int close = 0;
3504 int fatal = 0;
3505 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003506
Steve Wise2f5b48c2010-09-10 11:15:36 -05003507 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003508
3509 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3510 states[ep->com.state], abrupt);
3511
Hariprasad S6e410d82016-05-05 01:27:31 +05303512 /*
3513 * Ref the ep here in case we have fatal errors causing the
3514 * ep to be released and freed.
3515 */
3516 c4iw_get_ep(&ep->com);
3517
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 rdev = &ep->com.dev->rdev;
3519 if (c4iw_fatal_error(rdev)) {
3520 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303521 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003522 ep->com.state = DEAD;
3523 }
3524 switch (ep->com.state) {
3525 case MPA_REQ_WAIT:
3526 case MPA_REQ_SENT:
3527 case MPA_REQ_RCVD:
3528 case MPA_REP_SENT:
3529 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303530 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003531 close = 1;
3532 if (abrupt)
3533 ep->com.state = ABORTING;
3534 else {
3535 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003536
3537 /*
3538 * if we close before we see the fw4_ack() then we fix
3539 * up the timer state since we're reusing it.
3540 */
3541 if (ep->mpa_skb &&
3542 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3543 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3544 stop_ep_timer(ep);
3545 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003546 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003547 }
3548 set_bit(CLOSE_SENT, &ep->com.flags);
3549 break;
3550 case CLOSING:
3551 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3552 close = 1;
3553 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003554 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003555 ep->com.state = ABORTING;
3556 } else
3557 ep->com.state = MORIBUND;
3558 }
3559 break;
3560 case MORIBUND:
3561 case ABORTING:
3562 case DEAD:
3563 PDBG("%s ignoring disconnect ep %p state %u\n",
3564 __func__, ep, ep->com.state);
3565 break;
3566 default:
3567 BUG();
3568 break;
3569 }
3570
Steve Wisecfdda9d2010-04-21 15:30:06 -07003571 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003572 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003573 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303574 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303575 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003576 } else {
3577 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303578 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003579 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303580 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303581 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303582 if (!abrupt) {
3583 stop_ep_timer(ep);
3584 close_complete_upcall(ep, -EIO);
3585 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303586 if (ep->com.qp) {
3587 struct c4iw_qp_attributes attrs;
3588
3589 attrs.next_state = C4IW_QP_STATE_ERROR;
3590 ret = c4iw_modify_qp(ep->com.qp->rhp,
3591 ep->com.qp,
3592 C4IW_QP_ATTR_NEXT_STATE,
3593 &attrs, 1);
3594 if (ret)
Joe Perches700456b2017-02-09 14:23:50 -08003595 pr_err("%s - qp <- error failed!\n",
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303596 __func__);
3597 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003598 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303599 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003600 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003601 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303602 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003603 if (fatal)
3604 release_ep_resources(ep);
3605 return ret;
3606}
3607
Vipul Pandya1cab7752012-12-10 09:30:55 +00003608static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3609 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3610{
3611 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003612 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003613
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003614 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3615 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003616 if (!ep)
3617 return;
3618
3619 switch (req->retval) {
3620 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003621 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3622 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3623 send_fw_act_open_req(ep, atid);
3624 return;
3625 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003626 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003627 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3628 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3629 send_fw_act_open_req(ep, atid);
3630 return;
3631 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003632 break;
3633 default:
3634 pr_info("%s unexpected ofld conn wr retval %d\n",
3635 __func__, req->retval);
3636 break;
3637 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003638 pr_err("active ofld_connect_wr failure %d atid %d\n",
3639 req->retval, atid);
3640 mutex_lock(&dev->rdev.stats.lock);
3641 dev->rdev.stats.act_ofld_conn_fails++;
3642 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003643 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003644 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303645 if (ep->com.remote_addr.ss_family == AF_INET6) {
3646 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003647 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303648 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3649 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3650 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003651 remove_handle(dev, &dev->atid_idr, atid);
3652 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3653 dst_release(ep->dst);
3654 cxgb4_l2t_release(ep->l2t);
3655 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003656}
3657
3658static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3659 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3660{
3661 struct sk_buff *rpl_skb;
3662 struct cpl_pass_accept_req *cpl;
3663 int ret;
3664
Paul Bolle710a3112013-02-05 20:51:30 +00003665 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003666 BUG_ON(!rpl_skb);
3667 if (req->retval) {
3668 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003669 mutex_lock(&dev->rdev.stats.lock);
3670 dev->rdev.stats.pas_ofld_conn_fails++;
3671 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003672 kfree_skb(rpl_skb);
3673 } else {
3674 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3675 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003676 (__force u32) htonl(
3677 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003678 ret = pass_accept_req(dev, rpl_skb);
3679 if (!ret)
3680 kfree_skb(rpl_skb);
3681 }
3682 return;
3683}
3684
3685static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003686{
3687 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003688 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3689
3690 switch (rpl->type) {
3691 case FW6_TYPE_CQE:
3692 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3693 break;
3694 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3695 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3696 switch (req->t_state) {
3697 case TCP_SYN_SENT:
3698 active_ofld_conn_reply(dev, skb, req);
3699 break;
3700 case TCP_SYN_RECV:
3701 passive_ofld_conn_reply(dev, skb, req);
3702 break;
3703 default:
3704 pr_err("%s unexpected ofld conn wr state %d\n",
3705 __func__, req->t_state);
3706 break;
3707 }
3708 break;
3709 }
3710 return 0;
3711}
3712
3713static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3714{
Hariprasad S963cab52015-09-23 17:19:27 +05303715 __be32 l2info;
3716 __be16 hdr_len, vlantag, len;
3717 u16 eth_hdr_len;
3718 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003719 u8 intf;
3720 struct cpl_rx_pkt *cpl = cplhdr(skb);
3721 struct cpl_pass_accept_req *req;
3722 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003723 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303724 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003725
Vipul Pandyaf079af72013-03-14 05:08:58 +00003726 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303728 vlantag = cpl->vlan;
3729 len = cpl->len;
3730 l2info = cpl->l2info;
3731 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732 intf = cpl->iff;
3733
3734 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3735
3736 /*
3737 * We need to parse the TCP options from SYN packet.
3738 * to generate cpl_pass_accept_req.
3739 */
3740 memset(&tmp_opt, 0, sizeof(tmp_opt));
3741 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003742 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003743
3744 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3745 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303746 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3747 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303748 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303749 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303750 type = dev->rdev.lldi.adapter_type;
3751 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3752 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3753 req->hdr_len =
3754 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3755 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3756 eth_hdr_len = is_t4(type) ?
3757 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3758 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3759 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3760 IP_HDR_LEN_V(ip_hdr_len) |
3761 ETH_HDR_LEN_V(eth_hdr_len));
3762 } else { /* T6 and later */
3763 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3764 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3765 T6_IP_HDR_LEN_V(ip_hdr_len) |
3766 T6_ETH_HDR_LEN_V(eth_hdr_len));
3767 }
3768 req->vlan = vlantag;
3769 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003770 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3771 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003772 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3773 if (tmp_opt.wscale_ok)
3774 req->tcpopt.wsf = tmp_opt.snd_wscale;
3775 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3776 if (tmp_opt.sack_ok)
3777 req->tcpopt.sack = 1;
3778 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3779 return;
3780}
3781
3782static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3783 __be32 laddr, __be16 lport,
3784 __be32 raddr, __be16 rport,
3785 u32 rcv_isn, u32 filter, u16 window,
3786 u32 rss_qid, u8 port_id)
3787{
3788 struct sk_buff *req_skb;
3789 struct fw_ofld_connection_wr *req;
3790 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303791 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003792
3793 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3794 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3795 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003796 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303797 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303798 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003799 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003800 req->le.lport = lport;
3801 req->le.pport = rport;
3802 req->le.u.ipv4.lip = laddr;
3803 req->le.u.ipv4.pip = raddr;
3804 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3805 req->tcb.rcv_adv = htons(window);
3806 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303807 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3808 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3809 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003810 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003811
3812 /*
3813 * We store the qid in opt2 which will be used by the firmware
3814 * to send us the wr response.
3815 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003816 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003817
3818 /*
3819 * We initialize the MSS index in TCB to 0xF.
3820 * So that when driver sends cpl_pass_accept_rpl
3821 * TCB picks up the correct value. If this was 0
3822 * TP will ignore any value > 0 for MSS index.
3823 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003824 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303825 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826
3827 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303828 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3829 if (ret < 0) {
3830 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3831 ret);
3832 kfree_skb(skb);
3833 kfree_skb(req_skb);
3834 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003835}
3836
3837/*
3838 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3839 * messages when a filter is being used instead of server to
3840 * redirect a syn packet. When packets hit filter they are redirected
3841 * to the offload queue and driver tries to establish the connection
3842 * using firmware work request.
3843 */
3844static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3845{
3846 int stid;
3847 unsigned int filter;
3848 struct ethhdr *eh = NULL;
3849 struct vlan_ethhdr *vlan_eh = NULL;
3850 struct iphdr *iph;
3851 struct tcphdr *tcph;
3852 struct rss_header *rss = (void *)skb->data;
3853 struct cpl_rx_pkt *cpl = (void *)skb->data;
3854 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3855 struct l2t_entry *e;
3856 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303857 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003858 u16 window;
3859 struct port_info *pi;
3860 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003861 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003862 int step;
3863 u32 tx_chan;
3864 struct neighbour *neigh;
3865
3866 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003867 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003868 goto reject;
3869
3870 /*
3871 * Drop all packets which did not hit the filter.
3872 * Unlikely to happen.
3873 */
3874 if (!(rss->filter_hit && rss->filter_tid))
3875 goto reject;
3876
3877 /*
3878 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3879 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303880 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003881
Hariprasad Sf86fac72016-05-06 22:18:07 +05303882 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003883 if (!lep) {
3884 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3885 goto reject;
3886 }
3887
Hariprasad S963cab52015-09-23 17:19:27 +05303888 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3889 case CHELSIO_T4:
3890 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3891 break;
3892 case CHELSIO_T5:
3893 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3894 break;
3895 case CHELSIO_T6:
3896 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3897 break;
3898 default:
3899 pr_err("T%d Chip is not supported\n",
3900 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3901 goto reject;
3902 }
3903
Vipul Pandyaf079af72013-03-14 05:08:58 +00003904 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003905 eh = (struct ethhdr *)(req + 1);
3906 iph = (struct iphdr *)(eh + 1);
3907 } else {
3908 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3909 iph = (struct iphdr *)(vlan_eh + 1);
3910 skb->vlan_tci = ntohs(cpl->vlan);
3911 }
3912
3913 if (iph->version != 0x4)
3914 goto reject;
3915
3916 tcph = (struct tcphdr *)(iph + 1);
3917 skb_set_network_header(skb, (void *)iph - (void *)rss);
3918 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3919 skb_get(skb);
3920
3921 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3922 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3923 ntohs(tcph->source), iph->tos);
3924
Varun Prakash804c2f32016-09-13 21:23:57 +05303925 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3926 iph->daddr, iph->saddr, tcph->dest,
3927 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303928 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003929 pr_err("%s - failed to find dst entry!\n",
3930 __func__);
3931 goto reject;
3932 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003933 neigh = dst_neigh_lookup_skb(dst, skb);
3934
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003935 if (!neigh) {
3936 pr_err("%s - failed to allocate neigh!\n",
3937 __func__);
3938 goto free_dst;
3939 }
3940
Vipul Pandya1cab7752012-12-10 09:30:55 +00003941 if (neigh->dev->flags & IFF_LOOPBACK) {
3942 pdev = ip_dev_find(&init_net, iph->daddr);
3943 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3944 pdev, 0);
3945 pi = (struct port_info *)netdev_priv(pdev);
3946 tx_chan = cxgb4_port_chan(pdev);
3947 dev_put(pdev);
3948 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303949 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003950 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303951 pdev, 0);
3952 pi = (struct port_info *)netdev_priv(pdev);
3953 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003954 }
Steve Wiseebf00062014-03-19 17:44:40 +05303955 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003956 if (!e) {
3957 pr_err("%s - failed to allocate l2t entry!\n",
3958 __func__);
3959 goto free_dst;
3960 }
3961
3962 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3963 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003964 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003965
3966 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303967 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3968 dev->rdev.lldi.ports[0],
3969 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003970
3971 /*
3972 * Synthesize the cpl_pass_accept_req. We have everything except the
3973 * TID. Once firmware sends a reply with TID we update the TID field
3974 * in cpl and pass it through the regular cpl_pass_accept_req path.
3975 */
3976 build_cpl_pass_accept_req(skb, stid, iph->tos);
3977 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3978 tcph->source, ntohl(tcph->seq), filter, window,
3979 rss_qid, pi->port_id);
3980 cxgb4_l2t_release(e);
3981free_dst:
3982 dst_release(dst);
3983reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303984 if (lep)
3985 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003986 return 0;
3987}
3988
Steve Wisecfdda9d2010-04-21 15:30:06 -07003989/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003990 * These are the real handlers that are called from a
3991 * work queue.
3992 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303993static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003994 [CPL_ACT_ESTABLISH] = act_establish,
3995 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3996 [CPL_RX_DATA] = rx_data,
3997 [CPL_ABORT_RPL_RSS] = abort_rpl,
3998 [CPL_ABORT_RPL] = abort_rpl,
3999 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4000 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4001 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4002 [CPL_PASS_ESTABLISH] = pass_establish,
4003 [CPL_PEER_CLOSE] = peer_close,
4004 [CPL_ABORT_REQ_RSS] = peer_abort,
4005 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4006 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004007 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004008 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304009 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304010 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4011 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004012};
4013
4014static void process_timeout(struct c4iw_ep *ep)
4015{
4016 struct c4iw_qp_attributes attrs;
4017 int abort = 1;
4018
Steve Wise2f5b48c2010-09-10 11:15:36 -05004019 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004020 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4021 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004022 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004023 switch (ep->com.state) {
4024 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004025 connect_reply_upcall(ep, -ETIMEDOUT);
4026 break;
4027 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304028 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304029 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304030 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004031 break;
4032 case CLOSING:
4033 case MORIBUND:
4034 if (ep->com.cm_id && ep->com.qp) {
4035 attrs.next_state = C4IW_QP_STATE_ERROR;
4036 c4iw_modify_qp(ep->com.qp->rhp,
4037 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4038 &attrs, 1);
4039 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304040 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004041 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004042 case ABORTING:
4043 case DEAD:
4044
4045 /*
4046 * These states are expected if the ep timed out at the same
4047 * time as another thread was calling stop_ep_timer().
4048 * So we silently do nothing for these states.
4049 */
4050 abort = 0;
4051 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004053 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004054 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055 abort = 0;
4056 }
Steve Wisecc18b932014-04-24 14:31:53 -05004057 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304058 if (abort)
4059 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004060 c4iw_put_ep(&ep->com);
4061}
4062
4063static void process_timedout_eps(void)
4064{
4065 struct c4iw_ep *ep;
4066
4067 spin_lock_irq(&timeout_lock);
4068 while (!list_empty(&timeout_list)) {
4069 struct list_head *tmp;
4070
4071 tmp = timeout_list.next;
4072 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004073 tmp->next = NULL;
4074 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004075 spin_unlock_irq(&timeout_lock);
4076 ep = list_entry(tmp, struct c4iw_ep, entry);
4077 process_timeout(ep);
4078 spin_lock_irq(&timeout_lock);
4079 }
4080 spin_unlock_irq(&timeout_lock);
4081}
4082
4083static void process_work(struct work_struct *work)
4084{
4085 struct sk_buff *skb = NULL;
4086 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004087 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004088 unsigned int opcode;
4089 int ret;
4090
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004091 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004092 while ((skb = skb_dequeue(&rxq))) {
4093 rpl = cplhdr(skb);
4094 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4095 opcode = rpl->ot.opcode;
4096
4097 BUG_ON(!work_handlers[opcode]);
4098 ret = work_handlers[opcode](dev, skb);
4099 if (!ret)
4100 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004101 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004102 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103}
4104
4105static DECLARE_WORK(skb_work, process_work);
4106
4107static void ep_timeout(unsigned long arg)
4108{
4109 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004110 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004111
4112 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004113 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004114 /*
4115 * Only insert if it is not already on the list.
4116 */
4117 if (!ep->entry.next) {
4118 list_add_tail(&ep->entry, &timeout_list);
4119 kickit = 1;
4120 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004121 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004122 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004123 if (kickit)
4124 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004125}
4126
4127/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004128 * All the CM events are handled on a work queue to have a safe context.
4129 */
4130static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4131{
4132
4133 /*
4134 * Save dev in the skb->cb area.
4135 */
4136 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4137
4138 /*
4139 * Queue the skb and schedule the worker thread.
4140 */
4141 skb_queue_tail(&rxq, skb);
4142 queue_work(workq, &skb_work);
4143 return 0;
4144}
4145
4146static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4147{
4148 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4149
4150 if (rpl->status != CPL_ERR_NONE) {
Joe Perches700456b2017-02-09 14:23:50 -08004151 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4152 rpl->status, GET_TID(rpl));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004153 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004154 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004155 return 0;
4156}
4157
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004158static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4159{
4160 struct cpl_fw6_msg *rpl = cplhdr(skb);
4161 struct c4iw_wr_wait *wr_waitp;
4162 int ret;
4163
4164 PDBG("%s type %u\n", __func__, rpl->type);
4165
4166 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004167 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004168 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004169 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004170 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004171 if (wr_waitp)
4172 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004173 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004174 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004175 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004176 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004177 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004178 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004179 default:
Joe Perches700456b2017-02-09 14:23:50 -08004180 pr_err("%s unexpected fw6 msg type %u\n",
4181 __func__, rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004182 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004183 break;
4184 }
4185 return 0;
4186}
4187
Steve Wise8da7e7a2011-06-14 20:59:27 +00004188static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4189{
4190 struct cpl_abort_req_rss *req = cplhdr(skb);
4191 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004192 unsigned int tid = GET_TID(req);
4193
Hariprasad S944661d2016-05-06 22:18:03 +05304194 ep = get_ep_from_tid(dev, tid);
4195 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004196 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08004197 pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
Steve Wise14b92222012-04-30 15:31:29 -05004198 kfree_skb(skb);
4199 return 0;
4200 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304201 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304202 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4203 __func__, ep->hwtid, req->status,
4204 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304205 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004206 }
4207 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4208 ep->com.state);
4209
Hariprasad S093108c2016-05-06 22:18:09 +05304210 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304211out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004212 sched(dev, skb);
4213 return 0;
4214}
4215
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004216/*
4217 * Most upcalls from the T4 Core go to sched() to
4218 * schedule the processing on a work queue.
4219 */
4220c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4221 [CPL_ACT_ESTABLISH] = sched,
4222 [CPL_ACT_OPEN_RPL] = sched,
4223 [CPL_RX_DATA] = sched,
4224 [CPL_ABORT_RPL_RSS] = sched,
4225 [CPL_ABORT_RPL] = sched,
4226 [CPL_PASS_OPEN_RPL] = sched,
4227 [CPL_CLOSE_LISTSRV_RPL] = sched,
4228 [CPL_PASS_ACCEPT_REQ] = sched,
4229 [CPL_PASS_ESTABLISH] = sched,
4230 [CPL_PEER_CLOSE] = sched,
4231 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004232 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004233 [CPL_RDMA_TERMINATE] = sched,
4234 [CPL_FW4_ACK] = sched,
4235 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004236 [CPL_FW6_MSG] = fw6_msg,
4237 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004238};
4239
Steve Wisecfdda9d2010-04-21 15:30:06 -07004240int __init c4iw_cm_init(void)
4241{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004242 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004243 skb_queue_head_init(&rxq);
4244
Bhaktipriya Shridhar52ee1a02016-08-15 23:39:14 +05304245 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004246 if (!workq)
4247 return -ENOMEM;
4248
Steve Wisecfdda9d2010-04-21 15:30:06 -07004249 return 0;
4250}
4251
Steve Wise46c13762014-06-20 14:26:25 -05004252void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004253{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004254 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004255 flush_workqueue(workq);
4256 destroy_workqueue(workq);
4257}