blob: b818bd6d1fb5f5c1e20ef86a7e88c9f835ca526b [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Varun Prakash85e42b02016-09-13 21:23:56 +053052#include <libcxgb_cm.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070053#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053054#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070055
56static char *states[] = {
57 "idle",
58 "listen",
59 "connecting",
60 "mpa_wait_req",
61 "mpa_req_sent",
62 "mpa_req_rcvd",
63 "mpa_rep_sent",
64 "fpdu_mode",
65 "aborting",
66 "closing",
67 "moribund",
68 "dead",
69 NULL,
70};
71
Vipul Pandya5be78ee2012-12-10 09:30:54 +000072static int nocong;
73module_param(nocong, int, 0644);
74MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
75
76static int enable_ecn;
77module_param(enable_ecn, int, 0644);
78MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
79
Steve Wiseb52fe092011-03-11 22:30:01 +000080static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000081module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000082MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000083
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053084uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070085module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053086MODULE_PARM_DESC(c4iw_max_read_depth,
87 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070088
Steve Wisecfdda9d2010-04-21 15:30:06 -070089static int enable_tcp_timestamps;
90module_param(enable_tcp_timestamps, int, 0644);
91MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
92
93static int enable_tcp_sack;
94module_param(enable_tcp_sack, int, 0644);
95MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
96
97static int enable_tcp_window_scaling = 1;
98module_param(enable_tcp_window_scaling, int, 0644);
99MODULE_PARM_DESC(enable_tcp_window_scaling,
100 "Enable tcp window scaling (default=1)");
101
102int c4iw_debug;
103module_param(c4iw_debug, int, 0644);
104MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
105
Steve Wisedf2d5132014-03-19 17:44:44 +0530106static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700107module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530108MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700109
110static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
111module_param(p2p_type, int, 0644);
112MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
113 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
114
115static int ep_timeout_secs = 60;
116module_param(ep_timeout_secs, int, 0644);
117MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
118 "in seconds (default=60)");
119
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530120static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700121module_param(mpa_rev, int, 0644);
122MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530123 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530124 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700125
126static int markers_enabled;
127module_param(markers_enabled, int, 0644);
128MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
129
130static int crc_enabled = 1;
131module_param(crc_enabled, int, 0644);
132MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
133
134static int rcv_win = 256 * 1024;
135module_param(rcv_win, int, 0644);
136MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
137
Steve Wise98ae68b2010-09-10 11:15:41 -0500138static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700139module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500140MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700143
144static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700145
146static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
147static void ep_timeout(unsigned long arg);
148static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530149static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700151static LIST_HEAD(timeout_list);
152static spinlock_t timeout_lock;
153
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530154static void deref_cm_id(struct c4iw_ep_common *epc)
155{
156 epc->cm_id->rem_ref(epc->cm_id);
157 epc->cm_id = NULL;
158 set_bit(CM_ID_DEREFED, &epc->history);
159}
160
161static void ref_cm_id(struct c4iw_ep_common *epc)
162{
163 set_bit(CM_ID_REFED, &epc->history);
164 epc->cm_id->add_ref(epc->cm_id);
165}
166
Vipul Pandya325abea2013-01-07 13:11:53 +0000167static void deref_qp(struct c4iw_ep *ep)
168{
169 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
170 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530171 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000172}
173
174static void ref_qp(struct c4iw_ep *ep)
175{
176 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530177 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000178 c4iw_qp_add_ref(&ep->com.qp->ibqp);
179}
180
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181static void start_ep_timer(struct c4iw_ep *ep)
182{
183 PDBG("%s ep %p\n", __func__, ep);
184 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000185 pr_err("%s timer already started! ep %p\n",
186 __func__, ep);
187 return;
188 }
189 clear_bit(TIMEOUT, &ep->com.flags);
190 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700191 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
192 ep->timer.data = (unsigned long)ep;
193 ep->timer.function = ep_timeout;
194 add_timer(&ep->timer);
195}
196
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500197static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700198{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000199 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700200 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500201 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000202 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500203 return 0;
204 }
205 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700206}
207
208static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
209 struct l2t_entry *l2e)
210{
211 int error = 0;
212
213 if (c4iw_fatal_error(rdev)) {
214 kfree_skb(skb);
215 PDBG("%s - device in error state - dropping\n", __func__);
216 return -EIO;
217 }
218 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
219 if (error < 0)
220 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530221 else if (error == NET_XMIT_DROP)
222 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500223 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700224}
225
226int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
227{
228 int error = 0;
229
230 if (c4iw_fatal_error(rdev)) {
231 kfree_skb(skb);
232 PDBG("%s - device in error state - dropping\n", __func__);
233 return -EIO;
234 }
235 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
236 if (error < 0)
237 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500238 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700239}
240
241static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
242{
Varun Prakasha1a23452016-09-13 21:24:02 +0530243 u32 len = roundup(sizeof(struct cpl_tid_release), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700244
Varun Prakasha1a23452016-09-13 21:24:02 +0530245 skb = get_skb(skb, len, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700246 if (!skb)
247 return;
Varun Prakasha1a23452016-09-13 21:24:02 +0530248
249 cxgb_mk_tid_release(skb, len, hwtid, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700250 c4iw_ofld_send(rdev, skb);
251 return;
252}
253
254static void set_emss(struct c4iw_ep *ep, u16 opt)
255{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800256 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530257 ((AF_INET == ep->com.remote_addr.ss_family) ?
258 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
259 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700260 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800261 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530262 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700263 if (ep->emss < 128)
264 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530265 if (ep->emss & 7)
266 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800267 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
268 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700269 ep->mss, ep->emss);
270}
271
272static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
273{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700274 enum c4iw_ep_state state;
275
Steve Wise2f5b48c2010-09-10 11:15:36 -0500276 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700277 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500278 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279 return state;
280}
281
282static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
283{
284 epc->state = new;
285}
286
287static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
288{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500289 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700290 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
291 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500292 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700293 return;
294}
295
Hariprasad S4a740832016-06-10 01:05:15 +0530296static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
297{
298 struct sk_buff *skb;
299 unsigned int i;
300 size_t len;
301
302 len = roundup(sizeof(union cpl_wr_size), 16);
303 for (i = 0; i < size; i++) {
304 skb = alloc_skb(len, GFP_KERNEL);
305 if (!skb)
306 goto fail;
307 skb_queue_tail(ep_skb_list, skb);
308 }
309 return 0;
310fail:
311 skb_queue_purge(ep_skb_list);
312 return -ENOMEM;
313}
314
Steve Wisecfdda9d2010-04-21 15:30:06 -0700315static void *alloc_ep(int size, gfp_t gfp)
316{
317 struct c4iw_ep_common *epc;
318
319 epc = kzalloc(size, gfp);
320 if (epc) {
321 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500322 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500323 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700324 }
325 PDBG("%s alloc ep %p\n", __func__, epc);
326 return epc;
327}
328
Hariprasad S944661d2016-05-06 22:18:03 +0530329static void remove_ep_tid(struct c4iw_ep *ep)
330{
331 unsigned long flags;
332
333 spin_lock_irqsave(&ep->com.dev->lock, flags);
334 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
335 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
336}
337
338static void insert_ep_tid(struct c4iw_ep *ep)
339{
340 unsigned long flags;
341
342 spin_lock_irqsave(&ep->com.dev->lock, flags);
343 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
344 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
345}
346
347/*
348 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
349 */
350static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
351{
352 struct c4iw_ep *ep;
353 unsigned long flags;
354
355 spin_lock_irqsave(&dev->lock, flags);
356 ep = idr_find(&dev->hwtid_idr, tid);
357 if (ep)
358 c4iw_get_ep(&ep->com);
359 spin_unlock_irqrestore(&dev->lock, flags);
360 return ep;
361}
362
Hariprasad Sf86fac72016-05-06 22:18:07 +0530363/*
364 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
365 */
366static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
367 unsigned int stid)
368{
369 struct c4iw_listen_ep *ep;
370 unsigned long flags;
371
372 spin_lock_irqsave(&dev->lock, flags);
373 ep = idr_find(&dev->stid_idr, stid);
374 if (ep)
375 c4iw_get_ep(&ep->com);
376 spin_unlock_irqrestore(&dev->lock, flags);
377 return ep;
378}
379
Steve Wisecfdda9d2010-04-21 15:30:06 -0700380void _c4iw_free_ep(struct kref *kref)
381{
382 struct c4iw_ep *ep;
383
384 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530385 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000386 if (test_bit(QP_REFERENCED, &ep->com.flags))
387 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700388 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530389 if (ep->com.remote_addr.ss_family == AF_INET6) {
390 struct sockaddr_in6 *sin6 =
391 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600392 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530393
394 cxgb4_clip_release(
395 ep->com.dev->rdev.lldi.ports[0],
396 (const u32 *)&sin6->sin6_addr.s6_addr,
397 1);
398 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700399 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
400 dst_release(ep->dst);
401 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530402 if (ep->mpa_skb)
403 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700404 }
Hariprasad S4a740832016-06-10 01:05:15 +0530405 if (!skb_queue_empty(&ep->com.ep_skb_list))
406 skb_queue_purge(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700407 kfree(ep);
408}
409
410static void release_ep_resources(struct c4iw_ep *ep)
411{
412 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530413
414 /*
415 * If we have a hwtid, then remove it from the idr table
416 * so lookups will no longer find this endpoint. Otherwise
417 * we have a race where one thread finds the ep ptr just
418 * before the other thread is freeing the ep memory.
419 */
420 if (ep->hwtid != -1)
421 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700422 c4iw_put_ep(&ep->com);
423}
424
Steve Wisecfdda9d2010-04-21 15:30:06 -0700425static int status2errno(int status)
426{
427 switch (status) {
428 case CPL_ERR_NONE:
429 return 0;
430 case CPL_ERR_CONN_RESET:
431 return -ECONNRESET;
432 case CPL_ERR_ARP_MISS:
433 return -EHOSTUNREACH;
434 case CPL_ERR_CONN_TIMEDOUT:
435 return -ETIMEDOUT;
436 case CPL_ERR_TCAM_FULL:
437 return -ENOMEM;
438 case CPL_ERR_CONN_EXIST:
439 return -EADDRINUSE;
440 default:
441 return -EIO;
442 }
443}
444
445/*
446 * Try and reuse skbs already allocated...
447 */
448static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
449{
450 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
451 skb_trim(skb, 0);
452 skb_get(skb);
453 skb_reset_transport_header(skb);
454 } else {
455 skb = alloc_skb(len, gfp);
456 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530457 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700458 return skb;
459}
460
Vipul Pandya830662f2013-07-04 16:10:47 +0530461static struct net_device *get_real_dev(struct net_device *egress_dev)
462{
Steve Wise11b8e222014-05-16 12:42:46 -0500463 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530464}
465
Steve Wisecfdda9d2010-04-21 15:30:06 -0700466static void arp_failure_discard(void *handle, struct sk_buff *skb)
467{
Hariprasad S9dec9002016-05-05 01:27:29 +0530468 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700469 kfree_skb(skb);
470}
471
Hariprasad S64bec742016-05-06 22:18:10 +0530472static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
473{
474 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
475}
476
Hariprasad S9dec9002016-05-05 01:27:29 +0530477enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530478 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530479 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530480 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530481};
482
483static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
484{
485 struct c4iw_ep *ep;
486
487 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
488 release_ep_resources(ep);
489 return 0;
490}
491
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530492static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
493{
494 struct c4iw_ep *ep;
495
496 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
497 c4iw_put_ep(&ep->parent_ep->com);
498 release_ep_resources(ep);
499 return 0;
500}
501
Hariprasad S9dec9002016-05-05 01:27:29 +0530502/*
503 * Fake up a special CPL opcode and call sched() so process_work() will call
504 * _put_ep_safe() in a safe context to free the ep resources. This is needed
505 * because ARP error handlers are called in an ATOMIC context, and
506 * _c4iw_free_ep() needs to block.
507 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530508static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
509 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530510{
511 struct cpl_act_establish *rpl = cplhdr(skb);
512
513 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530514 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530515
516 /*
517 * Save ep in the skb->cb area, after where sched() will save the dev
518 * ptr.
519 */
520 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
521 sched(ep->com.dev, skb);
522}
523
524/* Handle an ARP failure for an accept */
525static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
526{
527 struct c4iw_ep *ep = handle;
528
529 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
530 ep->hwtid);
531
532 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530533 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530534}
535
Steve Wisecfdda9d2010-04-21 15:30:06 -0700536/*
537 * Handle an ARP failure for an active open.
538 */
539static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
540{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530541 struct c4iw_ep *ep = handle;
542
Masanari Iidae3d132d2015-10-16 21:14:29 +0900543 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530544 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530545 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530546 if (ep->com.remote_addr.ss_family == AF_INET6) {
547 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600548 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530549 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
550 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
551 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530552 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
553 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530554 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700555}
556
557/*
558 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
559 * and send it along.
560 */
561static void abort_arp_failure(void *handle, struct sk_buff *skb)
562{
Hariprasad S761e19a2016-05-06 22:18:02 +0530563 int ret;
564 struct c4iw_ep *ep = handle;
565 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700566 struct cpl_abort_req *req = cplhdr(skb);
567
568 PDBG("%s rdev %p\n", __func__, rdev);
569 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530570 ret = c4iw_ofld_send(rdev, skb);
571 if (ret) {
572 __state_set(&ep->com, DEAD);
573 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
574 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700575}
576
Hariprasad S4a740832016-06-10 01:05:15 +0530577static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700578{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700579 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530580 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530582 u16 vlan = ep->l2t->vlan;
583 int nparams;
584
Hariprasad S4a740832016-06-10 01:05:15 +0530585 if (WARN_ON(!skb))
586 return -ENOMEM;
587
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530588 if (vlan == CPL_L2T_VLAN_NONE)
589 nparams = 8;
590 else
591 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700592
Hariprasad S4a740832016-06-10 01:05:15 +0530593 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700594
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530595 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530596 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530597 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530598 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700599
600 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530601 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530602 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700603 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
604 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
605 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
606 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
607 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
608 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
609 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
610 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
611 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
612 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
613 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530614 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700615 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
616 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530617 if (nparams == 9) {
618 u16 pri;
619
620 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
621 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
622 flowc->mnemval[8].val = cpu_to_be32(pri);
623 } else {
624 /* Pad WR to 16 byte boundary */
625 flowc->mnemval[8].mnemonic = 0;
626 flowc->mnemval[8].val = 0;
627 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700628 for (i = 0; i < 9; i++) {
629 flowc->mnemval[i].r4[0] = 0;
630 flowc->mnemval[i].r4[1] = 0;
631 flowc->mnemval[i].r4[2] = 0;
632 }
633
634 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530635 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700636}
637
Hariprasad S4a740832016-06-10 01:05:15 +0530638static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700639{
640 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530641 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642 int wrlen = roundup(sizeof *req, 16);
643
644 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530645 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700646 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530647
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
649 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
650 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
651 memset(req, 0, wrlen);
652 INIT_TP_WR(req, ep->hwtid);
653 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
654 ep->hwtid));
655 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
656}
657
Hariprasad S4a740832016-06-10 01:05:15 +0530658static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700659{
660 struct cpl_abort_req *req;
661 int wrlen = roundup(sizeof *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
664 PDBG("%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
668 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
669 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
670 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700671 memset(req, 0, wrlen);
672 INIT_TP_WR(req, ep->hwtid);
673 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
674 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530675 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700676}
677
678static int send_connect(struct c4iw_ep *ep)
679{
Hariprasad S963cab52015-09-23 17:19:27 +0530680 struct cpl_act_open_req *req = NULL;
681 struct cpl_t5_act_open_req *t5req = NULL;
682 struct cpl_t6_act_open_req *t6req = NULL;
683 struct cpl_act_open_req6 *req6 = NULL;
684 struct cpl_t5_act_open_req6 *t5req6 = NULL;
685 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700686 struct sk_buff *skb;
687 u64 opt0;
688 u32 opt2;
689 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530690 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530691 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500692 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600693 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500694 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600695 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500696 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600697 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500698 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600699 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530700 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530701 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
702 u32 isn = (prandom_u32() & ~7UL) - 1;
703
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
727 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
728
729 skb = get_skb(NULL, wrlen, GFP_KERNEL);
730 if (!skb) {
731 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
732 __func__);
733 return -ENOMEM;
734 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000735 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700736
Varun Prakash44c6d062016-09-13 21:24:00 +0530737 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
738 enable_tcp_timestamps,
739 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530740 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530741
742 /*
743 * Specify the largest window that will fit in opt0. The
744 * remainder will be specified in the rx_data_ack.
745 */
746 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800747 if (win > RCV_BUFSIZ_M)
748 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530749
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800750 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800751 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800752 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800753 WND_SCALE_V(wscale) |
754 MSS_IDX_V(mtu_idx) |
755 L2T_IDX_V(ep->l2t->idx) |
756 TX_CHAN_V(ep->tx_chan) |
757 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530758 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800759 ULP_MODE_V(ULP_MODE_TCPDDP) |
760 RCV_BUFSIZ_V(win);
761 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800762 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800763 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700764 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800765 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700766 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800767 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700768 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800769 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530770 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
771 if (peer2peer)
772 isn += 4;
773
Anish Bhattd7990b02014-11-12 17:15:57 -0800774 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530775 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530776 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500777 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530778
779 if (ep->com.remote_addr.ss_family == AF_INET6)
780 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
781 (const u32 *)&la6->sin6_addr.s6_addr, 1);
782
Hariprasad S5dab6d32014-06-23 19:12:36 +0530783 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700784
Hariprasad S963cab52015-09-23 17:19:27 +0530785 if (ep->com.remote_addr.ss_family == AF_INET) {
786 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
787 case CHELSIO_T4:
788 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530789 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530790 break;
791 case CHELSIO_T5:
792 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
793 wrlen);
794 INIT_TP_WR(t5req, 0);
795 req = (struct cpl_act_open_req *)t5req;
796 break;
797 case CHELSIO_T6:
798 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
799 wrlen);
800 INIT_TP_WR(t6req, 0);
801 req = (struct cpl_act_open_req *)t6req;
802 t5req = (struct cpl_t5_act_open_req *)t6req;
803 break;
804 default:
805 pr_err("T%d Chip is not supported\n",
806 CHELSIO_CHIP_VERSION(adapter_type));
807 ret = -EINVAL;
808 goto clip_release;
809 }
810
811 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
812 ((ep->rss_qid<<14) | ep->atid)));
813 req->local_port = la->sin_port;
814 req->peer_port = ra->sin_port;
815 req->local_ip = la->sin_addr.s_addr;
816 req->peer_ip = ra->sin_addr.s_addr;
817 req->opt0 = cpu_to_be64(opt0);
818
819 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530820 req->params = cpu_to_be32(cxgb4_select_ntuple(
821 ep->com.dev->rdev.lldi.ports[0],
822 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530823 req->opt2 = cpu_to_be32(opt2);
824 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530825 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
826 cxgb4_select_ntuple(
827 ep->com.dev->rdev.lldi.ports[0],
828 ep->l2t)));
829 t5req->rsvd = cpu_to_be32(isn);
830 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
831 t5req->opt2 = cpu_to_be32(opt2);
832 }
833 } else {
834 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
835 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530836 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530837 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530838 break;
839 case CHELSIO_T5:
840 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
841 wrlen);
842 INIT_TP_WR(t5req6, 0);
843 req6 = (struct cpl_act_open_req6 *)t5req6;
844 break;
845 case CHELSIO_T6:
846 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
847 wrlen);
848 INIT_TP_WR(t6req6, 0);
849 req6 = (struct cpl_act_open_req6 *)t6req6;
850 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
851 break;
852 default:
853 pr_err("T%d Chip is not supported\n",
854 CHELSIO_CHIP_VERSION(adapter_type));
855 ret = -EINVAL;
856 goto clip_release;
857 }
858
859 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
860 ((ep->rss_qid<<14)|ep->atid)));
861 req6->local_port = la6->sin6_port;
862 req6->peer_port = ra6->sin6_port;
863 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
864 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
865 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
866 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
867 req6->opt0 = cpu_to_be64(opt0);
868
869 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530870 req6->params = cpu_to_be32(cxgb4_select_ntuple(
871 ep->com.dev->rdev.lldi.ports[0],
872 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530873 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530874 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530875 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
876 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530877 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530878 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530879 t5req6->rsvd = cpu_to_be32(isn);
880 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
881 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530882 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000883 }
884
Vipul Pandya793dad92012-12-10 09:30:56 +0000885 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530886 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530887clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530888 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
889 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
890 (const u32 *)&la6->sin6_addr.s6_addr, 1);
891 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700892}
893
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530894static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
895 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700896{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530897 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700898 struct fw_ofld_tx_data_wr *req;
899 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530900 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700901
902 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
903
904 BUG_ON(skb_cloned(skb));
905
906 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530907 if (mpa_rev_to_use == 2)
908 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700909 wrlen = roundup(mpalen + sizeof *req, 16);
910 skb = get_skb(skb, wrlen, GFP_KERNEL);
911 if (!skb) {
912 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530913 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700914 }
915 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
916
917 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
918 memset(req, 0, wrlen);
919 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530920 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
921 FW_WR_COMPL_F |
922 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700923 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530924 FW_WR_FLOWID_V(ep->hwtid) |
925 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926 req->plen = cpu_to_be32(mpalen);
927 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530928 FW_OFLD_TX_DATA_WR_FLUSH_F |
929 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930
931 mpa = (struct mpa_message *)(req + 1);
932 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530933
934 mpa->flags = 0;
935 if (crc_enabled)
936 mpa->flags |= MPA_CRC;
937 if (markers_enabled) {
938 mpa->flags |= MPA_MARKERS;
939 ep->mpa_attr.recv_marker_enabled = 1;
940 } else {
941 ep->mpa_attr.recv_marker_enabled = 0;
942 }
943 if (mpa_rev_to_use == 2)
944 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
945
Steve Wisecfdda9d2010-04-21 15:30:06 -0700946 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530947 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530948 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530949 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530950 ep->retry_with_mpa_v1 = 0;
951 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700952
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530953 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700954 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
955 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530956 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
957 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530958 mpa_v2_params.ird = htons((u16)ep->ird);
959 mpa_v2_params.ord = htons((u16)ep->ord);
960
961 if (peer2peer) {
962 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
963 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
964 mpa_v2_params.ord |=
965 htons(MPA_V2_RDMA_WRITE_RTR);
966 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
967 mpa_v2_params.ord |=
968 htons(MPA_V2_RDMA_READ_RTR);
969 }
970 memcpy(mpa->private_data, &mpa_v2_params,
971 sizeof(struct mpa_v2_conn_params));
972
973 if (ep->plen)
974 memcpy(mpa->private_data +
975 sizeof(struct mpa_v2_conn_params),
976 ep->mpa_pkt + sizeof(*mpa), ep->plen);
977 } else
978 if (ep->plen)
979 memcpy(mpa->private_data,
980 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700981
982 /*
983 * Reference the mpa skb. This ensures the data area
984 * will remain in memory until the hw acks the tx.
985 * Function fw4_ack() will deref it.
986 */
987 skb_get(skb);
988 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
989 BUG_ON(ep->mpa_skb);
990 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530991 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
992 if (ret)
993 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530995 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530997 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530998 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700999}
1000
1001static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1002{
1003 int mpalen, wrlen;
1004 struct fw_ofld_tx_data_wr *req;
1005 struct mpa_message *mpa;
1006 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301007 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001008
1009 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1010
1011 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301012 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1013 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001014 wrlen = roundup(mpalen + sizeof *req, 16);
1015
1016 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1017 if (!skb) {
1018 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1019 return -ENOMEM;
1020 }
1021 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1022
1023 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1024 memset(req, 0, wrlen);
1025 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301026 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1027 FW_WR_COMPL_F |
1028 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001029 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301030 FW_WR_FLOWID_V(ep->hwtid) |
1031 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001032 req->plen = cpu_to_be32(mpalen);
1033 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301034 FW_OFLD_TX_DATA_WR_FLUSH_F |
1035 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001036
1037 mpa = (struct mpa_message *)(req + 1);
1038 memset(mpa, 0, sizeof(*mpa));
1039 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1040 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001041 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001042 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301043
1044 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1045 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001046 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1047 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301048 mpa_v2_params.ird = htons(((u16)ep->ird) |
1049 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1050 0));
1051 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1052 (p2p_type ==
1053 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1054 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1055 FW_RI_INIT_P2PTYPE_READ_REQ ?
1056 MPA_V2_RDMA_READ_RTR : 0) : 0));
1057 memcpy(mpa->private_data, &mpa_v2_params,
1058 sizeof(struct mpa_v2_conn_params));
1059
1060 if (ep->plen)
1061 memcpy(mpa->private_data +
1062 sizeof(struct mpa_v2_conn_params), pdata, plen);
1063 } else
1064 if (plen)
1065 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001066
1067 /*
1068 * Reference the mpa skb again. This ensures the data area
1069 * will remain in memory until the hw acks the tx.
1070 * Function fw4_ack() will deref it.
1071 */
1072 skb_get(skb);
1073 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301074 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001075 BUG_ON(ep->mpa_skb);
1076 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301077 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001078 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1079}
1080
1081static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1082{
1083 int mpalen, wrlen;
1084 struct fw_ofld_tx_data_wr *req;
1085 struct mpa_message *mpa;
1086 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301087 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088
1089 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1090
1091 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301092 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1093 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094 wrlen = roundup(mpalen + sizeof *req, 16);
1095
1096 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1097 if (!skb) {
1098 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1099 return -ENOMEM;
1100 }
1101 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1102
1103 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1104 memset(req, 0, wrlen);
1105 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301106 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1107 FW_WR_COMPL_F |
1108 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001109 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301110 FW_WR_FLOWID_V(ep->hwtid) |
1111 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001112 req->plen = cpu_to_be32(mpalen);
1113 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301114 FW_OFLD_TX_DATA_WR_FLUSH_F |
1115 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001116
1117 mpa = (struct mpa_message *)(req + 1);
1118 memset(mpa, 0, sizeof(*mpa));
1119 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301120 mpa->flags = 0;
1121 if (ep->mpa_attr.crc_enabled)
1122 mpa->flags |= MPA_CRC;
1123 if (ep->mpa_attr.recv_marker_enabled)
1124 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301125 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001126 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301127
1128 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1129 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001130 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1131 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301132 mpa_v2_params.ird = htons((u16)ep->ird);
1133 mpa_v2_params.ord = htons((u16)ep->ord);
1134 if (peer2peer && (ep->mpa_attr.p2p_type !=
1135 FW_RI_INIT_P2PTYPE_DISABLED)) {
1136 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1137
1138 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1139 mpa_v2_params.ord |=
1140 htons(MPA_V2_RDMA_WRITE_RTR);
1141 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1142 mpa_v2_params.ord |=
1143 htons(MPA_V2_RDMA_READ_RTR);
1144 }
1145
1146 memcpy(mpa->private_data, &mpa_v2_params,
1147 sizeof(struct mpa_v2_conn_params));
1148
1149 if (ep->plen)
1150 memcpy(mpa->private_data +
1151 sizeof(struct mpa_v2_conn_params), pdata, plen);
1152 } else
1153 if (plen)
1154 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001155
1156 /*
1157 * Reference the mpa skb. This ensures the data area
1158 * will remain in memory until the hw acks the tx.
1159 * Function fw4_ack() will deref it.
1160 */
1161 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301162 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001163 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301164 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301165 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001166 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1167}
1168
1169static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1170{
1171 struct c4iw_ep *ep;
1172 struct cpl_act_establish *req = cplhdr(skb);
1173 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001174 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301176 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177
1178 ep = lookup_atid(t, atid);
1179
1180 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1181 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1182
Steve Wisea7db89e2014-03-21 20:40:35 +05301183 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001184 dst_confirm(ep->dst);
1185
1186 /* setup the hwtid for this connection */
1187 ep->hwtid = tid;
1188 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301189 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001190
1191 ep->snd_seq = be32_to_cpu(req->snd_isn);
1192 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1193
1194 set_emss(ep, ntohs(req->tcp_opt));
1195
1196 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001197 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001199 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200
1201 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301202 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301203 if (ret)
1204 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301205 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301206 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301207 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301208 ret = send_mpa_req(ep, skb, mpa_rev);
1209 if (ret)
1210 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301211 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301213err:
1214 mutex_unlock(&ep->com.mutex);
1215 connect_reply_upcall(ep, -ENOMEM);
1216 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1217 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001218}
1219
Steve Wisebe13b2d2014-03-21 20:40:33 +05301220static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001221{
1222 struct iw_cm_event event;
1223
1224 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1225 memset(&event, 0, sizeof(event));
1226 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301227 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001228 if (ep->com.cm_id) {
1229 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1230 ep, ep->com.cm_id, ep->hwtid);
1231 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301232 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001233 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001234 }
1235}
1236
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237static void peer_close_upcall(struct c4iw_ep *ep)
1238{
1239 struct iw_cm_event event;
1240
1241 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1242 memset(&event, 0, sizeof(event));
1243 event.event = IW_CM_EVENT_DISCONNECT;
1244 if (ep->com.cm_id) {
1245 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1246 ep, ep->com.cm_id, ep->hwtid);
1247 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001248 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001249 }
1250}
1251
1252static void peer_abort_upcall(struct c4iw_ep *ep)
1253{
1254 struct iw_cm_event event;
1255
1256 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1257 memset(&event, 0, sizeof(event));
1258 event.event = IW_CM_EVENT_CLOSE;
1259 event.status = -ECONNRESET;
1260 if (ep->com.cm_id) {
1261 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1262 ep->com.cm_id, ep->hwtid);
1263 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301264 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001265 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001266 }
1267}
1268
1269static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1270{
1271 struct iw_cm_event event;
1272
1273 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1274 memset(&event, 0, sizeof(event));
1275 event.event = IW_CM_EVENT_CONNECT_REPLY;
1276 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301277 memcpy(&event.local_addr, &ep->com.local_addr,
1278 sizeof(ep->com.local_addr));
1279 memcpy(&event.remote_addr, &ep->com.remote_addr,
1280 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001281
1282 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301283 if (!ep->tried_with_mpa_v1) {
1284 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301285 event.ord = ep->ird;
1286 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301287 event.private_data_len = ep->plen -
1288 sizeof(struct mpa_v2_conn_params);
1289 event.private_data = ep->mpa_pkt +
1290 sizeof(struct mpa_message) +
1291 sizeof(struct mpa_v2_conn_params);
1292 } else {
1293 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301294 event.ord = cur_max_read_depth(ep->com.dev);
1295 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301296 event.private_data_len = ep->plen;
1297 event.private_data = ep->mpa_pkt +
1298 sizeof(struct mpa_message);
1299 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300 }
Roland Dreier85963e42010-07-19 13:13:09 -07001301
1302 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1303 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001304 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001305 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1306
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301307 if (status < 0)
1308 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001309}
1310
Steve Wisebe13b2d2014-03-21 20:40:33 +05301311static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001312{
1313 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301314 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001315
1316 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1317 memset(&event, 0, sizeof(event));
1318 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301319 memcpy(&event.local_addr, &ep->com.local_addr,
1320 sizeof(ep->com.local_addr));
1321 memcpy(&event.remote_addr, &ep->com.remote_addr,
1322 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001323 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301324 if (!ep->tried_with_mpa_v1) {
1325 /* this means MPA_v2 is used */
1326 event.ord = ep->ord;
1327 event.ird = ep->ird;
1328 event.private_data_len = ep->plen -
1329 sizeof(struct mpa_v2_conn_params);
1330 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1331 sizeof(struct mpa_v2_conn_params);
1332 } else {
1333 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301334 event.ord = cur_max_read_depth(ep->com.dev);
1335 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301336 event.private_data_len = ep->plen;
1337 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1338 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301339 c4iw_get_ep(&ep->com);
1340 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1341 &event);
1342 if (ret)
1343 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001344 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001345 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301346 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001347}
1348
1349static void established_upcall(struct c4iw_ep *ep)
1350{
1351 struct iw_cm_event event;
1352
1353 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1354 memset(&event, 0, sizeof(event));
1355 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301356 event.ird = ep->ord;
1357 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001358 if (ep->com.cm_id) {
1359 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1360 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001361 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001362 }
1363}
1364
1365static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1366{
1367 struct cpl_rx_data_ack *req;
1368 struct sk_buff *skb;
1369 int wrlen = roundup(sizeof *req, 16);
1370
1371 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1372 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1373 if (!skb) {
1374 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1375 return 0;
1376 }
1377
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301378 /*
1379 * If we couldn't specify the entire rcv window at connection setup
1380 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1381 * then add the overage in to the credits returned.
1382 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001383 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1384 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301385
Steve Wisecfdda9d2010-04-21 15:30:06 -07001386 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1387 memset(req, 0, wrlen);
1388 INIT_TP_WR(req, ep->hwtid);
1389 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1390 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001391 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301392 RX_DACK_CHANGE_F |
1393 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001394 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001395 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1396 return credits;
1397}
1398
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301399#define RELAXED_IRD_NEGOTIATION 1
1400
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301401/*
1402 * process_mpa_reply - process streaming mode MPA reply
1403 *
1404 * Returns:
1405 *
1406 * 0 upon success indicating a connect request was delivered to the ULP
1407 * or the mpa request is incomplete but valid so far.
1408 *
1409 * 1 if a failure requires the caller to close the connection.
1410 *
1411 * 2 if a failure requires the caller to abort the connection.
1412 */
Steve Wisecc18b932014-04-24 14:31:53 -05001413static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001414{
1415 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301416 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001417 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301418 u16 resp_ird, resp_ord;
1419 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001420 struct c4iw_qp_attributes attrs;
1421 enum c4iw_qp_attr_mask mask;
1422 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001423 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001424
1425 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1426
1427 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001428 * If we get more than the supported amount of private data
1429 * then we must fail this connection.
1430 */
1431 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1432 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301433 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001434 }
1435
1436 /*
1437 * copy the new data into our accumulation buffer.
1438 */
1439 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1440 skb->len);
1441 ep->mpa_pkt_len += skb->len;
1442
1443 /*
1444 * if we don't even have the mpa message, then bail.
1445 */
1446 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001447 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001448 mpa = (struct mpa_message *) ep->mpa_pkt;
1449
1450 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301451 if (mpa->revision > mpa_rev) {
1452 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1453 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001454 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301455 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001456 }
1457 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1458 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301459 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001460 }
1461
1462 plen = ntohs(mpa->private_data_size);
1463
1464 /*
1465 * Fail if there's too much private data.
1466 */
1467 if (plen > MPA_MAX_PRIVATE_DATA) {
1468 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301469 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001470 }
1471
1472 /*
1473 * If plen does not account for pkt size
1474 */
1475 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1476 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301477 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001478 }
1479
1480 ep->plen = (u8) plen;
1481
1482 /*
1483 * If we don't have all the pdata yet, then bail.
1484 * We'll continue process when more data arrives.
1485 */
1486 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001487 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001488
1489 if (mpa->flags & MPA_REJECT) {
1490 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301491 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001492 }
1493
1494 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301495 * Stop mpa timer. If it expired, then
1496 * we ignore the MPA reply. process_timeout()
1497 * will abort the connection.
1498 */
1499 if (stop_ep_timer(ep))
1500 return 0;
1501
1502 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001503 * If we get here we have accumulated the entire mpa
1504 * start reply message including private data. And
1505 * the MPA header is valid.
1506 */
Steve Wisec529fb52014-03-21 20:40:37 +05301507 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001508 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001509 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301510 ep->mpa_attr.version = mpa->revision;
1511 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1512
1513 if (mpa->revision == 2) {
1514 ep->mpa_attr.enhanced_rdma_conn =
1515 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1516 if (ep->mpa_attr.enhanced_rdma_conn) {
1517 mpa_v2_params = (struct mpa_v2_conn_params *)
1518 (ep->mpa_pkt + sizeof(*mpa));
1519 resp_ird = ntohs(mpa_v2_params->ird) &
1520 MPA_V2_IRD_ORD_MASK;
1521 resp_ord = ntohs(mpa_v2_params->ord) &
1522 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301523 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1524 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301525
1526 /*
1527 * This is a double-check. Ideally, below checks are
1528 * not required since ird/ord stuff has been taken
1529 * care of in c4iw_accept_cr
1530 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301531 if (ep->ird < resp_ord) {
1532 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1533 ep->com.dev->rdev.lldi.max_ordird_qp)
1534 ep->ird = resp_ord;
1535 else
1536 insuff_ird = 1;
1537 } else if (ep->ird > resp_ord) {
1538 ep->ird = resp_ord;
1539 }
1540 if (ep->ord > resp_ird) {
1541 if (RELAXED_IRD_NEGOTIATION)
1542 ep->ord = resp_ird;
1543 else
1544 insuff_ird = 1;
1545 }
1546 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301547 err = -ENOMEM;
1548 ep->ird = resp_ord;
1549 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301550 }
1551
1552 if (ntohs(mpa_v2_params->ird) &
1553 MPA_V2_PEER2PEER_MODEL) {
1554 if (ntohs(mpa_v2_params->ord) &
1555 MPA_V2_RDMA_WRITE_RTR)
1556 ep->mpa_attr.p2p_type =
1557 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1558 else if (ntohs(mpa_v2_params->ord) &
1559 MPA_V2_RDMA_READ_RTR)
1560 ep->mpa_attr.p2p_type =
1561 FW_RI_INIT_P2PTYPE_READ_REQ;
1562 }
1563 }
1564 } else if (mpa->revision == 1)
1565 if (peer2peer)
1566 ep->mpa_attr.p2p_type = p2p_type;
1567
Steve Wisecfdda9d2010-04-21 15:30:06 -07001568 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301569 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1570 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1571 ep->mpa_attr.recv_marker_enabled,
1572 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1573 ep->mpa_attr.p2p_type, p2p_type);
1574
1575 /*
1576 * If responder's RTR does not match with that of initiator, assign
1577 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1578 * generated when moving QP to RTS state.
1579 * A TERM message will be sent after QP has moved to RTS state
1580 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001581 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301582 (ep->mpa_attr.p2p_type != p2p_type)) {
1583 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1584 rtr_mismatch = 1;
1585 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001586
1587 attrs.mpa_attr = ep->mpa_attr;
1588 attrs.max_ird = ep->ird;
1589 attrs.max_ord = ep->ord;
1590 attrs.llp_stream_handle = ep;
1591 attrs.next_state = C4IW_QP_STATE_RTS;
1592
1593 mask = C4IW_QP_ATTR_NEXT_STATE |
1594 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1595 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1596
1597 /* bind QP and TID with INIT_WR */
1598 err = c4iw_modify_qp(ep->com.qp->rhp,
1599 ep->com.qp, mask, &attrs, 1);
1600 if (err)
1601 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301602
1603 /*
1604 * If responder's RTR requirement did not match with what initiator
1605 * supports, generate TERM message
1606 */
1607 if (rtr_mismatch) {
1608 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1609 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1610 attrs.ecode = MPA_NOMATCH_RTR;
1611 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001612 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301613 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001614 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301615 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001616 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301617 goto out;
1618 }
1619
1620 /*
1621 * Generate TERM if initiator IRD is not sufficient for responder
1622 * provided ORD. Currently, we do the same behaviour even when
1623 * responder provided IRD is also not sufficient as regards to
1624 * initiator ORD.
1625 */
1626 if (insuff_ird) {
1627 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1628 __func__);
1629 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1630 attrs.ecode = MPA_INSUFF_IRD;
1631 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001632 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301633 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001634 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301635 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001636 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301637 goto out;
1638 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001639 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301640err_stop_timer:
1641 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001642err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301643 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001644out:
1645 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001646 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001647}
1648
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301649/*
1650 * process_mpa_request - process streaming mode MPA request
1651 *
1652 * Returns:
1653 *
1654 * 0 upon success indicating a connect request was delivered to the ULP
1655 * or the mpa request is incomplete but valid so far.
1656 *
1657 * 1 if a failure requires the caller to close the connection.
1658 *
1659 * 2 if a failure requires the caller to abort the connection.
1660 */
1661static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001662{
1663 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301664 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001665 u16 plen;
1666
1667 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1668
Steve Wisecfdda9d2010-04-21 15:30:06 -07001669 /*
1670 * If we get more than the supported amount of private data
1671 * then we must fail this connection.
1672 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301673 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1674 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001675
1676 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1677
1678 /*
1679 * Copy the new data into our accumulation buffer.
1680 */
1681 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1682 skb->len);
1683 ep->mpa_pkt_len += skb->len;
1684
1685 /*
1686 * If we don't even have the mpa message, then bail.
1687 * We'll continue process when more data arrives.
1688 */
1689 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301690 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691
1692 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693 mpa = (struct mpa_message *) ep->mpa_pkt;
1694
1695 /*
1696 * Validate MPA Header.
1697 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301698 if (mpa->revision > mpa_rev) {
1699 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1700 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301701 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001702 }
1703
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301704 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1705 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001706
1707 plen = ntohs(mpa->private_data_size);
1708
1709 /*
1710 * Fail if there's too much private data.
1711 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301712 if (plen > MPA_MAX_PRIVATE_DATA)
1713 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001714
1715 /*
1716 * If plen does not account for pkt size
1717 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301718 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1719 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001720 ep->plen = (u8) plen;
1721
1722 /*
1723 * If we don't have all the pdata yet, then bail.
1724 */
1725 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301726 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001727
1728 /*
1729 * If we get here we have accumulated the entire mpa
1730 * start reply message including private data.
1731 */
1732 ep->mpa_attr.initiator = 0;
1733 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1734 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1735 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301736 ep->mpa_attr.version = mpa->revision;
1737 if (mpa->revision == 1)
1738 ep->tried_with_mpa_v1 = 1;
1739 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1740
1741 if (mpa->revision == 2) {
1742 ep->mpa_attr.enhanced_rdma_conn =
1743 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1744 if (ep->mpa_attr.enhanced_rdma_conn) {
1745 mpa_v2_params = (struct mpa_v2_conn_params *)
1746 (ep->mpa_pkt + sizeof(*mpa));
1747 ep->ird = ntohs(mpa_v2_params->ird) &
1748 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001749 ep->ird = min_t(u32, ep->ird,
1750 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301751 ep->ord = ntohs(mpa_v2_params->ord) &
1752 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001753 ep->ord = min_t(u32, ep->ord,
1754 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301755 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1756 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301757 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1758 if (peer2peer) {
1759 if (ntohs(mpa_v2_params->ord) &
1760 MPA_V2_RDMA_WRITE_RTR)
1761 ep->mpa_attr.p2p_type =
1762 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1763 else if (ntohs(mpa_v2_params->ord) &
1764 MPA_V2_RDMA_READ_RTR)
1765 ep->mpa_attr.p2p_type =
1766 FW_RI_INIT_P2PTYPE_READ_REQ;
1767 }
1768 }
1769 } else if (mpa->revision == 1)
1770 if (peer2peer)
1771 ep->mpa_attr.p2p_type = p2p_type;
1772
Steve Wisecfdda9d2010-04-21 15:30:06 -07001773 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1774 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1775 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1776 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1777 ep->mpa_attr.p2p_type);
1778
Hariprasad Se4b76a22016-05-06 22:17:59 +05301779 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001780
Hariprasad Se4b76a22016-05-06 22:17:59 +05301781 /* drive upcall */
1782 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1783 if (ep->parent_ep->com.state != DEAD) {
1784 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301785 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301786 } else {
1787 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301788 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301789 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301790 return 0;
1791
1792err_unlock_parent:
1793 mutex_unlock(&ep->parent_ep->com.mutex);
1794 goto err_out;
1795err_stop_timer:
1796 (void)stop_ep_timer(ep);
1797err_out:
1798 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001799}
1800
1801static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1802{
1803 struct c4iw_ep *ep;
1804 struct cpl_rx_data *hdr = cplhdr(skb);
1805 unsigned int dlen = ntohs(hdr->len);
1806 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001807 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001808 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809
Hariprasad S944661d2016-05-06 22:18:03 +05301810 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301811 if (!ep)
1812 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001813 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1814 skb_pull(skb, sizeof(*hdr));
1815 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301816 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817
Steve Wisecfdda9d2010-04-21 15:30:06 -07001818 /* update RX credits */
1819 update_rx_credits(ep, dlen);
1820
Steve Wisec529fb52014-03-21 20:40:37 +05301821 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001822 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001823 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001824 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001825 break;
1826 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001827 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301828 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001830 case FPDU_MODE: {
1831 struct c4iw_qp_attributes attrs;
1832 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001833 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001834 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001835 " qpid %u ep %p state %d tid %u status %d\n",
1836 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301837 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301838 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001839 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001840 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1841 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001842 break;
1843 }
Vipul Pandya15579672013-01-07 13:11:52 +00001844 default:
1845 break;
1846 }
Steve Wisec529fb52014-03-21 20:40:37 +05301847 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001848 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301849 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301850 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001851 return 0;
1852}
1853
1854static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1855{
1856 struct c4iw_ep *ep;
1857 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858 int release = 0;
1859 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001860
Hariprasad S944661d2016-05-06 22:18:03 +05301861 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301862 if (!ep) {
1863 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1864 return 0;
1865 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001866 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001867 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001868 switch (ep->com.state) {
1869 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001870 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001871 __state_set(&ep->com, DEAD);
1872 release = 1;
1873 break;
1874 default:
1875 printk(KERN_ERR "%s ep %p state %d\n",
1876 __func__, ep, ep->com.state);
1877 break;
1878 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001879 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001880
1881 if (release)
1882 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301883 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001884 return 0;
1885}
1886
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301887static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001888{
1889 struct sk_buff *skb;
1890 struct fw_ofld_connection_wr *req;
1891 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301892 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301893 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301894 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001895
1896 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1897 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1898 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001899 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301900 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301901 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1902 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001903 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001904 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301905 req->le.lport = sin->sin_port;
1906 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001907 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301908 req->le.pport = sin->sin_port;
1909 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001910 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301911 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1912 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001913 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301914 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001915 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001916 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301917 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1918 enable_tcp_timestamps,
1919 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301920 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301921
1922 /*
1923 * Specify the largest window that will fit in opt0. The
1924 * remainder will be specified in the rx_data_ack.
1925 */
1926 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001927 if (win > RCV_BUFSIZ_M)
1928 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301929
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001930 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1931 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001932 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001933 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001934 WND_SCALE_V(wscale) |
1935 MSS_IDX_V(mtu_idx) |
1936 L2T_IDX_V(ep->l2t->idx) |
1937 TX_CHAN_V(ep->tx_chan) |
1938 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301939 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001940 ULP_MODE_V(ULP_MODE_TCPDDP) |
1941 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001942 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1943 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001944 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001945 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001946 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001947 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001948 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001949 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001950 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001951 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001952 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1953 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1954 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001955 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1956 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301957 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001958}
1959
Steve Wisecfdda9d2010-04-21 15:30:06 -07001960/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301961 * Some of the error codes above implicitly indicate that there is no TID
1962 * allocated with the result of an ACT_OPEN. We use this predicate to make
1963 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001964 */
1965static inline int act_open_has_tid(int status)
1966{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301967 return (status != CPL_ERR_TCAM_PARITY &&
1968 status != CPL_ERR_TCAM_MISS &&
1969 status != CPL_ERR_TCAM_FULL &&
1970 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1971 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001972}
1973
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301974static char *neg_adv_str(unsigned int status)
1975{
1976 switch (status) {
1977 case CPL_ERR_RTX_NEG_ADVICE:
1978 return "Retransmit timeout";
1979 case CPL_ERR_PERSIST_NEG_ADVICE:
1980 return "Persist timeout";
1981 case CPL_ERR_KEEPALV_NEG_ADVICE:
1982 return "Keepalive timeout";
1983 default:
1984 return "Unknown";
1985 }
1986}
1987
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301988static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1989{
1990 ep->snd_win = snd_win;
1991 ep->rcv_win = rcv_win;
1992 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1993}
1994
Vipul Pandya793dad92012-12-10 09:30:56 +00001995#define ACT_OPEN_RETRY_COUNT 2
1996
Vipul Pandya830662f2013-07-04 16:10:47 +05301997static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1998 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301999 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302000{
2001 struct neighbour *n;
2002 int err, step;
2003 struct net_device *pdev;
2004
2005 n = dst_neigh_lookup(dst, peer_ip);
2006 if (!n)
2007 return -ENODEV;
2008
2009 rcu_read_lock();
2010 err = -ENOMEM;
2011 if (n->dev->flags & IFF_LOOPBACK) {
2012 if (iptype == 4)
2013 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2014 else if (IS_ENABLED(CONFIG_IPV6))
2015 for_each_netdev(&init_net, pdev) {
2016 if (ipv6_chk_addr(&init_net,
2017 (struct in6_addr *)peer_ip,
2018 pdev, 1))
2019 break;
2020 }
2021 else
2022 pdev = NULL;
2023
2024 if (!pdev) {
2025 err = -ENODEV;
2026 goto out;
2027 }
2028 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302029 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302030 if (!ep->l2t)
2031 goto out;
2032 ep->mtu = pdev->mtu;
2033 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302034 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2035 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302036 step = cdev->rdev.lldi.ntxq /
2037 cdev->rdev.lldi.nchan;
2038 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2039 step = cdev->rdev.lldi.nrxq /
2040 cdev->rdev.lldi.nchan;
2041 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2042 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2043 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302044 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302045 dev_put(pdev);
2046 } else {
2047 pdev = get_real_dev(n->dev);
2048 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2049 n, pdev, 0);
2050 if (!ep->l2t)
2051 goto out;
2052 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002053 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302054 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2055 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302056 step = cdev->rdev.lldi.ntxq /
2057 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002058 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2059 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302060 step = cdev->rdev.lldi.nrxq /
2061 cdev->rdev.lldi.nchan;
2062 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002063 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302064 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302065
2066 if (clear_mpa_v1) {
2067 ep->retry_with_mpa_v1 = 0;
2068 ep->tried_with_mpa_v1 = 0;
2069 }
2070 }
2071 err = 0;
2072out:
2073 rcu_read_unlock();
2074
2075 neigh_release(n);
2076
2077 return err;
2078}
2079
Vipul Pandya793dad92012-12-10 09:30:56 +00002080static int c4iw_reconnect(struct c4iw_ep *ep)
2081{
2082 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302083 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302084 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002085 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302086 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002087 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302088 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002089 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302090 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002091 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302092 int iptype;
2093 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002094
2095 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2096 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302097 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002098
Hariprasad S4a740832016-06-10 01:05:15 +05302099 /* When MPA revision is different on nodes, the node with MPA_rev=2
2100 * tries to reconnect with MPA_rev 1 for the same EP through
2101 * c4iw_reconnect(), where the same EP is assigned with new tid for
2102 * further connection establishment. As we are using the same EP pointer
2103 * for reconnect, few skbs are used during the previous c4iw_connect(),
2104 * which leaves the EP with inadequate skbs for further
2105 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2106 * skb_list() during peer_abort(). Allocate skbs which is already used.
2107 */
2108 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2109 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2110 err = -ENOMEM;
2111 goto fail1;
2112 }
2113
Vipul Pandya793dad92012-12-10 09:30:56 +00002114 /*
2115 * Allocate an active TID to initiate a TCP connection.
2116 */
2117 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2118 if (ep->atid == -1) {
2119 pr_err("%s - cannot alloc atid.\n", __func__);
2120 err = -ENOMEM;
2121 goto fail2;
2122 }
2123 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2124
2125 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002126 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302127 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2128 laddr->sin_addr.s_addr,
2129 raddr->sin_addr.s_addr,
2130 laddr->sin_port,
2131 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302132 iptype = 4;
2133 ra = (__u8 *)&raddr->sin_addr;
2134 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302135 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2136 get_real_dev,
2137 laddr6->sin6_addr.s6_addr,
2138 raddr6->sin6_addr.s6_addr,
2139 laddr6->sin6_port,
2140 raddr6->sin6_port, 0,
2141 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302142 iptype = 6;
2143 ra = (__u8 *)&raddr6->sin6_addr;
2144 }
2145 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002146 pr_err("%s - cannot find route.\n", __func__);
2147 err = -EHOSTUNREACH;
2148 goto fail3;
2149 }
Hariprasad S963cab52015-09-23 17:19:27 +05302150 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302151 ep->com.dev->rdev.lldi.adapter_type,
2152 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302153 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002154 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002155 goto fail4;
2156 }
2157
2158 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2159 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2160 ep->l2t->idx);
2161
2162 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302163 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002164
2165 /* send connect request to rnic */
2166 err = send_connect(ep);
2167 if (!err)
2168 goto out;
2169
2170 cxgb4_l2t_release(ep->l2t);
2171fail4:
2172 dst_release(ep->dst);
2173fail3:
2174 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2175 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2176fail2:
2177 /*
2178 * remember to send notification to upper layer.
2179 * We are in here so the upper layer is not aware that this is
2180 * re-connect attempt and so, upper layer is still waiting for
2181 * response of 1st connect request.
2182 */
2183 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302184fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002185 c4iw_put_ep(&ep->com);
2186out:
2187 return err;
2188}
2189
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2191{
2192 struct c4iw_ep *ep;
2193 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002194 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2195 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002197 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302198 struct sockaddr_in *la;
2199 struct sockaddr_in *ra;
2200 struct sockaddr_in6 *la6;
2201 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302202 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002203
2204 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002205 la = (struct sockaddr_in *)&ep->com.local_addr;
2206 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2207 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2208 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002209
2210 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2211 status, status2errno(status));
2212
Varun Prakashb65eef02016-09-13 21:23:59 +05302213 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302214 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2215 __func__, atid, status, neg_adv_str(status));
2216 ep->stats.connect_neg_adv++;
2217 mutex_lock(&dev->rdev.stats.lock);
2218 dev->rdev.stats.neg_adv++;
2219 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002220 return 0;
2221 }
2222
Vipul Pandya793dad92012-12-10 09:30:56 +00002223 set_bit(ACT_OPEN_RPL, &ep->com.history);
2224
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302225 /*
2226 * Log interesting failures.
2227 */
2228 switch (status) {
2229 case CPL_ERR_CONN_RESET:
2230 case CPL_ERR_CONN_TIMEDOUT:
2231 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002232 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302233 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002234 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302235 mutex_unlock(&dev->rdev.stats.lock);
2236 if (ep->com.local_addr.ss_family == AF_INET &&
2237 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302238 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2239 ntohl(rpl->atid_status))));
2240 if (ret)
2241 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002242 return 0;
2243 }
2244 break;
2245 case CPL_ERR_CONN_EXIST:
2246 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2247 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302248 if (ep->com.remote_addr.ss_family == AF_INET6) {
2249 struct sockaddr_in6 *sin6 =
2250 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002251 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302252 cxgb4_clip_release(
2253 ep->com.dev->rdev.lldi.ports[0],
2254 (const u32 *)
2255 &sin6->sin6_addr.s6_addr, 1);
2256 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002257 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2258 atid);
2259 cxgb4_free_atid(t, atid);
2260 dst_release(ep->dst);
2261 cxgb4_l2t_release(ep->l2t);
2262 c4iw_reconnect(ep);
2263 return 0;
2264 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002265 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302266 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302267 if (ep->com.local_addr.ss_family == AF_INET) {
2268 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2269 atid, status, status2errno(status),
2270 &la->sin_addr.s_addr, ntohs(la->sin_port),
2271 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2272 } else {
2273 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2274 atid, status, status2errno(status),
2275 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2276 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2277 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302278 break;
2279 }
2280
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302281fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 connect_reply_upcall(ep, status2errno(status));
2283 state_set(&ep->com, DEAD);
2284
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302285 if (ep->com.remote_addr.ss_family == AF_INET6) {
2286 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002287 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302288 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2289 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2290 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002291 if (status && act_open_has_tid(status))
2292 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2293
Vipul Pandya793dad92012-12-10 09:30:56 +00002294 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295 cxgb4_free_atid(t, atid);
2296 dst_release(ep->dst);
2297 cxgb4_l2t_release(ep->l2t);
2298 c4iw_put_ep(&ep->com);
2299
2300 return 0;
2301}
2302
2303static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2304{
2305 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002306 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302307 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308
2309 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002310 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2311 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002312 }
2313 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2314 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002315 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302316 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002317out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318 return 0;
2319}
2320
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2322{
2323 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302325 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002326
2327 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002328 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302329 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002330 return 0;
2331}
2332
Hariprasad S9dec9002016-05-05 01:27:29 +05302333static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2334 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002335{
2336 struct cpl_pass_accept_rpl *rpl;
2337 unsigned int mtu_idx;
2338 u64 opt0;
2339 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302340 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302341 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302342 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302343 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344
2345 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2346 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302347
Steve Wisecfdda9d2010-04-21 15:30:06 -07002348 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302349 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302350 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302351 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2352 rpl5 = (void *)rpl;
2353 INIT_TP_WR(rpl5, ep->hwtid);
2354 } else {
2355 skb_trim(skb, sizeof(*rpl));
2356 INIT_TP_WR(rpl, ep->hwtid);
2357 }
2358 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2359 ep->hwtid));
2360
Varun Prakash44c6d062016-09-13 21:24:00 +05302361 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2362 enable_tcp_timestamps && req->tcpopt.tstamp,
2363 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302364 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302365
2366 /*
2367 * Specify the largest window that will fit in opt0. The
2368 * remainder will be specified in the rx_data_ack.
2369 */
2370 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002371 if (win > RCV_BUFSIZ_M)
2372 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002373 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002374 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002375 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002376 WND_SCALE_V(wscale) |
2377 MSS_IDX_V(mtu_idx) |
2378 L2T_IDX_V(ep->l2t->idx) |
2379 TX_CHAN_V(ep->tx_chan) |
2380 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002381 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002382 ULP_MODE_V(ULP_MODE_TCPDDP) |
2383 RCV_BUFSIZ_V(win);
2384 opt2 = RX_CHANNEL_V(0) |
2385 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002386
2387 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002388 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002389 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002390 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002392 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002393 if (enable_ecn) {
2394 const struct tcphdr *tcph;
2395 u32 hlen = ntohl(req->hdr_len);
2396
Hariprasad S963cab52015-09-23 17:19:27 +05302397 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2398 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2399 IP_HDR_LEN_G(hlen);
2400 else
2401 tcph = (const void *)(req + 1) +
2402 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002403 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002404 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002405 }
Hariprasad S963cab52015-09-23 17:19:27 +05302406 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302407 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002408 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302409 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302410 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302411 rpl5 = (void *)rpl;
2412 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2413 if (peer2peer)
2414 isn += 4;
2415 rpl5->iss = cpu_to_be32(isn);
2416 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002417 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 rpl->opt0 = cpu_to_be64(opt0);
2420 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002421 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302422 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423
Hariprasad S9dec9002016-05-05 01:27:29 +05302424 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425}
2426
Vipul Pandya830662f2013-07-04 16:10:47 +05302427static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428{
Vipul Pandya830662f2013-07-04 16:10:47 +05302429 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430 BUG_ON(skb_cloned(skb));
2431 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 release_tid(&dev->rdev, hwtid, skb);
2433 return;
2434}
2435
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2437{
Vipul Pandya793dad92012-12-10 09:30:56 +00002438 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002439 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002440 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441 struct tid_info *t = dev->rdev.lldi.tids;
2442 unsigned int hwtid = GET_TID(req);
2443 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302444 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002445 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302446 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002447 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002448 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302449 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302450 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302451 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002452
Hariprasad Sf86fac72016-05-06 22:18:07 +05302453 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002454 if (!parent_ep) {
2455 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2456 goto reject;
2457 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002458
Steve Wisecfdda9d2010-04-21 15:30:06 -07002459 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302460 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461 goto reject;
2462 }
2463
Varun Prakash85e42b02016-09-13 21:23:56 +05302464 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2465 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302466
Steve Wisecfdda9d2010-04-21 15:30:06 -07002467 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302468 if (iptype == 4) {
2469 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2470 , __func__, parent_ep, hwtid,
2471 local_ip, peer_ip, ntohs(local_port),
2472 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302473 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2474 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2475 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302476 } else {
2477 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2478 , __func__, parent_ep, hwtid,
2479 local_ip, peer_ip, ntohs(local_port),
2480 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302481 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2482 local_ip, peer_ip, local_port, peer_port,
2483 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2484 ((struct sockaddr_in6 *)
2485 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302486 }
2487 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002488 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2489 __func__);
2490 goto reject;
2491 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492
2493 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2494 if (!child_ep) {
2495 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2496 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002497 dst_release(dst);
2498 goto reject;
2499 }
David Miller3786cf12011-12-02 16:52:31 +00002500
Hariprasad S963cab52015-09-23 17:19:27 +05302501 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302502 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002503 if (err) {
2504 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2505 __func__);
2506 dst_release(dst);
2507 kfree(child_ep);
2508 goto reject;
2509 }
2510
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302511 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2512 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2513 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2514 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002515
Hariprasad S4a740832016-06-10 01:05:15 +05302516 skb_queue_head_init(&child_ep->com.ep_skb_list);
2517 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2518 goto fail;
2519
Steve Wisecfdda9d2010-04-21 15:30:06 -07002520 state_set(&child_ep->com, CONNECTING);
2521 child_ep->com.dev = dev;
2522 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002523
Vipul Pandya830662f2013-07-04 16:10:47 +05302524 if (iptype == 4) {
2525 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002526 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002527
Vipul Pandya830662f2013-07-04 16:10:47 +05302528 sin->sin_family = PF_INET;
2529 sin->sin_port = local_port;
2530 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002531
2532 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2533 sin->sin_family = PF_INET;
2534 sin->sin_port = ((struct sockaddr_in *)
2535 &parent_ep->com.local_addr)->sin_port;
2536 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2537
Steve Wise170003c2016-02-26 09:18:03 -06002538 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302539 sin->sin_family = PF_INET;
2540 sin->sin_port = peer_port;
2541 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2542 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002543 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302544 sin6->sin6_family = PF_INET6;
2545 sin6->sin6_port = local_port;
2546 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002547
2548 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2549 sin6->sin6_family = PF_INET6;
2550 sin6->sin6_port = ((struct sockaddr_in6 *)
2551 &parent_ep->com.local_addr)->sin6_port;
2552 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2553
Steve Wise170003c2016-02-26 09:18:03 -06002554 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302555 sin6->sin6_family = PF_INET6;
2556 sin6->sin6_port = peer_port;
2557 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2558 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002559
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560 c4iw_get_ep(&parent_ep->com);
2561 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302562 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002563 child_ep->dst = dst;
2564 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565
2566 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002567 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002568
2569 init_timer(&child_ep->timer);
2570 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302571 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302572 if (accept_cr(child_ep, skb, req)) {
2573 c4iw_put_ep(&parent_ep->com);
2574 release_ep_resources(child_ep);
2575 } else {
2576 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2577 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302578 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002579 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302580 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2581 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2582 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002583 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302584fail:
2585 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002586reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302587 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302588 if (parent_ep)
2589 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002590out:
2591 return 0;
2592}
2593
2594static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2595{
2596 struct c4iw_ep *ep;
2597 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002598 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302599 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600
Hariprasad S944661d2016-05-06 22:18:03 +05302601 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2603 ep->snd_seq = be32_to_cpu(req->snd_isn);
2604 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2605
Vipul Pandya1cab7752012-12-10 09:30:55 +00002606 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2607 ntohs(req->tcp_opt));
2608
Steve Wisecfdda9d2010-04-21 15:30:06 -07002609 set_emss(ep, ntohs(req->tcp_opt));
2610
2611 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302612 mutex_lock(&ep->com.mutex);
2613 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002614 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002615 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302616 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302617 mutex_unlock(&ep->com.mutex);
2618 if (ret)
2619 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302620 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621
2622 return 0;
2623}
2624
2625static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2626{
2627 struct cpl_peer_close *hdr = cplhdr(skb);
2628 struct c4iw_ep *ep;
2629 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002630 int disconnect = 1;
2631 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002632 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002633 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634
Hariprasad S944661d2016-05-06 22:18:03 +05302635 ep = get_ep_from_tid(dev, tid);
2636 if (!ep)
2637 return 0;
2638
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2640 dst_confirm(ep->dst);
2641
Vipul Pandya793dad92012-12-10 09:30:56 +00002642 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002643 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 switch (ep->com.state) {
2645 case MPA_REQ_WAIT:
2646 __state_set(&ep->com, CLOSING);
2647 break;
2648 case MPA_REQ_SENT:
2649 __state_set(&ep->com, CLOSING);
2650 connect_reply_upcall(ep, -ECONNRESET);
2651 break;
2652 case MPA_REQ_RCVD:
2653
2654 /*
2655 * We're gonna mark this puppy DEAD, but keep
2656 * the reference on it until the ULP accepts or
2657 * rejects the CR. Also wake up anyone waiting
2658 * in rdma connection migration (see c4iw_accept_cr()).
2659 */
2660 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002662 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 break;
2664 case MPA_REP_SENT:
2665 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002666 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002667 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 break;
2669 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002670 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002671 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002672 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002673 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002674 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002675 if (ret != -ECONNRESET) {
2676 peer_close_upcall(ep);
2677 disconnect = 1;
2678 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002679 break;
2680 case ABORTING:
2681 disconnect = 0;
2682 break;
2683 case CLOSING:
2684 __state_set(&ep->com, MORIBUND);
2685 disconnect = 0;
2686 break;
2687 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002688 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002689 if (ep->com.cm_id && ep->com.qp) {
2690 attrs.next_state = C4IW_QP_STATE_IDLE;
2691 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2692 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2693 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302694 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002695 __state_set(&ep->com, DEAD);
2696 release = 1;
2697 disconnect = 0;
2698 break;
2699 case DEAD:
2700 disconnect = 0;
2701 break;
2702 default:
2703 BUG_ON(1);
2704 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002705 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 if (disconnect)
2707 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2708 if (release)
2709 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302710 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002711 return 0;
2712}
2713
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2715{
2716 struct cpl_abort_req_rss *req = cplhdr(skb);
2717 struct c4iw_ep *ep;
2718 struct cpl_abort_rpl *rpl;
2719 struct sk_buff *rpl_skb;
2720 struct c4iw_qp_attributes attrs;
2721 int ret;
2722 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002723 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724
Hariprasad S944661d2016-05-06 22:18:03 +05302725 ep = get_ep_from_tid(dev, tid);
2726 if (!ep)
2727 return 0;
2728
Varun Prakashb65eef02016-09-13 21:23:59 +05302729 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302730 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2731 __func__, ep->hwtid, req->status,
2732 neg_adv_str(req->status));
2733 ep->stats.abort_neg_adv++;
2734 mutex_lock(&dev->rdev.stats.lock);
2735 dev->rdev.stats.neg_adv++;
2736 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302737 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002738 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2740 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002741 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002742
2743 /*
2744 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302745 * However, this is not needed if com state is just
2746 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002747 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302748 if (ep->com.state != MPA_REQ_SENT)
2749 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002750
2751 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 switch (ep->com.state) {
2753 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302754 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002755 break;
2756 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002757 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002758 break;
2759 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002760 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002761 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302762 connect_reply_upcall(ep, -ECONNRESET);
2763 else {
2764 /*
2765 * we just don't send notification upwards because we
2766 * want to retry with mpa_v1 without upper layers even
2767 * knowing it.
2768 *
2769 * do some housekeeping so as to re-initiate the
2770 * connection
2771 */
2772 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2773 mpa_rev);
2774 ep->retry_with_mpa_v1 = 1;
2775 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002776 break;
2777 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778 break;
2779 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 break;
2781 case MORIBUND:
2782 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002783 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002784 /*FALLTHROUGH*/
2785 case FPDU_MODE:
2786 if (ep->com.cm_id && ep->com.qp) {
2787 attrs.next_state = C4IW_QP_STATE_ERROR;
2788 ret = c4iw_modify_qp(ep->com.qp->rhp,
2789 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2790 &attrs, 1);
2791 if (ret)
2792 printk(KERN_ERR MOD
2793 "%s - qp <- error failed!\n",
2794 __func__);
2795 }
2796 peer_abort_upcall(ep);
2797 break;
2798 case ABORTING:
2799 break;
2800 case DEAD:
2801 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002802 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302803 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002804 default:
2805 BUG_ON(1);
2806 break;
2807 }
2808 dst_confirm(ep->dst);
2809 if (ep->com.state != ABORTING) {
2810 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302811 /* we don't release if we want to retry with mpa_v1 */
2812 if (!ep->retry_with_mpa_v1)
2813 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002815 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816
Hariprasad S4a740832016-06-10 01:05:15 +05302817 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2818 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002819 release = 1;
2820 goto out;
2821 }
2822 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2823 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2824 INIT_TP_WR(rpl, ep->hwtid);
2825 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2826 rpl->cmd = CPL_ABORT_NO_RST;
2827 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2828out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 if (release)
2830 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002831 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302832 if (ep->com.remote_addr.ss_family == AF_INET6) {
2833 struct sockaddr_in6 *sin6 =
2834 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002835 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302836 cxgb4_clip_release(
2837 ep->com.dev->rdev.lldi.ports[0],
2838 (const u32 *)&sin6->sin6_addr.s6_addr,
2839 1);
2840 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002841 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302842 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2843 dst_release(ep->dst);
2844 cxgb4_l2t_release(ep->l2t);
2845 c4iw_reconnect(ep);
2846 }
2847
Hariprasad S944661d2016-05-06 22:18:03 +05302848deref_ep:
2849 c4iw_put_ep(&ep->com);
2850 /* Dereferencing ep, referenced in peer_abort_intr() */
2851 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002852 return 0;
2853}
2854
2855static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2856{
2857 struct c4iw_ep *ep;
2858 struct c4iw_qp_attributes attrs;
2859 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862
Hariprasad S944661d2016-05-06 22:18:03 +05302863 ep = get_ep_from_tid(dev, tid);
2864 if (!ep)
2865 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866
2867 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2868 BUG_ON(!ep);
2869
2870 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002871 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302872 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002873 switch (ep->com.state) {
2874 case CLOSING:
2875 __state_set(&ep->com, MORIBUND);
2876 break;
2877 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002878 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002879 if ((ep->com.cm_id) && (ep->com.qp)) {
2880 attrs.next_state = C4IW_QP_STATE_IDLE;
2881 c4iw_modify_qp(ep->com.qp->rhp,
2882 ep->com.qp,
2883 C4IW_QP_ATTR_NEXT_STATE,
2884 &attrs, 1);
2885 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302886 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002887 __state_set(&ep->com, DEAD);
2888 release = 1;
2889 break;
2890 case ABORTING:
2891 case DEAD:
2892 break;
2893 default:
2894 BUG_ON(1);
2895 break;
2896 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002897 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002898 if (release)
2899 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302900 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002901 return 0;
2902}
2903
2904static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2905{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002906 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002907 unsigned int tid = GET_TID(rpl);
2908 struct c4iw_ep *ep;
2909 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002910
Hariprasad S944661d2016-05-06 22:18:03 +05302911 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002912 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913
Steve Wise30c95c22011-05-09 22:06:22 -07002914 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002915 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2916 ep->com.qp->wq.sq.qid);
2917 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2918 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2919 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2920 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002921 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302922 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 return 0;
2925}
2926
2927/*
2928 * Upcall from the adapter indicating data has been transmitted.
2929 * For us its just the single MPA request or reply. We can now free
2930 * the skb holding the mpa message.
2931 */
2932static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2933{
2934 struct c4iw_ep *ep;
2935 struct cpl_fw4_ack *hdr = cplhdr(skb);
2936 u8 credits = hdr->credits;
2937 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938
2939
Hariprasad S944661d2016-05-06 22:18:03 +05302940 ep = get_ep_from_tid(dev, tid);
2941 if (!ep)
2942 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2944 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002945 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2946 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302947 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 }
2949
2950 dst_confirm(ep->dst);
2951 if (ep->mpa_skb) {
2952 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2953 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2954 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002955 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956 kfree_skb(ep->mpa_skb);
2957 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302958 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2959 stop_ep_timer(ep);
2960 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002961 }
Hariprasad S944661d2016-05-06 22:18:03 +05302962out:
2963 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002964 return 0;
2965}
2966
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2968{
Hariprasad Sbce28412016-06-10 01:05:13 +05302969 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002970 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302971
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2973
Steve Wisea7db89e2014-03-21 20:40:35 +05302974 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302975 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302976 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002977 c4iw_put_ep(&ep->com);
2978 return -ECONNRESET;
2979 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002980 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302982 abort = 1;
2983 else
2984 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302985 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302986
2987 stop_ep_timer(ep);
2988 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002989 c4iw_put_ep(&ep->com);
2990 return 0;
2991}
2992
2993int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2994{
2995 int err;
2996 struct c4iw_qp_attributes attrs;
2997 enum c4iw_qp_attr_mask mask;
2998 struct c4iw_ep *ep = to_ep(cm_id);
2999 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3000 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303001 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002
3003 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303004
3005 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303006 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003007 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303008 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 }
3010
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 BUG_ON(!qp);
3012
Vipul Pandya793dad92012-12-10 09:30:56 +00003013 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303014 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3015 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003016 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303017 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 }
3019
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303020 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3021 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303022 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003023 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303024 } else {
3025 ep->ird = conn_param->ird;
3026 ep->ord = conn_param->ord;
3027 send_mpa_reject(ep, conn_param->private_data,
3028 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303029 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303030 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303031 }
3032 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303033 if (conn_param->ird < ep->ord) {
3034 if (RELAXED_IRD_NEGOTIATION &&
3035 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3036 conn_param->ird = ep->ord;
3037 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303038 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303039 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303040 }
3041 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303042 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 ep->ird = conn_param->ird;
3044 ep->ord = conn_param->ord;
3045
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303046 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303047 if (peer2peer && ep->ird == 0)
3048 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303049 } else {
3050 if (peer2peer &&
3051 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303052 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303053 ep->ird = 1;
3054 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003055
3056 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3057
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303058 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303059 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303060 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003061 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303062
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063 /* bind QP to EP and move to RTS */
3064 attrs.mpa_attr = ep->mpa_attr;
3065 attrs.max_ird = ep->ird;
3066 attrs.max_ord = ep->ord;
3067 attrs.llp_stream_handle = ep;
3068 attrs.next_state = C4IW_QP_STATE_RTS;
3069
3070 /* bind QP and TID with INIT_WR */
3071 mask = C4IW_QP_ATTR_NEXT_STATE |
3072 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3073 C4IW_QP_ATTR_MPA_ATTR |
3074 C4IW_QP_ATTR_MAX_IRD |
3075 C4IW_QP_ATTR_MAX_ORD;
3076
3077 err = c4iw_modify_qp(ep->com.qp->rhp,
3078 ep->com.qp, mask, &attrs, 1);
3079 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303080 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303081
3082 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003083 err = send_mpa_reply(ep, conn_param->private_data,
3084 conn_param->private_data_len);
3085 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303086 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087
Steve Wisea7db89e2014-03-21 20:40:35 +05303088 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003089 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303090 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003091 c4iw_put_ep(&ep->com);
3092 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303093err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303094 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303095err_abort:
3096 abort = 1;
3097err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303098 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303099 if (abort)
3100 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003101 c4iw_put_ep(&ep->com);
3102 return err;
3103}
3104
Vipul Pandya830662f2013-07-04 16:10:47 +05303105static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3106{
3107 struct in_device *ind;
3108 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003109 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3110 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303111
3112 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3113 if (!ind)
3114 return -EADDRNOTAVAIL;
3115 for_primary_ifa(ind) {
3116 laddr->sin_addr.s_addr = ifa->ifa_address;
3117 raddr->sin_addr.s_addr = ifa->ifa_address;
3118 found = 1;
3119 break;
3120 }
3121 endfor_ifa(ind);
3122 in_dev_put(ind);
3123 return found ? 0 : -EADDRNOTAVAIL;
3124}
3125
3126static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3127 unsigned char banned_flags)
3128{
3129 struct inet6_dev *idev;
3130 int err = -EADDRNOTAVAIL;
3131
3132 rcu_read_lock();
3133 idev = __in6_dev_get(dev);
3134 if (idev != NULL) {
3135 struct inet6_ifaddr *ifp;
3136
3137 read_lock_bh(&idev->lock);
3138 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3139 if (ifp->scope == IFA_LINK &&
3140 !(ifp->flags & banned_flags)) {
3141 memcpy(addr, &ifp->addr, 16);
3142 err = 0;
3143 break;
3144 }
3145 }
3146 read_unlock_bh(&idev->lock);
3147 }
3148 rcu_read_unlock();
3149 return err;
3150}
3151
3152static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3153{
3154 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003155 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3156 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303157
Nicholas Krause54b9a962015-08-26 23:00:59 -04003158 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303159 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3160 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3161 return 0;
3162 }
3163 return -EADDRNOTAVAIL;
3164}
3165
Steve Wisecfdda9d2010-04-21 15:30:06 -07003166int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3167{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003168 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3169 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003170 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003171 struct sockaddr_in *laddr;
3172 struct sockaddr_in *raddr;
3173 struct sockaddr_in6 *laddr6;
3174 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303175 __u8 *ra;
3176 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003177
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303178 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3179 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003180 err = -EINVAL;
3181 goto out;
3182 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003183 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3184 if (!ep) {
3185 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3186 err = -ENOMEM;
3187 goto out;
3188 }
Hariprasad S4a740832016-06-10 01:05:15 +05303189
3190 skb_queue_head_init(&ep->com.ep_skb_list);
3191 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3192 err = -ENOMEM;
3193 goto fail1;
3194 }
3195
Steve Wisecfdda9d2010-04-21 15:30:06 -07003196 init_timer(&ep->timer);
3197 ep->plen = conn_param->private_data_len;
3198 if (ep->plen)
3199 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3200 conn_param->private_data, ep->plen);
3201 ep->ird = conn_param->ird;
3202 ep->ord = conn_param->ord;
3203
3204 if (peer2peer && ep->ord == 0)
3205 ep->ord = 1;
3206
Steve Wisecfdda9d2010-04-21 15:30:06 -07003207 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303208 ref_cm_id(&ep->com);
3209 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003210 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303211 if (!ep->com.qp) {
3212 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3213 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303214 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303215 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003216 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003217 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3218 ep->com.qp, cm_id);
3219
3220 /*
3221 * Allocate an active TID to initiate a TCP connection.
3222 */
3223 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3224 if (ep->atid == -1) {
3225 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3226 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303227 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003228 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003229 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230
Steve Wise170003c2016-02-26 09:18:03 -06003231 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003232 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003233 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003234 sizeof(ep->com.remote_addr));
3235
Steve Wise170003c2016-02-26 09:18:03 -06003236 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3237 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3238 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3239 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003240
Steve Wise170003c2016-02-26 09:18:03 -06003241 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303242 iptype = 4;
3243 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003244
Vipul Pandya830662f2013-07-04 16:10:47 +05303245 /*
3246 * Handle loopback requests to INADDR_ANY.
3247 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003248 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303249 err = pick_local_ipaddrs(dev, cm_id);
3250 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303251 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303252 }
3253
3254 /* find a route */
3255 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3256 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3257 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303258 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3259 laddr->sin_addr.s_addr,
3260 raddr->sin_addr.s_addr,
3261 laddr->sin_port,
3262 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303263 } else {
3264 iptype = 6;
3265 ra = (__u8 *)&raddr6->sin6_addr;
3266
3267 /*
3268 * Handle loopback requests to INADDR_ANY.
3269 */
3270 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3271 err = pick_local_ip6addrs(dev, cm_id);
3272 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303273 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303274 }
3275
3276 /* find a route */
3277 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3278 __func__, laddr6->sin6_addr.s6_addr,
3279 ntohs(laddr6->sin6_port),
3280 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303281 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3282 laddr6->sin6_addr.s6_addr,
3283 raddr6->sin6_addr.s6_addr,
3284 laddr6->sin6_port,
3285 raddr6->sin6_port, 0,
3286 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303287 }
3288 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003289 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3290 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303291 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003293
Hariprasad S963cab52015-09-23 17:19:27 +05303294 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303295 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003296 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003297 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303298 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003299 }
3300
3301 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3302 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3303 ep->l2t->idx);
3304
3305 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303306 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003307
3308 /* send connect request to rnic */
3309 err = send_connect(ep);
3310 if (!err)
3311 goto out;
3312
3313 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303314fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003315 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303316fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003317 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303319fail2:
3320 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303321 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303322fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003323 c4iw_put_ep(&ep->com);
3324out:
3325 return err;
3326}
3327
Vipul Pandya830662f2013-07-04 16:10:47 +05303328static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3329{
3330 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003331 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003332 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303333
Hariprasad S28de1f72016-01-13 10:03:14 +05303334 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3335 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3336 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3337 if (err)
3338 return err;
3339 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303340 c4iw_init_wr_wait(&ep->com.wr_wait);
3341 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3342 ep->stid, &sin6->sin6_addr,
3343 sin6->sin6_port,
3344 ep->com.dev->rdev.lldi.rxq_ids[0]);
3345 if (!err)
3346 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3347 &ep->com.wr_wait,
3348 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303349 else if (err > 0)
3350 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303351 if (err) {
3352 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3353 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303354 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3355 err, ep->stid,
3356 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303357 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303358 return err;
3359}
3360
3361static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3362{
3363 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003364 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003365 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303366
3367 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3368 do {
3369 err = cxgb4_create_server_filter(
3370 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3371 sin->sin_addr.s_addr, sin->sin_port, 0,
3372 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3373 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303374 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3375 err = -EIO;
3376 break;
3377 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303378 set_current_state(TASK_UNINTERRUPTIBLE);
3379 schedule_timeout(usecs_to_jiffies(100));
3380 }
3381 } while (err == -EBUSY);
3382 } else {
3383 c4iw_init_wr_wait(&ep->com.wr_wait);
3384 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3385 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3386 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3387 if (!err)
3388 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3389 &ep->com.wr_wait,
3390 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303391 else if (err > 0)
3392 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303393 }
3394 if (err)
3395 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3396 , err, ep->stid,
3397 &sin->sin_addr, ntohs(sin->sin_port));
3398 return err;
3399}
3400
Steve Wisecfdda9d2010-04-21 15:30:06 -07003401int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3402{
3403 int err = 0;
3404 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3405 struct c4iw_listen_ep *ep;
3406
Steve Wisecfdda9d2010-04-21 15:30:06 -07003407 might_sleep();
3408
3409 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3410 if (!ep) {
3411 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3412 err = -ENOMEM;
3413 goto fail1;
3414 }
Hariprasad S4a740832016-06-10 01:05:15 +05303415 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003416 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003417 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303418 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003419 ep->com.dev = dev;
3420 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003421 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303422 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423
3424 /*
3425 * Allocate a server TID.
3426 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303427 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3428 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303429 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003430 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003431 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303432 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003433 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003434
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003436 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003437 err = -ENOMEM;
3438 goto fail2;
3439 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003440 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003441
Steve Wise170003c2016-02-26 09:18:03 -06003442 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3443 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003444
Steve Wisecfdda9d2010-04-21 15:30:06 -07003445 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303446 if (ep->com.local_addr.ss_family == AF_INET)
3447 err = create_server4(dev, ep);
3448 else
3449 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003450 if (!err) {
3451 cm_id->provider_data = ep;
3452 goto out;
3453 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003454
Vipul Pandya830662f2013-07-04 16:10:47 +05303455 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3456 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003457fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303458 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459 c4iw_put_ep(&ep->com);
3460fail1:
3461out:
3462 return err;
3463}
3464
3465int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3466{
3467 int err;
3468 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3469
3470 PDBG("%s ep %p\n", __func__, ep);
3471
3472 might_sleep();
3473 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303474 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3475 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003476 err = cxgb4_remove_server_filter(
3477 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3478 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3479 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303480 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003481 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303482 err = cxgb4_remove_server(
3483 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3484 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003485 if (err)
3486 goto done;
3487 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3488 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003489 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303490 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3491 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003492 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003493 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303494 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3495 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003496done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303497 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498 c4iw_put_ep(&ep->com);
3499 return err;
3500}
3501
3502int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3503{
3504 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003505 int close = 0;
3506 int fatal = 0;
3507 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003508
Steve Wise2f5b48c2010-09-10 11:15:36 -05003509 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003510
3511 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3512 states[ep->com.state], abrupt);
3513
Hariprasad S6e410d82016-05-05 01:27:31 +05303514 /*
3515 * Ref the ep here in case we have fatal errors causing the
3516 * ep to be released and freed.
3517 */
3518 c4iw_get_ep(&ep->com);
3519
Steve Wisecfdda9d2010-04-21 15:30:06 -07003520 rdev = &ep->com.dev->rdev;
3521 if (c4iw_fatal_error(rdev)) {
3522 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303523 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003524 ep->com.state = DEAD;
3525 }
3526 switch (ep->com.state) {
3527 case MPA_REQ_WAIT:
3528 case MPA_REQ_SENT:
3529 case MPA_REQ_RCVD:
3530 case MPA_REP_SENT:
3531 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303532 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003533 close = 1;
3534 if (abrupt)
3535 ep->com.state = ABORTING;
3536 else {
3537 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003538
3539 /*
3540 * if we close before we see the fw4_ack() then we fix
3541 * up the timer state since we're reusing it.
3542 */
3543 if (ep->mpa_skb &&
3544 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3545 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3546 stop_ep_timer(ep);
3547 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003548 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003549 }
3550 set_bit(CLOSE_SENT, &ep->com.flags);
3551 break;
3552 case CLOSING:
3553 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3554 close = 1;
3555 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003556 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003557 ep->com.state = ABORTING;
3558 } else
3559 ep->com.state = MORIBUND;
3560 }
3561 break;
3562 case MORIBUND:
3563 case ABORTING:
3564 case DEAD:
3565 PDBG("%s ignoring disconnect ep %p state %u\n",
3566 __func__, ep, ep->com.state);
3567 break;
3568 default:
3569 BUG();
3570 break;
3571 }
3572
Steve Wisecfdda9d2010-04-21 15:30:06 -07003573 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003574 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003575 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303576 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303577 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003578 } else {
3579 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303580 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003581 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303582 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303583 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303584 if (!abrupt) {
3585 stop_ep_timer(ep);
3586 close_complete_upcall(ep, -EIO);
3587 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303588 if (ep->com.qp) {
3589 struct c4iw_qp_attributes attrs;
3590
3591 attrs.next_state = C4IW_QP_STATE_ERROR;
3592 ret = c4iw_modify_qp(ep->com.qp->rhp,
3593 ep->com.qp,
3594 C4IW_QP_ATTR_NEXT_STATE,
3595 &attrs, 1);
3596 if (ret)
3597 pr_err(MOD
3598 "%s - qp <- error failed!\n",
3599 __func__);
3600 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003601 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303602 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003603 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003604 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303605 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003606 if (fatal)
3607 release_ep_resources(ep);
3608 return ret;
3609}
3610
Vipul Pandya1cab7752012-12-10 09:30:55 +00003611static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3612 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3613{
3614 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003615 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003616
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003617 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3618 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003619 if (!ep)
3620 return;
3621
3622 switch (req->retval) {
3623 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003624 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3625 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3626 send_fw_act_open_req(ep, atid);
3627 return;
3628 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003629 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003630 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3631 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3632 send_fw_act_open_req(ep, atid);
3633 return;
3634 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003635 break;
3636 default:
3637 pr_info("%s unexpected ofld conn wr retval %d\n",
3638 __func__, req->retval);
3639 break;
3640 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003641 pr_err("active ofld_connect_wr failure %d atid %d\n",
3642 req->retval, atid);
3643 mutex_lock(&dev->rdev.stats.lock);
3644 dev->rdev.stats.act_ofld_conn_fails++;
3645 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003646 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003647 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303648 if (ep->com.remote_addr.ss_family == AF_INET6) {
3649 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003650 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303651 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3652 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3653 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003654 remove_handle(dev, &dev->atid_idr, atid);
3655 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3656 dst_release(ep->dst);
3657 cxgb4_l2t_release(ep->l2t);
3658 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003659}
3660
3661static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3662 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3663{
3664 struct sk_buff *rpl_skb;
3665 struct cpl_pass_accept_req *cpl;
3666 int ret;
3667
Paul Bolle710a3112013-02-05 20:51:30 +00003668 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003669 BUG_ON(!rpl_skb);
3670 if (req->retval) {
3671 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003672 mutex_lock(&dev->rdev.stats.lock);
3673 dev->rdev.stats.pas_ofld_conn_fails++;
3674 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003675 kfree_skb(rpl_skb);
3676 } else {
3677 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3678 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003679 (__force u32) htonl(
3680 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003681 ret = pass_accept_req(dev, rpl_skb);
3682 if (!ret)
3683 kfree_skb(rpl_skb);
3684 }
3685 return;
3686}
3687
3688static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003689{
3690 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003691 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3692
3693 switch (rpl->type) {
3694 case FW6_TYPE_CQE:
3695 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3696 break;
3697 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3698 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3699 switch (req->t_state) {
3700 case TCP_SYN_SENT:
3701 active_ofld_conn_reply(dev, skb, req);
3702 break;
3703 case TCP_SYN_RECV:
3704 passive_ofld_conn_reply(dev, skb, req);
3705 break;
3706 default:
3707 pr_err("%s unexpected ofld conn wr state %d\n",
3708 __func__, req->t_state);
3709 break;
3710 }
3711 break;
3712 }
3713 return 0;
3714}
3715
3716static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3717{
Hariprasad S963cab52015-09-23 17:19:27 +05303718 __be32 l2info;
3719 __be16 hdr_len, vlantag, len;
3720 u16 eth_hdr_len;
3721 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003722 u8 intf;
3723 struct cpl_rx_pkt *cpl = cplhdr(skb);
3724 struct cpl_pass_accept_req *req;
3725 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003726 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303727 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003728
Vipul Pandyaf079af72013-03-14 05:08:58 +00003729 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303731 vlantag = cpl->vlan;
3732 len = cpl->len;
3733 l2info = cpl->l2info;
3734 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003735 intf = cpl->iff;
3736
3737 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3738
3739 /*
3740 * We need to parse the TCP options from SYN packet.
3741 * to generate cpl_pass_accept_req.
3742 */
3743 memset(&tmp_opt, 0, sizeof(tmp_opt));
3744 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003745 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003746
3747 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3748 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303749 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3750 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303751 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303752 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303753 type = dev->rdev.lldi.adapter_type;
3754 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3755 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3756 req->hdr_len =
3757 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3758 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3759 eth_hdr_len = is_t4(type) ?
3760 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3761 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3762 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3763 IP_HDR_LEN_V(ip_hdr_len) |
3764 ETH_HDR_LEN_V(eth_hdr_len));
3765 } else { /* T6 and later */
3766 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3767 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3768 T6_IP_HDR_LEN_V(ip_hdr_len) |
3769 T6_ETH_HDR_LEN_V(eth_hdr_len));
3770 }
3771 req->vlan = vlantag;
3772 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003773 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3774 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3776 if (tmp_opt.wscale_ok)
3777 req->tcpopt.wsf = tmp_opt.snd_wscale;
3778 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3779 if (tmp_opt.sack_ok)
3780 req->tcpopt.sack = 1;
3781 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3782 return;
3783}
3784
3785static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3786 __be32 laddr, __be16 lport,
3787 __be32 raddr, __be16 rport,
3788 u32 rcv_isn, u32 filter, u16 window,
3789 u32 rss_qid, u8 port_id)
3790{
3791 struct sk_buff *req_skb;
3792 struct fw_ofld_connection_wr *req;
3793 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303794 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003795
3796 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3797 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3798 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003799 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303800 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303801 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003802 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003803 req->le.lport = lport;
3804 req->le.pport = rport;
3805 req->le.u.ipv4.lip = laddr;
3806 req->le.u.ipv4.pip = raddr;
3807 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3808 req->tcb.rcv_adv = htons(window);
3809 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303810 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3811 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3812 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003813 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814
3815 /*
3816 * We store the qid in opt2 which will be used by the firmware
3817 * to send us the wr response.
3818 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003819 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003820
3821 /*
3822 * We initialize the MSS index in TCB to 0xF.
3823 * So that when driver sends cpl_pass_accept_rpl
3824 * TCB picks up the correct value. If this was 0
3825 * TP will ignore any value > 0 for MSS index.
3826 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003827 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303828 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003829
3830 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303831 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3832 if (ret < 0) {
3833 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3834 ret);
3835 kfree_skb(skb);
3836 kfree_skb(req_skb);
3837 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003838}
3839
3840/*
3841 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3842 * messages when a filter is being used instead of server to
3843 * redirect a syn packet. When packets hit filter they are redirected
3844 * to the offload queue and driver tries to establish the connection
3845 * using firmware work request.
3846 */
3847static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3848{
3849 int stid;
3850 unsigned int filter;
3851 struct ethhdr *eh = NULL;
3852 struct vlan_ethhdr *vlan_eh = NULL;
3853 struct iphdr *iph;
3854 struct tcphdr *tcph;
3855 struct rss_header *rss = (void *)skb->data;
3856 struct cpl_rx_pkt *cpl = (void *)skb->data;
3857 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3858 struct l2t_entry *e;
3859 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303860 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003861 u16 window;
3862 struct port_info *pi;
3863 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003864 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003865 int step;
3866 u32 tx_chan;
3867 struct neighbour *neigh;
3868
3869 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003870 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 goto reject;
3872
3873 /*
3874 * Drop all packets which did not hit the filter.
3875 * Unlikely to happen.
3876 */
3877 if (!(rss->filter_hit && rss->filter_tid))
3878 goto reject;
3879
3880 /*
3881 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3882 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303883 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884
Hariprasad Sf86fac72016-05-06 22:18:07 +05303885 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003886 if (!lep) {
3887 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3888 goto reject;
3889 }
3890
Hariprasad S963cab52015-09-23 17:19:27 +05303891 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3892 case CHELSIO_T4:
3893 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3894 break;
3895 case CHELSIO_T5:
3896 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3897 break;
3898 case CHELSIO_T6:
3899 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3900 break;
3901 default:
3902 pr_err("T%d Chip is not supported\n",
3903 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3904 goto reject;
3905 }
3906
Vipul Pandyaf079af72013-03-14 05:08:58 +00003907 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003908 eh = (struct ethhdr *)(req + 1);
3909 iph = (struct iphdr *)(eh + 1);
3910 } else {
3911 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3912 iph = (struct iphdr *)(vlan_eh + 1);
3913 skb->vlan_tci = ntohs(cpl->vlan);
3914 }
3915
3916 if (iph->version != 0x4)
3917 goto reject;
3918
3919 tcph = (struct tcphdr *)(iph + 1);
3920 skb_set_network_header(skb, (void *)iph - (void *)rss);
3921 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3922 skb_get(skb);
3923
3924 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3925 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3926 ntohs(tcph->source), iph->tos);
3927
Varun Prakash804c2f32016-09-13 21:23:57 +05303928 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3929 iph->daddr, iph->saddr, tcph->dest,
3930 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303931 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003932 pr_err("%s - failed to find dst entry!\n",
3933 __func__);
3934 goto reject;
3935 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003936 neigh = dst_neigh_lookup_skb(dst, skb);
3937
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003938 if (!neigh) {
3939 pr_err("%s - failed to allocate neigh!\n",
3940 __func__);
3941 goto free_dst;
3942 }
3943
Vipul Pandya1cab7752012-12-10 09:30:55 +00003944 if (neigh->dev->flags & IFF_LOOPBACK) {
3945 pdev = ip_dev_find(&init_net, iph->daddr);
3946 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3947 pdev, 0);
3948 pi = (struct port_info *)netdev_priv(pdev);
3949 tx_chan = cxgb4_port_chan(pdev);
3950 dev_put(pdev);
3951 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303952 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003953 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303954 pdev, 0);
3955 pi = (struct port_info *)netdev_priv(pdev);
3956 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003957 }
Steve Wiseebf00062014-03-19 17:44:40 +05303958 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003959 if (!e) {
3960 pr_err("%s - failed to allocate l2t entry!\n",
3961 __func__);
3962 goto free_dst;
3963 }
3964
3965 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3966 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003967 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003968
3969 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303970 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3971 dev->rdev.lldi.ports[0],
3972 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003973
3974 /*
3975 * Synthesize the cpl_pass_accept_req. We have everything except the
3976 * TID. Once firmware sends a reply with TID we update the TID field
3977 * in cpl and pass it through the regular cpl_pass_accept_req path.
3978 */
3979 build_cpl_pass_accept_req(skb, stid, iph->tos);
3980 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3981 tcph->source, ntohl(tcph->seq), filter, window,
3982 rss_qid, pi->port_id);
3983 cxgb4_l2t_release(e);
3984free_dst:
3985 dst_release(dst);
3986reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303987 if (lep)
3988 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003989 return 0;
3990}
3991
Steve Wisecfdda9d2010-04-21 15:30:06 -07003992/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003993 * These are the real handlers that are called from a
3994 * work queue.
3995 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303996static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003997 [CPL_ACT_ESTABLISH] = act_establish,
3998 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3999 [CPL_RX_DATA] = rx_data,
4000 [CPL_ABORT_RPL_RSS] = abort_rpl,
4001 [CPL_ABORT_RPL] = abort_rpl,
4002 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4003 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4004 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4005 [CPL_PASS_ESTABLISH] = pass_establish,
4006 [CPL_PEER_CLOSE] = peer_close,
4007 [CPL_ABORT_REQ_RSS] = peer_abort,
4008 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4009 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004010 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004011 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304012 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304013 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4014 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004015};
4016
4017static void process_timeout(struct c4iw_ep *ep)
4018{
4019 struct c4iw_qp_attributes attrs;
4020 int abort = 1;
4021
Steve Wise2f5b48c2010-09-10 11:15:36 -05004022 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004023 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4024 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004025 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004026 switch (ep->com.state) {
4027 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028 connect_reply_upcall(ep, -ETIMEDOUT);
4029 break;
4030 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304031 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304032 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304033 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004034 break;
4035 case CLOSING:
4036 case MORIBUND:
4037 if (ep->com.cm_id && ep->com.qp) {
4038 attrs.next_state = C4IW_QP_STATE_ERROR;
4039 c4iw_modify_qp(ep->com.qp->rhp,
4040 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4041 &attrs, 1);
4042 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304043 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004044 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004045 case ABORTING:
4046 case DEAD:
4047
4048 /*
4049 * These states are expected if the ep timed out at the same
4050 * time as another thread was calling stop_ep_timer().
4051 * So we silently do nothing for these states.
4052 */
4053 abort = 0;
4054 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004056 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004057 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004058 abort = 0;
4059 }
Steve Wisecc18b932014-04-24 14:31:53 -05004060 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304061 if (abort)
4062 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 c4iw_put_ep(&ep->com);
4064}
4065
4066static void process_timedout_eps(void)
4067{
4068 struct c4iw_ep *ep;
4069
4070 spin_lock_irq(&timeout_lock);
4071 while (!list_empty(&timeout_list)) {
4072 struct list_head *tmp;
4073
4074 tmp = timeout_list.next;
4075 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004076 tmp->next = NULL;
4077 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004078 spin_unlock_irq(&timeout_lock);
4079 ep = list_entry(tmp, struct c4iw_ep, entry);
4080 process_timeout(ep);
4081 spin_lock_irq(&timeout_lock);
4082 }
4083 spin_unlock_irq(&timeout_lock);
4084}
4085
4086static void process_work(struct work_struct *work)
4087{
4088 struct sk_buff *skb = NULL;
4089 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004090 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004091 unsigned int opcode;
4092 int ret;
4093
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004094 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095 while ((skb = skb_dequeue(&rxq))) {
4096 rpl = cplhdr(skb);
4097 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4098 opcode = rpl->ot.opcode;
4099
4100 BUG_ON(!work_handlers[opcode]);
4101 ret = work_handlers[opcode](dev, skb);
4102 if (!ret)
4103 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004104 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004105 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106}
4107
4108static DECLARE_WORK(skb_work, process_work);
4109
4110static void ep_timeout(unsigned long arg)
4111{
4112 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004113 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004114
4115 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004116 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004117 /*
4118 * Only insert if it is not already on the list.
4119 */
4120 if (!ep->entry.next) {
4121 list_add_tail(&ep->entry, &timeout_list);
4122 kickit = 1;
4123 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004124 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004125 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004126 if (kickit)
4127 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004128}
4129
4130/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004131 * All the CM events are handled on a work queue to have a safe context.
4132 */
4133static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4134{
4135
4136 /*
4137 * Save dev in the skb->cb area.
4138 */
4139 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4140
4141 /*
4142 * Queue the skb and schedule the worker thread.
4143 */
4144 skb_queue_tail(&rxq, skb);
4145 queue_work(workq, &skb_work);
4146 return 0;
4147}
4148
4149static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4150{
4151 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4152
4153 if (rpl->status != CPL_ERR_NONE) {
4154 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4155 "for tid %u\n", rpl->status, GET_TID(rpl));
4156 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004157 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004158 return 0;
4159}
4160
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004161static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4162{
4163 struct cpl_fw6_msg *rpl = cplhdr(skb);
4164 struct c4iw_wr_wait *wr_waitp;
4165 int ret;
4166
4167 PDBG("%s type %u\n", __func__, rpl->type);
4168
4169 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004170 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004171 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004172 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004173 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004174 if (wr_waitp)
4175 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004176 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004177 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004178 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004179 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004180 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004181 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004182 default:
4183 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4184 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004185 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004186 break;
4187 }
4188 return 0;
4189}
4190
Steve Wise8da7e7a2011-06-14 20:59:27 +00004191static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4192{
4193 struct cpl_abort_req_rss *req = cplhdr(skb);
4194 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004195 unsigned int tid = GET_TID(req);
4196
Hariprasad S944661d2016-05-06 22:18:03 +05304197 ep = get_ep_from_tid(dev, tid);
4198 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004199 if (!ep) {
4200 printk(KERN_WARNING MOD
4201 "Abort on non-existent endpoint, tid %d\n", tid);
4202 kfree_skb(skb);
4203 return 0;
4204 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304205 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304206 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4207 __func__, ep->hwtid, req->status,
4208 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304209 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004210 }
4211 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4212 ep->com.state);
4213
Hariprasad S093108c2016-05-06 22:18:09 +05304214 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304215out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004216 sched(dev, skb);
4217 return 0;
4218}
4219
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004220/*
4221 * Most upcalls from the T4 Core go to sched() to
4222 * schedule the processing on a work queue.
4223 */
4224c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4225 [CPL_ACT_ESTABLISH] = sched,
4226 [CPL_ACT_OPEN_RPL] = sched,
4227 [CPL_RX_DATA] = sched,
4228 [CPL_ABORT_RPL_RSS] = sched,
4229 [CPL_ABORT_RPL] = sched,
4230 [CPL_PASS_OPEN_RPL] = sched,
4231 [CPL_CLOSE_LISTSRV_RPL] = sched,
4232 [CPL_PASS_ACCEPT_REQ] = sched,
4233 [CPL_PASS_ESTABLISH] = sched,
4234 [CPL_PEER_CLOSE] = sched,
4235 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004236 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004237 [CPL_RDMA_TERMINATE] = sched,
4238 [CPL_FW4_ACK] = sched,
4239 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004240 [CPL_FW6_MSG] = fw6_msg,
4241 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004242};
4243
Steve Wisecfdda9d2010-04-21 15:30:06 -07004244int __init c4iw_cm_init(void)
4245{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004246 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004247 skb_queue_head_init(&rxq);
4248
4249 workq = create_singlethread_workqueue("iw_cxgb4");
4250 if (!workq)
4251 return -ENOMEM;
4252
Steve Wisecfdda9d2010-04-21 15:30:06 -07004253 return 0;
4254}
4255
Steve Wise46c13762014-06-20 14:26:25 -05004256void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004257{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004258 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004259 flush_workqueue(workq);
4260 destroy_workqueue(workq);
4261}