blob: 22bccd87c5d29c748e5467fab133c451739c509e [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{
Hariprasad S4a740832016-06-10 01:05:15 +0530640 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Varun Prakash29fb6f42016-09-13 21:24:03 +0530641 u32 wrlen = roundup(sizeof(struct cpl_close_con_req), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700642
643 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530644 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530646
Varun Prakash29fb6f42016-09-13 21:24:03 +0530647 cxgb_mk_close_con_req(skb, wrlen, ep->hwtid, ep->txq_idx,
648 NULL, arp_failure_discard);
649
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
651}
652
Hariprasad S4a740832016-06-10 01:05:15 +0530653static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700654{
655 struct cpl_abort_req *req;
656 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530657 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700658
659 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530660 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530662
663 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
664 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
665 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666 memset(req, 0, wrlen);
667 INIT_TP_WR(req, ep->hwtid);
668 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
669 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530670 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700671}
672
673static int send_connect(struct c4iw_ep *ep)
674{
Hariprasad S963cab52015-09-23 17:19:27 +0530675 struct cpl_act_open_req *req = NULL;
676 struct cpl_t5_act_open_req *t5req = NULL;
677 struct cpl_t6_act_open_req *t6req = NULL;
678 struct cpl_act_open_req6 *req6 = NULL;
679 struct cpl_t5_act_open_req6 *t5req6 = NULL;
680 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700681 struct sk_buff *skb;
682 u64 opt0;
683 u32 opt2;
684 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530685 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530686 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500687 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600688 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500689 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600690 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500691 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600692 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500693 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600694 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530695 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530696 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
697 u32 isn = (prandom_u32() & ~7UL) - 1;
698
699 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
700 case CHELSIO_T4:
701 sizev4 = sizeof(struct cpl_act_open_req);
702 sizev6 = sizeof(struct cpl_act_open_req6);
703 break;
704 case CHELSIO_T5:
705 sizev4 = sizeof(struct cpl_t5_act_open_req);
706 sizev6 = sizeof(struct cpl_t5_act_open_req6);
707 break;
708 case CHELSIO_T6:
709 sizev4 = sizeof(struct cpl_t6_act_open_req);
710 sizev6 = sizeof(struct cpl_t6_act_open_req6);
711 break;
712 default:
713 pr_err("T%d Chip is not supported\n",
714 CHELSIO_CHIP_VERSION(adapter_type));
715 return -EINVAL;
716 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530717
718 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
719 roundup(sizev4, 16) :
720 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700721
722 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
723
724 skb = get_skb(NULL, wrlen, GFP_KERNEL);
725 if (!skb) {
726 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
727 __func__);
728 return -ENOMEM;
729 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000730 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700731
Varun Prakash44c6d062016-09-13 21:24:00 +0530732 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
733 enable_tcp_timestamps,
734 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530735 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530736
737 /*
738 * Specify the largest window that will fit in opt0. The
739 * remainder will be specified in the rx_data_ack.
740 */
741 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800742 if (win > RCV_BUFSIZ_M)
743 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530744
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800745 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800746 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800747 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800748 WND_SCALE_V(wscale) |
749 MSS_IDX_V(mtu_idx) |
750 L2T_IDX_V(ep->l2t->idx) |
751 TX_CHAN_V(ep->tx_chan) |
752 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530753 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800754 ULP_MODE_V(ULP_MODE_TCPDDP) |
755 RCV_BUFSIZ_V(win);
756 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800757 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800758 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700759 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800760 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700761 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800762 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700763 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800764 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530765 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
766 if (peer2peer)
767 isn += 4;
768
Anish Bhattd7990b02014-11-12 17:15:57 -0800769 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530770 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530771 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500772 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530773
774 if (ep->com.remote_addr.ss_family == AF_INET6)
775 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
776 (const u32 *)&la6->sin6_addr.s6_addr, 1);
777
Hariprasad S5dab6d32014-06-23 19:12:36 +0530778 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700779
Hariprasad S963cab52015-09-23 17:19:27 +0530780 if (ep->com.remote_addr.ss_family == AF_INET) {
781 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
782 case CHELSIO_T4:
783 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530784 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530785 break;
786 case CHELSIO_T5:
787 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
788 wrlen);
789 INIT_TP_WR(t5req, 0);
790 req = (struct cpl_act_open_req *)t5req;
791 break;
792 case CHELSIO_T6:
793 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
794 wrlen);
795 INIT_TP_WR(t6req, 0);
796 req = (struct cpl_act_open_req *)t6req;
797 t5req = (struct cpl_t5_act_open_req *)t6req;
798 break;
799 default:
800 pr_err("T%d Chip is not supported\n",
801 CHELSIO_CHIP_VERSION(adapter_type));
802 ret = -EINVAL;
803 goto clip_release;
804 }
805
806 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
807 ((ep->rss_qid<<14) | ep->atid)));
808 req->local_port = la->sin_port;
809 req->peer_port = ra->sin_port;
810 req->local_ip = la->sin_addr.s_addr;
811 req->peer_ip = ra->sin_addr.s_addr;
812 req->opt0 = cpu_to_be64(opt0);
813
814 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530815 req->params = cpu_to_be32(cxgb4_select_ntuple(
816 ep->com.dev->rdev.lldi.ports[0],
817 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530818 req->opt2 = cpu_to_be32(opt2);
819 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530820 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
821 cxgb4_select_ntuple(
822 ep->com.dev->rdev.lldi.ports[0],
823 ep->l2t)));
824 t5req->rsvd = cpu_to_be32(isn);
825 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
826 t5req->opt2 = cpu_to_be32(opt2);
827 }
828 } else {
829 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
830 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530831 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530832 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530833 break;
834 case CHELSIO_T5:
835 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
836 wrlen);
837 INIT_TP_WR(t5req6, 0);
838 req6 = (struct cpl_act_open_req6 *)t5req6;
839 break;
840 case CHELSIO_T6:
841 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
842 wrlen);
843 INIT_TP_WR(t6req6, 0);
844 req6 = (struct cpl_act_open_req6 *)t6req6;
845 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
846 break;
847 default:
848 pr_err("T%d Chip is not supported\n",
849 CHELSIO_CHIP_VERSION(adapter_type));
850 ret = -EINVAL;
851 goto clip_release;
852 }
853
854 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
855 ((ep->rss_qid<<14)|ep->atid)));
856 req6->local_port = la6->sin6_port;
857 req6->peer_port = ra6->sin6_port;
858 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
859 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
860 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
861 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
862 req6->opt0 = cpu_to_be64(opt0);
863
864 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530865 req6->params = cpu_to_be32(cxgb4_select_ntuple(
866 ep->com.dev->rdev.lldi.ports[0],
867 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530868 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530869 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530870 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
871 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530872 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530873 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530874 t5req6->rsvd = cpu_to_be32(isn);
875 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
876 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530877 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000878 }
879
Vipul Pandya793dad92012-12-10 09:30:56 +0000880 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530881 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530882clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530883 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
884 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
885 (const u32 *)&la6->sin6_addr.s6_addr, 1);
886 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700887}
888
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530889static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
890 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530892 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700893 struct fw_ofld_tx_data_wr *req;
894 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530895 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700896
897 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
898
899 BUG_ON(skb_cloned(skb));
900
901 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530902 if (mpa_rev_to_use == 2)
903 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700904 wrlen = roundup(mpalen + sizeof *req, 16);
905 skb = get_skb(skb, wrlen, GFP_KERNEL);
906 if (!skb) {
907 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530908 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700909 }
910 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
911
912 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
913 memset(req, 0, wrlen);
914 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530915 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
916 FW_WR_COMPL_F |
917 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700918 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530919 FW_WR_FLOWID_V(ep->hwtid) |
920 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700921 req->plen = cpu_to_be32(mpalen);
922 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530923 FW_OFLD_TX_DATA_WR_FLUSH_F |
924 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700925
926 mpa = (struct mpa_message *)(req + 1);
927 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530928
929 mpa->flags = 0;
930 if (crc_enabled)
931 mpa->flags |= MPA_CRC;
932 if (markers_enabled) {
933 mpa->flags |= MPA_MARKERS;
934 ep->mpa_attr.recv_marker_enabled = 1;
935 } else {
936 ep->mpa_attr.recv_marker_enabled = 0;
937 }
938 if (mpa_rev_to_use == 2)
939 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
940
Steve Wisecfdda9d2010-04-21 15:30:06 -0700941 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530942 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530943 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530944 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530945 ep->retry_with_mpa_v1 = 0;
946 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700947
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530948 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700949 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
950 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530951 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
952 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530953 mpa_v2_params.ird = htons((u16)ep->ird);
954 mpa_v2_params.ord = htons((u16)ep->ord);
955
956 if (peer2peer) {
957 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
958 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
959 mpa_v2_params.ord |=
960 htons(MPA_V2_RDMA_WRITE_RTR);
961 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
962 mpa_v2_params.ord |=
963 htons(MPA_V2_RDMA_READ_RTR);
964 }
965 memcpy(mpa->private_data, &mpa_v2_params,
966 sizeof(struct mpa_v2_conn_params));
967
968 if (ep->plen)
969 memcpy(mpa->private_data +
970 sizeof(struct mpa_v2_conn_params),
971 ep->mpa_pkt + sizeof(*mpa), ep->plen);
972 } else
973 if (ep->plen)
974 memcpy(mpa->private_data,
975 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700976
977 /*
978 * Reference the mpa skb. This ensures the data area
979 * will remain in memory until the hw acks the tx.
980 * Function fw4_ack() will deref it.
981 */
982 skb_get(skb);
983 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
984 BUG_ON(ep->mpa_skb);
985 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530986 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
987 if (ret)
988 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700989 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530990 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700991 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530992 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530993 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994}
995
996static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
997{
998 int mpalen, wrlen;
999 struct fw_ofld_tx_data_wr *req;
1000 struct mpa_message *mpa;
1001 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301002 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001003
1004 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1005
1006 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301007 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1008 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001009 wrlen = roundup(mpalen + sizeof *req, 16);
1010
1011 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1012 if (!skb) {
1013 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1014 return -ENOMEM;
1015 }
1016 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1017
1018 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1019 memset(req, 0, wrlen);
1020 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301021 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1022 FW_WR_COMPL_F |
1023 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301025 FW_WR_FLOWID_V(ep->hwtid) |
1026 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001027 req->plen = cpu_to_be32(mpalen);
1028 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301029 FW_OFLD_TX_DATA_WR_FLUSH_F |
1030 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001031
1032 mpa = (struct mpa_message *)(req + 1);
1033 memset(mpa, 0, sizeof(*mpa));
1034 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1035 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001036 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301038
1039 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1040 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001041 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1042 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301043 mpa_v2_params.ird = htons(((u16)ep->ird) |
1044 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1045 0));
1046 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1047 (p2p_type ==
1048 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1049 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1050 FW_RI_INIT_P2PTYPE_READ_REQ ?
1051 MPA_V2_RDMA_READ_RTR : 0) : 0));
1052 memcpy(mpa->private_data, &mpa_v2_params,
1053 sizeof(struct mpa_v2_conn_params));
1054
1055 if (ep->plen)
1056 memcpy(mpa->private_data +
1057 sizeof(struct mpa_v2_conn_params), pdata, plen);
1058 } else
1059 if (plen)
1060 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001061
1062 /*
1063 * Reference the mpa skb again. This ensures the data area
1064 * will remain in memory until the hw acks the tx.
1065 * Function fw4_ack() will deref it.
1066 */
1067 skb_get(skb);
1068 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301069 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 BUG_ON(ep->mpa_skb);
1071 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301072 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001073 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1074}
1075
1076static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1077{
1078 int mpalen, wrlen;
1079 struct fw_ofld_tx_data_wr *req;
1080 struct mpa_message *mpa;
1081 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301082 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001083
1084 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1085
1086 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301087 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1088 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001089 wrlen = roundup(mpalen + sizeof *req, 16);
1090
1091 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1092 if (!skb) {
1093 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1094 return -ENOMEM;
1095 }
1096 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1097
1098 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1099 memset(req, 0, wrlen);
1100 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301101 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1102 FW_WR_COMPL_F |
1103 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301105 FW_WR_FLOWID_V(ep->hwtid) |
1106 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001107 req->plen = cpu_to_be32(mpalen);
1108 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301109 FW_OFLD_TX_DATA_WR_FLUSH_F |
1110 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001111
1112 mpa = (struct mpa_message *)(req + 1);
1113 memset(mpa, 0, sizeof(*mpa));
1114 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301115 mpa->flags = 0;
1116 if (ep->mpa_attr.crc_enabled)
1117 mpa->flags |= MPA_CRC;
1118 if (ep->mpa_attr.recv_marker_enabled)
1119 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301120 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001121 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301122
1123 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1124 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001125 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1126 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301127 mpa_v2_params.ird = htons((u16)ep->ird);
1128 mpa_v2_params.ord = htons((u16)ep->ord);
1129 if (peer2peer && (ep->mpa_attr.p2p_type !=
1130 FW_RI_INIT_P2PTYPE_DISABLED)) {
1131 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1132
1133 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1134 mpa_v2_params.ord |=
1135 htons(MPA_V2_RDMA_WRITE_RTR);
1136 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1137 mpa_v2_params.ord |=
1138 htons(MPA_V2_RDMA_READ_RTR);
1139 }
1140
1141 memcpy(mpa->private_data, &mpa_v2_params,
1142 sizeof(struct mpa_v2_conn_params));
1143
1144 if (ep->plen)
1145 memcpy(mpa->private_data +
1146 sizeof(struct mpa_v2_conn_params), pdata, plen);
1147 } else
1148 if (plen)
1149 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001150
1151 /*
1152 * Reference the mpa skb. This ensures the data area
1153 * will remain in memory until the hw acks the tx.
1154 * Function fw4_ack() will deref it.
1155 */
1156 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301157 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301159 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301160 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001161 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1162}
1163
1164static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1165{
1166 struct c4iw_ep *ep;
1167 struct cpl_act_establish *req = cplhdr(skb);
1168 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001169 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001170 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301171 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001172
1173 ep = lookup_atid(t, atid);
1174
1175 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1176 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1177
Steve Wisea7db89e2014-03-21 20:40:35 +05301178 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179 dst_confirm(ep->dst);
1180
1181 /* setup the hwtid for this connection */
1182 ep->hwtid = tid;
1183 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301184 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001185
1186 ep->snd_seq = be32_to_cpu(req->snd_isn);
1187 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1188
1189 set_emss(ep, ntohs(req->tcp_opt));
1190
1191 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001192 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001194 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001195
1196 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301197 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301198 if (ret)
1199 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301200 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301201 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301202 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301203 ret = send_mpa_req(ep, skb, mpa_rev);
1204 if (ret)
1205 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301206 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001207 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301208err:
1209 mutex_unlock(&ep->com.mutex);
1210 connect_reply_upcall(ep, -ENOMEM);
1211 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1212 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001213}
1214
Steve Wisebe13b2d2014-03-21 20:40:33 +05301215static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001216{
1217 struct iw_cm_event event;
1218
1219 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1220 memset(&event, 0, sizeof(event));
1221 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301222 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001223 if (ep->com.cm_id) {
1224 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1225 ep, ep->com.cm_id, ep->hwtid);
1226 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301227 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001228 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001229 }
1230}
1231
Steve Wisecfdda9d2010-04-21 15:30:06 -07001232static void peer_close_upcall(struct c4iw_ep *ep)
1233{
1234 struct iw_cm_event event;
1235
1236 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1237 memset(&event, 0, sizeof(event));
1238 event.event = IW_CM_EVENT_DISCONNECT;
1239 if (ep->com.cm_id) {
1240 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1241 ep, ep->com.cm_id, ep->hwtid);
1242 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001243 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001244 }
1245}
1246
1247static void peer_abort_upcall(struct c4iw_ep *ep)
1248{
1249 struct iw_cm_event event;
1250
1251 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1252 memset(&event, 0, sizeof(event));
1253 event.event = IW_CM_EVENT_CLOSE;
1254 event.status = -ECONNRESET;
1255 if (ep->com.cm_id) {
1256 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1257 ep->com.cm_id, ep->hwtid);
1258 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301259 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001260 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001261 }
1262}
1263
1264static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1265{
1266 struct iw_cm_event event;
1267
1268 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1269 memset(&event, 0, sizeof(event));
1270 event.event = IW_CM_EVENT_CONNECT_REPLY;
1271 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301272 memcpy(&event.local_addr, &ep->com.local_addr,
1273 sizeof(ep->com.local_addr));
1274 memcpy(&event.remote_addr, &ep->com.remote_addr,
1275 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001276
1277 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301278 if (!ep->tried_with_mpa_v1) {
1279 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301280 event.ord = ep->ird;
1281 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301282 event.private_data_len = ep->plen -
1283 sizeof(struct mpa_v2_conn_params);
1284 event.private_data = ep->mpa_pkt +
1285 sizeof(struct mpa_message) +
1286 sizeof(struct mpa_v2_conn_params);
1287 } else {
1288 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301289 event.ord = cur_max_read_depth(ep->com.dev);
1290 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301291 event.private_data_len = ep->plen;
1292 event.private_data = ep->mpa_pkt +
1293 sizeof(struct mpa_message);
1294 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001295 }
Roland Dreier85963e42010-07-19 13:13:09 -07001296
1297 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1298 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001299 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001300 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1301
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301302 if (status < 0)
1303 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304}
1305
Steve Wisebe13b2d2014-03-21 20:40:33 +05301306static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001307{
1308 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301309 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001310
1311 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1312 memset(&event, 0, sizeof(event));
1313 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301314 memcpy(&event.local_addr, &ep->com.local_addr,
1315 sizeof(ep->com.local_addr));
1316 memcpy(&event.remote_addr, &ep->com.remote_addr,
1317 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001318 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301319 if (!ep->tried_with_mpa_v1) {
1320 /* this means MPA_v2 is used */
1321 event.ord = ep->ord;
1322 event.ird = ep->ird;
1323 event.private_data_len = ep->plen -
1324 sizeof(struct mpa_v2_conn_params);
1325 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1326 sizeof(struct mpa_v2_conn_params);
1327 } else {
1328 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301329 event.ord = cur_max_read_depth(ep->com.dev);
1330 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301331 event.private_data_len = ep->plen;
1332 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1333 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301334 c4iw_get_ep(&ep->com);
1335 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1336 &event);
1337 if (ret)
1338 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001339 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001340 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301341 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001342}
1343
1344static void established_upcall(struct c4iw_ep *ep)
1345{
1346 struct iw_cm_event event;
1347
1348 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1349 memset(&event, 0, sizeof(event));
1350 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301351 event.ird = ep->ord;
1352 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001353 if (ep->com.cm_id) {
1354 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1355 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001356 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001357 }
1358}
1359
1360static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1361{
1362 struct cpl_rx_data_ack *req;
1363 struct sk_buff *skb;
1364 int wrlen = roundup(sizeof *req, 16);
1365
1366 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1367 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1368 if (!skb) {
1369 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1370 return 0;
1371 }
1372
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301373 /*
1374 * If we couldn't specify the entire rcv window at connection setup
1375 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1376 * then add the overage in to the credits returned.
1377 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001378 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1379 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301380
Steve Wisecfdda9d2010-04-21 15:30:06 -07001381 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1382 memset(req, 0, wrlen);
1383 INIT_TP_WR(req, ep->hwtid);
1384 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1385 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001386 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301387 RX_DACK_CHANGE_F |
1388 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001389 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001390 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1391 return credits;
1392}
1393
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301394#define RELAXED_IRD_NEGOTIATION 1
1395
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301396/*
1397 * process_mpa_reply - process streaming mode MPA reply
1398 *
1399 * Returns:
1400 *
1401 * 0 upon success indicating a connect request was delivered to the ULP
1402 * or the mpa request is incomplete but valid so far.
1403 *
1404 * 1 if a failure requires the caller to close the connection.
1405 *
1406 * 2 if a failure requires the caller to abort the connection.
1407 */
Steve Wisecc18b932014-04-24 14:31:53 -05001408static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409{
1410 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301411 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001412 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301413 u16 resp_ird, resp_ord;
1414 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001415 struct c4iw_qp_attributes attrs;
1416 enum c4iw_qp_attr_mask mask;
1417 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001418 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001419
1420 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1421
1422 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001423 * If we get more than the supported amount of private data
1424 * then we must fail this connection.
1425 */
1426 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1427 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301428 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429 }
1430
1431 /*
1432 * copy the new data into our accumulation buffer.
1433 */
1434 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1435 skb->len);
1436 ep->mpa_pkt_len += skb->len;
1437
1438 /*
1439 * if we don't even have the mpa message, then bail.
1440 */
1441 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001442 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001443 mpa = (struct mpa_message *) ep->mpa_pkt;
1444
1445 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301446 if (mpa->revision > mpa_rev) {
1447 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1448 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001449 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301450 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001451 }
1452 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1453 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301454 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001455 }
1456
1457 plen = ntohs(mpa->private_data_size);
1458
1459 /*
1460 * Fail if there's too much private data.
1461 */
1462 if (plen > MPA_MAX_PRIVATE_DATA) {
1463 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301464 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001465 }
1466
1467 /*
1468 * If plen does not account for pkt size
1469 */
1470 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1471 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301472 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 }
1474
1475 ep->plen = (u8) plen;
1476
1477 /*
1478 * If we don't have all the pdata yet, then bail.
1479 * We'll continue process when more data arrives.
1480 */
1481 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001482 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483
1484 if (mpa->flags & MPA_REJECT) {
1485 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301486 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001487 }
1488
1489 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301490 * Stop mpa timer. If it expired, then
1491 * we ignore the MPA reply. process_timeout()
1492 * will abort the connection.
1493 */
1494 if (stop_ep_timer(ep))
1495 return 0;
1496
1497 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001498 * If we get here we have accumulated the entire mpa
1499 * start reply message including private data. And
1500 * the MPA header is valid.
1501 */
Steve Wisec529fb52014-03-21 20:40:37 +05301502 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001503 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001504 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301505 ep->mpa_attr.version = mpa->revision;
1506 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1507
1508 if (mpa->revision == 2) {
1509 ep->mpa_attr.enhanced_rdma_conn =
1510 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1511 if (ep->mpa_attr.enhanced_rdma_conn) {
1512 mpa_v2_params = (struct mpa_v2_conn_params *)
1513 (ep->mpa_pkt + sizeof(*mpa));
1514 resp_ird = ntohs(mpa_v2_params->ird) &
1515 MPA_V2_IRD_ORD_MASK;
1516 resp_ord = ntohs(mpa_v2_params->ord) &
1517 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301518 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1519 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301520
1521 /*
1522 * This is a double-check. Ideally, below checks are
1523 * not required since ird/ord stuff has been taken
1524 * care of in c4iw_accept_cr
1525 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301526 if (ep->ird < resp_ord) {
1527 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1528 ep->com.dev->rdev.lldi.max_ordird_qp)
1529 ep->ird = resp_ord;
1530 else
1531 insuff_ird = 1;
1532 } else if (ep->ird > resp_ord) {
1533 ep->ird = resp_ord;
1534 }
1535 if (ep->ord > resp_ird) {
1536 if (RELAXED_IRD_NEGOTIATION)
1537 ep->ord = resp_ird;
1538 else
1539 insuff_ird = 1;
1540 }
1541 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301542 err = -ENOMEM;
1543 ep->ird = resp_ord;
1544 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301545 }
1546
1547 if (ntohs(mpa_v2_params->ird) &
1548 MPA_V2_PEER2PEER_MODEL) {
1549 if (ntohs(mpa_v2_params->ord) &
1550 MPA_V2_RDMA_WRITE_RTR)
1551 ep->mpa_attr.p2p_type =
1552 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1553 else if (ntohs(mpa_v2_params->ord) &
1554 MPA_V2_RDMA_READ_RTR)
1555 ep->mpa_attr.p2p_type =
1556 FW_RI_INIT_P2PTYPE_READ_REQ;
1557 }
1558 }
1559 } else if (mpa->revision == 1)
1560 if (peer2peer)
1561 ep->mpa_attr.p2p_type = p2p_type;
1562
Steve Wisecfdda9d2010-04-21 15:30:06 -07001563 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1565 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1566 ep->mpa_attr.recv_marker_enabled,
1567 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1568 ep->mpa_attr.p2p_type, p2p_type);
1569
1570 /*
1571 * If responder's RTR does not match with that of initiator, assign
1572 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1573 * generated when moving QP to RTS state.
1574 * A TERM message will be sent after QP has moved to RTS state
1575 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001576 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301577 (ep->mpa_attr.p2p_type != p2p_type)) {
1578 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1579 rtr_mismatch = 1;
1580 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001581
1582 attrs.mpa_attr = ep->mpa_attr;
1583 attrs.max_ird = ep->ird;
1584 attrs.max_ord = ep->ord;
1585 attrs.llp_stream_handle = ep;
1586 attrs.next_state = C4IW_QP_STATE_RTS;
1587
1588 mask = C4IW_QP_ATTR_NEXT_STATE |
1589 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1590 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1591
1592 /* bind QP and TID with INIT_WR */
1593 err = c4iw_modify_qp(ep->com.qp->rhp,
1594 ep->com.qp, mask, &attrs, 1);
1595 if (err)
1596 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597
1598 /*
1599 * If responder's RTR requirement did not match with what initiator
1600 * supports, generate TERM message
1601 */
1602 if (rtr_mismatch) {
1603 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1604 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1605 attrs.ecode = MPA_NOMATCH_RTR;
1606 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001607 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301608 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001609 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301610 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001611 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301612 goto out;
1613 }
1614
1615 /*
1616 * Generate TERM if initiator IRD is not sufficient for responder
1617 * provided ORD. Currently, we do the same behaviour even when
1618 * responder provided IRD is also not sufficient as regards to
1619 * initiator ORD.
1620 */
1621 if (insuff_ird) {
1622 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1623 __func__);
1624 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1625 attrs.ecode = MPA_INSUFF_IRD;
1626 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001627 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301628 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001629 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301630 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001631 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301632 goto out;
1633 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001634 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301635err_stop_timer:
1636 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001637err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301638 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001639out:
1640 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001641 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001642}
1643
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301644/*
1645 * process_mpa_request - process streaming mode MPA request
1646 *
1647 * Returns:
1648 *
1649 * 0 upon success indicating a connect request was delivered to the ULP
1650 * or the mpa request is incomplete but valid so far.
1651 *
1652 * 1 if a failure requires the caller to close the connection.
1653 *
1654 * 2 if a failure requires the caller to abort the connection.
1655 */
1656static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001657{
1658 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301659 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001660 u16 plen;
1661
1662 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1663
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664 /*
1665 * If we get more than the supported amount of private data
1666 * then we must fail this connection.
1667 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301668 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1669 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001670
1671 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1672
1673 /*
1674 * Copy the new data into our accumulation buffer.
1675 */
1676 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1677 skb->len);
1678 ep->mpa_pkt_len += skb->len;
1679
1680 /*
1681 * If we don't even have the mpa message, then bail.
1682 * We'll continue process when more data arrives.
1683 */
1684 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301685 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001686
1687 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001688 mpa = (struct mpa_message *) ep->mpa_pkt;
1689
1690 /*
1691 * Validate MPA Header.
1692 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301693 if (mpa->revision > mpa_rev) {
1694 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1695 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301696 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001697 }
1698
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301699 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1700 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001701
1702 plen = ntohs(mpa->private_data_size);
1703
1704 /*
1705 * Fail if there's too much private data.
1706 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301707 if (plen > MPA_MAX_PRIVATE_DATA)
1708 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709
1710 /*
1711 * If plen does not account for pkt size
1712 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301713 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1714 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001715 ep->plen = (u8) plen;
1716
1717 /*
1718 * If we don't have all the pdata yet, then bail.
1719 */
1720 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301721 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001722
1723 /*
1724 * If we get here we have accumulated the entire mpa
1725 * start reply message including private data.
1726 */
1727 ep->mpa_attr.initiator = 0;
1728 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1729 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1730 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301731 ep->mpa_attr.version = mpa->revision;
1732 if (mpa->revision == 1)
1733 ep->tried_with_mpa_v1 = 1;
1734 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1735
1736 if (mpa->revision == 2) {
1737 ep->mpa_attr.enhanced_rdma_conn =
1738 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1739 if (ep->mpa_attr.enhanced_rdma_conn) {
1740 mpa_v2_params = (struct mpa_v2_conn_params *)
1741 (ep->mpa_pkt + sizeof(*mpa));
1742 ep->ird = ntohs(mpa_v2_params->ird) &
1743 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001744 ep->ird = min_t(u32, ep->ird,
1745 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301746 ep->ord = ntohs(mpa_v2_params->ord) &
1747 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001748 ep->ord = min_t(u32, ep->ord,
1749 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301750 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1751 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301752 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1753 if (peer2peer) {
1754 if (ntohs(mpa_v2_params->ord) &
1755 MPA_V2_RDMA_WRITE_RTR)
1756 ep->mpa_attr.p2p_type =
1757 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1758 else if (ntohs(mpa_v2_params->ord) &
1759 MPA_V2_RDMA_READ_RTR)
1760 ep->mpa_attr.p2p_type =
1761 FW_RI_INIT_P2PTYPE_READ_REQ;
1762 }
1763 }
1764 } else if (mpa->revision == 1)
1765 if (peer2peer)
1766 ep->mpa_attr.p2p_type = p2p_type;
1767
Steve Wisecfdda9d2010-04-21 15:30:06 -07001768 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1769 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1770 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1771 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1772 ep->mpa_attr.p2p_type);
1773
Hariprasad Se4b76a22016-05-06 22:17:59 +05301774 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775
Hariprasad Se4b76a22016-05-06 22:17:59 +05301776 /* drive upcall */
1777 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1778 if (ep->parent_ep->com.state != DEAD) {
1779 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301780 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301781 } else {
1782 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301783 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301784 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301785 return 0;
1786
1787err_unlock_parent:
1788 mutex_unlock(&ep->parent_ep->com.mutex);
1789 goto err_out;
1790err_stop_timer:
1791 (void)stop_ep_timer(ep);
1792err_out:
1793 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001794}
1795
1796static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1797{
1798 struct c4iw_ep *ep;
1799 struct cpl_rx_data *hdr = cplhdr(skb);
1800 unsigned int dlen = ntohs(hdr->len);
1801 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001802 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001803 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804
Hariprasad S944661d2016-05-06 22:18:03 +05301805 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301806 if (!ep)
1807 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001808 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1809 skb_pull(skb, sizeof(*hdr));
1810 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301811 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812
Steve Wisecfdda9d2010-04-21 15:30:06 -07001813 /* update RX credits */
1814 update_rx_credits(ep, dlen);
1815
Steve Wisec529fb52014-03-21 20:40:37 +05301816 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001817 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001818 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001819 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820 break;
1821 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001822 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301823 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001824 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001825 case FPDU_MODE: {
1826 struct c4iw_qp_attributes attrs;
1827 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001828 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001829 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001830 " qpid %u ep %p state %d tid %u status %d\n",
1831 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301832 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301833 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001834 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001835 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1836 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001837 break;
1838 }
Vipul Pandya15579672013-01-07 13:11:52 +00001839 default:
1840 break;
1841 }
Steve Wisec529fb52014-03-21 20:40:37 +05301842 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001843 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301844 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301845 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001846 return 0;
1847}
1848
1849static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1850{
1851 struct c4iw_ep *ep;
1852 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001853 int release = 0;
1854 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855
Hariprasad S944661d2016-05-06 22:18:03 +05301856 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301857 if (!ep) {
1858 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1859 return 0;
1860 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001861 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001862 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001863 switch (ep->com.state) {
1864 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001865 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001866 __state_set(&ep->com, DEAD);
1867 release = 1;
1868 break;
1869 default:
1870 printk(KERN_ERR "%s ep %p state %d\n",
1871 __func__, ep, ep->com.state);
1872 break;
1873 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001874 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001875
1876 if (release)
1877 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301878 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001879 return 0;
1880}
1881
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301882static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001883{
1884 struct sk_buff *skb;
1885 struct fw_ofld_connection_wr *req;
1886 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301887 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301888 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301889 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001890
1891 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1892 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1893 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001894 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301895 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301896 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1897 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001898 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001899 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301900 req->le.lport = sin->sin_port;
1901 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001902 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301903 req->le.pport = sin->sin_port;
1904 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001905 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301906 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1907 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001908 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301909 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001910 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001911 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301912 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1913 enable_tcp_timestamps,
1914 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301915 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301916
1917 /*
1918 * Specify the largest window that will fit in opt0. The
1919 * remainder will be specified in the rx_data_ack.
1920 */
1921 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001922 if (win > RCV_BUFSIZ_M)
1923 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301924
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001925 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1926 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001927 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001928 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001929 WND_SCALE_V(wscale) |
1930 MSS_IDX_V(mtu_idx) |
1931 L2T_IDX_V(ep->l2t->idx) |
1932 TX_CHAN_V(ep->tx_chan) |
1933 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301934 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001935 ULP_MODE_V(ULP_MODE_TCPDDP) |
1936 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001937 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1938 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001939 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001940 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001941 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001942 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001943 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001944 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001945 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001946 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001947 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1948 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1949 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001950 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1951 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301952 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001953}
1954
Steve Wisecfdda9d2010-04-21 15:30:06 -07001955/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301956 * Some of the error codes above implicitly indicate that there is no TID
1957 * allocated with the result of an ACT_OPEN. We use this predicate to make
1958 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001959 */
1960static inline int act_open_has_tid(int status)
1961{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301962 return (status != CPL_ERR_TCAM_PARITY &&
1963 status != CPL_ERR_TCAM_MISS &&
1964 status != CPL_ERR_TCAM_FULL &&
1965 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1966 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001967}
1968
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301969static char *neg_adv_str(unsigned int status)
1970{
1971 switch (status) {
1972 case CPL_ERR_RTX_NEG_ADVICE:
1973 return "Retransmit timeout";
1974 case CPL_ERR_PERSIST_NEG_ADVICE:
1975 return "Persist timeout";
1976 case CPL_ERR_KEEPALV_NEG_ADVICE:
1977 return "Keepalive timeout";
1978 default:
1979 return "Unknown";
1980 }
1981}
1982
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301983static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1984{
1985 ep->snd_win = snd_win;
1986 ep->rcv_win = rcv_win;
1987 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1988}
1989
Vipul Pandya793dad92012-12-10 09:30:56 +00001990#define ACT_OPEN_RETRY_COUNT 2
1991
Vipul Pandya830662f2013-07-04 16:10:47 +05301992static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1993 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301994 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301995{
1996 struct neighbour *n;
1997 int err, step;
1998 struct net_device *pdev;
1999
2000 n = dst_neigh_lookup(dst, peer_ip);
2001 if (!n)
2002 return -ENODEV;
2003
2004 rcu_read_lock();
2005 err = -ENOMEM;
2006 if (n->dev->flags & IFF_LOOPBACK) {
2007 if (iptype == 4)
2008 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2009 else if (IS_ENABLED(CONFIG_IPV6))
2010 for_each_netdev(&init_net, pdev) {
2011 if (ipv6_chk_addr(&init_net,
2012 (struct in6_addr *)peer_ip,
2013 pdev, 1))
2014 break;
2015 }
2016 else
2017 pdev = NULL;
2018
2019 if (!pdev) {
2020 err = -ENODEV;
2021 goto out;
2022 }
2023 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302024 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302025 if (!ep->l2t)
2026 goto out;
2027 ep->mtu = pdev->mtu;
2028 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302029 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2030 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302031 step = cdev->rdev.lldi.ntxq /
2032 cdev->rdev.lldi.nchan;
2033 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2034 step = cdev->rdev.lldi.nrxq /
2035 cdev->rdev.lldi.nchan;
2036 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2037 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2038 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302039 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302040 dev_put(pdev);
2041 } else {
2042 pdev = get_real_dev(n->dev);
2043 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2044 n, pdev, 0);
2045 if (!ep->l2t)
2046 goto out;
2047 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002048 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302049 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2050 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302051 step = cdev->rdev.lldi.ntxq /
2052 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002053 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2054 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302055 step = cdev->rdev.lldi.nrxq /
2056 cdev->rdev.lldi.nchan;
2057 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002058 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302059 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302060
2061 if (clear_mpa_v1) {
2062 ep->retry_with_mpa_v1 = 0;
2063 ep->tried_with_mpa_v1 = 0;
2064 }
2065 }
2066 err = 0;
2067out:
2068 rcu_read_unlock();
2069
2070 neigh_release(n);
2071
2072 return err;
2073}
2074
Vipul Pandya793dad92012-12-10 09:30:56 +00002075static int c4iw_reconnect(struct c4iw_ep *ep)
2076{
2077 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302078 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302079 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002080 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302081 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002082 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302083 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002084 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302085 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002086 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302087 int iptype;
2088 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002089
2090 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2091 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302092 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002093
Hariprasad S4a740832016-06-10 01:05:15 +05302094 /* When MPA revision is different on nodes, the node with MPA_rev=2
2095 * tries to reconnect with MPA_rev 1 for the same EP through
2096 * c4iw_reconnect(), where the same EP is assigned with new tid for
2097 * further connection establishment. As we are using the same EP pointer
2098 * for reconnect, few skbs are used during the previous c4iw_connect(),
2099 * which leaves the EP with inadequate skbs for further
2100 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2101 * skb_list() during peer_abort(). Allocate skbs which is already used.
2102 */
2103 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2104 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2105 err = -ENOMEM;
2106 goto fail1;
2107 }
2108
Vipul Pandya793dad92012-12-10 09:30:56 +00002109 /*
2110 * Allocate an active TID to initiate a TCP connection.
2111 */
2112 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2113 if (ep->atid == -1) {
2114 pr_err("%s - cannot alloc atid.\n", __func__);
2115 err = -ENOMEM;
2116 goto fail2;
2117 }
2118 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2119
2120 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002121 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302122 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2123 laddr->sin_addr.s_addr,
2124 raddr->sin_addr.s_addr,
2125 laddr->sin_port,
2126 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302127 iptype = 4;
2128 ra = (__u8 *)&raddr->sin_addr;
2129 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302130 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2131 get_real_dev,
2132 laddr6->sin6_addr.s6_addr,
2133 raddr6->sin6_addr.s6_addr,
2134 laddr6->sin6_port,
2135 raddr6->sin6_port, 0,
2136 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302137 iptype = 6;
2138 ra = (__u8 *)&raddr6->sin6_addr;
2139 }
2140 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002141 pr_err("%s - cannot find route.\n", __func__);
2142 err = -EHOSTUNREACH;
2143 goto fail3;
2144 }
Hariprasad S963cab52015-09-23 17:19:27 +05302145 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302146 ep->com.dev->rdev.lldi.adapter_type,
2147 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302148 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002149 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002150 goto fail4;
2151 }
2152
2153 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2154 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2155 ep->l2t->idx);
2156
2157 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302158 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002159
2160 /* send connect request to rnic */
2161 err = send_connect(ep);
2162 if (!err)
2163 goto out;
2164
2165 cxgb4_l2t_release(ep->l2t);
2166fail4:
2167 dst_release(ep->dst);
2168fail3:
2169 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2170 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2171fail2:
2172 /*
2173 * remember to send notification to upper layer.
2174 * We are in here so the upper layer is not aware that this is
2175 * re-connect attempt and so, upper layer is still waiting for
2176 * response of 1st connect request.
2177 */
2178 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302179fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002180 c4iw_put_ep(&ep->com);
2181out:
2182 return err;
2183}
2184
Steve Wisecfdda9d2010-04-21 15:30:06 -07002185static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2186{
2187 struct c4iw_ep *ep;
2188 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002189 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2190 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002191 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002192 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302193 struct sockaddr_in *la;
2194 struct sockaddr_in *ra;
2195 struct sockaddr_in6 *la6;
2196 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302197 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198
2199 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002200 la = (struct sockaddr_in *)&ep->com.local_addr;
2201 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2202 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2203 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002204
2205 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2206 status, status2errno(status));
2207
Varun Prakashb65eef02016-09-13 21:23:59 +05302208 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302209 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2210 __func__, atid, status, neg_adv_str(status));
2211 ep->stats.connect_neg_adv++;
2212 mutex_lock(&dev->rdev.stats.lock);
2213 dev->rdev.stats.neg_adv++;
2214 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002215 return 0;
2216 }
2217
Vipul Pandya793dad92012-12-10 09:30:56 +00002218 set_bit(ACT_OPEN_RPL, &ep->com.history);
2219
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302220 /*
2221 * Log interesting failures.
2222 */
2223 switch (status) {
2224 case CPL_ERR_CONN_RESET:
2225 case CPL_ERR_CONN_TIMEDOUT:
2226 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002227 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302228 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002229 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302230 mutex_unlock(&dev->rdev.stats.lock);
2231 if (ep->com.local_addr.ss_family == AF_INET &&
2232 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302233 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2234 ntohl(rpl->atid_status))));
2235 if (ret)
2236 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002237 return 0;
2238 }
2239 break;
2240 case CPL_ERR_CONN_EXIST:
2241 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2242 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302243 if (ep->com.remote_addr.ss_family == AF_INET6) {
2244 struct sockaddr_in6 *sin6 =
2245 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002246 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302247 cxgb4_clip_release(
2248 ep->com.dev->rdev.lldi.ports[0],
2249 (const u32 *)
2250 &sin6->sin6_addr.s6_addr, 1);
2251 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002252 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2253 atid);
2254 cxgb4_free_atid(t, atid);
2255 dst_release(ep->dst);
2256 cxgb4_l2t_release(ep->l2t);
2257 c4iw_reconnect(ep);
2258 return 0;
2259 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002260 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302261 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302262 if (ep->com.local_addr.ss_family == AF_INET) {
2263 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2264 atid, status, status2errno(status),
2265 &la->sin_addr.s_addr, ntohs(la->sin_port),
2266 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2267 } else {
2268 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2269 atid, status, status2errno(status),
2270 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2271 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2272 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302273 break;
2274 }
2275
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302276fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002277 connect_reply_upcall(ep, status2errno(status));
2278 state_set(&ep->com, DEAD);
2279
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302280 if (ep->com.remote_addr.ss_family == AF_INET6) {
2281 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002282 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302283 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2284 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2285 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002286 if (status && act_open_has_tid(status))
2287 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2288
Vipul Pandya793dad92012-12-10 09:30:56 +00002289 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002290 cxgb4_free_atid(t, atid);
2291 dst_release(ep->dst);
2292 cxgb4_l2t_release(ep->l2t);
2293 c4iw_put_ep(&ep->com);
2294
2295 return 0;
2296}
2297
2298static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2299{
2300 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002301 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302302 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002303
2304 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002305 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2306 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307 }
2308 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2309 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002310 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302311 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002312out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313 return 0;
2314}
2315
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2317{
2318 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002319 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302320 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002321
2322 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002323 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302324 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002325 return 0;
2326}
2327
Hariprasad S9dec9002016-05-05 01:27:29 +05302328static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2329 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002330{
2331 struct cpl_pass_accept_rpl *rpl;
2332 unsigned int mtu_idx;
2333 u64 opt0;
2334 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302335 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302336 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302337 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302338 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002339
2340 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2341 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302342
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302344 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302345 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302346 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2347 rpl5 = (void *)rpl;
2348 INIT_TP_WR(rpl5, ep->hwtid);
2349 } else {
2350 skb_trim(skb, sizeof(*rpl));
2351 INIT_TP_WR(rpl, ep->hwtid);
2352 }
2353 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2354 ep->hwtid));
2355
Varun Prakash44c6d062016-09-13 21:24:00 +05302356 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2357 enable_tcp_timestamps && req->tcpopt.tstamp,
2358 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302359 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302360
2361 /*
2362 * Specify the largest window that will fit in opt0. The
2363 * remainder will be specified in the rx_data_ack.
2364 */
2365 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002366 if (win > RCV_BUFSIZ_M)
2367 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002368 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002369 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002370 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002371 WND_SCALE_V(wscale) |
2372 MSS_IDX_V(mtu_idx) |
2373 L2T_IDX_V(ep->l2t->idx) |
2374 TX_CHAN_V(ep->tx_chan) |
2375 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002376 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002377 ULP_MODE_V(ULP_MODE_TCPDDP) |
2378 RCV_BUFSIZ_V(win);
2379 opt2 = RX_CHANNEL_V(0) |
2380 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002381
2382 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002383 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002385 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002386 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002387 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002388 if (enable_ecn) {
2389 const struct tcphdr *tcph;
2390 u32 hlen = ntohl(req->hdr_len);
2391
Hariprasad S963cab52015-09-23 17:19:27 +05302392 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2393 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2394 IP_HDR_LEN_G(hlen);
2395 else
2396 tcph = (const void *)(req + 1) +
2397 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002398 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002399 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002400 }
Hariprasad S963cab52015-09-23 17:19:27 +05302401 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302402 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002403 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302404 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302405 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302406 rpl5 = (void *)rpl;
2407 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2408 if (peer2peer)
2409 isn += 4;
2410 rpl5->iss = cpu_to_be32(isn);
2411 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002412 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002413
Steve Wisecfdda9d2010-04-21 15:30:06 -07002414 rpl->opt0 = cpu_to_be64(opt0);
2415 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002416 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302417 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002418
Hariprasad S9dec9002016-05-05 01:27:29 +05302419 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420}
2421
Vipul Pandya830662f2013-07-04 16:10:47 +05302422static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423{
Vipul Pandya830662f2013-07-04 16:10:47 +05302424 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425 BUG_ON(skb_cloned(skb));
2426 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427 release_tid(&dev->rdev, hwtid, skb);
2428 return;
2429}
2430
Steve Wisecfdda9d2010-04-21 15:30:06 -07002431static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2432{
Vipul Pandya793dad92012-12-10 09:30:56 +00002433 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002435 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002436 struct tid_info *t = dev->rdev.lldi.tids;
2437 unsigned int hwtid = GET_TID(req);
2438 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302439 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002440 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302441 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002442 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002443 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302444 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302445 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302446 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002447
Hariprasad Sf86fac72016-05-06 22:18:07 +05302448 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002449 if (!parent_ep) {
2450 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2451 goto reject;
2452 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002453
Steve Wisecfdda9d2010-04-21 15:30:06 -07002454 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302455 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002456 goto reject;
2457 }
2458
Varun Prakash85e42b02016-09-13 21:23:56 +05302459 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2460 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302461
Steve Wisecfdda9d2010-04-21 15:30:06 -07002462 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302463 if (iptype == 4) {
2464 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2465 , __func__, parent_ep, hwtid,
2466 local_ip, peer_ip, ntohs(local_port),
2467 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302468 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2469 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2470 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302471 } else {
2472 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2473 , __func__, parent_ep, hwtid,
2474 local_ip, peer_ip, ntohs(local_port),
2475 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302476 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2477 local_ip, peer_ip, local_port, peer_port,
2478 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2479 ((struct sockaddr_in6 *)
2480 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302481 }
2482 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2484 __func__);
2485 goto reject;
2486 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002487
2488 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2489 if (!child_ep) {
2490 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2491 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 dst_release(dst);
2493 goto reject;
2494 }
David Miller3786cf12011-12-02 16:52:31 +00002495
Hariprasad S963cab52015-09-23 17:19:27 +05302496 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302497 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002498 if (err) {
2499 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2500 __func__);
2501 dst_release(dst);
2502 kfree(child_ep);
2503 goto reject;
2504 }
2505
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302506 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2507 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2508 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2509 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002510
Hariprasad S4a740832016-06-10 01:05:15 +05302511 skb_queue_head_init(&child_ep->com.ep_skb_list);
2512 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2513 goto fail;
2514
Steve Wisecfdda9d2010-04-21 15:30:06 -07002515 state_set(&child_ep->com, CONNECTING);
2516 child_ep->com.dev = dev;
2517 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002518
Vipul Pandya830662f2013-07-04 16:10:47 +05302519 if (iptype == 4) {
2520 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002521 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002522
Vipul Pandya830662f2013-07-04 16:10:47 +05302523 sin->sin_family = PF_INET;
2524 sin->sin_port = local_port;
2525 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002526
2527 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2528 sin->sin_family = PF_INET;
2529 sin->sin_port = ((struct sockaddr_in *)
2530 &parent_ep->com.local_addr)->sin_port;
2531 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2532
Steve Wise170003c2016-02-26 09:18:03 -06002533 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302534 sin->sin_family = PF_INET;
2535 sin->sin_port = peer_port;
2536 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2537 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002538 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302539 sin6->sin6_family = PF_INET6;
2540 sin6->sin6_port = local_port;
2541 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002542
2543 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2544 sin6->sin6_family = PF_INET6;
2545 sin6->sin6_port = ((struct sockaddr_in6 *)
2546 &parent_ep->com.local_addr)->sin6_port;
2547 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2548
Steve Wise170003c2016-02-26 09:18:03 -06002549 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302550 sin6->sin6_family = PF_INET6;
2551 sin6->sin6_port = peer_port;
2552 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2553 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002554
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555 c4iw_get_ep(&parent_ep->com);
2556 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302557 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558 child_ep->dst = dst;
2559 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002560
2561 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002562 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002563
2564 init_timer(&child_ep->timer);
2565 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302566 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302567 if (accept_cr(child_ep, skb, req)) {
2568 c4iw_put_ep(&parent_ep->com);
2569 release_ep_resources(child_ep);
2570 } else {
2571 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2572 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302573 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002574 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302575 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2576 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2577 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002578 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302579fail:
2580 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302582 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302583 if (parent_ep)
2584 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585out:
2586 return 0;
2587}
2588
2589static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2590{
2591 struct c4iw_ep *ep;
2592 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002593 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302594 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002595
Hariprasad S944661d2016-05-06 22:18:03 +05302596 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2598 ep->snd_seq = be32_to_cpu(req->snd_isn);
2599 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2600
Vipul Pandya1cab7752012-12-10 09:30:55 +00002601 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2602 ntohs(req->tcp_opt));
2603
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 set_emss(ep, ntohs(req->tcp_opt));
2605
2606 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302607 mutex_lock(&ep->com.mutex);
2608 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002609 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002610 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302611 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302612 mutex_unlock(&ep->com.mutex);
2613 if (ret)
2614 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302615 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616
2617 return 0;
2618}
2619
2620static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2621{
2622 struct cpl_peer_close *hdr = cplhdr(skb);
2623 struct c4iw_ep *ep;
2624 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002625 int disconnect = 1;
2626 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002627 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002628 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629
Hariprasad S944661d2016-05-06 22:18:03 +05302630 ep = get_ep_from_tid(dev, tid);
2631 if (!ep)
2632 return 0;
2633
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2635 dst_confirm(ep->dst);
2636
Vipul Pandya793dad92012-12-10 09:30:56 +00002637 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002638 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 switch (ep->com.state) {
2640 case MPA_REQ_WAIT:
2641 __state_set(&ep->com, CLOSING);
2642 break;
2643 case MPA_REQ_SENT:
2644 __state_set(&ep->com, CLOSING);
2645 connect_reply_upcall(ep, -ECONNRESET);
2646 break;
2647 case MPA_REQ_RCVD:
2648
2649 /*
2650 * We're gonna mark this puppy DEAD, but keep
2651 * the reference on it until the ULP accepts or
2652 * rejects the CR. Also wake up anyone waiting
2653 * in rdma connection migration (see c4iw_accept_cr()).
2654 */
2655 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002656 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002657 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 break;
2659 case MPA_REP_SENT:
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 FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002665 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002666 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002667 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002668 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002669 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002670 if (ret != -ECONNRESET) {
2671 peer_close_upcall(ep);
2672 disconnect = 1;
2673 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002674 break;
2675 case ABORTING:
2676 disconnect = 0;
2677 break;
2678 case CLOSING:
2679 __state_set(&ep->com, MORIBUND);
2680 disconnect = 0;
2681 break;
2682 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002683 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002684 if (ep->com.cm_id && ep->com.qp) {
2685 attrs.next_state = C4IW_QP_STATE_IDLE;
2686 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2687 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2688 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302689 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002690 __state_set(&ep->com, DEAD);
2691 release = 1;
2692 disconnect = 0;
2693 break;
2694 case DEAD:
2695 disconnect = 0;
2696 break;
2697 default:
2698 BUG_ON(1);
2699 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002700 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701 if (disconnect)
2702 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2703 if (release)
2704 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302705 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706 return 0;
2707}
2708
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2710{
2711 struct cpl_abort_req_rss *req = cplhdr(skb);
2712 struct c4iw_ep *ep;
2713 struct cpl_abort_rpl *rpl;
2714 struct sk_buff *rpl_skb;
2715 struct c4iw_qp_attributes attrs;
2716 int ret;
2717 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002718 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719
Hariprasad S944661d2016-05-06 22:18:03 +05302720 ep = get_ep_from_tid(dev, tid);
2721 if (!ep)
2722 return 0;
2723
Varun Prakashb65eef02016-09-13 21:23:59 +05302724 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302725 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2726 __func__, ep->hwtid, req->status,
2727 neg_adv_str(req->status));
2728 ep->stats.abort_neg_adv++;
2729 mutex_lock(&dev->rdev.stats.lock);
2730 dev->rdev.stats.neg_adv++;
2731 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302732 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002733 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2735 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002736 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002737
2738 /*
2739 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302740 * However, this is not needed if com state is just
2741 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002742 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302743 if (ep->com.state != MPA_REQ_SENT)
2744 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002745
2746 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002747 switch (ep->com.state) {
2748 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302749 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 break;
2751 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002752 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753 break;
2754 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002755 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002756 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302757 connect_reply_upcall(ep, -ECONNRESET);
2758 else {
2759 /*
2760 * we just don't send notification upwards because we
2761 * want to retry with mpa_v1 without upper layers even
2762 * knowing it.
2763 *
2764 * do some housekeeping so as to re-initiate the
2765 * connection
2766 */
2767 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2768 mpa_rev);
2769 ep->retry_with_mpa_v1 = 1;
2770 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002771 break;
2772 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002773 break;
2774 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002775 break;
2776 case MORIBUND:
2777 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002778 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002779 /*FALLTHROUGH*/
2780 case FPDU_MODE:
2781 if (ep->com.cm_id && ep->com.qp) {
2782 attrs.next_state = C4IW_QP_STATE_ERROR;
2783 ret = c4iw_modify_qp(ep->com.qp->rhp,
2784 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2785 &attrs, 1);
2786 if (ret)
2787 printk(KERN_ERR MOD
2788 "%s - qp <- error failed!\n",
2789 __func__);
2790 }
2791 peer_abort_upcall(ep);
2792 break;
2793 case ABORTING:
2794 break;
2795 case DEAD:
2796 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002797 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302798 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 default:
2800 BUG_ON(1);
2801 break;
2802 }
2803 dst_confirm(ep->dst);
2804 if (ep->com.state != ABORTING) {
2805 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302806 /* we don't release if we want to retry with mpa_v1 */
2807 if (!ep->retry_with_mpa_v1)
2808 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002810 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002811
Hariprasad S4a740832016-06-10 01:05:15 +05302812 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2813 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 release = 1;
2815 goto out;
2816 }
2817 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2818 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2819 INIT_TP_WR(rpl, ep->hwtid);
2820 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2821 rpl->cmd = CPL_ABORT_NO_RST;
2822 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2823out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824 if (release)
2825 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002826 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302827 if (ep->com.remote_addr.ss_family == AF_INET6) {
2828 struct sockaddr_in6 *sin6 =
2829 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002830 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302831 cxgb4_clip_release(
2832 ep->com.dev->rdev.lldi.ports[0],
2833 (const u32 *)&sin6->sin6_addr.s6_addr,
2834 1);
2835 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002836 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302837 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2838 dst_release(ep->dst);
2839 cxgb4_l2t_release(ep->l2t);
2840 c4iw_reconnect(ep);
2841 }
2842
Hariprasad S944661d2016-05-06 22:18:03 +05302843deref_ep:
2844 c4iw_put_ep(&ep->com);
2845 /* Dereferencing ep, referenced in peer_abort_intr() */
2846 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847 return 0;
2848}
2849
2850static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2851{
2852 struct c4iw_ep *ep;
2853 struct c4iw_qp_attributes attrs;
2854 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002855 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002856 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002857
Hariprasad S944661d2016-05-06 22:18:03 +05302858 ep = get_ep_from_tid(dev, tid);
2859 if (!ep)
2860 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861
2862 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2863 BUG_ON(!ep);
2864
2865 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002866 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302867 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002868 switch (ep->com.state) {
2869 case CLOSING:
2870 __state_set(&ep->com, MORIBUND);
2871 break;
2872 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002873 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002874 if ((ep->com.cm_id) && (ep->com.qp)) {
2875 attrs.next_state = C4IW_QP_STATE_IDLE;
2876 c4iw_modify_qp(ep->com.qp->rhp,
2877 ep->com.qp,
2878 C4IW_QP_ATTR_NEXT_STATE,
2879 &attrs, 1);
2880 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302881 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002882 __state_set(&ep->com, DEAD);
2883 release = 1;
2884 break;
2885 case ABORTING:
2886 case DEAD:
2887 break;
2888 default:
2889 BUG_ON(1);
2890 break;
2891 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002892 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002893 if (release)
2894 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302895 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896 return 0;
2897}
2898
2899static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2900{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002901 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002902 unsigned int tid = GET_TID(rpl);
2903 struct c4iw_ep *ep;
2904 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002905
Hariprasad S944661d2016-05-06 22:18:03 +05302906 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002907 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002908
Steve Wise30c95c22011-05-09 22:06:22 -07002909 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002910 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2911 ep->com.qp->wq.sq.qid);
2912 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2913 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2914 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2915 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002916 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302917 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002918
Steve Wisecfdda9d2010-04-21 15:30:06 -07002919 return 0;
2920}
2921
2922/*
2923 * Upcall from the adapter indicating data has been transmitted.
2924 * For us its just the single MPA request or reply. We can now free
2925 * the skb holding the mpa message.
2926 */
2927static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2928{
2929 struct c4iw_ep *ep;
2930 struct cpl_fw4_ack *hdr = cplhdr(skb);
2931 u8 credits = hdr->credits;
2932 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933
2934
Hariprasad S944661d2016-05-06 22:18:03 +05302935 ep = get_ep_from_tid(dev, tid);
2936 if (!ep)
2937 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2939 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002940 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2941 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302942 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002943 }
2944
2945 dst_confirm(ep->dst);
2946 if (ep->mpa_skb) {
2947 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2948 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2949 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002950 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951 kfree_skb(ep->mpa_skb);
2952 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302953 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2954 stop_ep_timer(ep);
2955 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956 }
Hariprasad S944661d2016-05-06 22:18:03 +05302957out:
2958 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 return 0;
2960}
2961
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2963{
Hariprasad Sbce28412016-06-10 01:05:13 +05302964 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002965 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302966
Steve Wisecfdda9d2010-04-21 15:30:06 -07002967 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2968
Steve Wisea7db89e2014-03-21 20:40:35 +05302969 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302970 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302971 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 c4iw_put_ep(&ep->com);
2973 return -ECONNRESET;
2974 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002975 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002976 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302977 abort = 1;
2978 else
2979 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302980 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302981
2982 stop_ep_timer(ep);
2983 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002984 c4iw_put_ep(&ep->com);
2985 return 0;
2986}
2987
2988int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2989{
2990 int err;
2991 struct c4iw_qp_attributes attrs;
2992 enum c4iw_qp_attr_mask mask;
2993 struct c4iw_ep *ep = to_ep(cm_id);
2994 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2995 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302996 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002997
2998 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302999
3000 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303001 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303003 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003004 }
3005
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006 BUG_ON(!qp);
3007
Vipul Pandya793dad92012-12-10 09:30:56 +00003008 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303009 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3010 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303012 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003013 }
3014
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303015 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3016 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303017 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003018 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303019 } else {
3020 ep->ird = conn_param->ird;
3021 ep->ord = conn_param->ord;
3022 send_mpa_reject(ep, conn_param->private_data,
3023 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303024 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303025 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303026 }
3027 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303028 if (conn_param->ird < ep->ord) {
3029 if (RELAXED_IRD_NEGOTIATION &&
3030 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3031 conn_param->ird = ep->ord;
3032 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303033 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303034 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303035 }
3036 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303037 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038 ep->ird = conn_param->ird;
3039 ep->ord = conn_param->ord;
3040
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303041 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303042 if (peer2peer && ep->ird == 0)
3043 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303044 } else {
3045 if (peer2peer &&
3046 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303047 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303048 ep->ird = 1;
3049 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003050
3051 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3052
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303053 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303054 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303055 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003056 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303057
Steve Wisecfdda9d2010-04-21 15:30:06 -07003058 /* bind QP to EP and move to RTS */
3059 attrs.mpa_attr = ep->mpa_attr;
3060 attrs.max_ird = ep->ird;
3061 attrs.max_ord = ep->ord;
3062 attrs.llp_stream_handle = ep;
3063 attrs.next_state = C4IW_QP_STATE_RTS;
3064
3065 /* bind QP and TID with INIT_WR */
3066 mask = C4IW_QP_ATTR_NEXT_STATE |
3067 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3068 C4IW_QP_ATTR_MPA_ATTR |
3069 C4IW_QP_ATTR_MAX_IRD |
3070 C4IW_QP_ATTR_MAX_ORD;
3071
3072 err = c4iw_modify_qp(ep->com.qp->rhp,
3073 ep->com.qp, mask, &attrs, 1);
3074 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303075 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303076
3077 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003078 err = send_mpa_reply(ep, conn_param->private_data,
3079 conn_param->private_data_len);
3080 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303081 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003082
Steve Wisea7db89e2014-03-21 20:40:35 +05303083 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003084 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303085 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003086 c4iw_put_ep(&ep->com);
3087 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303088err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303089 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303090err_abort:
3091 abort = 1;
3092err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303093 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303094 if (abort)
3095 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003096 c4iw_put_ep(&ep->com);
3097 return err;
3098}
3099
Vipul Pandya830662f2013-07-04 16:10:47 +05303100static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3101{
3102 struct in_device *ind;
3103 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003104 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3105 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303106
3107 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3108 if (!ind)
3109 return -EADDRNOTAVAIL;
3110 for_primary_ifa(ind) {
3111 laddr->sin_addr.s_addr = ifa->ifa_address;
3112 raddr->sin_addr.s_addr = ifa->ifa_address;
3113 found = 1;
3114 break;
3115 }
3116 endfor_ifa(ind);
3117 in_dev_put(ind);
3118 return found ? 0 : -EADDRNOTAVAIL;
3119}
3120
3121static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3122 unsigned char banned_flags)
3123{
3124 struct inet6_dev *idev;
3125 int err = -EADDRNOTAVAIL;
3126
3127 rcu_read_lock();
3128 idev = __in6_dev_get(dev);
3129 if (idev != NULL) {
3130 struct inet6_ifaddr *ifp;
3131
3132 read_lock_bh(&idev->lock);
3133 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3134 if (ifp->scope == IFA_LINK &&
3135 !(ifp->flags & banned_flags)) {
3136 memcpy(addr, &ifp->addr, 16);
3137 err = 0;
3138 break;
3139 }
3140 }
3141 read_unlock_bh(&idev->lock);
3142 }
3143 rcu_read_unlock();
3144 return err;
3145}
3146
3147static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3148{
3149 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003150 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3151 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303152
Nicholas Krause54b9a962015-08-26 23:00:59 -04003153 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303154 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3155 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3156 return 0;
3157 }
3158 return -EADDRNOTAVAIL;
3159}
3160
Steve Wisecfdda9d2010-04-21 15:30:06 -07003161int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3162{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003163 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3164 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003165 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003166 struct sockaddr_in *laddr;
3167 struct sockaddr_in *raddr;
3168 struct sockaddr_in6 *laddr6;
3169 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303170 __u8 *ra;
3171 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003172
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303173 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3174 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003175 err = -EINVAL;
3176 goto out;
3177 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003178 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3179 if (!ep) {
3180 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3181 err = -ENOMEM;
3182 goto out;
3183 }
Hariprasad S4a740832016-06-10 01:05:15 +05303184
3185 skb_queue_head_init(&ep->com.ep_skb_list);
3186 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3187 err = -ENOMEM;
3188 goto fail1;
3189 }
3190
Steve Wisecfdda9d2010-04-21 15:30:06 -07003191 init_timer(&ep->timer);
3192 ep->plen = conn_param->private_data_len;
3193 if (ep->plen)
3194 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3195 conn_param->private_data, ep->plen);
3196 ep->ird = conn_param->ird;
3197 ep->ord = conn_param->ord;
3198
3199 if (peer2peer && ep->ord == 0)
3200 ep->ord = 1;
3201
Steve Wisecfdda9d2010-04-21 15:30:06 -07003202 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303203 ref_cm_id(&ep->com);
3204 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003205 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303206 if (!ep->com.qp) {
3207 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3208 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303209 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303210 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003211 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003212 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3213 ep->com.qp, cm_id);
3214
3215 /*
3216 * Allocate an active TID to initiate a TCP connection.
3217 */
3218 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3219 if (ep->atid == -1) {
3220 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3221 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303222 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003223 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003224 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003225
Steve Wise170003c2016-02-26 09:18:03 -06003226 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003227 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003228 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003229 sizeof(ep->com.remote_addr));
3230
Steve Wise170003c2016-02-26 09:18:03 -06003231 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3232 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3233 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3234 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003235
Steve Wise170003c2016-02-26 09:18:03 -06003236 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303237 iptype = 4;
3238 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003239
Vipul Pandya830662f2013-07-04 16:10:47 +05303240 /*
3241 * Handle loopback requests to INADDR_ANY.
3242 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003243 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303244 err = pick_local_ipaddrs(dev, cm_id);
3245 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303246 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303247 }
3248
3249 /* find a route */
3250 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3251 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3252 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303253 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3254 laddr->sin_addr.s_addr,
3255 raddr->sin_addr.s_addr,
3256 laddr->sin_port,
3257 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303258 } else {
3259 iptype = 6;
3260 ra = (__u8 *)&raddr6->sin6_addr;
3261
3262 /*
3263 * Handle loopback requests to INADDR_ANY.
3264 */
3265 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3266 err = pick_local_ip6addrs(dev, cm_id);
3267 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303268 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303269 }
3270
3271 /* find a route */
3272 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3273 __func__, laddr6->sin6_addr.s6_addr,
3274 ntohs(laddr6->sin6_port),
3275 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303276 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3277 laddr6->sin6_addr.s6_addr,
3278 raddr6->sin6_addr.s6_addr,
3279 laddr6->sin6_port,
3280 raddr6->sin6_port, 0,
3281 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303282 }
3283 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003284 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3285 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303286 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003287 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003288
Hariprasad S963cab52015-09-23 17:19:27 +05303289 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303290 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003291 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303293 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003294 }
3295
3296 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3297 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3298 ep->l2t->idx);
3299
3300 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303301 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003302
3303 /* send connect request to rnic */
3304 err = send_connect(ep);
3305 if (!err)
3306 goto out;
3307
3308 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303309fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003310 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303311fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003312 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003313 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303314fail2:
3315 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303316 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303317fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318 c4iw_put_ep(&ep->com);
3319out:
3320 return err;
3321}
3322
Vipul Pandya830662f2013-07-04 16:10:47 +05303323static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3324{
3325 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003326 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003327 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303328
Hariprasad S28de1f72016-01-13 10:03:14 +05303329 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3330 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3331 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3332 if (err)
3333 return err;
3334 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303335 c4iw_init_wr_wait(&ep->com.wr_wait);
3336 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3337 ep->stid, &sin6->sin6_addr,
3338 sin6->sin6_port,
3339 ep->com.dev->rdev.lldi.rxq_ids[0]);
3340 if (!err)
3341 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3342 &ep->com.wr_wait,
3343 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303344 else if (err > 0)
3345 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303346 if (err) {
3347 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3348 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303349 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3350 err, ep->stid,
3351 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303352 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303353 return err;
3354}
3355
3356static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3357{
3358 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003359 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003360 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303361
3362 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3363 do {
3364 err = cxgb4_create_server_filter(
3365 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3366 sin->sin_addr.s_addr, sin->sin_port, 0,
3367 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3368 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303369 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3370 err = -EIO;
3371 break;
3372 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303373 set_current_state(TASK_UNINTERRUPTIBLE);
3374 schedule_timeout(usecs_to_jiffies(100));
3375 }
3376 } while (err == -EBUSY);
3377 } else {
3378 c4iw_init_wr_wait(&ep->com.wr_wait);
3379 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3380 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3381 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3382 if (!err)
3383 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3384 &ep->com.wr_wait,
3385 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303386 else if (err > 0)
3387 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303388 }
3389 if (err)
3390 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3391 , err, ep->stid,
3392 &sin->sin_addr, ntohs(sin->sin_port));
3393 return err;
3394}
3395
Steve Wisecfdda9d2010-04-21 15:30:06 -07003396int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3397{
3398 int err = 0;
3399 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3400 struct c4iw_listen_ep *ep;
3401
Steve Wisecfdda9d2010-04-21 15:30:06 -07003402 might_sleep();
3403
3404 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3405 if (!ep) {
3406 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3407 err = -ENOMEM;
3408 goto fail1;
3409 }
Hariprasad S4a740832016-06-10 01:05:15 +05303410 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003411 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003412 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303413 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003414 ep->com.dev = dev;
3415 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003416 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303417 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003418
3419 /*
3420 * Allocate a server TID.
3421 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303422 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3423 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303424 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003425 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003426 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303427 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003428 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003429
Steve Wisecfdda9d2010-04-21 15:30:06 -07003430 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003431 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003432 err = -ENOMEM;
3433 goto fail2;
3434 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003435 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003436
Steve Wise170003c2016-02-26 09:18:03 -06003437 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3438 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003439
Steve Wisecfdda9d2010-04-21 15:30:06 -07003440 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303441 if (ep->com.local_addr.ss_family == AF_INET)
3442 err = create_server4(dev, ep);
3443 else
3444 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003445 if (!err) {
3446 cm_id->provider_data = ep;
3447 goto out;
3448 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003449
Vipul Pandya830662f2013-07-04 16:10:47 +05303450 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3451 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003452fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303453 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003454 c4iw_put_ep(&ep->com);
3455fail1:
3456out:
3457 return err;
3458}
3459
3460int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3461{
3462 int err;
3463 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3464
3465 PDBG("%s ep %p\n", __func__, ep);
3466
3467 might_sleep();
3468 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303469 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3470 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003471 err = cxgb4_remove_server_filter(
3472 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3473 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3474 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303475 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003476 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303477 err = cxgb4_remove_server(
3478 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3479 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003480 if (err)
3481 goto done;
3482 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3483 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003484 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303485 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3486 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003487 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003488 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303489 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3490 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003491done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303492 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003493 c4iw_put_ep(&ep->com);
3494 return err;
3495}
3496
3497int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3498{
3499 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003500 int close = 0;
3501 int fatal = 0;
3502 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003503
Steve Wise2f5b48c2010-09-10 11:15:36 -05003504 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003505
3506 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3507 states[ep->com.state], abrupt);
3508
Hariprasad S6e410d82016-05-05 01:27:31 +05303509 /*
3510 * Ref the ep here in case we have fatal errors causing the
3511 * ep to be released and freed.
3512 */
3513 c4iw_get_ep(&ep->com);
3514
Steve Wisecfdda9d2010-04-21 15:30:06 -07003515 rdev = &ep->com.dev->rdev;
3516 if (c4iw_fatal_error(rdev)) {
3517 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303518 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003519 ep->com.state = DEAD;
3520 }
3521 switch (ep->com.state) {
3522 case MPA_REQ_WAIT:
3523 case MPA_REQ_SENT:
3524 case MPA_REQ_RCVD:
3525 case MPA_REP_SENT:
3526 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303527 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003528 close = 1;
3529 if (abrupt)
3530 ep->com.state = ABORTING;
3531 else {
3532 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003533
3534 /*
3535 * if we close before we see the fw4_ack() then we fix
3536 * up the timer state since we're reusing it.
3537 */
3538 if (ep->mpa_skb &&
3539 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3540 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3541 stop_ep_timer(ep);
3542 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003543 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003544 }
3545 set_bit(CLOSE_SENT, &ep->com.flags);
3546 break;
3547 case CLOSING:
3548 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3549 close = 1;
3550 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003551 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003552 ep->com.state = ABORTING;
3553 } else
3554 ep->com.state = MORIBUND;
3555 }
3556 break;
3557 case MORIBUND:
3558 case ABORTING:
3559 case DEAD:
3560 PDBG("%s ignoring disconnect ep %p state %u\n",
3561 __func__, ep, ep->com.state);
3562 break;
3563 default:
3564 BUG();
3565 break;
3566 }
3567
Steve Wisecfdda9d2010-04-21 15:30:06 -07003568 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003569 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003570 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303571 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303572 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003573 } else {
3574 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303575 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003576 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303577 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303578 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303579 if (!abrupt) {
3580 stop_ep_timer(ep);
3581 close_complete_upcall(ep, -EIO);
3582 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303583 if (ep->com.qp) {
3584 struct c4iw_qp_attributes attrs;
3585
3586 attrs.next_state = C4IW_QP_STATE_ERROR;
3587 ret = c4iw_modify_qp(ep->com.qp->rhp,
3588 ep->com.qp,
3589 C4IW_QP_ATTR_NEXT_STATE,
3590 &attrs, 1);
3591 if (ret)
3592 pr_err(MOD
3593 "%s - qp <- error failed!\n",
3594 __func__);
3595 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003596 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303597 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003598 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003599 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303600 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003601 if (fatal)
3602 release_ep_resources(ep);
3603 return ret;
3604}
3605
Vipul Pandya1cab7752012-12-10 09:30:55 +00003606static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3607 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3608{
3609 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003610 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003611
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003612 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3613 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003614 if (!ep)
3615 return;
3616
3617 switch (req->retval) {
3618 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003619 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3620 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3621 send_fw_act_open_req(ep, atid);
3622 return;
3623 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003624 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003625 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3626 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3627 send_fw_act_open_req(ep, atid);
3628 return;
3629 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630 break;
3631 default:
3632 pr_info("%s unexpected ofld conn wr retval %d\n",
3633 __func__, req->retval);
3634 break;
3635 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003636 pr_err("active ofld_connect_wr failure %d atid %d\n",
3637 req->retval, atid);
3638 mutex_lock(&dev->rdev.stats.lock);
3639 dev->rdev.stats.act_ofld_conn_fails++;
3640 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003641 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003642 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303643 if (ep->com.remote_addr.ss_family == AF_INET6) {
3644 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003645 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303646 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3647 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3648 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003649 remove_handle(dev, &dev->atid_idr, atid);
3650 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3651 dst_release(ep->dst);
3652 cxgb4_l2t_release(ep->l2t);
3653 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654}
3655
3656static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3657 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3658{
3659 struct sk_buff *rpl_skb;
3660 struct cpl_pass_accept_req *cpl;
3661 int ret;
3662
Paul Bolle710a3112013-02-05 20:51:30 +00003663 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003664 BUG_ON(!rpl_skb);
3665 if (req->retval) {
3666 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003667 mutex_lock(&dev->rdev.stats.lock);
3668 dev->rdev.stats.pas_ofld_conn_fails++;
3669 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670 kfree_skb(rpl_skb);
3671 } else {
3672 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3673 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003674 (__force u32) htonl(
3675 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003676 ret = pass_accept_req(dev, rpl_skb);
3677 if (!ret)
3678 kfree_skb(rpl_skb);
3679 }
3680 return;
3681}
3682
3683static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003684{
3685 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003686 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3687
3688 switch (rpl->type) {
3689 case FW6_TYPE_CQE:
3690 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3691 break;
3692 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3693 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3694 switch (req->t_state) {
3695 case TCP_SYN_SENT:
3696 active_ofld_conn_reply(dev, skb, req);
3697 break;
3698 case TCP_SYN_RECV:
3699 passive_ofld_conn_reply(dev, skb, req);
3700 break;
3701 default:
3702 pr_err("%s unexpected ofld conn wr state %d\n",
3703 __func__, req->t_state);
3704 break;
3705 }
3706 break;
3707 }
3708 return 0;
3709}
3710
3711static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3712{
Hariprasad S963cab52015-09-23 17:19:27 +05303713 __be32 l2info;
3714 __be16 hdr_len, vlantag, len;
3715 u16 eth_hdr_len;
3716 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003717 u8 intf;
3718 struct cpl_rx_pkt *cpl = cplhdr(skb);
3719 struct cpl_pass_accept_req *req;
3720 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003721 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303722 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003723
Vipul Pandyaf079af72013-03-14 05:08:58 +00003724 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003725 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303726 vlantag = cpl->vlan;
3727 len = cpl->len;
3728 l2info = cpl->l2info;
3729 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730 intf = cpl->iff;
3731
3732 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3733
3734 /*
3735 * We need to parse the TCP options from SYN packet.
3736 * to generate cpl_pass_accept_req.
3737 */
3738 memset(&tmp_opt, 0, sizeof(tmp_opt));
3739 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003740 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003741
3742 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3743 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303744 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3745 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303746 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303747 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303748 type = dev->rdev.lldi.adapter_type;
3749 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3750 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3751 req->hdr_len =
3752 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3753 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3754 eth_hdr_len = is_t4(type) ?
3755 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3756 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3757 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3758 IP_HDR_LEN_V(ip_hdr_len) |
3759 ETH_HDR_LEN_V(eth_hdr_len));
3760 } else { /* T6 and later */
3761 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3762 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3763 T6_IP_HDR_LEN_V(ip_hdr_len) |
3764 T6_ETH_HDR_LEN_V(eth_hdr_len));
3765 }
3766 req->vlan = vlantag;
3767 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003768 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3769 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003770 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3771 if (tmp_opt.wscale_ok)
3772 req->tcpopt.wsf = tmp_opt.snd_wscale;
3773 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3774 if (tmp_opt.sack_ok)
3775 req->tcpopt.sack = 1;
3776 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3777 return;
3778}
3779
3780static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3781 __be32 laddr, __be16 lport,
3782 __be32 raddr, __be16 rport,
3783 u32 rcv_isn, u32 filter, u16 window,
3784 u32 rss_qid, u8 port_id)
3785{
3786 struct sk_buff *req_skb;
3787 struct fw_ofld_connection_wr *req;
3788 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303789 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003790
3791 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3792 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3793 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003794 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303795 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303796 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003797 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003798 req->le.lport = lport;
3799 req->le.pport = rport;
3800 req->le.u.ipv4.lip = laddr;
3801 req->le.u.ipv4.pip = raddr;
3802 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3803 req->tcb.rcv_adv = htons(window);
3804 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303805 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3806 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3807 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003808 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003809
3810 /*
3811 * We store the qid in opt2 which will be used by the firmware
3812 * to send us the wr response.
3813 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003814 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003815
3816 /*
3817 * We initialize the MSS index in TCB to 0xF.
3818 * So that when driver sends cpl_pass_accept_rpl
3819 * TCB picks up the correct value. If this was 0
3820 * TP will ignore any value > 0 for MSS index.
3821 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003822 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303823 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003824
3825 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303826 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3827 if (ret < 0) {
3828 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3829 ret);
3830 kfree_skb(skb);
3831 kfree_skb(req_skb);
3832 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003833}
3834
3835/*
3836 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3837 * messages when a filter is being used instead of server to
3838 * redirect a syn packet. When packets hit filter they are redirected
3839 * to the offload queue and driver tries to establish the connection
3840 * using firmware work request.
3841 */
3842static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3843{
3844 int stid;
3845 unsigned int filter;
3846 struct ethhdr *eh = NULL;
3847 struct vlan_ethhdr *vlan_eh = NULL;
3848 struct iphdr *iph;
3849 struct tcphdr *tcph;
3850 struct rss_header *rss = (void *)skb->data;
3851 struct cpl_rx_pkt *cpl = (void *)skb->data;
3852 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3853 struct l2t_entry *e;
3854 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303855 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003856 u16 window;
3857 struct port_info *pi;
3858 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003859 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003860 int step;
3861 u32 tx_chan;
3862 struct neighbour *neigh;
3863
3864 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003865 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003866 goto reject;
3867
3868 /*
3869 * Drop all packets which did not hit the filter.
3870 * Unlikely to happen.
3871 */
3872 if (!(rss->filter_hit && rss->filter_tid))
3873 goto reject;
3874
3875 /*
3876 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3877 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303878 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003879
Hariprasad Sf86fac72016-05-06 22:18:07 +05303880 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003881 if (!lep) {
3882 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3883 goto reject;
3884 }
3885
Hariprasad S963cab52015-09-23 17:19:27 +05303886 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3887 case CHELSIO_T4:
3888 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3889 break;
3890 case CHELSIO_T5:
3891 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3892 break;
3893 case CHELSIO_T6:
3894 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3895 break;
3896 default:
3897 pr_err("T%d Chip is not supported\n",
3898 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3899 goto reject;
3900 }
3901
Vipul Pandyaf079af72013-03-14 05:08:58 +00003902 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003903 eh = (struct ethhdr *)(req + 1);
3904 iph = (struct iphdr *)(eh + 1);
3905 } else {
3906 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3907 iph = (struct iphdr *)(vlan_eh + 1);
3908 skb->vlan_tci = ntohs(cpl->vlan);
3909 }
3910
3911 if (iph->version != 0x4)
3912 goto reject;
3913
3914 tcph = (struct tcphdr *)(iph + 1);
3915 skb_set_network_header(skb, (void *)iph - (void *)rss);
3916 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3917 skb_get(skb);
3918
3919 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3920 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3921 ntohs(tcph->source), iph->tos);
3922
Varun Prakash804c2f32016-09-13 21:23:57 +05303923 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3924 iph->daddr, iph->saddr, tcph->dest,
3925 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303926 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003927 pr_err("%s - failed to find dst entry!\n",
3928 __func__);
3929 goto reject;
3930 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003931 neigh = dst_neigh_lookup_skb(dst, skb);
3932
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003933 if (!neigh) {
3934 pr_err("%s - failed to allocate neigh!\n",
3935 __func__);
3936 goto free_dst;
3937 }
3938
Vipul Pandya1cab7752012-12-10 09:30:55 +00003939 if (neigh->dev->flags & IFF_LOOPBACK) {
3940 pdev = ip_dev_find(&init_net, iph->daddr);
3941 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3942 pdev, 0);
3943 pi = (struct port_info *)netdev_priv(pdev);
3944 tx_chan = cxgb4_port_chan(pdev);
3945 dev_put(pdev);
3946 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303947 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003948 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303949 pdev, 0);
3950 pi = (struct port_info *)netdev_priv(pdev);
3951 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003952 }
Steve Wiseebf00062014-03-19 17:44:40 +05303953 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003954 if (!e) {
3955 pr_err("%s - failed to allocate l2t entry!\n",
3956 __func__);
3957 goto free_dst;
3958 }
3959
3960 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3961 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003962 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003963
3964 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303965 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3966 dev->rdev.lldi.ports[0],
3967 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003968
3969 /*
3970 * Synthesize the cpl_pass_accept_req. We have everything except the
3971 * TID. Once firmware sends a reply with TID we update the TID field
3972 * in cpl and pass it through the regular cpl_pass_accept_req path.
3973 */
3974 build_cpl_pass_accept_req(skb, stid, iph->tos);
3975 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3976 tcph->source, ntohl(tcph->seq), filter, window,
3977 rss_qid, pi->port_id);
3978 cxgb4_l2t_release(e);
3979free_dst:
3980 dst_release(dst);
3981reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303982 if (lep)
3983 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003984 return 0;
3985}
3986
Steve Wisecfdda9d2010-04-21 15:30:06 -07003987/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003988 * These are the real handlers that are called from a
3989 * work queue.
3990 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303991static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003992 [CPL_ACT_ESTABLISH] = act_establish,
3993 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3994 [CPL_RX_DATA] = rx_data,
3995 [CPL_ABORT_RPL_RSS] = abort_rpl,
3996 [CPL_ABORT_RPL] = abort_rpl,
3997 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3998 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3999 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4000 [CPL_PASS_ESTABLISH] = pass_establish,
4001 [CPL_PEER_CLOSE] = peer_close,
4002 [CPL_ABORT_REQ_RSS] = peer_abort,
4003 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4004 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004005 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004006 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304007 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304008 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4009 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004010};
4011
4012static void process_timeout(struct c4iw_ep *ep)
4013{
4014 struct c4iw_qp_attributes attrs;
4015 int abort = 1;
4016
Steve Wise2f5b48c2010-09-10 11:15:36 -05004017 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004018 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4019 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004020 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004021 switch (ep->com.state) {
4022 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004023 connect_reply_upcall(ep, -ETIMEDOUT);
4024 break;
4025 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304026 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304027 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304028 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004029 break;
4030 case CLOSING:
4031 case MORIBUND:
4032 if (ep->com.cm_id && ep->com.qp) {
4033 attrs.next_state = C4IW_QP_STATE_ERROR;
4034 c4iw_modify_qp(ep->com.qp->rhp,
4035 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4036 &attrs, 1);
4037 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304038 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004039 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004040 case ABORTING:
4041 case DEAD:
4042
4043 /*
4044 * These states are expected if the ep timed out at the same
4045 * time as another thread was calling stop_ep_timer().
4046 * So we silently do nothing for these states.
4047 */
4048 abort = 0;
4049 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004050 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004051 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004053 abort = 0;
4054 }
Steve Wisecc18b932014-04-24 14:31:53 -05004055 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304056 if (abort)
4057 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004058 c4iw_put_ep(&ep->com);
4059}
4060
4061static void process_timedout_eps(void)
4062{
4063 struct c4iw_ep *ep;
4064
4065 spin_lock_irq(&timeout_lock);
4066 while (!list_empty(&timeout_list)) {
4067 struct list_head *tmp;
4068
4069 tmp = timeout_list.next;
4070 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004071 tmp->next = NULL;
4072 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004073 spin_unlock_irq(&timeout_lock);
4074 ep = list_entry(tmp, struct c4iw_ep, entry);
4075 process_timeout(ep);
4076 spin_lock_irq(&timeout_lock);
4077 }
4078 spin_unlock_irq(&timeout_lock);
4079}
4080
4081static void process_work(struct work_struct *work)
4082{
4083 struct sk_buff *skb = NULL;
4084 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004085 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004086 unsigned int opcode;
4087 int ret;
4088
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004089 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004090 while ((skb = skb_dequeue(&rxq))) {
4091 rpl = cplhdr(skb);
4092 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4093 opcode = rpl->ot.opcode;
4094
4095 BUG_ON(!work_handlers[opcode]);
4096 ret = work_handlers[opcode](dev, skb);
4097 if (!ret)
4098 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004099 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004100 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004101}
4102
4103static DECLARE_WORK(skb_work, process_work);
4104
4105static void ep_timeout(unsigned long arg)
4106{
4107 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004108 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004109
4110 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004111 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004112 /*
4113 * Only insert if it is not already on the list.
4114 */
4115 if (!ep->entry.next) {
4116 list_add_tail(&ep->entry, &timeout_list);
4117 kickit = 1;
4118 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004119 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004120 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004121 if (kickit)
4122 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004123}
4124
4125/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004126 * All the CM events are handled on a work queue to have a safe context.
4127 */
4128static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4129{
4130
4131 /*
4132 * Save dev in the skb->cb area.
4133 */
4134 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4135
4136 /*
4137 * Queue the skb and schedule the worker thread.
4138 */
4139 skb_queue_tail(&rxq, skb);
4140 queue_work(workq, &skb_work);
4141 return 0;
4142}
4143
4144static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4145{
4146 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4147
4148 if (rpl->status != CPL_ERR_NONE) {
4149 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4150 "for tid %u\n", rpl->status, GET_TID(rpl));
4151 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004152 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004153 return 0;
4154}
4155
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004156static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4157{
4158 struct cpl_fw6_msg *rpl = cplhdr(skb);
4159 struct c4iw_wr_wait *wr_waitp;
4160 int ret;
4161
4162 PDBG("%s type %u\n", __func__, rpl->type);
4163
4164 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004165 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004166 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004167 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004168 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004169 if (wr_waitp)
4170 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004171 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004172 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004173 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004174 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004175 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004176 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004177 default:
4178 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4179 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004180 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181 break;
4182 }
4183 return 0;
4184}
4185
Steve Wise8da7e7a2011-06-14 20:59:27 +00004186static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4187{
4188 struct cpl_abort_req_rss *req = cplhdr(skb);
4189 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004190 unsigned int tid = GET_TID(req);
4191
Hariprasad S944661d2016-05-06 22:18:03 +05304192 ep = get_ep_from_tid(dev, tid);
4193 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004194 if (!ep) {
4195 printk(KERN_WARNING MOD
4196 "Abort on non-existent endpoint, tid %d\n", tid);
4197 kfree_skb(skb);
4198 return 0;
4199 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304200 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304201 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4202 __func__, ep->hwtid, req->status,
4203 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304204 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004205 }
4206 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4207 ep->com.state);
4208
Hariprasad S093108c2016-05-06 22:18:09 +05304209 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304210out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004211 sched(dev, skb);
4212 return 0;
4213}
4214
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004215/*
4216 * Most upcalls from the T4 Core go to sched() to
4217 * schedule the processing on a work queue.
4218 */
4219c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4220 [CPL_ACT_ESTABLISH] = sched,
4221 [CPL_ACT_OPEN_RPL] = sched,
4222 [CPL_RX_DATA] = sched,
4223 [CPL_ABORT_RPL_RSS] = sched,
4224 [CPL_ABORT_RPL] = sched,
4225 [CPL_PASS_OPEN_RPL] = sched,
4226 [CPL_CLOSE_LISTSRV_RPL] = sched,
4227 [CPL_PASS_ACCEPT_REQ] = sched,
4228 [CPL_PASS_ESTABLISH] = sched,
4229 [CPL_PEER_CLOSE] = sched,
4230 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004231 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004232 [CPL_RDMA_TERMINATE] = sched,
4233 [CPL_FW4_ACK] = sched,
4234 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004235 [CPL_FW6_MSG] = fw6_msg,
4236 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004237};
4238
Steve Wisecfdda9d2010-04-21 15:30:06 -07004239int __init c4iw_cm_init(void)
4240{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004241 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004242 skb_queue_head_init(&rxq);
4243
4244 workq = create_singlethread_workqueue("iw_cxgb4");
4245 if (!workq)
4246 return -ENOMEM;
4247
Steve Wisecfdda9d2010-04-21 15:30:06 -07004248 return 0;
4249}
4250
Steve Wise46c13762014-06-20 14:26:25 -05004251void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004252{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004253 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004254 flush_workqueue(workq);
4255 destroy_workqueue(workq);
4256}