blob: 0910faf3587b547e873bc4e5572e7defd93623b3 [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);
Joe Perchesa9a42882017-02-09 14:23:51 -0800104MODULE_PARM_DESC(c4iw_debug, "obsolete");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700105
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{
Joe Perchesa9a42882017-02-09 14:23:51 -0800183 pr_debug("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700184 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{
Joe Perchesa9a42882017-02-09 14:23:51 -0800199 pr_debug("%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);
Joe Perchesa9a42882017-02-09 14:23:51 -0800215 pr_debug("%s - device in error state - dropping\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700216 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);
Joe Perchesa9a42882017-02-09 14:23:51 -0800232 pr_debug("%s - device in error state - dropping\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700233 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)
Joe Perchesa9a42882017-02-09 14:23:51 -0800266 pr_debug("Warning: misaligned mtu idx %u mss %u emss=%u\n",
267 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
268 pr_debug("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
269 ep->mss, ep->emss);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700270}
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);
Joe Perchesa9a42882017-02-09 14:23:51 -0800290 pr_debug("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 __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 }
Joe Perchesa9a42882017-02-09 14:23:51 -0800325 pr_debug("%s alloc ep %p\n", __func__, epc);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700326 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);
Joe Perchesa9a42882017-02-09 14:23:51 -0800387 pr_debug("%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);
Raju Rangoju1dad0eb2017-05-15 06:40:39 +0000491 kfree_skb(skb);
Hariprasad S9dec9002016-05-05 01:27:29 +0530492 return 0;
493}
494
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530495static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
496{
497 struct c4iw_ep *ep;
498
499 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
500 c4iw_put_ep(&ep->parent_ep->com);
501 release_ep_resources(ep);
Raju Rangoju1dad0eb2017-05-15 06:40:39 +0000502 kfree_skb(skb);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530503 return 0;
504}
505
Hariprasad S9dec9002016-05-05 01:27:29 +0530506/*
507 * Fake up a special CPL opcode and call sched() so process_work() will call
508 * _put_ep_safe() in a safe context to free the ep resources. This is needed
509 * because ARP error handlers are called in an ATOMIC context, and
510 * _c4iw_free_ep() needs to block.
511 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530512static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
513 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530514{
515 struct cpl_act_establish *rpl = cplhdr(skb);
516
517 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530518 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530519
520 /*
521 * Save ep in the skb->cb area, after where sched() will save the dev
522 * ptr.
523 */
524 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
525 sched(ep->com.dev, skb);
526}
527
528/* Handle an ARP failure for an accept */
529static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
530{
531 struct c4iw_ep *ep = handle;
532
Joe Perches700456b2017-02-09 14:23:50 -0800533 pr_err("ARP failure during accept - tid %u - dropping connection\n",
Hariprasad S9dec9002016-05-05 01:27:29 +0530534 ep->hwtid);
535
536 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530537 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530538}
539
Steve Wisecfdda9d2010-04-21 15:30:06 -0700540/*
541 * Handle an ARP failure for an active open.
542 */
543static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
544{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530545 struct c4iw_ep *ep = handle;
546
Joe Perches700456b2017-02-09 14:23:50 -0800547 pr_err("ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530548 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530549 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530550 if (ep->com.remote_addr.ss_family == AF_INET6) {
551 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600552 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530553 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
554 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
555 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530556 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
557 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530558 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700559}
560
561/*
562 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
563 * and send it along.
564 */
565static void abort_arp_failure(void *handle, struct sk_buff *skb)
566{
Hariprasad S761e19a2016-05-06 22:18:02 +0530567 int ret;
568 struct c4iw_ep *ep = handle;
569 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700570 struct cpl_abort_req *req = cplhdr(skb);
571
Joe Perchesa9a42882017-02-09 14:23:51 -0800572 pr_debug("%s rdev %p\n", __func__, rdev);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700573 req->cmd = CPL_ABORT_NO_RST;
Raju Rangoju1dad0eb2017-05-15 06:40:39 +0000574 skb_get(skb);
Hariprasad S761e19a2016-05-06 22:18:02 +0530575 ret = c4iw_ofld_send(rdev, skb);
576 if (ret) {
577 __state_set(&ep->com, DEAD);
578 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Raju Rangoju1dad0eb2017-05-15 06:40:39 +0000579 } else
580 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581}
582
Hariprasad S4a740832016-06-10 01:05:15 +0530583static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700584{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700585 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530586 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700587 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530588 u16 vlan = ep->l2t->vlan;
589 int nparams;
590
Hariprasad S4a740832016-06-10 01:05:15 +0530591 if (WARN_ON(!skb))
592 return -ENOMEM;
593
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530594 if (vlan == CPL_L2T_VLAN_NONE)
595 nparams = 8;
596 else
597 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700598
Hariprasad S4a740832016-06-10 01:05:15 +0530599 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530601 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530602 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530603 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530604 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700605
606 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530607 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530608 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700609 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
610 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
611 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
612 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
613 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
614 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
615 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
616 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
617 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
618 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
619 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530620 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700621 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
622 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530623 if (nparams == 9) {
624 u16 pri;
625
626 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
627 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
628 flowc->mnemval[8].val = cpu_to_be32(pri);
629 } else {
630 /* Pad WR to 16 byte boundary */
631 flowc->mnemval[8].mnemonic = 0;
632 flowc->mnemval[8].val = 0;
633 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700634 for (i = 0; i < 9; i++) {
635 flowc->mnemval[i].r4[0] = 0;
636 flowc->mnemval[i].r4[1] = 0;
637 flowc->mnemval[i].r4[2] = 0;
638 }
639
640 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530641 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642}
643
Hariprasad S4a740832016-06-10 01:05:15 +0530644static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645{
Hariprasad S4a740832016-06-10 01:05:15 +0530646 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Varun Prakash29fb6f42016-09-13 21:24:03 +0530647 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648
Joe Perchesa9a42882017-02-09 14:23:51 -0800649 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530650 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700651 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530652
Varun Prakash29fb6f42016-09-13 21:24:03 +0530653 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
654 NULL, arp_failure_discard);
655
Steve Wisecfdda9d2010-04-21 15:30:06 -0700656 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
657}
658
Hariprasad S4a740832016-06-10 01:05:15 +0530659static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700660{
Varun Prakasha7e1a972016-09-13 21:24:04 +0530661 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530662 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700663
Joe Perchesa9a42882017-02-09 14:23:51 -0800664 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530665 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530667
Varun Prakasha7e1a972016-09-13 21:24:04 +0530668 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
669 ep, abort_arp_failure);
670
Hariprasad S4a740832016-06-10 01:05:15 +0530671 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700672}
673
674static int send_connect(struct c4iw_ep *ep)
675{
Hariprasad S963cab52015-09-23 17:19:27 +0530676 struct cpl_act_open_req *req = NULL;
677 struct cpl_t5_act_open_req *t5req = NULL;
678 struct cpl_t6_act_open_req *t6req = NULL;
679 struct cpl_act_open_req6 *req6 = NULL;
680 struct cpl_t5_act_open_req6 *t5req6 = NULL;
681 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700682 struct sk_buff *skb;
683 u64 opt0;
684 u32 opt2;
685 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530686 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530687 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500688 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600689 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500690 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600691 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500692 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600693 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500694 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600695 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530696 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530697 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
698 u32 isn = (prandom_u32() & ~7UL) - 1;
Ganesh Goudar192539f2017-01-31 12:00:09 +0530699 struct net_device *netdev;
700 u64 params;
701
702 netdev = ep->com.dev->rdev.lldi.ports[0];
Hariprasad S963cab52015-09-23 17:19:27 +0530703
704 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
705 case CHELSIO_T4:
706 sizev4 = sizeof(struct cpl_act_open_req);
707 sizev6 = sizeof(struct cpl_act_open_req6);
708 break;
709 case CHELSIO_T5:
710 sizev4 = sizeof(struct cpl_t5_act_open_req);
711 sizev6 = sizeof(struct cpl_t5_act_open_req6);
712 break;
713 case CHELSIO_T6:
714 sizev4 = sizeof(struct cpl_t6_act_open_req);
715 sizev6 = sizeof(struct cpl_t6_act_open_req6);
716 break;
717 default:
718 pr_err("T%d Chip is not supported\n",
719 CHELSIO_CHIP_VERSION(adapter_type));
720 return -EINVAL;
721 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530722
723 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
724 roundup(sizev4, 16) :
725 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726
Joe Perchesa9a42882017-02-09 14:23:51 -0800727 pr_debug("%s ep %p atid %u\n", __func__, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700728
729 skb = get_skb(NULL, wrlen, GFP_KERNEL);
730 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -0800731 pr_err("%s - failed to alloc skb\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700732 return -ENOMEM;
733 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000734 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700735
Varun Prakash44c6d062016-09-13 21:24:00 +0530736 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
737 enable_tcp_timestamps,
738 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530739 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530740
741 /*
742 * Specify the largest window that will fit in opt0. The
743 * remainder will be specified in the rx_data_ack.
744 */
745 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800746 if (win > RCV_BUFSIZ_M)
747 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530748
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800749 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800750 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800751 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800752 WND_SCALE_V(wscale) |
753 MSS_IDX_V(mtu_idx) |
754 L2T_IDX_V(ep->l2t->idx) |
755 TX_CHAN_V(ep->tx_chan) |
756 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530757 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800758 ULP_MODE_V(ULP_MODE_TCPDDP) |
759 RCV_BUFSIZ_V(win);
760 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800761 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800762 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700763 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800764 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700765 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800766 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700767 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800768 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530769 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
770 if (peer2peer)
771 isn += 4;
772
Anish Bhattd7990b02014-11-12 17:15:57 -0800773 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530774 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530775 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500776 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530777
Ganesh Goudar192539f2017-01-31 12:00:09 +0530778 params = cxgb4_select_ntuple(netdev, ep->l2t);
779
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530780 if (ep->com.remote_addr.ss_family == AF_INET6)
781 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
782 (const u32 *)&la6->sin6_addr.s6_addr, 1);
783
Hariprasad S5dab6d32014-06-23 19:12:36 +0530784 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700785
Hariprasad S963cab52015-09-23 17:19:27 +0530786 if (ep->com.remote_addr.ss_family == AF_INET) {
787 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
788 case CHELSIO_T4:
789 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530790 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530791 break;
792 case CHELSIO_T5:
793 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
794 wrlen);
795 INIT_TP_WR(t5req, 0);
796 req = (struct cpl_act_open_req *)t5req;
797 break;
798 case CHELSIO_T6:
799 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
800 wrlen);
801 INIT_TP_WR(t6req, 0);
802 req = (struct cpl_act_open_req *)t6req;
803 t5req = (struct cpl_t5_act_open_req *)t6req;
804 break;
805 default:
806 pr_err("T%d Chip is not supported\n",
807 CHELSIO_CHIP_VERSION(adapter_type));
808 ret = -EINVAL;
809 goto clip_release;
810 }
811
812 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
813 ((ep->rss_qid<<14) | ep->atid)));
814 req->local_port = la->sin_port;
815 req->peer_port = ra->sin_port;
816 req->local_ip = la->sin_addr.s_addr;
817 req->peer_ip = ra->sin_addr.s_addr;
818 req->opt0 = cpu_to_be64(opt0);
819
820 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530821 req->params = cpu_to_be32(params);
Vipul Pandya830662f2013-07-04 16:10:47 +0530822 req->opt2 = cpu_to_be32(opt2);
823 } else {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530824 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
825 t5req->params =
826 cpu_to_be64(FILTER_TUPLE_V(params));
827 t5req->rsvd = cpu_to_be32(isn);
Joe Perchesa9a42882017-02-09 14:23:51 -0800828 pr_debug("%s snd_isn %u\n", __func__, t5req->rsvd);
Ganesh Goudar192539f2017-01-31 12:00:09 +0530829 t5req->opt2 = cpu_to_be32(opt2);
830 } else {
831 t6req->params =
832 cpu_to_be64(FILTER_TUPLE_V(params));
833 t6req->rsvd = cpu_to_be32(isn);
Doug Ledford339e7572017-04-20 22:18:54 -0400834 pr_debug("%s snd_isn %u\n", __func__, t6req->rsvd);
Ganesh Goudar192539f2017-01-31 12:00:09 +0530835 t6req->opt2 = cpu_to_be32(opt2);
836 }
Hariprasad S963cab52015-09-23 17:19:27 +0530837 }
838 } else {
839 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
840 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530841 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530842 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530843 break;
844 case CHELSIO_T5:
845 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
846 wrlen);
847 INIT_TP_WR(t5req6, 0);
848 req6 = (struct cpl_act_open_req6 *)t5req6;
849 break;
850 case CHELSIO_T6:
851 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
852 wrlen);
853 INIT_TP_WR(t6req6, 0);
854 req6 = (struct cpl_act_open_req6 *)t6req6;
855 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
856 break;
857 default:
858 pr_err("T%d Chip is not supported\n",
859 CHELSIO_CHIP_VERSION(adapter_type));
860 ret = -EINVAL;
861 goto clip_release;
862 }
863
864 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
865 ((ep->rss_qid<<14)|ep->atid)));
866 req6->local_port = la6->sin6_port;
867 req6->peer_port = ra6->sin6_port;
868 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
869 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
870 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
871 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
872 req6->opt0 = cpu_to_be64(opt0);
873
874 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530875 req6->params = cpu_to_be32(cxgb4_select_ntuple(netdev,
876 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530877 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530878 } else {
Ganesh Goudar192539f2017-01-31 12:00:09 +0530879 if (is_t5(ep->com.dev->rdev.lldi.adapter_type)) {
880 t5req6->params =
881 cpu_to_be64(FILTER_TUPLE_V(params));
882 t5req6->rsvd = cpu_to_be32(isn);
Joe Perchesa9a42882017-02-09 14:23:51 -0800883 pr_debug("%s snd_isn %u\n", __func__, t5req6->rsvd);
Ganesh Goudar192539f2017-01-31 12:00:09 +0530884 t5req6->opt2 = cpu_to_be32(opt2);
885 } else {
886 t6req6->params =
887 cpu_to_be64(FILTER_TUPLE_V(params));
888 t6req6->rsvd = cpu_to_be32(isn);
Doug Ledford339e7572017-04-20 22:18:54 -0400889 pr_debug("%s snd_isn %u\n", __func__, t6req6->rsvd);
Ganesh Goudar192539f2017-01-31 12:00:09 +0530890 t6req6->opt2 = cpu_to_be32(opt2);
891 }
892
Vipul Pandya830662f2013-07-04 16:10:47 +0530893 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000894 }
895
Vipul Pandya793dad92012-12-10 09:30:56 +0000896 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530897 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530898clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530899 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
900 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
901 (const u32 *)&la6->sin6_addr.s6_addr, 1);
902 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903}
904
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530905static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
906 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700907{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530908 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700909 struct fw_ofld_tx_data_wr *req;
910 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530911 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700912
Joe Perchesa9a42882017-02-09 14:23:51 -0800913 pr_debug("%s ep %p tid %u pd_len %d\n",
914 __func__, ep, ep->hwtid, ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700915
916 BUG_ON(skb_cloned(skb));
917
918 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530919 if (mpa_rev_to_use == 2)
920 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700921 wrlen = roundup(mpalen + sizeof *req, 16);
922 skb = get_skb(skb, wrlen, GFP_KERNEL);
923 if (!skb) {
924 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530925 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926 }
927 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
928
929 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
930 memset(req, 0, wrlen);
931 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530932 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
933 FW_WR_COMPL_F |
934 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700935 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530936 FW_WR_FLOWID_V(ep->hwtid) |
937 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700938 req->plen = cpu_to_be32(mpalen);
939 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530940 FW_OFLD_TX_DATA_WR_FLUSH_F |
941 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700942
943 mpa = (struct mpa_message *)(req + 1);
944 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530945
946 mpa->flags = 0;
947 if (crc_enabled)
948 mpa->flags |= MPA_CRC;
949 if (markers_enabled) {
950 mpa->flags |= MPA_MARKERS;
951 ep->mpa_attr.recv_marker_enabled = 1;
952 } else {
953 ep->mpa_attr.recv_marker_enabled = 0;
954 }
955 if (mpa_rev_to_use == 2)
956 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
957
Steve Wisecfdda9d2010-04-21 15:30:06 -0700958 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530959 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530960 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530961 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530962 ep->retry_with_mpa_v1 = 0;
963 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700964
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700966 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
967 sizeof (struct mpa_v2_conn_params));
Joe Perchesa9a42882017-02-09 14:23:51 -0800968 pr_debug("%s initiator ird %u ord %u\n", __func__, ep->ird,
969 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530970 mpa_v2_params.ird = htons((u16)ep->ird);
971 mpa_v2_params.ord = htons((u16)ep->ord);
972
973 if (peer2peer) {
974 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
975 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
976 mpa_v2_params.ord |=
977 htons(MPA_V2_RDMA_WRITE_RTR);
978 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
979 mpa_v2_params.ord |=
980 htons(MPA_V2_RDMA_READ_RTR);
981 }
982 memcpy(mpa->private_data, &mpa_v2_params,
983 sizeof(struct mpa_v2_conn_params));
984
985 if (ep->plen)
986 memcpy(mpa->private_data +
987 sizeof(struct mpa_v2_conn_params),
988 ep->mpa_pkt + sizeof(*mpa), ep->plen);
989 } else
990 if (ep->plen)
991 memcpy(mpa->private_data,
992 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700993
994 /*
995 * Reference the mpa skb. This ensures the data area
996 * will remain in memory until the hw acks the tx.
997 * Function fw4_ack() will deref it.
998 */
999 skb_get(skb);
1000 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1001 BUG_ON(ep->mpa_skb);
1002 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301003 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1004 if (ret)
1005 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001006 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301007 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001008 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301009 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301010 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001011}
1012
1013static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1014{
1015 int mpalen, wrlen;
1016 struct fw_ofld_tx_data_wr *req;
1017 struct mpa_message *mpa;
1018 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301019 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001020
Joe Perchesa9a42882017-02-09 14:23:51 -08001021 pr_debug("%s ep %p tid %u pd_len %d\n",
1022 __func__, ep, ep->hwtid, ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001023
1024 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301025 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1026 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 wrlen = roundup(mpalen + sizeof *req, 16);
1028
1029 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1030 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001031 pr_err("%s - cannot alloc skb!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001032 return -ENOMEM;
1033 }
1034 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1035
1036 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1037 memset(req, 0, wrlen);
1038 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301039 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1040 FW_WR_COMPL_F |
1041 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001042 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301043 FW_WR_FLOWID_V(ep->hwtid) |
1044 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001045 req->plen = cpu_to_be32(mpalen);
1046 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301047 FW_OFLD_TX_DATA_WR_FLUSH_F |
1048 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001049
1050 mpa = (struct mpa_message *)(req + 1);
1051 memset(mpa, 0, sizeof(*mpa));
1052 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1053 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001054 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001055 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301056
1057 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1058 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001059 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1060 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301061 mpa_v2_params.ird = htons(((u16)ep->ird) |
1062 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1063 0));
1064 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1065 (p2p_type ==
1066 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1067 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1068 FW_RI_INIT_P2PTYPE_READ_REQ ?
1069 MPA_V2_RDMA_READ_RTR : 0) : 0));
1070 memcpy(mpa->private_data, &mpa_v2_params,
1071 sizeof(struct mpa_v2_conn_params));
1072
1073 if (ep->plen)
1074 memcpy(mpa->private_data +
1075 sizeof(struct mpa_v2_conn_params), pdata, plen);
1076 } else
1077 if (plen)
1078 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001079
1080 /*
1081 * Reference the mpa skb again. This ensures the data area
1082 * will remain in memory until the hw acks the tx.
1083 * Function fw4_ack() will deref it.
1084 */
1085 skb_get(skb);
1086 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301087 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088 BUG_ON(ep->mpa_skb);
1089 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301090 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001091 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1092}
1093
1094static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1095{
1096 int mpalen, wrlen;
1097 struct fw_ofld_tx_data_wr *req;
1098 struct mpa_message *mpa;
1099 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301100 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001101
Joe Perchesa9a42882017-02-09 14:23:51 -08001102 pr_debug("%s ep %p tid %u pd_len %d\n",
1103 __func__, ep, ep->hwtid, ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104
1105 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301106 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1107 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001108 wrlen = roundup(mpalen + sizeof *req, 16);
1109
1110 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1111 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001112 pr_err("%s - cannot alloc skb!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001113 return -ENOMEM;
1114 }
1115 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1116
1117 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1118 memset(req, 0, wrlen);
1119 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301120 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1121 FW_WR_COMPL_F |
1122 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001123 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301124 FW_WR_FLOWID_V(ep->hwtid) |
1125 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001126 req->plen = cpu_to_be32(mpalen);
1127 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301128 FW_OFLD_TX_DATA_WR_FLUSH_F |
1129 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001130
1131 mpa = (struct mpa_message *)(req + 1);
1132 memset(mpa, 0, sizeof(*mpa));
1133 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301134 mpa->flags = 0;
1135 if (ep->mpa_attr.crc_enabled)
1136 mpa->flags |= MPA_CRC;
1137 if (ep->mpa_attr.recv_marker_enabled)
1138 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301139 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001140 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301141
1142 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1143 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001144 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1145 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301146 mpa_v2_params.ird = htons((u16)ep->ird);
1147 mpa_v2_params.ord = htons((u16)ep->ord);
1148 if (peer2peer && (ep->mpa_attr.p2p_type !=
1149 FW_RI_INIT_P2PTYPE_DISABLED)) {
1150 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1151
1152 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1153 mpa_v2_params.ord |=
1154 htons(MPA_V2_RDMA_WRITE_RTR);
1155 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1156 mpa_v2_params.ord |=
1157 htons(MPA_V2_RDMA_READ_RTR);
1158 }
1159
1160 memcpy(mpa->private_data, &mpa_v2_params,
1161 sizeof(struct mpa_v2_conn_params));
1162
1163 if (ep->plen)
1164 memcpy(mpa->private_data +
1165 sizeof(struct mpa_v2_conn_params), pdata, plen);
1166 } else
1167 if (plen)
1168 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001169
1170 /*
1171 * Reference the mpa skb. This ensures the data area
1172 * will remain in memory until the hw acks the tx.
1173 * Function fw4_ack() will deref it.
1174 */
1175 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301176 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301178 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301179 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1181}
1182
1183static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1184{
1185 struct c4iw_ep *ep;
1186 struct cpl_act_establish *req = cplhdr(skb);
1187 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001188 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001189 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301190 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001191
1192 ep = lookup_atid(t, atid);
1193
Joe Perchesa9a42882017-02-09 14:23:51 -08001194 pr_debug("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1195 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001196
Steve Wisea7db89e2014-03-21 20:40:35 +05301197 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198 dst_confirm(ep->dst);
1199
1200 /* setup the hwtid for this connection */
1201 ep->hwtid = tid;
1202 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301203 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001204
1205 ep->snd_seq = be32_to_cpu(req->snd_isn);
1206 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1207
1208 set_emss(ep, ntohs(req->tcp_opt));
1209
1210 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001211 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001213 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001214
1215 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301216 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301217 if (ret)
1218 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301219 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301220 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301221 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301222 ret = send_mpa_req(ep, skb, mpa_rev);
1223 if (ret)
1224 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301225 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001226 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301227err:
1228 mutex_unlock(&ep->com.mutex);
1229 connect_reply_upcall(ep, -ENOMEM);
1230 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1231 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001232}
1233
Steve Wisebe13b2d2014-03-21 20:40:33 +05301234static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001235{
1236 struct iw_cm_event event;
1237
Joe Perchesa9a42882017-02-09 14:23:51 -08001238 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001239 memset(&event, 0, sizeof(event));
1240 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301241 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001242 if (ep->com.cm_id) {
Joe Perchesa9a42882017-02-09 14:23:51 -08001243 pr_debug("close complete delivered ep %p cm_id %p tid %u\n",
1244 ep, ep->com.cm_id, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001245 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301246 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001247 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001248 }
1249}
1250
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251static void peer_close_upcall(struct c4iw_ep *ep)
1252{
1253 struct iw_cm_event event;
1254
Joe Perchesa9a42882017-02-09 14:23:51 -08001255 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 memset(&event, 0, sizeof(event));
1257 event.event = IW_CM_EVENT_DISCONNECT;
1258 if (ep->com.cm_id) {
Joe Perchesa9a42882017-02-09 14:23:51 -08001259 pr_debug("peer close delivered ep %p cm_id %p tid %u\n",
1260 ep, ep->com.cm_id, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001261 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001262 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001263 }
1264}
1265
1266static void peer_abort_upcall(struct c4iw_ep *ep)
1267{
1268 struct iw_cm_event event;
1269
Joe Perchesa9a42882017-02-09 14:23:51 -08001270 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271 memset(&event, 0, sizeof(event));
1272 event.event = IW_CM_EVENT_CLOSE;
1273 event.status = -ECONNRESET;
1274 if (ep->com.cm_id) {
Joe Perchesa9a42882017-02-09 14:23:51 -08001275 pr_debug("abort delivered ep %p cm_id %p tid %u\n", ep,
1276 ep->com.cm_id, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001277 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301278 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001279 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001280 }
1281}
1282
1283static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1284{
1285 struct iw_cm_event event;
1286
Joe Perchesa9a42882017-02-09 14:23:51 -08001287 pr_debug("%s ep %p tid %u status %d\n",
1288 __func__, ep, ep->hwtid, status);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001289 memset(&event, 0, sizeof(event));
1290 event.event = IW_CM_EVENT_CONNECT_REPLY;
1291 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301292 memcpy(&event.local_addr, &ep->com.local_addr,
1293 sizeof(ep->com.local_addr));
1294 memcpy(&event.remote_addr, &ep->com.remote_addr,
1295 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001296
1297 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301298 if (!ep->tried_with_mpa_v1) {
1299 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301300 event.ord = ep->ird;
1301 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301302 event.private_data_len = ep->plen -
1303 sizeof(struct mpa_v2_conn_params);
1304 event.private_data = ep->mpa_pkt +
1305 sizeof(struct mpa_message) +
1306 sizeof(struct mpa_v2_conn_params);
1307 } else {
1308 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301309 event.ord = cur_max_read_depth(ep->com.dev);
1310 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301311 event.private_data_len = ep->plen;
1312 event.private_data = ep->mpa_pkt +
1313 sizeof(struct mpa_message);
1314 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315 }
Roland Dreier85963e42010-07-19 13:13:09 -07001316
Joe Perchesa9a42882017-02-09 14:23:51 -08001317 pr_debug("%s ep %p tid %u status %d\n", __func__, ep,
1318 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001319 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001320 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1321
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301322 if (status < 0)
1323 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001324}
1325
Steve Wisebe13b2d2014-03-21 20:40:33 +05301326static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001327{
1328 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301329 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001330
Joe Perchesa9a42882017-02-09 14:23:51 -08001331 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001332 memset(&event, 0, sizeof(event));
1333 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301334 memcpy(&event.local_addr, &ep->com.local_addr,
1335 sizeof(ep->com.local_addr));
1336 memcpy(&event.remote_addr, &ep->com.remote_addr,
1337 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001338 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301339 if (!ep->tried_with_mpa_v1) {
1340 /* this means MPA_v2 is used */
1341 event.ord = ep->ord;
1342 event.ird = ep->ird;
1343 event.private_data_len = ep->plen -
1344 sizeof(struct mpa_v2_conn_params);
1345 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1346 sizeof(struct mpa_v2_conn_params);
1347 } else {
1348 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301349 event.ord = cur_max_read_depth(ep->com.dev);
1350 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301351 event.private_data_len = ep->plen;
1352 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1353 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301354 c4iw_get_ep(&ep->com);
1355 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1356 &event);
1357 if (ret)
1358 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001359 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301361 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362}
1363
1364static void established_upcall(struct c4iw_ep *ep)
1365{
1366 struct iw_cm_event event;
1367
Joe Perchesa9a42882017-02-09 14:23:51 -08001368 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001369 memset(&event, 0, sizeof(event));
1370 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301371 event.ird = ep->ord;
1372 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001373 if (ep->com.cm_id) {
Joe Perchesa9a42882017-02-09 14:23:51 -08001374 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001375 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001376 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001377 }
1378}
1379
1380static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1381{
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382 struct sk_buff *skb;
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301383 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1384 u32 credit_dack;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001385
Joe Perchesa9a42882017-02-09 14:23:51 -08001386 pr_debug("%s ep %p tid %u credits %u\n",
1387 __func__, ep, ep->hwtid, credits);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001388 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1389 if (!skb) {
Joe Perches700456b2017-02-09 14:23:50 -08001390 pr_err("update_rx_credits - cannot alloc skb!\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -07001391 return 0;
1392 }
1393
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301394 /*
1395 * If we couldn't specify the entire rcv window at connection setup
1396 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1397 * then add the overage in to the credits returned.
1398 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001399 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1400 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301401
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301402 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1403 RX_DACK_MODE_V(dack_mode);
1404
1405 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1406 credit_dack);
1407
Steve Wisecfdda9d2010-04-21 15:30:06 -07001408 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1409 return credits;
1410}
1411
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301412#define RELAXED_IRD_NEGOTIATION 1
1413
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301414/*
1415 * process_mpa_reply - process streaming mode MPA reply
1416 *
1417 * Returns:
1418 *
1419 * 0 upon success indicating a connect request was delivered to the ULP
1420 * or the mpa request is incomplete but valid so far.
1421 *
1422 * 1 if a failure requires the caller to close the connection.
1423 *
1424 * 2 if a failure requires the caller to abort the connection.
1425 */
Steve Wisecc18b932014-04-24 14:31:53 -05001426static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427{
1428 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301429 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301431 u16 resp_ird, resp_ord;
1432 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001433 struct c4iw_qp_attributes attrs;
1434 enum c4iw_qp_attr_mask mask;
1435 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001436 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437
Joe Perchesa9a42882017-02-09 14:23:51 -08001438 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001439
1440 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 * If we get more than the supported amount of private data
1442 * then we must fail this connection.
1443 */
1444 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1445 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301446 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001447 }
1448
1449 /*
1450 * copy the new data into our accumulation buffer.
1451 */
1452 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1453 skb->len);
1454 ep->mpa_pkt_len += skb->len;
1455
1456 /*
1457 * if we don't even have the mpa message, then bail.
1458 */
1459 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001460 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001461 mpa = (struct mpa_message *) ep->mpa_pkt;
1462
1463 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301464 if (mpa->revision > mpa_rev) {
Joe Perches700456b2017-02-09 14:23:50 -08001465 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1466 __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301468 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469 }
1470 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1471 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301472 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 }
1474
1475 plen = ntohs(mpa->private_data_size);
1476
1477 /*
1478 * Fail if there's too much private data.
1479 */
1480 if (plen > MPA_MAX_PRIVATE_DATA) {
1481 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301482 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483 }
1484
1485 /*
1486 * If plen does not account for pkt size
1487 */
1488 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1489 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301490 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001491 }
1492
1493 ep->plen = (u8) plen;
1494
1495 /*
1496 * If we don't have all the pdata yet, then bail.
1497 * We'll continue process when more data arrives.
1498 */
1499 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001500 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001501
1502 if (mpa->flags & MPA_REJECT) {
1503 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301504 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 }
1506
1507 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301508 * Stop mpa timer. If it expired, then
1509 * we ignore the MPA reply. process_timeout()
1510 * will abort the connection.
1511 */
1512 if (stop_ep_timer(ep))
1513 return 0;
1514
1515 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001516 * If we get here we have accumulated the entire mpa
1517 * start reply message including private data. And
1518 * the MPA header is valid.
1519 */
Steve Wisec529fb52014-03-21 20:40:37 +05301520 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001521 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001522 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301523 ep->mpa_attr.version = mpa->revision;
1524 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1525
1526 if (mpa->revision == 2) {
1527 ep->mpa_attr.enhanced_rdma_conn =
1528 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1529 if (ep->mpa_attr.enhanced_rdma_conn) {
1530 mpa_v2_params = (struct mpa_v2_conn_params *)
1531 (ep->mpa_pkt + sizeof(*mpa));
1532 resp_ird = ntohs(mpa_v2_params->ird) &
1533 MPA_V2_IRD_ORD_MASK;
1534 resp_ord = ntohs(mpa_v2_params->ord) &
1535 MPA_V2_IRD_ORD_MASK;
Joe Perchesa9a42882017-02-09 14:23:51 -08001536 pr_debug("%s responder ird %u ord %u ep ird %u ord %u\n",
1537 __func__,
1538 resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301539
1540 /*
1541 * This is a double-check. Ideally, below checks are
1542 * not required since ird/ord stuff has been taken
1543 * care of in c4iw_accept_cr
1544 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301545 if (ep->ird < resp_ord) {
1546 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1547 ep->com.dev->rdev.lldi.max_ordird_qp)
1548 ep->ird = resp_ord;
1549 else
1550 insuff_ird = 1;
1551 } else if (ep->ird > resp_ord) {
1552 ep->ird = resp_ord;
1553 }
1554 if (ep->ord > resp_ird) {
1555 if (RELAXED_IRD_NEGOTIATION)
1556 ep->ord = resp_ird;
1557 else
1558 insuff_ird = 1;
1559 }
1560 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301561 err = -ENOMEM;
1562 ep->ird = resp_ord;
1563 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 }
1565
1566 if (ntohs(mpa_v2_params->ird) &
1567 MPA_V2_PEER2PEER_MODEL) {
1568 if (ntohs(mpa_v2_params->ord) &
1569 MPA_V2_RDMA_WRITE_RTR)
1570 ep->mpa_attr.p2p_type =
1571 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1572 else if (ntohs(mpa_v2_params->ord) &
1573 MPA_V2_RDMA_READ_RTR)
1574 ep->mpa_attr.p2p_type =
1575 FW_RI_INIT_P2PTYPE_READ_REQ;
1576 }
1577 }
1578 } else if (mpa->revision == 1)
1579 if (peer2peer)
1580 ep->mpa_attr.p2p_type = p2p_type;
1581
Joe Perchesa9a42882017-02-09 14:23:51 -08001582 pr_debug("%s - crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = %d\n",
1583 __func__, ep->mpa_attr.crc_enabled,
1584 ep->mpa_attr.recv_marker_enabled,
1585 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1586 ep->mpa_attr.p2p_type, p2p_type);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301587
1588 /*
1589 * If responder's RTR does not match with that of initiator, assign
1590 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1591 * generated when moving QP to RTS state.
1592 * A TERM message will be sent after QP has moved to RTS state
1593 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001594 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301595 (ep->mpa_attr.p2p_type != p2p_type)) {
1596 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1597 rtr_mismatch = 1;
1598 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001599
1600 attrs.mpa_attr = ep->mpa_attr;
1601 attrs.max_ird = ep->ird;
1602 attrs.max_ord = ep->ord;
1603 attrs.llp_stream_handle = ep;
1604 attrs.next_state = C4IW_QP_STATE_RTS;
1605
1606 mask = C4IW_QP_ATTR_NEXT_STATE |
1607 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1608 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1609
1610 /* bind QP and TID with INIT_WR */
1611 err = c4iw_modify_qp(ep->com.qp->rhp,
1612 ep->com.qp, mask, &attrs, 1);
1613 if (err)
1614 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301615
1616 /*
1617 * If responder's RTR requirement did not match with what initiator
1618 * supports, generate TERM message
1619 */
1620 if (rtr_mismatch) {
Joe Perches700456b2017-02-09 14:23:50 -08001621 pr_err("%s: RTR mismatch, sending TERM\n", __func__);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301622 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1623 attrs.ecode = MPA_NOMATCH_RTR;
1624 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001625 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301626 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001627 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301628 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001629 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301630 goto out;
1631 }
1632
1633 /*
1634 * Generate TERM if initiator IRD is not sufficient for responder
1635 * provided ORD. Currently, we do the same behaviour even when
1636 * responder provided IRD is also not sufficient as regards to
1637 * initiator ORD.
1638 */
1639 if (insuff_ird) {
Joe Perches700456b2017-02-09 14:23:50 -08001640 pr_err("%s: Insufficient IRD, sending TERM\n", __func__);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301641 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1642 attrs.ecode = MPA_INSUFF_IRD;
1643 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001644 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301645 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001646 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301647 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001648 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301649 goto out;
1650 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001651 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301652err_stop_timer:
1653 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001654err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301655 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001656out:
1657 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001658 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001659}
1660
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301661/*
1662 * process_mpa_request - process streaming mode MPA request
1663 *
1664 * Returns:
1665 *
1666 * 0 upon success indicating a connect request was delivered to the ULP
1667 * or the mpa request is incomplete but valid so far.
1668 *
1669 * 1 if a failure requires the caller to close the connection.
1670 *
1671 * 2 if a failure requires the caller to abort the connection.
1672 */
1673static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001674{
1675 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301676 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001677 u16 plen;
1678
Joe Perchesa9a42882017-02-09 14:23:51 -08001679 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001680
Steve Wisecfdda9d2010-04-21 15:30:06 -07001681 /*
1682 * If we get more than the supported amount of private data
1683 * then we must fail this connection.
1684 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301685 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1686 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001687
Joe Perchesa9a42882017-02-09 14:23:51 -08001688 pr_debug("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001689
1690 /*
1691 * Copy the new data into our accumulation buffer.
1692 */
1693 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1694 skb->len);
1695 ep->mpa_pkt_len += skb->len;
1696
1697 /*
1698 * If we don't even have the mpa message, then bail.
1699 * We'll continue process when more data arrives.
1700 */
1701 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301702 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001703
Joe Perchesa9a42882017-02-09 14:23:51 -08001704 pr_debug("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001705 mpa = (struct mpa_message *) ep->mpa_pkt;
1706
1707 /*
1708 * Validate MPA Header.
1709 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301710 if (mpa->revision > mpa_rev) {
Joe Perches700456b2017-02-09 14:23:50 -08001711 pr_err("%s MPA version mismatch. Local = %d, Received = %d\n",
1712 __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301713 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001714 }
1715
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301716 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1717 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718
1719 plen = ntohs(mpa->private_data_size);
1720
1721 /*
1722 * Fail if there's too much private data.
1723 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301724 if (plen > MPA_MAX_PRIVATE_DATA)
1725 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726
1727 /*
1728 * If plen does not account for pkt size
1729 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301730 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1731 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001732 ep->plen = (u8) plen;
1733
1734 /*
1735 * If we don't have all the pdata yet, then bail.
1736 */
1737 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301738 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001739
1740 /*
1741 * If we get here we have accumulated the entire mpa
1742 * start reply message including private data.
1743 */
1744 ep->mpa_attr.initiator = 0;
1745 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1746 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1747 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301748 ep->mpa_attr.version = mpa->revision;
1749 if (mpa->revision == 1)
1750 ep->tried_with_mpa_v1 = 1;
1751 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1752
1753 if (mpa->revision == 2) {
1754 ep->mpa_attr.enhanced_rdma_conn =
1755 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1756 if (ep->mpa_attr.enhanced_rdma_conn) {
1757 mpa_v2_params = (struct mpa_v2_conn_params *)
1758 (ep->mpa_pkt + sizeof(*mpa));
1759 ep->ird = ntohs(mpa_v2_params->ird) &
1760 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001761 ep->ird = min_t(u32, ep->ird,
1762 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301763 ep->ord = ntohs(mpa_v2_params->ord) &
1764 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001765 ep->ord = min_t(u32, ep->ord,
1766 cur_max_read_depth(ep->com.dev));
Joe Perchesa9a42882017-02-09 14:23:51 -08001767 pr_debug("%s initiator ird %u ord %u\n",
1768 __func__, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301769 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1770 if (peer2peer) {
1771 if (ntohs(mpa_v2_params->ord) &
1772 MPA_V2_RDMA_WRITE_RTR)
1773 ep->mpa_attr.p2p_type =
1774 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1775 else if (ntohs(mpa_v2_params->ord) &
1776 MPA_V2_RDMA_READ_RTR)
1777 ep->mpa_attr.p2p_type =
1778 FW_RI_INIT_P2PTYPE_READ_REQ;
1779 }
1780 }
1781 } else if (mpa->revision == 1)
1782 if (peer2peer)
1783 ep->mpa_attr.p2p_type = p2p_type;
1784
Joe Perchesa9a42882017-02-09 14:23:51 -08001785 pr_debug("%s - crc_enabled=%d, recv_marker_enabled=%d, xmit_marker_enabled=%d, version=%d p2p_type=%d\n",
1786 __func__,
1787 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1788 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1789 ep->mpa_attr.p2p_type);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001790
Hariprasad Se4b76a22016-05-06 22:17:59 +05301791 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001792
Hariprasad Se4b76a22016-05-06 22:17:59 +05301793 /* drive upcall */
1794 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1795 if (ep->parent_ep->com.state != DEAD) {
1796 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301797 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301798 } else {
1799 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301800 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301801 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301802 return 0;
1803
1804err_unlock_parent:
1805 mutex_unlock(&ep->parent_ep->com.mutex);
1806 goto err_out;
1807err_stop_timer:
1808 (void)stop_ep_timer(ep);
1809err_out:
1810 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001811}
1812
1813static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1814{
1815 struct c4iw_ep *ep;
1816 struct cpl_rx_data *hdr = cplhdr(skb);
1817 unsigned int dlen = ntohs(hdr->len);
1818 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001819 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001820 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001821
Hariprasad S944661d2016-05-06 22:18:03 +05301822 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301823 if (!ep)
1824 return 0;
Joe Perchesa9a42882017-02-09 14:23:51 -08001825 pr_debug("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001826 skb_pull(skb, sizeof(*hdr));
1827 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301828 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829
Steve Wisec529fb52014-03-21 20:40:37 +05301830 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831 case MPA_REQ_SENT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001832 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001833 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001834 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001835 break;
1836 case MPA_REQ_WAIT:
Steve Wise3bcf96e2016-12-22 07:40:37 -08001837 update_rx_credits(ep, dlen);
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001838 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301839 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001840 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001841 case FPDU_MODE: {
1842 struct c4iw_qp_attributes attrs;
Steve Wise3bcf96e2016-12-22 07:40:37 -08001843
1844 update_rx_credits(ep, dlen);
Vipul Pandya15579672013-01-07 13:11:52 +00001845 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001846 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001847 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001848 " qpid %u ep %p state %d tid %u status %d\n",
1849 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301850 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301851 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001852 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001853 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1854 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855 break;
1856 }
Vipul Pandya15579672013-01-07 13:11:52 +00001857 default:
1858 break;
1859 }
Steve Wisec529fb52014-03-21 20:40:37 +05301860 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001861 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301862 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301863 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001864 return 0;
1865}
1866
1867static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1868{
1869 struct c4iw_ep *ep;
1870 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001871 int release = 0;
1872 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873
Hariprasad S944661d2016-05-06 22:18:03 +05301874 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301875 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08001876 pr_warn("Abort rpl to freed endpoint\n");
Vipul Pandya49840372012-05-18 15:29:29 +05301877 return 0;
1878 }
Joe Perchesa9a42882017-02-09 14:23:51 -08001879 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001880 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001881 switch (ep->com.state) {
1882 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001883 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001884 __state_set(&ep->com, DEAD);
1885 release = 1;
1886 break;
1887 default:
Joe Perches700456b2017-02-09 14:23:50 -08001888 pr_err("%s ep %p state %d\n", __func__, ep, ep->com.state);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001889 break;
1890 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001891 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001892
1893 if (release)
1894 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301895 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001896 return 0;
1897}
1898
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301899static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900{
1901 struct sk_buff *skb;
1902 struct fw_ofld_connection_wr *req;
1903 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301904 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301905 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301906 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001907
1908 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1909 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1910 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001911 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301912 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301913 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1914 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001916 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301917 req->le.lport = sin->sin_port;
1918 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001919 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301920 req->le.pport = sin->sin_port;
1921 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001922 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301923 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1924 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001925 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301926 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001927 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001928 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301929 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1930 enable_tcp_timestamps,
1931 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301932 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301933
1934 /*
1935 * Specify the largest window that will fit in opt0. The
1936 * remainder will be specified in the rx_data_ack.
1937 */
1938 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001939 if (win > RCV_BUFSIZ_M)
1940 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301941
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001942 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1943 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001944 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001945 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001946 WND_SCALE_V(wscale) |
1947 MSS_IDX_V(mtu_idx) |
1948 L2T_IDX_V(ep->l2t->idx) |
1949 TX_CHAN_V(ep->tx_chan) |
1950 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301951 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001952 ULP_MODE_V(ULP_MODE_TCPDDP) |
1953 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001954 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1955 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001956 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001957 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001958 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001959 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001960 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001961 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001962 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001963 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001964 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1965 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1966 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001967 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1968 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301969 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001970}
1971
Steve Wisecfdda9d2010-04-21 15:30:06 -07001972/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301973 * Some of the error codes above implicitly indicate that there is no TID
1974 * allocated with the result of an ACT_OPEN. We use this predicate to make
1975 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001976 */
1977static inline int act_open_has_tid(int status)
1978{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301979 return (status != CPL_ERR_TCAM_PARITY &&
1980 status != CPL_ERR_TCAM_MISS &&
1981 status != CPL_ERR_TCAM_FULL &&
1982 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1983 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001984}
1985
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301986static char *neg_adv_str(unsigned int status)
1987{
1988 switch (status) {
1989 case CPL_ERR_RTX_NEG_ADVICE:
1990 return "Retransmit timeout";
1991 case CPL_ERR_PERSIST_NEG_ADVICE:
1992 return "Persist timeout";
1993 case CPL_ERR_KEEPALV_NEG_ADVICE:
1994 return "Keepalive timeout";
1995 default:
1996 return "Unknown";
1997 }
1998}
1999
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302000static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2001{
2002 ep->snd_win = snd_win;
2003 ep->rcv_win = rcv_win;
Joe Perchesa9a42882017-02-09 14:23:51 -08002004 pr_debug("%s snd_win %d rcv_win %d\n",
2005 __func__, ep->snd_win, ep->rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302006}
2007
Vipul Pandya793dad92012-12-10 09:30:56 +00002008#define ACT_OPEN_RETRY_COUNT 2
2009
Vipul Pandya830662f2013-07-04 16:10:47 +05302010static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2011 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302012 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302013{
2014 struct neighbour *n;
2015 int err, step;
2016 struct net_device *pdev;
2017
2018 n = dst_neigh_lookup(dst, peer_ip);
2019 if (!n)
2020 return -ENODEV;
2021
2022 rcu_read_lock();
2023 err = -ENOMEM;
2024 if (n->dev->flags & IFF_LOOPBACK) {
2025 if (iptype == 4)
2026 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2027 else if (IS_ENABLED(CONFIG_IPV6))
2028 for_each_netdev(&init_net, pdev) {
2029 if (ipv6_chk_addr(&init_net,
2030 (struct in6_addr *)peer_ip,
2031 pdev, 1))
2032 break;
2033 }
2034 else
2035 pdev = NULL;
2036
2037 if (!pdev) {
2038 err = -ENODEV;
2039 goto out;
2040 }
2041 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302042 n, pdev, rt_tos2priority(tos));
Steve Wise609e9412016-09-01 06:43:46 -07002043 if (!ep->l2t) {
2044 dev_put(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302045 goto out;
Steve Wise609e9412016-09-01 06:43:46 -07002046 }
Vipul Pandya830662f2013-07-04 16:10:47 +05302047 ep->mtu = pdev->mtu;
2048 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302049 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2050 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302051 step = cdev->rdev.lldi.ntxq /
2052 cdev->rdev.lldi.nchan;
2053 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2054 step = cdev->rdev.lldi.nrxq /
2055 cdev->rdev.lldi.nchan;
2056 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2057 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2058 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302059 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302060 dev_put(pdev);
2061 } else {
2062 pdev = get_real_dev(n->dev);
2063 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2064 n, pdev, 0);
2065 if (!ep->l2t)
2066 goto out;
2067 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002068 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302069 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2070 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302071 step = cdev->rdev.lldi.ntxq /
2072 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002073 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2074 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302075 step = cdev->rdev.lldi.nrxq /
2076 cdev->rdev.lldi.nchan;
2077 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002078 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302079 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302080
2081 if (clear_mpa_v1) {
2082 ep->retry_with_mpa_v1 = 0;
2083 ep->tried_with_mpa_v1 = 0;
2084 }
2085 }
2086 err = 0;
2087out:
2088 rcu_read_unlock();
2089
2090 neigh_release(n);
2091
2092 return err;
2093}
2094
Vipul Pandya793dad92012-12-10 09:30:56 +00002095static int c4iw_reconnect(struct c4iw_ep *ep)
2096{
2097 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302098 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302099 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002100 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302101 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002102 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302103 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002104 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302105 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002106 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302107 int iptype;
2108 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002109
Joe Perchesa9a42882017-02-09 14:23:51 -08002110 pr_debug("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
Vipul Pandya793dad92012-12-10 09:30:56 +00002111 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302112 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002113
Hariprasad S4a740832016-06-10 01:05:15 +05302114 /* When MPA revision is different on nodes, the node with MPA_rev=2
2115 * tries to reconnect with MPA_rev 1 for the same EP through
2116 * c4iw_reconnect(), where the same EP is assigned with new tid for
2117 * further connection establishment. As we are using the same EP pointer
2118 * for reconnect, few skbs are used during the previous c4iw_connect(),
2119 * which leaves the EP with inadequate skbs for further
2120 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2121 * skb_list() during peer_abort(). Allocate skbs which is already used.
2122 */
2123 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2124 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2125 err = -ENOMEM;
2126 goto fail1;
2127 }
2128
Vipul Pandya793dad92012-12-10 09:30:56 +00002129 /*
2130 * Allocate an active TID to initiate a TCP connection.
2131 */
2132 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2133 if (ep->atid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08002134 pr_err("%s - cannot alloc atid\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002135 err = -ENOMEM;
2136 goto fail2;
2137 }
2138 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2139
2140 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002141 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302142 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2143 laddr->sin_addr.s_addr,
2144 raddr->sin_addr.s_addr,
2145 laddr->sin_port,
2146 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302147 iptype = 4;
2148 ra = (__u8 *)&raddr->sin_addr;
2149 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302150 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2151 get_real_dev,
2152 laddr6->sin6_addr.s6_addr,
2153 raddr6->sin6_addr.s6_addr,
2154 laddr6->sin6_port,
2155 raddr6->sin6_port, 0,
2156 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302157 iptype = 6;
2158 ra = (__u8 *)&raddr6->sin6_addr;
2159 }
2160 if (!ep->dst) {
Joe Perches700456b2017-02-09 14:23:50 -08002161 pr_err("%s - cannot find route\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002162 err = -EHOSTUNREACH;
2163 goto fail3;
2164 }
Hariprasad S963cab52015-09-23 17:19:27 +05302165 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302166 ep->com.dev->rdev.lldi.adapter_type,
2167 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302168 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08002169 pr_err("%s - cannot alloc l2e\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002170 goto fail4;
2171 }
2172
Joe Perchesa9a42882017-02-09 14:23:51 -08002173 pr_debug("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2174 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2175 ep->l2t->idx);
Vipul Pandya793dad92012-12-10 09:30:56 +00002176
2177 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302178 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002179
2180 /* send connect request to rnic */
2181 err = send_connect(ep);
2182 if (!err)
2183 goto out;
2184
2185 cxgb4_l2t_release(ep->l2t);
2186fail4:
2187 dst_release(ep->dst);
2188fail3:
2189 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2190 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2191fail2:
2192 /*
2193 * remember to send notification to upper layer.
2194 * We are in here so the upper layer is not aware that this is
2195 * re-connect attempt and so, upper layer is still waiting for
2196 * response of 1st connect request.
2197 */
2198 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302199fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002200 c4iw_put_ep(&ep->com);
2201out:
2202 return err;
2203}
2204
Steve Wisecfdda9d2010-04-21 15:30:06 -07002205static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2206{
2207 struct c4iw_ep *ep;
2208 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002209 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2210 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002211 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002212 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302213 struct sockaddr_in *la;
2214 struct sockaddr_in *ra;
2215 struct sockaddr_in6 *la6;
2216 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302217 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002218
2219 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002220 la = (struct sockaddr_in *)&ep->com.local_addr;
2221 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2222 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2223 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002224
Joe Perchesa9a42882017-02-09 14:23:51 -08002225 pr_debug("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2226 status, status2errno(status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002227
Varun Prakashb65eef02016-09-13 21:23:59 +05302228 if (cxgb_is_neg_adv(status)) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002229 pr_debug("%s Connection problems for atid %u status %u (%s)\n",
2230 __func__, atid, status, neg_adv_str(status));
Hariprasad S179d03b2015-05-05 03:55:24 +05302231 ep->stats.connect_neg_adv++;
2232 mutex_lock(&dev->rdev.stats.lock);
2233 dev->rdev.stats.neg_adv++;
2234 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 return 0;
2236 }
2237
Vipul Pandya793dad92012-12-10 09:30:56 +00002238 set_bit(ACT_OPEN_RPL, &ep->com.history);
2239
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302240 /*
2241 * Log interesting failures.
2242 */
2243 switch (status) {
2244 case CPL_ERR_CONN_RESET:
2245 case CPL_ERR_CONN_TIMEDOUT:
2246 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002247 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302248 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002249 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302250 mutex_unlock(&dev->rdev.stats.lock);
2251 if (ep->com.local_addr.ss_family == AF_INET &&
2252 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302253 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2254 ntohl(rpl->atid_status))));
2255 if (ret)
2256 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002257 return 0;
2258 }
2259 break;
2260 case CPL_ERR_CONN_EXIST:
2261 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2262 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302263 if (ep->com.remote_addr.ss_family == AF_INET6) {
2264 struct sockaddr_in6 *sin6 =
2265 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002266 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302267 cxgb4_clip_release(
2268 ep->com.dev->rdev.lldi.ports[0],
2269 (const u32 *)
2270 &sin6->sin6_addr.s6_addr, 1);
2271 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002272 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2273 atid);
2274 cxgb4_free_atid(t, atid);
2275 dst_release(ep->dst);
2276 cxgb4_l2t_release(ep->l2t);
2277 c4iw_reconnect(ep);
2278 return 0;
2279 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002280 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302281 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302282 if (ep->com.local_addr.ss_family == AF_INET) {
2283 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2284 atid, status, status2errno(status),
2285 &la->sin_addr.s_addr, ntohs(la->sin_port),
2286 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2287 } else {
2288 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2289 atid, status, status2errno(status),
2290 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2291 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2292 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302293 break;
2294 }
2295
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302296fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 connect_reply_upcall(ep, status2errno(status));
2298 state_set(&ep->com, DEAD);
2299
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302300 if (ep->com.remote_addr.ss_family == AF_INET6) {
2301 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002302 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302303 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2304 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2305 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002306 if (status && act_open_has_tid(status))
2307 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2308
Vipul Pandya793dad92012-12-10 09:30:56 +00002309 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002310 cxgb4_free_atid(t, atid);
2311 dst_release(ep->dst);
2312 cxgb4_l2t_release(ep->l2t);
2313 c4iw_put_ep(&ep->com);
2314
2315 return 0;
2316}
2317
2318static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2319{
2320 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302322 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323
2324 if (!ep) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002325 pr_debug("%s stid %d lookup failure!\n", __func__, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002326 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002327 }
Joe Perchesa9a42882017-02-09 14:23:51 -08002328 pr_debug("%s ep %p status %d error %d\n", __func__, ep,
2329 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002330 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302331 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002332out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333 return 0;
2334}
2335
Steve Wisecfdda9d2010-04-21 15:30:06 -07002336static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2337{
2338 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302340 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002341
Joe Perchesa9a42882017-02-09 14:23:51 -08002342 pr_debug("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002343 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302344 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 return 0;
2346}
2347
Hariprasad S9dec9002016-05-05 01:27:29 +05302348static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2349 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350{
2351 struct cpl_pass_accept_rpl *rpl;
2352 unsigned int mtu_idx;
2353 u64 opt0;
2354 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302355 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302356 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302357 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302358 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002359
Joe Perchesa9a42882017-02-09 14:23:51 -08002360 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002361 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302362
Steve Wisecfdda9d2010-04-21 15:30:06 -07002363 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302364 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302365 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302366 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2367 rpl5 = (void *)rpl;
2368 INIT_TP_WR(rpl5, ep->hwtid);
2369 } else {
2370 skb_trim(skb, sizeof(*rpl));
2371 INIT_TP_WR(rpl, ep->hwtid);
2372 }
2373 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2374 ep->hwtid));
2375
Varun Prakash44c6d062016-09-13 21:24:00 +05302376 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2377 enable_tcp_timestamps && req->tcpopt.tstamp,
2378 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302379 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302380
2381 /*
2382 * Specify the largest window that will fit in opt0. The
2383 * remainder will be specified in the rx_data_ack.
2384 */
2385 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002386 if (win > RCV_BUFSIZ_M)
2387 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002388 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002389 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002390 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002391 WND_SCALE_V(wscale) |
2392 MSS_IDX_V(mtu_idx) |
2393 L2T_IDX_V(ep->l2t->idx) |
2394 TX_CHAN_V(ep->tx_chan) |
2395 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002396 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002397 ULP_MODE_V(ULP_MODE_TCPDDP) |
2398 RCV_BUFSIZ_V(win);
2399 opt2 = RX_CHANNEL_V(0) |
2400 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002401
2402 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002403 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002404 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002405 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002407 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002408 if (enable_ecn) {
2409 const struct tcphdr *tcph;
2410 u32 hlen = ntohl(req->hdr_len);
2411
Hariprasad S963cab52015-09-23 17:19:27 +05302412 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2413 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2414 IP_HDR_LEN_G(hlen);
2415 else
2416 tcph = (const void *)(req + 1) +
2417 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002418 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002419 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002420 }
Hariprasad S963cab52015-09-23 17:19:27 +05302421 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302422 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002423 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302424 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302425 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302426 rpl5 = (void *)rpl;
2427 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2428 if (peer2peer)
2429 isn += 4;
2430 rpl5->iss = cpu_to_be32(isn);
Joe Perchesa9a42882017-02-09 14:23:51 -08002431 pr_debug("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002432 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002433
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 rpl->opt0 = cpu_to_be64(opt0);
2435 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002436 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302437 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438
Hariprasad S9dec9002016-05-05 01:27:29 +05302439 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440}
2441
Vipul Pandya830662f2013-07-04 16:10:47 +05302442static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443{
Joe Perchesa9a42882017-02-09 14:23:51 -08002444 pr_debug("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445 BUG_ON(skb_cloned(skb));
2446 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002447 release_tid(&dev->rdev, hwtid, skb);
2448 return;
2449}
2450
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2452{
Vipul Pandya793dad92012-12-10 09:30:56 +00002453 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002454 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002455 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002456 struct tid_info *t = dev->rdev.lldi.tids;
2457 unsigned int hwtid = GET_TID(req);
2458 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302459 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002460 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302461 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002462 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002463 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302464 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302465 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302466 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002467
Hariprasad Sf86fac72016-05-06 22:18:07 +05302468 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002469 if (!parent_ep) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002470 pr_debug("%s connect request on invalid stid %d\n",
2471 __func__, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002472 goto reject;
2473 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002474
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 if (state_read(&parent_ep->com) != LISTEN) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002476 pr_debug("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 goto reject;
2478 }
2479
Varun Prakash85e42b02016-09-13 21:23:56 +05302480 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2481 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302482
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302484 if (iptype == 4) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002485 pr_debug("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2486 , __func__, parent_ep, hwtid,
2487 local_ip, peer_ip, ntohs(local_port),
2488 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302489 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2490 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2491 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302492 } else {
Joe Perchesa9a42882017-02-09 14:23:51 -08002493 pr_debug("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2494 , __func__, parent_ep, hwtid,
2495 local_ip, peer_ip, ntohs(local_port),
2496 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302497 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2498 local_ip, peer_ip, local_port, peer_port,
2499 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2500 ((struct sockaddr_in6 *)
2501 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302502 }
2503 if (!dst) {
Joe Perches700456b2017-02-09 14:23:50 -08002504 pr_err("%s - failed to find dst entry!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002505 goto reject;
2506 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507
2508 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2509 if (!child_ep) {
Joe Perches700456b2017-02-09 14:23:50 -08002510 pr_err("%s - failed to allocate ep entry!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002511 dst_release(dst);
2512 goto reject;
2513 }
David Miller3786cf12011-12-02 16:52:31 +00002514
Hariprasad S963cab52015-09-23 17:19:27 +05302515 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302516 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002517 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08002518 pr_err("%s - failed to allocate l2t entry!\n", __func__);
David Miller3786cf12011-12-02 16:52:31 +00002519 dst_release(dst);
2520 kfree(child_ep);
2521 goto reject;
2522 }
2523
Raju Rangoju98b80a22017-05-31 12:06:58 +05302524 hdrs = ((iptype == 4) ? sizeof(struct iphdr) : sizeof(struct ipv6hdr)) +
2525 sizeof(struct tcphdr) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302526 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2527 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2528 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002529
Hariprasad S4a740832016-06-10 01:05:15 +05302530 skb_queue_head_init(&child_ep->com.ep_skb_list);
2531 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2532 goto fail;
2533
Steve Wisecfdda9d2010-04-21 15:30:06 -07002534 state_set(&child_ep->com, CONNECTING);
2535 child_ep->com.dev = dev;
2536 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002537
Vipul Pandya830662f2013-07-04 16:10:47 +05302538 if (iptype == 4) {
2539 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002540 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002541
ssh10b462b062016-12-24 07:14:35 +05302542 sin->sin_family = AF_INET;
Vipul Pandya830662f2013-07-04 16:10:47 +05302543 sin->sin_port = local_port;
2544 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002545
2546 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
ssh10b462b062016-12-24 07:14:35 +05302547 sin->sin_family = AF_INET;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002548 sin->sin_port = ((struct sockaddr_in *)
2549 &parent_ep->com.local_addr)->sin_port;
2550 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2551
Steve Wise170003c2016-02-26 09:18:03 -06002552 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
ssh10b462b062016-12-24 07:14:35 +05302553 sin->sin_family = AF_INET;
Vipul Pandya830662f2013-07-04 16:10:47 +05302554 sin->sin_port = peer_port;
2555 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2556 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002557 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302558 sin6->sin6_family = PF_INET6;
2559 sin6->sin6_port = local_port;
2560 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002561
2562 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2563 sin6->sin6_family = PF_INET6;
2564 sin6->sin6_port = ((struct sockaddr_in6 *)
2565 &parent_ep->com.local_addr)->sin6_port;
2566 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2567
Steve Wise170003c2016-02-26 09:18:03 -06002568 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302569 sin6->sin6_family = PF_INET6;
2570 sin6->sin6_port = peer_port;
2571 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2572 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002573
Steve Wisecfdda9d2010-04-21 15:30:06 -07002574 c4iw_get_ep(&parent_ep->com);
2575 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302576 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577 child_ep->dst = dst;
2578 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002579
Joe Perchesa9a42882017-02-09 14:23:51 -08002580 pr_debug("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
2581 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582
2583 init_timer(&child_ep->timer);
2584 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302585 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302586 if (accept_cr(child_ep, skb, req)) {
2587 c4iw_put_ep(&parent_ep->com);
2588 release_ep_resources(child_ep);
2589 } else {
2590 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2591 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302592 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002593 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302594 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2595 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2596 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302598fail:
2599 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302601 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302602 if (parent_ep)
2603 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604out:
2605 return 0;
2606}
2607
2608static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2609{
2610 struct c4iw_ep *ep;
2611 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002612 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302613 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614
Hariprasad S944661d2016-05-06 22:18:03 +05302615 ep = get_ep_from_tid(dev, tid);
Joe Perchesa9a42882017-02-09 14:23:51 -08002616 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617 ep->snd_seq = be32_to_cpu(req->snd_isn);
2618 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2619
Joe Perchesa9a42882017-02-09 14:23:51 -08002620 pr_debug("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2621 ntohs(req->tcp_opt));
Vipul Pandya1cab7752012-12-10 09:30:55 +00002622
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 set_emss(ep, ntohs(req->tcp_opt));
2624
2625 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302626 mutex_lock(&ep->com.mutex);
2627 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002628 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002629 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302630 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302631 mutex_unlock(&ep->com.mutex);
2632 if (ret)
2633 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302634 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002635
2636 return 0;
2637}
2638
2639static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2640{
2641 struct cpl_peer_close *hdr = cplhdr(skb);
2642 struct c4iw_ep *ep;
2643 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 int disconnect = 1;
2645 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002647 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648
Hariprasad S944661d2016-05-06 22:18:03 +05302649 ep = get_ep_from_tid(dev, tid);
2650 if (!ep)
2651 return 0;
2652
Joe Perchesa9a42882017-02-09 14:23:51 -08002653 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002654 dst_confirm(ep->dst);
2655
Vipul Pandya793dad92012-12-10 09:30:56 +00002656 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002657 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 switch (ep->com.state) {
2659 case MPA_REQ_WAIT:
2660 __state_set(&ep->com, CLOSING);
2661 break;
2662 case MPA_REQ_SENT:
2663 __state_set(&ep->com, CLOSING);
2664 connect_reply_upcall(ep, -ECONNRESET);
2665 break;
2666 case MPA_REQ_RCVD:
2667
2668 /*
2669 * We're gonna mark this puppy DEAD, but keep
2670 * the reference on it until the ULP accepts or
2671 * rejects the CR. Also wake up anyone waiting
2672 * in rdma connection migration (see c4iw_accept_cr()).
2673 */
2674 __state_set(&ep->com, CLOSING);
Joe Perchesa9a42882017-02-09 14:23:51 -08002675 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002676 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002677 break;
2678 case MPA_REP_SENT:
2679 __state_set(&ep->com, CLOSING);
Joe Perchesa9a42882017-02-09 14:23:51 -08002680 pr_debug("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002681 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002682 break;
2683 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002684 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002686 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002687 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002688 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002689 if (ret != -ECONNRESET) {
2690 peer_close_upcall(ep);
2691 disconnect = 1;
2692 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 break;
2694 case ABORTING:
2695 disconnect = 0;
2696 break;
2697 case CLOSING:
2698 __state_set(&ep->com, MORIBUND);
2699 disconnect = 0;
2700 break;
2701 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002702 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703 if (ep->com.cm_id && ep->com.qp) {
2704 attrs.next_state = C4IW_QP_STATE_IDLE;
2705 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2706 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2707 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302708 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709 __state_set(&ep->com, DEAD);
2710 release = 1;
2711 disconnect = 0;
2712 break;
2713 case DEAD:
2714 disconnect = 0;
2715 break;
2716 default:
2717 BUG_ON(1);
2718 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002719 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 if (disconnect)
2721 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2722 if (release)
2723 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302724 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 return 0;
2726}
2727
Steve Wisecfdda9d2010-04-21 15:30:06 -07002728static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2729{
2730 struct cpl_abort_req_rss *req = cplhdr(skb);
2731 struct c4iw_ep *ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 struct sk_buff *rpl_skb;
2733 struct c4iw_qp_attributes attrs;
2734 int ret;
2735 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 unsigned int tid = GET_TID(req);
Varun Prakash052f4732016-09-13 21:24:05 +05302737 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738
Hariprasad S944661d2016-05-06 22:18:03 +05302739 ep = get_ep_from_tid(dev, tid);
2740 if (!ep)
2741 return 0;
2742
Varun Prakashb65eef02016-09-13 21:23:59 +05302743 if (cxgb_is_neg_adv(req->status)) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002744 pr_debug("%s Negative advice on abort- tid %u status %d (%s)\n",
2745 __func__, ep->hwtid, req->status,
2746 neg_adv_str(req->status));
Hariprasad S179d03b2015-05-05 03:55:24 +05302747 ep->stats.abort_neg_adv++;
2748 mutex_lock(&dev->rdev.stats.lock);
2749 dev->rdev.stats.neg_adv++;
2750 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302751 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 }
Joe Perchesa9a42882017-02-09 14:23:51 -08002753 pr_debug("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2754 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002755 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002756
2757 /*
2758 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302759 * However, this is not needed if com state is just
2760 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002761 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302762 if (ep->com.state != MPA_REQ_SENT)
2763 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002764
2765 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002766 switch (ep->com.state) {
2767 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302768 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002769 break;
2770 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002771 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 break;
2773 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002774 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002775 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302776 connect_reply_upcall(ep, -ECONNRESET);
2777 else {
2778 /*
2779 * we just don't send notification upwards because we
2780 * want to retry with mpa_v1 without upper layers even
2781 * knowing it.
2782 *
2783 * do some housekeeping so as to re-initiate the
2784 * connection
2785 */
Joe Perchesa9a42882017-02-09 14:23:51 -08002786 pr_debug("%s: mpa_rev=%d. Retrying with mpav1\n",
2787 __func__, mpa_rev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302788 ep->retry_with_mpa_v1 = 1;
2789 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002790 break;
2791 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002792 break;
2793 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002794 break;
2795 case MORIBUND:
2796 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002797 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798 /*FALLTHROUGH*/
2799 case FPDU_MODE:
2800 if (ep->com.cm_id && ep->com.qp) {
2801 attrs.next_state = C4IW_QP_STATE_ERROR;
2802 ret = c4iw_modify_qp(ep->com.qp->rhp,
2803 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2804 &attrs, 1);
2805 if (ret)
Joe Perches700456b2017-02-09 14:23:50 -08002806 pr_err("%s - qp <- error failed!\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002807 }
2808 peer_abort_upcall(ep);
2809 break;
2810 case ABORTING:
2811 break;
2812 case DEAD:
Joe Perchesa9a42882017-02-09 14:23:51 -08002813 pr_debug("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002814 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302815 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 default:
2817 BUG_ON(1);
2818 break;
2819 }
2820 dst_confirm(ep->dst);
2821 if (ep->com.state != ABORTING) {
2822 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302823 /* we don't release if we want to retry with mpa_v1 */
2824 if (!ep->retry_with_mpa_v1)
2825 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002827 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002828
Hariprasad S4a740832016-06-10 01:05:15 +05302829 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2830 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002831 release = 1;
2832 goto out;
2833 }
Varun Prakash052f4732016-09-13 21:24:05 +05302834
2835 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2836
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2838out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 if (release)
2840 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002841 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302842 if (ep->com.remote_addr.ss_family == AF_INET6) {
2843 struct sockaddr_in6 *sin6 =
2844 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002845 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302846 cxgb4_clip_release(
2847 ep->com.dev->rdev.lldi.ports[0],
2848 (const u32 *)&sin6->sin6_addr.s6_addr,
2849 1);
2850 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002851 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302852 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2853 dst_release(ep->dst);
2854 cxgb4_l2t_release(ep->l2t);
2855 c4iw_reconnect(ep);
2856 }
2857
Hariprasad S944661d2016-05-06 22:18:03 +05302858deref_ep:
2859 c4iw_put_ep(&ep->com);
2860 /* Dereferencing ep, referenced in peer_abort_intr() */
2861 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 return 0;
2863}
2864
2865static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2866{
2867 struct c4iw_ep *ep;
2868 struct c4iw_qp_attributes attrs;
2869 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002870 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002872
Hariprasad S944661d2016-05-06 22:18:03 +05302873 ep = get_ep_from_tid(dev, tid);
2874 if (!ep)
2875 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002876
Joe Perchesa9a42882017-02-09 14:23:51 -08002877 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002878 BUG_ON(!ep);
2879
2880 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002881 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302882 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883 switch (ep->com.state) {
2884 case CLOSING:
2885 __state_set(&ep->com, MORIBUND);
2886 break;
2887 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002888 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889 if ((ep->com.cm_id) && (ep->com.qp)) {
2890 attrs.next_state = C4IW_QP_STATE_IDLE;
2891 c4iw_modify_qp(ep->com.qp->rhp,
2892 ep->com.qp,
2893 C4IW_QP_ATTR_NEXT_STATE,
2894 &attrs, 1);
2895 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302896 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002897 __state_set(&ep->com, DEAD);
2898 release = 1;
2899 break;
2900 case ABORTING:
2901 case DEAD:
2902 break;
2903 default:
2904 BUG_ON(1);
2905 break;
2906 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002907 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002908 if (release)
2909 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302910 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002911 return 0;
2912}
2913
2914static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2915{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002916 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002917 unsigned int tid = GET_TID(rpl);
2918 struct c4iw_ep *ep;
2919 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002920
Hariprasad S944661d2016-05-06 22:18:03 +05302921 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002922 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923
Steve Wise30c95c22011-05-09 22:06:22 -07002924 if (ep && ep->com.qp) {
Joe Perches700456b2017-02-09 14:23:50 -08002925 pr_warn("TERM received tid %u qpid %u\n",
2926 tid, ep->com.qp->wq.sq.qid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002927 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2928 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2929 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2930 } else
Joe Perches700456b2017-02-09 14:23:50 -08002931 pr_warn("TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302932 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 return 0;
2935}
2936
2937/*
2938 * Upcall from the adapter indicating data has been transmitted.
2939 * For us its just the single MPA request or reply. We can now free
2940 * the skb holding the mpa message.
2941 */
2942static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2943{
2944 struct c4iw_ep *ep;
2945 struct cpl_fw4_ack *hdr = cplhdr(skb);
2946 u8 credits = hdr->credits;
2947 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948
2949
Hariprasad S944661d2016-05-06 22:18:03 +05302950 ep = get_ep_from_tid(dev, tid);
2951 if (!ep)
2952 return 0;
Joe Perchesa9a42882017-02-09 14:23:51 -08002953 pr_debug("%s ep %p tid %u credits %u\n",
2954 __func__, ep, ep->hwtid, credits);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002955 if (credits == 0) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002956 pr_debug("%s 0 credit ack ep %p tid %u state %u\n",
2957 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302958 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 }
2960
2961 dst_confirm(ep->dst);
2962 if (ep->mpa_skb) {
Joe Perchesa9a42882017-02-09 14:23:51 -08002963 pr_debug("%s last streaming msg ack ep %p tid %u state %u initiator %u freeing skb\n",
2964 __func__, ep, ep->hwtid,
2965 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002966 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967 kfree_skb(ep->mpa_skb);
2968 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302969 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2970 stop_ep_timer(ep);
2971 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 }
Hariprasad S944661d2016-05-06 22:18:03 +05302973out:
2974 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975 return 0;
2976}
2977
Steve Wisecfdda9d2010-04-21 15:30:06 -07002978int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2979{
Hariprasad Sbce28412016-06-10 01:05:13 +05302980 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302982
Joe Perchesa9a42882017-02-09 14:23:51 -08002983 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002984
Steve Wisea7db89e2014-03-21 20:40:35 +05302985 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302986 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302987 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002988 c4iw_put_ep(&ep->com);
2989 return -ECONNRESET;
2990 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002991 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302993 abort = 1;
2994 else
2995 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302996 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302997
2998 stop_ep_timer(ep);
2999 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003000 c4iw_put_ep(&ep->com);
3001 return 0;
3002}
3003
3004int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3005{
3006 int err;
3007 struct c4iw_qp_attributes attrs;
3008 enum c4iw_qp_attr_mask mask;
3009 struct c4iw_ep *ep = to_ep(cm_id);
3010 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3011 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303012 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003013
Joe Perchesa9a42882017-02-09 14:23:51 -08003014 pr_debug("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303015
3016 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303017 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303019 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020 }
3021
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022 BUG_ON(!qp);
3023
Vipul Pandya793dad92012-12-10 09:30:56 +00003024 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303025 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3026 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003027 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303028 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003029 }
3030
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303031 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3032 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303033 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003034 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303035 } else {
3036 ep->ird = conn_param->ird;
3037 ep->ord = conn_param->ord;
3038 send_mpa_reject(ep, conn_param->private_data,
3039 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303040 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303041 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303042 }
3043 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303044 if (conn_param->ird < ep->ord) {
3045 if (RELAXED_IRD_NEGOTIATION &&
3046 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3047 conn_param->ird = ep->ord;
3048 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303049 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303050 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303051 }
3052 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303053 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003054 ep->ird = conn_param->ird;
3055 ep->ord = conn_param->ord;
3056
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303057 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303058 if (peer2peer && ep->ird == 0)
3059 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303060 } else {
3061 if (peer2peer &&
3062 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303063 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303064 ep->ird = 1;
3065 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003066
Joe Perchesa9a42882017-02-09 14:23:51 -08003067 pr_debug("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303069 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303070 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303071 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003072 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303073
Steve Wisecfdda9d2010-04-21 15:30:06 -07003074 /* bind QP to EP and move to RTS */
3075 attrs.mpa_attr = ep->mpa_attr;
3076 attrs.max_ird = ep->ird;
3077 attrs.max_ord = ep->ord;
3078 attrs.llp_stream_handle = ep;
3079 attrs.next_state = C4IW_QP_STATE_RTS;
3080
3081 /* bind QP and TID with INIT_WR */
3082 mask = C4IW_QP_ATTR_NEXT_STATE |
3083 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3084 C4IW_QP_ATTR_MPA_ATTR |
3085 C4IW_QP_ATTR_MAX_IRD |
3086 C4IW_QP_ATTR_MAX_ORD;
3087
3088 err = c4iw_modify_qp(ep->com.qp->rhp,
3089 ep->com.qp, mask, &attrs, 1);
3090 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303091 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303092
3093 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003094 err = send_mpa_reply(ep, conn_param->private_data,
3095 conn_param->private_data_len);
3096 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303097 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003098
Steve Wisea7db89e2014-03-21 20:40:35 +05303099 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003100 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303101 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003102 c4iw_put_ep(&ep->com);
3103 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303104err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303105 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303106err_abort:
3107 abort = 1;
3108err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303109 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303110 if (abort)
3111 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003112 c4iw_put_ep(&ep->com);
3113 return err;
3114}
3115
Vipul Pandya830662f2013-07-04 16:10:47 +05303116static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3117{
3118 struct in_device *ind;
3119 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003120 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3121 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303122
3123 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3124 if (!ind)
3125 return -EADDRNOTAVAIL;
3126 for_primary_ifa(ind) {
3127 laddr->sin_addr.s_addr = ifa->ifa_address;
3128 raddr->sin_addr.s_addr = ifa->ifa_address;
3129 found = 1;
3130 break;
3131 }
3132 endfor_ifa(ind);
3133 in_dev_put(ind);
3134 return found ? 0 : -EADDRNOTAVAIL;
3135}
3136
3137static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3138 unsigned char banned_flags)
3139{
3140 struct inet6_dev *idev;
3141 int err = -EADDRNOTAVAIL;
3142
3143 rcu_read_lock();
3144 idev = __in6_dev_get(dev);
3145 if (idev != NULL) {
3146 struct inet6_ifaddr *ifp;
3147
3148 read_lock_bh(&idev->lock);
3149 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3150 if (ifp->scope == IFA_LINK &&
3151 !(ifp->flags & banned_flags)) {
3152 memcpy(addr, &ifp->addr, 16);
3153 err = 0;
3154 break;
3155 }
3156 }
3157 read_unlock_bh(&idev->lock);
3158 }
3159 rcu_read_unlock();
3160 return err;
3161}
3162
3163static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3164{
3165 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003166 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3167 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303168
Nicholas Krause54b9a962015-08-26 23:00:59 -04003169 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303170 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3171 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3172 return 0;
3173 }
3174 return -EADDRNOTAVAIL;
3175}
3176
Steve Wisecfdda9d2010-04-21 15:30:06 -07003177int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3178{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003179 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3180 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003181 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003182 struct sockaddr_in *laddr;
3183 struct sockaddr_in *raddr;
3184 struct sockaddr_in6 *laddr6;
3185 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303186 __u8 *ra;
3187 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003188
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303189 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3190 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003191 err = -EINVAL;
3192 goto out;
3193 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003194 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3195 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08003196 pr_err("%s - cannot alloc ep\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003197 err = -ENOMEM;
3198 goto out;
3199 }
Hariprasad S4a740832016-06-10 01:05:15 +05303200
3201 skb_queue_head_init(&ep->com.ep_skb_list);
3202 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3203 err = -ENOMEM;
3204 goto fail1;
3205 }
3206
Steve Wisecfdda9d2010-04-21 15:30:06 -07003207 init_timer(&ep->timer);
3208 ep->plen = conn_param->private_data_len;
3209 if (ep->plen)
3210 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3211 conn_param->private_data, ep->plen);
3212 ep->ird = conn_param->ird;
3213 ep->ord = conn_param->ord;
3214
3215 if (peer2peer && ep->ord == 0)
3216 ep->ord = 1;
3217
Steve Wisecfdda9d2010-04-21 15:30:06 -07003218 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303219 ref_cm_id(&ep->com);
3220 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003221 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303222 if (!ep->com.qp) {
Joe Perchesa9a42882017-02-09 14:23:51 -08003223 pr_debug("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303224 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303225 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303226 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003227 ref_qp(ep);
Joe Perchesa9a42882017-02-09 14:23:51 -08003228 pr_debug("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3229 ep->com.qp, cm_id);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230
3231 /*
3232 * Allocate an active TID to initiate a TCP connection.
3233 */
3234 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3235 if (ep->atid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08003236 pr_err("%s - cannot alloc atid\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003237 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303238 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003240 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003241
Steve Wise170003c2016-02-26 09:18:03 -06003242 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003243 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003244 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003245 sizeof(ep->com.remote_addr));
3246
Steve Wise170003c2016-02-26 09:18:03 -06003247 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3248 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3249 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3250 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003251
Steve Wise170003c2016-02-26 09:18:03 -06003252 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303253 iptype = 4;
3254 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255
Vipul Pandya830662f2013-07-04 16:10:47 +05303256 /*
3257 * Handle loopback requests to INADDR_ANY.
3258 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003259 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303260 err = pick_local_ipaddrs(dev, cm_id);
3261 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303262 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303263 }
3264
3265 /* find a route */
Joe Perchesa9a42882017-02-09 14:23:51 -08003266 pr_debug("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3267 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3268 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303269 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3270 laddr->sin_addr.s_addr,
3271 raddr->sin_addr.s_addr,
3272 laddr->sin_port,
3273 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303274 } else {
3275 iptype = 6;
3276 ra = (__u8 *)&raddr6->sin6_addr;
3277
3278 /*
3279 * Handle loopback requests to INADDR_ANY.
3280 */
3281 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3282 err = pick_local_ip6addrs(dev, cm_id);
3283 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303284 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303285 }
3286
3287 /* find a route */
Joe Perchesa9a42882017-02-09 14:23:51 -08003288 pr_debug("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3289 __func__, laddr6->sin6_addr.s6_addr,
3290 ntohs(laddr6->sin6_port),
3291 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303292 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3293 laddr6->sin6_addr.s6_addr,
3294 raddr6->sin6_addr.s6_addr,
3295 laddr6->sin6_port,
3296 raddr6->sin6_port, 0,
3297 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303298 }
3299 if (!ep->dst) {
Joe Perches700456b2017-02-09 14:23:50 -08003300 pr_err("%s - cannot find route\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003301 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303302 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003304
Hariprasad S963cab52015-09-23 17:19:27 +05303305 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303306 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003307 if (err) {
Joe Perches700456b2017-02-09 14:23:50 -08003308 pr_err("%s - cannot alloc l2e\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303309 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003310 }
3311
Joe Perchesa9a42882017-02-09 14:23:51 -08003312 pr_debug("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3313 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3314 ep->l2t->idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003315
3316 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303317 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318
3319 /* send connect request to rnic */
3320 err = send_connect(ep);
3321 if (!err)
3322 goto out;
3323
3324 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303325fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003326 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303327fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003328 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003329 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303330fail2:
3331 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303332 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303333fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003334 c4iw_put_ep(&ep->com);
3335out:
3336 return err;
3337}
3338
Vipul Pandya830662f2013-07-04 16:10:47 +05303339static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3340{
3341 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003342 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003343 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303344
Hariprasad S28de1f72016-01-13 10:03:14 +05303345 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3346 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3347 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3348 if (err)
3349 return err;
3350 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303351 c4iw_init_wr_wait(&ep->com.wr_wait);
3352 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3353 ep->stid, &sin6->sin6_addr,
3354 sin6->sin6_port,
3355 ep->com.dev->rdev.lldi.rxq_ids[0]);
3356 if (!err)
3357 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3358 &ep->com.wr_wait,
3359 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303360 else if (err > 0)
3361 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303362 if (err) {
3363 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3364 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303365 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3366 err, ep->stid,
3367 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303368 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303369 return err;
3370}
3371
3372static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3373{
3374 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003375 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003376 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303377
3378 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3379 do {
3380 err = cxgb4_create_server_filter(
3381 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3382 sin->sin_addr.s_addr, sin->sin_port, 0,
3383 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3384 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303385 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3386 err = -EIO;
3387 break;
3388 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303389 set_current_state(TASK_UNINTERRUPTIBLE);
3390 schedule_timeout(usecs_to_jiffies(100));
3391 }
3392 } while (err == -EBUSY);
3393 } else {
3394 c4iw_init_wr_wait(&ep->com.wr_wait);
3395 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3396 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3397 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3398 if (!err)
3399 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3400 &ep->com.wr_wait,
3401 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303402 else if (err > 0)
3403 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303404 }
3405 if (err)
3406 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3407 , err, ep->stid,
3408 &sin->sin_addr, ntohs(sin->sin_port));
3409 return err;
3410}
3411
Steve Wisecfdda9d2010-04-21 15:30:06 -07003412int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3413{
3414 int err = 0;
3415 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3416 struct c4iw_listen_ep *ep;
3417
Steve Wisecfdda9d2010-04-21 15:30:06 -07003418 might_sleep();
3419
3420 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3421 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08003422 pr_err("%s - cannot alloc ep\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423 err = -ENOMEM;
3424 goto fail1;
3425 }
Hariprasad S4a740832016-06-10 01:05:15 +05303426 skb_queue_head_init(&ep->com.ep_skb_list);
Joe Perchesa9a42882017-02-09 14:23:51 -08003427 pr_debug("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003428 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303429 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003430 ep->com.dev = dev;
3431 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003432 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303433 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003434
3435 /*
3436 * Allocate a server TID.
3437 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303438 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3439 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303440 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003441 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003442 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303443 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003444 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003445
Steve Wisecfdda9d2010-04-21 15:30:06 -07003446 if (ep->stid == -1) {
Joe Perches700456b2017-02-09 14:23:50 -08003447 pr_err("%s - cannot alloc stid\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003448 err = -ENOMEM;
3449 goto fail2;
3450 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003451 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003452
Steve Wise170003c2016-02-26 09:18:03 -06003453 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3454 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003455
Steve Wisecfdda9d2010-04-21 15:30:06 -07003456 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303457 if (ep->com.local_addr.ss_family == AF_INET)
3458 err = create_server4(dev, ep);
3459 else
3460 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003461 if (!err) {
3462 cm_id->provider_data = ep;
3463 goto out;
3464 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003465
Vipul Pandya830662f2013-07-04 16:10:47 +05303466 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3467 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003468fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303469 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003470 c4iw_put_ep(&ep->com);
3471fail1:
3472out:
3473 return err;
3474}
3475
3476int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3477{
3478 int err;
3479 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3480
Joe Perchesa9a42882017-02-09 14:23:51 -08003481 pr_debug("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482
3483 might_sleep();
3484 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303485 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3486 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003487 err = cxgb4_remove_server_filter(
3488 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3489 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3490 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303491 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003492 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303493 err = cxgb4_remove_server(
3494 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3495 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003496 if (err)
3497 goto done;
3498 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3499 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003500 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303501 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3502 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003503 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003504 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303505 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3506 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003507done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303508 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509 c4iw_put_ep(&ep->com);
3510 return err;
3511}
3512
3513int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3514{
3515 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003516 int close = 0;
3517 int fatal = 0;
3518 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003519
Steve Wise2f5b48c2010-09-10 11:15:36 -05003520 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003521
Joe Perchesa9a42882017-02-09 14:23:51 -08003522 pr_debug("%s ep %p state %s, abrupt %d\n", __func__, ep,
3523 states[ep->com.state], abrupt);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003524
Hariprasad S6e410d82016-05-05 01:27:31 +05303525 /*
3526 * Ref the ep here in case we have fatal errors causing the
3527 * ep to be released and freed.
3528 */
3529 c4iw_get_ep(&ep->com);
3530
Steve Wisecfdda9d2010-04-21 15:30:06 -07003531 rdev = &ep->com.dev->rdev;
3532 if (c4iw_fatal_error(rdev)) {
3533 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303534 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535 ep->com.state = DEAD;
3536 }
3537 switch (ep->com.state) {
3538 case MPA_REQ_WAIT:
3539 case MPA_REQ_SENT:
3540 case MPA_REQ_RCVD:
3541 case MPA_REP_SENT:
3542 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303543 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003544 close = 1;
3545 if (abrupt)
3546 ep->com.state = ABORTING;
3547 else {
3548 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003549
3550 /*
3551 * if we close before we see the fw4_ack() then we fix
3552 * up the timer state since we're reusing it.
3553 */
3554 if (ep->mpa_skb &&
3555 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3556 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3557 stop_ep_timer(ep);
3558 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003559 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003560 }
3561 set_bit(CLOSE_SENT, &ep->com.flags);
3562 break;
3563 case CLOSING:
3564 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3565 close = 1;
3566 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003567 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003568 ep->com.state = ABORTING;
3569 } else
3570 ep->com.state = MORIBUND;
3571 }
3572 break;
3573 case MORIBUND:
3574 case ABORTING:
3575 case DEAD:
Joe Perchesa9a42882017-02-09 14:23:51 -08003576 pr_debug("%s ignoring disconnect ep %p state %u\n",
3577 __func__, ep, ep->com.state);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003578 break;
3579 default:
3580 BUG();
3581 break;
3582 }
3583
Steve Wisecfdda9d2010-04-21 15:30:06 -07003584 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003585 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003586 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303587 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303588 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003589 } else {
3590 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303591 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003592 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303593 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303594 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303595 if (!abrupt) {
3596 stop_ep_timer(ep);
3597 close_complete_upcall(ep, -EIO);
3598 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303599 if (ep->com.qp) {
3600 struct c4iw_qp_attributes attrs;
3601
3602 attrs.next_state = C4IW_QP_STATE_ERROR;
3603 ret = c4iw_modify_qp(ep->com.qp->rhp,
3604 ep->com.qp,
3605 C4IW_QP_ATTR_NEXT_STATE,
3606 &attrs, 1);
3607 if (ret)
Joe Perches700456b2017-02-09 14:23:50 -08003608 pr_err("%s - qp <- error failed!\n",
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303609 __func__);
3610 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003611 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303612 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003613 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003614 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303615 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003616 if (fatal)
3617 release_ep_resources(ep);
3618 return ret;
3619}
3620
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3622 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3623{
3624 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003625 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003626
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003627 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3628 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003629 if (!ep)
3630 return;
3631
3632 switch (req->retval) {
3633 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003634 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3635 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3636 send_fw_act_open_req(ep, atid);
3637 return;
3638 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003639 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003640 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3641 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3642 send_fw_act_open_req(ep, atid);
3643 return;
3644 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003645 break;
3646 default:
3647 pr_info("%s unexpected ofld conn wr retval %d\n",
3648 __func__, req->retval);
3649 break;
3650 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003651 pr_err("active ofld_connect_wr failure %d atid %d\n",
3652 req->retval, atid);
3653 mutex_lock(&dev->rdev.stats.lock);
3654 dev->rdev.stats.act_ofld_conn_fails++;
3655 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003656 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003657 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303658 if (ep->com.remote_addr.ss_family == AF_INET6) {
3659 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003660 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303661 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3662 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3663 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003664 remove_handle(dev, &dev->atid_idr, atid);
3665 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3666 dst_release(ep->dst);
3667 cxgb4_l2t_release(ep->l2t);
3668 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003669}
3670
3671static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3672 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3673{
3674 struct sk_buff *rpl_skb;
3675 struct cpl_pass_accept_req *cpl;
3676 int ret;
3677
Paul Bolle710a3112013-02-05 20:51:30 +00003678 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003679 BUG_ON(!rpl_skb);
3680 if (req->retval) {
Joe Perchesa9a42882017-02-09 14:23:51 -08003681 pr_debug("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003682 mutex_lock(&dev->rdev.stats.lock);
3683 dev->rdev.stats.pas_ofld_conn_fails++;
3684 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003685 kfree_skb(rpl_skb);
3686 } else {
3687 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3688 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003689 (__force u32) htonl(
3690 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003691 ret = pass_accept_req(dev, rpl_skb);
3692 if (!ret)
3693 kfree_skb(rpl_skb);
3694 }
3695 return;
3696}
3697
3698static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003699{
3700 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003701 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3702
3703 switch (rpl->type) {
3704 case FW6_TYPE_CQE:
3705 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3706 break;
3707 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3708 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3709 switch (req->t_state) {
3710 case TCP_SYN_SENT:
3711 active_ofld_conn_reply(dev, skb, req);
3712 break;
3713 case TCP_SYN_RECV:
3714 passive_ofld_conn_reply(dev, skb, req);
3715 break;
3716 default:
3717 pr_err("%s unexpected ofld conn wr state %d\n",
3718 __func__, req->t_state);
3719 break;
3720 }
3721 break;
3722 }
3723 return 0;
3724}
3725
3726static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3727{
Hariprasad S963cab52015-09-23 17:19:27 +05303728 __be32 l2info;
3729 __be16 hdr_len, vlantag, len;
3730 u16 eth_hdr_len;
3731 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732 u8 intf;
3733 struct cpl_rx_pkt *cpl = cplhdr(skb);
3734 struct cpl_pass_accept_req *req;
3735 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003736 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303737 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003738
Vipul Pandyaf079af72013-03-14 05:08:58 +00003739 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003740 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303741 vlantag = cpl->vlan;
3742 len = cpl->len;
3743 l2info = cpl->l2info;
3744 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003745 intf = cpl->iff;
3746
3747 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3748
3749 /*
3750 * We need to parse the TCP options from SYN packet.
3751 * to generate cpl_pass_accept_req.
3752 */
3753 memset(&tmp_opt, 0, sizeof(tmp_opt));
3754 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003755 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003756
3757 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3758 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303759 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3760 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303761 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303762 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303763 type = dev->rdev.lldi.adapter_type;
3764 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3765 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3766 req->hdr_len =
3767 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3768 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3769 eth_hdr_len = is_t4(type) ?
3770 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3771 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3772 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3773 IP_HDR_LEN_V(ip_hdr_len) |
3774 ETH_HDR_LEN_V(eth_hdr_len));
3775 } else { /* T6 and later */
3776 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3777 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3778 T6_IP_HDR_LEN_V(ip_hdr_len) |
3779 T6_ETH_HDR_LEN_V(eth_hdr_len));
3780 }
3781 req->vlan = vlantag;
3782 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003783 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3784 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003785 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3786 if (tmp_opt.wscale_ok)
3787 req->tcpopt.wsf = tmp_opt.snd_wscale;
3788 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3789 if (tmp_opt.sack_ok)
3790 req->tcpopt.sack = 1;
3791 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3792 return;
3793}
3794
3795static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3796 __be32 laddr, __be16 lport,
3797 __be32 raddr, __be16 rport,
3798 u32 rcv_isn, u32 filter, u16 window,
3799 u32 rss_qid, u8 port_id)
3800{
3801 struct sk_buff *req_skb;
3802 struct fw_ofld_connection_wr *req;
3803 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303804 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003805
3806 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
Pan Bian9ef63f32017-04-23 17:09:11 +08003807 if (!req_skb)
3808 return;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003809 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3810 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003811 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303812 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303813 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003814 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003815 req->le.lport = lport;
3816 req->le.pport = rport;
3817 req->le.u.ipv4.lip = laddr;
3818 req->le.u.ipv4.pip = raddr;
3819 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3820 req->tcb.rcv_adv = htons(window);
3821 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303822 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3823 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3824 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003825 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826
3827 /*
3828 * We store the qid in opt2 which will be used by the firmware
3829 * to send us the wr response.
3830 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003831 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003832
3833 /*
3834 * We initialize the MSS index in TCB to 0xF.
3835 * So that when driver sends cpl_pass_accept_rpl
3836 * TCB picks up the correct value. If this was 0
3837 * TP will ignore any value > 0 for MSS index.
3838 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003839 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303840 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003841
3842 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303843 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3844 if (ret < 0) {
3845 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3846 ret);
3847 kfree_skb(skb);
3848 kfree_skb(req_skb);
3849 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003850}
3851
3852/*
3853 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3854 * messages when a filter is being used instead of server to
3855 * redirect a syn packet. When packets hit filter they are redirected
3856 * to the offload queue and driver tries to establish the connection
3857 * using firmware work request.
3858 */
3859static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3860{
3861 int stid;
3862 unsigned int filter;
3863 struct ethhdr *eh = NULL;
3864 struct vlan_ethhdr *vlan_eh = NULL;
3865 struct iphdr *iph;
3866 struct tcphdr *tcph;
3867 struct rss_header *rss = (void *)skb->data;
3868 struct cpl_rx_pkt *cpl = (void *)skb->data;
3869 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3870 struct l2t_entry *e;
3871 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303872 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003873 u16 window;
3874 struct port_info *pi;
3875 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003876 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003877 int step;
3878 u32 tx_chan;
3879 struct neighbour *neigh;
3880
3881 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003882 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003883 goto reject;
3884
3885 /*
3886 * Drop all packets which did not hit the filter.
3887 * Unlikely to happen.
3888 */
3889 if (!(rss->filter_hit && rss->filter_tid))
3890 goto reject;
3891
3892 /*
3893 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3894 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303895 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003896
Hariprasad Sf86fac72016-05-06 22:18:07 +05303897 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003898 if (!lep) {
Joe Perchesa9a42882017-02-09 14:23:51 -08003899 pr_debug("%s connect request on invalid stid %d\n",
3900 __func__, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003901 goto reject;
3902 }
3903
Hariprasad S963cab52015-09-23 17:19:27 +05303904 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3905 case CHELSIO_T4:
3906 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3907 break;
3908 case CHELSIO_T5:
3909 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3910 break;
3911 case CHELSIO_T6:
3912 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3913 break;
3914 default:
3915 pr_err("T%d Chip is not supported\n",
3916 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3917 goto reject;
3918 }
3919
Vipul Pandyaf079af72013-03-14 05:08:58 +00003920 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003921 eh = (struct ethhdr *)(req + 1);
3922 iph = (struct iphdr *)(eh + 1);
3923 } else {
3924 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3925 iph = (struct iphdr *)(vlan_eh + 1);
3926 skb->vlan_tci = ntohs(cpl->vlan);
3927 }
3928
3929 if (iph->version != 0x4)
3930 goto reject;
3931
3932 tcph = (struct tcphdr *)(iph + 1);
3933 skb_set_network_header(skb, (void *)iph - (void *)rss);
3934 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3935 skb_get(skb);
3936
Joe Perchesa9a42882017-02-09 14:23:51 -08003937 pr_debug("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3938 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3939 ntohs(tcph->source), iph->tos);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003940
Varun Prakash804c2f32016-09-13 21:23:57 +05303941 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3942 iph->daddr, iph->saddr, tcph->dest,
3943 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303944 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003945 pr_err("%s - failed to find dst entry!\n",
3946 __func__);
3947 goto reject;
3948 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003949 neigh = dst_neigh_lookup_skb(dst, skb);
3950
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003951 if (!neigh) {
3952 pr_err("%s - failed to allocate neigh!\n",
3953 __func__);
3954 goto free_dst;
3955 }
3956
Vipul Pandya1cab7752012-12-10 09:30:55 +00003957 if (neigh->dev->flags & IFF_LOOPBACK) {
3958 pdev = ip_dev_find(&init_net, iph->daddr);
3959 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3960 pdev, 0);
3961 pi = (struct port_info *)netdev_priv(pdev);
3962 tx_chan = cxgb4_port_chan(pdev);
3963 dev_put(pdev);
3964 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303965 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003966 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303967 pdev, 0);
3968 pi = (struct port_info *)netdev_priv(pdev);
3969 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003970 }
Steve Wiseebf00062014-03-19 17:44:40 +05303971 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003972 if (!e) {
3973 pr_err("%s - failed to allocate l2t entry!\n",
3974 __func__);
3975 goto free_dst;
3976 }
3977
3978 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3979 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003980 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003981
3982 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303983 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3984 dev->rdev.lldi.ports[0],
3985 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003986
3987 /*
3988 * Synthesize the cpl_pass_accept_req. We have everything except the
3989 * TID. Once firmware sends a reply with TID we update the TID field
3990 * in cpl and pass it through the regular cpl_pass_accept_req path.
3991 */
3992 build_cpl_pass_accept_req(skb, stid, iph->tos);
3993 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3994 tcph->source, ntohl(tcph->seq), filter, window,
3995 rss_qid, pi->port_id);
3996 cxgb4_l2t_release(e);
3997free_dst:
3998 dst_release(dst);
3999reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304000 if (lep)
4001 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004002 return 0;
4003}
4004
Steve Wisecfdda9d2010-04-21 15:30:06 -07004005/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004006 * These are the real handlers that are called from a
4007 * work queue.
4008 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304009static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004010 [CPL_ACT_ESTABLISH] = act_establish,
4011 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4012 [CPL_RX_DATA] = rx_data,
4013 [CPL_ABORT_RPL_RSS] = abort_rpl,
4014 [CPL_ABORT_RPL] = abort_rpl,
4015 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4016 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4017 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4018 [CPL_PASS_ESTABLISH] = pass_establish,
4019 [CPL_PEER_CLOSE] = peer_close,
4020 [CPL_ABORT_REQ_RSS] = peer_abort,
4021 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4022 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004023 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004024 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304025 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304026 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4027 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028};
4029
4030static void process_timeout(struct c4iw_ep *ep)
4031{
4032 struct c4iw_qp_attributes attrs;
4033 int abort = 1;
4034
Steve Wise2f5b48c2010-09-10 11:15:36 -05004035 mutex_lock(&ep->com.mutex);
Joe Perchesa9a42882017-02-09 14:23:51 -08004036 pr_debug("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4037 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004038 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004039 switch (ep->com.state) {
4040 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004041 connect_reply_upcall(ep, -ETIMEDOUT);
4042 break;
4043 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304044 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304045 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304046 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004047 break;
4048 case CLOSING:
4049 case MORIBUND:
4050 if (ep->com.cm_id && ep->com.qp) {
4051 attrs.next_state = C4IW_QP_STATE_ERROR;
4052 c4iw_modify_qp(ep->com.qp->rhp,
4053 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4054 &attrs, 1);
4055 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304056 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004057 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004058 case ABORTING:
4059 case DEAD:
4060
4061 /*
4062 * These states are expected if the ep timed out at the same
4063 * time as another thread was calling stop_ep_timer().
4064 * So we silently do nothing for these states.
4065 */
4066 abort = 0;
4067 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004068 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004069 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004070 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004071 abort = 0;
4072 }
Steve Wisecc18b932014-04-24 14:31:53 -05004073 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304074 if (abort)
4075 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004076 c4iw_put_ep(&ep->com);
4077}
4078
4079static void process_timedout_eps(void)
4080{
4081 struct c4iw_ep *ep;
4082
4083 spin_lock_irq(&timeout_lock);
4084 while (!list_empty(&timeout_list)) {
4085 struct list_head *tmp;
4086
4087 tmp = timeout_list.next;
4088 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004089 tmp->next = NULL;
4090 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004091 spin_unlock_irq(&timeout_lock);
4092 ep = list_entry(tmp, struct c4iw_ep, entry);
4093 process_timeout(ep);
4094 spin_lock_irq(&timeout_lock);
4095 }
4096 spin_unlock_irq(&timeout_lock);
4097}
4098
4099static void process_work(struct work_struct *work)
4100{
4101 struct sk_buff *skb = NULL;
4102 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004103 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004104 unsigned int opcode;
4105 int ret;
4106
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004107 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004108 while ((skb = skb_dequeue(&rxq))) {
4109 rpl = cplhdr(skb);
4110 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4111 opcode = rpl->ot.opcode;
4112
4113 BUG_ON(!work_handlers[opcode]);
4114 ret = work_handlers[opcode](dev, skb);
4115 if (!ret)
4116 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004117 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004118 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004119}
4120
4121static DECLARE_WORK(skb_work, process_work);
4122
4123static void ep_timeout(unsigned long arg)
4124{
4125 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004126 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004127
4128 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004129 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004130 /*
4131 * Only insert if it is not already on the list.
4132 */
4133 if (!ep->entry.next) {
4134 list_add_tail(&ep->entry, &timeout_list);
4135 kickit = 1;
4136 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004137 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004138 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004139 if (kickit)
4140 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004141}
4142
4143/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004144 * All the CM events are handled on a work queue to have a safe context.
4145 */
4146static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4147{
4148
4149 /*
4150 * Save dev in the skb->cb area.
4151 */
4152 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4153
4154 /*
4155 * Queue the skb and schedule the worker thread.
4156 */
4157 skb_queue_tail(&rxq, skb);
4158 queue_work(workq, &skb_work);
4159 return 0;
4160}
4161
4162static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4163{
4164 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4165
4166 if (rpl->status != CPL_ERR_NONE) {
Joe Perches700456b2017-02-09 14:23:50 -08004167 pr_err("Unexpected SET_TCB_RPL status %u for tid %u\n",
4168 rpl->status, GET_TID(rpl));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004169 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004170 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004171 return 0;
4172}
4173
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004174static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4175{
4176 struct cpl_fw6_msg *rpl = cplhdr(skb);
4177 struct c4iw_wr_wait *wr_waitp;
4178 int ret;
4179
Joe Perchesa9a42882017-02-09 14:23:51 -08004180 pr_debug("%s type %u\n", __func__, rpl->type);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181
4182 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004183 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004184 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004185 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Joe Perchesa9a42882017-02-09 14:23:51 -08004186 pr_debug("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004187 if (wr_waitp)
4188 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004189 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004190 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004191 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004192 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004193 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004194 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004195 default:
Joe Perches700456b2017-02-09 14:23:50 -08004196 pr_err("%s unexpected fw6 msg type %u\n",
4197 __func__, rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004198 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004199 break;
4200 }
4201 return 0;
4202}
4203
Steve Wise8da7e7a2011-06-14 20:59:27 +00004204static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4205{
4206 struct cpl_abort_req_rss *req = cplhdr(skb);
4207 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004208 unsigned int tid = GET_TID(req);
4209
Hariprasad S944661d2016-05-06 22:18:03 +05304210 ep = get_ep_from_tid(dev, tid);
4211 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004212 if (!ep) {
Joe Perches700456b2017-02-09 14:23:50 -08004213 pr_warn("Abort on non-existent endpoint, tid %d\n", tid);
Steve Wise14b92222012-04-30 15:31:29 -05004214 kfree_skb(skb);
4215 return 0;
4216 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304217 if (cxgb_is_neg_adv(req->status)) {
Joe Perchesa9a42882017-02-09 14:23:51 -08004218 pr_debug("%s Negative advice on abort- tid %u status %d (%s)\n",
4219 __func__, ep->hwtid, req->status,
4220 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304221 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004222 }
Joe Perchesa9a42882017-02-09 14:23:51 -08004223 pr_debug("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4224 ep->com.state);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004225
Hariprasad S093108c2016-05-06 22:18:09 +05304226 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304227out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004228 sched(dev, skb);
4229 return 0;
4230}
4231
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004232/*
4233 * Most upcalls from the T4 Core go to sched() to
4234 * schedule the processing on a work queue.
4235 */
4236c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4237 [CPL_ACT_ESTABLISH] = sched,
4238 [CPL_ACT_OPEN_RPL] = sched,
4239 [CPL_RX_DATA] = sched,
4240 [CPL_ABORT_RPL_RSS] = sched,
4241 [CPL_ABORT_RPL] = sched,
4242 [CPL_PASS_OPEN_RPL] = sched,
4243 [CPL_CLOSE_LISTSRV_RPL] = sched,
4244 [CPL_PASS_ACCEPT_REQ] = sched,
4245 [CPL_PASS_ESTABLISH] = sched,
4246 [CPL_PEER_CLOSE] = sched,
4247 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004248 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004249 [CPL_RDMA_TERMINATE] = sched,
4250 [CPL_FW4_ACK] = sched,
4251 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004252 [CPL_FW6_MSG] = fw6_msg,
4253 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004254};
4255
Steve Wisecfdda9d2010-04-21 15:30:06 -07004256int __init c4iw_cm_init(void)
4257{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004258 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004259 skb_queue_head_init(&rxq);
4260
Bhaktipriya Shridhar52ee1a02016-08-15 23:39:14 +05304261 workq = alloc_ordered_workqueue("iw_cxgb4", WQ_MEM_RECLAIM);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004262 if (!workq)
4263 return -ENOMEM;
4264
Steve Wisecfdda9d2010-04-21 15:30:06 -07004265 return 0;
4266}
4267
Steve Wise46c13762014-06-20 14:26:25 -05004268void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004269{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004270 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004271 flush_workqueue(workq);
4272 destroy_workqueue(workq);
4273}