blob: 3cbbfbe7da7c299b10da0f9c1881e9167afaa11b [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{
Varun Prakasha7e1a972016-09-13 21:24:04 +0530655 u32 wrlen = roundup(sizeof(struct cpl_abort_req), 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530656 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700657
658 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530659 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700660 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530661
Varun Prakasha7e1a972016-09-13 21:24:04 +0530662 cxgb_mk_abort_req(req_skb, wrlen, ep->hwtid, ep->txq_idx,
663 ep, abort_arp_failure);
664
Hariprasad S4a740832016-06-10 01:05:15 +0530665 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700666}
667
668static int send_connect(struct c4iw_ep *ep)
669{
Hariprasad S963cab52015-09-23 17:19:27 +0530670 struct cpl_act_open_req *req = NULL;
671 struct cpl_t5_act_open_req *t5req = NULL;
672 struct cpl_t6_act_open_req *t6req = NULL;
673 struct cpl_act_open_req6 *req6 = NULL;
674 struct cpl_t5_act_open_req6 *t5req6 = NULL;
675 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700676 struct sk_buff *skb;
677 u64 opt0;
678 u32 opt2;
679 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530680 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530681 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500682 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600683 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500684 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600685 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500686 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600687 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500688 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600689 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530690 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530691 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
692 u32 isn = (prandom_u32() & ~7UL) - 1;
693
694 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
695 case CHELSIO_T4:
696 sizev4 = sizeof(struct cpl_act_open_req);
697 sizev6 = sizeof(struct cpl_act_open_req6);
698 break;
699 case CHELSIO_T5:
700 sizev4 = sizeof(struct cpl_t5_act_open_req);
701 sizev6 = sizeof(struct cpl_t5_act_open_req6);
702 break;
703 case CHELSIO_T6:
704 sizev4 = sizeof(struct cpl_t6_act_open_req);
705 sizev6 = sizeof(struct cpl_t6_act_open_req6);
706 break;
707 default:
708 pr_err("T%d Chip is not supported\n",
709 CHELSIO_CHIP_VERSION(adapter_type));
710 return -EINVAL;
711 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530712
713 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
714 roundup(sizev4, 16) :
715 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716
717 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
718
719 skb = get_skb(NULL, wrlen, GFP_KERNEL);
720 if (!skb) {
721 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
722 __func__);
723 return -ENOMEM;
724 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000725 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726
Varun Prakash44c6d062016-09-13 21:24:00 +0530727 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
728 enable_tcp_timestamps,
729 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530730 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530731
732 /*
733 * Specify the largest window that will fit in opt0. The
734 * remainder will be specified in the rx_data_ack.
735 */
736 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800737 if (win > RCV_BUFSIZ_M)
738 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530739
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800740 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800741 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800742 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800743 WND_SCALE_V(wscale) |
744 MSS_IDX_V(mtu_idx) |
745 L2T_IDX_V(ep->l2t->idx) |
746 TX_CHAN_V(ep->tx_chan) |
747 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530748 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800749 ULP_MODE_V(ULP_MODE_TCPDDP) |
750 RCV_BUFSIZ_V(win);
751 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800752 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800753 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800755 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800757 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700758 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800759 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530760 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
761 if (peer2peer)
762 isn += 4;
763
Anish Bhattd7990b02014-11-12 17:15:57 -0800764 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530765 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530766 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500767 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530768
769 if (ep->com.remote_addr.ss_family == AF_INET6)
770 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
771 (const u32 *)&la6->sin6_addr.s6_addr, 1);
772
Hariprasad S5dab6d32014-06-23 19:12:36 +0530773 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700774
Hariprasad S963cab52015-09-23 17:19:27 +0530775 if (ep->com.remote_addr.ss_family == AF_INET) {
776 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
777 case CHELSIO_T4:
778 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530779 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530780 break;
781 case CHELSIO_T5:
782 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
783 wrlen);
784 INIT_TP_WR(t5req, 0);
785 req = (struct cpl_act_open_req *)t5req;
786 break;
787 case CHELSIO_T6:
788 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
789 wrlen);
790 INIT_TP_WR(t6req, 0);
791 req = (struct cpl_act_open_req *)t6req;
792 t5req = (struct cpl_t5_act_open_req *)t6req;
793 break;
794 default:
795 pr_err("T%d Chip is not supported\n",
796 CHELSIO_CHIP_VERSION(adapter_type));
797 ret = -EINVAL;
798 goto clip_release;
799 }
800
801 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
802 ((ep->rss_qid<<14) | ep->atid)));
803 req->local_port = la->sin_port;
804 req->peer_port = ra->sin_port;
805 req->local_ip = la->sin_addr.s_addr;
806 req->peer_ip = ra->sin_addr.s_addr;
807 req->opt0 = cpu_to_be64(opt0);
808
809 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530810 req->params = cpu_to_be32(cxgb4_select_ntuple(
811 ep->com.dev->rdev.lldi.ports[0],
812 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530813 req->opt2 = cpu_to_be32(opt2);
814 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530815 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
816 cxgb4_select_ntuple(
817 ep->com.dev->rdev.lldi.ports[0],
818 ep->l2t)));
819 t5req->rsvd = cpu_to_be32(isn);
820 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
821 t5req->opt2 = cpu_to_be32(opt2);
822 }
823 } else {
824 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
825 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530826 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530827 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530828 break;
829 case CHELSIO_T5:
830 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
831 wrlen);
832 INIT_TP_WR(t5req6, 0);
833 req6 = (struct cpl_act_open_req6 *)t5req6;
834 break;
835 case CHELSIO_T6:
836 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
837 wrlen);
838 INIT_TP_WR(t6req6, 0);
839 req6 = (struct cpl_act_open_req6 *)t6req6;
840 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
841 break;
842 default:
843 pr_err("T%d Chip is not supported\n",
844 CHELSIO_CHIP_VERSION(adapter_type));
845 ret = -EINVAL;
846 goto clip_release;
847 }
848
849 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
850 ((ep->rss_qid<<14)|ep->atid)));
851 req6->local_port = la6->sin6_port;
852 req6->peer_port = ra6->sin6_port;
853 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
854 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
855 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
856 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
857 req6->opt0 = cpu_to_be64(opt0);
858
859 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530860 req6->params = cpu_to_be32(cxgb4_select_ntuple(
861 ep->com.dev->rdev.lldi.ports[0],
862 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530863 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530864 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530865 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
866 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530867 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530868 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530869 t5req6->rsvd = cpu_to_be32(isn);
870 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
871 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530872 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000873 }
874
Vipul Pandya793dad92012-12-10 09:30:56 +0000875 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530876 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530877clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530878 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
879 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
880 (const u32 *)&la6->sin6_addr.s6_addr, 1);
881 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700882}
883
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530884static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
885 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700886{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530887 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888 struct fw_ofld_tx_data_wr *req;
889 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530890 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891
892 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
893
894 BUG_ON(skb_cloned(skb));
895
896 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530897 if (mpa_rev_to_use == 2)
898 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700899 wrlen = roundup(mpalen + sizeof *req, 16);
900 skb = get_skb(skb, wrlen, GFP_KERNEL);
901 if (!skb) {
902 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530903 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700904 }
905 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
906
907 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
908 memset(req, 0, wrlen);
909 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530910 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
911 FW_WR_COMPL_F |
912 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700913 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530914 FW_WR_FLOWID_V(ep->hwtid) |
915 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700916 req->plen = cpu_to_be32(mpalen);
917 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530918 FW_OFLD_TX_DATA_WR_FLUSH_F |
919 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700920
921 mpa = (struct mpa_message *)(req + 1);
922 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530923
924 mpa->flags = 0;
925 if (crc_enabled)
926 mpa->flags |= MPA_CRC;
927 if (markers_enabled) {
928 mpa->flags |= MPA_MARKERS;
929 ep->mpa_attr.recv_marker_enabled = 1;
930 } else {
931 ep->mpa_attr.recv_marker_enabled = 0;
932 }
933 if (mpa_rev_to_use == 2)
934 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
935
Steve Wisecfdda9d2010-04-21 15:30:06 -0700936 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530937 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530938 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530939 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530940 ep->retry_with_mpa_v1 = 0;
941 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700942
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530943 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700944 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
945 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530946 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
947 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530948 mpa_v2_params.ird = htons((u16)ep->ird);
949 mpa_v2_params.ord = htons((u16)ep->ord);
950
951 if (peer2peer) {
952 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
953 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
954 mpa_v2_params.ord |=
955 htons(MPA_V2_RDMA_WRITE_RTR);
956 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
957 mpa_v2_params.ord |=
958 htons(MPA_V2_RDMA_READ_RTR);
959 }
960 memcpy(mpa->private_data, &mpa_v2_params,
961 sizeof(struct mpa_v2_conn_params));
962
963 if (ep->plen)
964 memcpy(mpa->private_data +
965 sizeof(struct mpa_v2_conn_params),
966 ep->mpa_pkt + sizeof(*mpa), ep->plen);
967 } else
968 if (ep->plen)
969 memcpy(mpa->private_data,
970 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700971
972 /*
973 * Reference the mpa skb. This ensures the data area
974 * will remain in memory until the hw acks the tx.
975 * Function fw4_ack() will deref it.
976 */
977 skb_get(skb);
978 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
979 BUG_ON(ep->mpa_skb);
980 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530981 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
982 if (ret)
983 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700984 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530985 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700986 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530987 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530988 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700989}
990
991static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
992{
993 int mpalen, wrlen;
994 struct fw_ofld_tx_data_wr *req;
995 struct mpa_message *mpa;
996 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530997 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700998
999 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1000
1001 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301002 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1003 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001004 wrlen = roundup(mpalen + sizeof *req, 16);
1005
1006 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1007 if (!skb) {
1008 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1009 return -ENOMEM;
1010 }
1011 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1012
1013 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1014 memset(req, 0, wrlen);
1015 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301016 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1017 FW_WR_COMPL_F |
1018 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001019 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301020 FW_WR_FLOWID_V(ep->hwtid) |
1021 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001022 req->plen = cpu_to_be32(mpalen);
1023 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301024 FW_OFLD_TX_DATA_WR_FLUSH_F |
1025 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001026
1027 mpa = (struct mpa_message *)(req + 1);
1028 memset(mpa, 0, sizeof(*mpa));
1029 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1030 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001031 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001032 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301033
1034 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1035 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001036 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1037 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301038 mpa_v2_params.ird = htons(((u16)ep->ird) |
1039 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1040 0));
1041 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1042 (p2p_type ==
1043 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1044 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1045 FW_RI_INIT_P2PTYPE_READ_REQ ?
1046 MPA_V2_RDMA_READ_RTR : 0) : 0));
1047 memcpy(mpa->private_data, &mpa_v2_params,
1048 sizeof(struct mpa_v2_conn_params));
1049
1050 if (ep->plen)
1051 memcpy(mpa->private_data +
1052 sizeof(struct mpa_v2_conn_params), pdata, plen);
1053 } else
1054 if (plen)
1055 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001056
1057 /*
1058 * Reference the mpa skb again. This ensures the data area
1059 * will remain in memory until the hw acks the tx.
1060 * Function fw4_ack() will deref it.
1061 */
1062 skb_get(skb);
1063 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301064 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001065 BUG_ON(ep->mpa_skb);
1066 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301067 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001068 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1069}
1070
1071static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1072{
1073 int mpalen, wrlen;
1074 struct fw_ofld_tx_data_wr *req;
1075 struct mpa_message *mpa;
1076 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301077 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001078
1079 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1080
1081 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301082 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1083 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001084 wrlen = roundup(mpalen + sizeof *req, 16);
1085
1086 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1087 if (!skb) {
1088 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1089 return -ENOMEM;
1090 }
1091 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1092
1093 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1094 memset(req, 0, wrlen);
1095 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301096 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1097 FW_WR_COMPL_F |
1098 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001099 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301100 FW_WR_FLOWID_V(ep->hwtid) |
1101 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001102 req->plen = cpu_to_be32(mpalen);
1103 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301104 FW_OFLD_TX_DATA_WR_FLUSH_F |
1105 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001106
1107 mpa = (struct mpa_message *)(req + 1);
1108 memset(mpa, 0, sizeof(*mpa));
1109 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301110 mpa->flags = 0;
1111 if (ep->mpa_attr.crc_enabled)
1112 mpa->flags |= MPA_CRC;
1113 if (ep->mpa_attr.recv_marker_enabled)
1114 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301115 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001116 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301117
1118 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1119 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001120 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1121 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301122 mpa_v2_params.ird = htons((u16)ep->ird);
1123 mpa_v2_params.ord = htons((u16)ep->ord);
1124 if (peer2peer && (ep->mpa_attr.p2p_type !=
1125 FW_RI_INIT_P2PTYPE_DISABLED)) {
1126 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1127
1128 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1129 mpa_v2_params.ord |=
1130 htons(MPA_V2_RDMA_WRITE_RTR);
1131 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1132 mpa_v2_params.ord |=
1133 htons(MPA_V2_RDMA_READ_RTR);
1134 }
1135
1136 memcpy(mpa->private_data, &mpa_v2_params,
1137 sizeof(struct mpa_v2_conn_params));
1138
1139 if (ep->plen)
1140 memcpy(mpa->private_data +
1141 sizeof(struct mpa_v2_conn_params), pdata, plen);
1142 } else
1143 if (plen)
1144 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001145
1146 /*
1147 * Reference the mpa skb. This ensures the data area
1148 * will remain in memory until the hw acks the tx.
1149 * Function fw4_ack() will deref it.
1150 */
1151 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301152 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001153 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301154 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301155 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001156 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1157}
1158
1159static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1160{
1161 struct c4iw_ep *ep;
1162 struct cpl_act_establish *req = cplhdr(skb);
1163 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001164 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301166 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001167
1168 ep = lookup_atid(t, atid);
1169
1170 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1171 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1172
Steve Wisea7db89e2014-03-21 20:40:35 +05301173 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001174 dst_confirm(ep->dst);
1175
1176 /* setup the hwtid for this connection */
1177 ep->hwtid = tid;
1178 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301179 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001180
1181 ep->snd_seq = be32_to_cpu(req->snd_isn);
1182 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1183
1184 set_emss(ep, ntohs(req->tcp_opt));
1185
1186 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001187 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001188 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001189 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001190
1191 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301192 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301193 if (ret)
1194 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301195 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301196 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301197 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301198 ret = send_mpa_req(ep, skb, mpa_rev);
1199 if (ret)
1200 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301201 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301203err:
1204 mutex_unlock(&ep->com.mutex);
1205 connect_reply_upcall(ep, -ENOMEM);
1206 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1207 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208}
1209
Steve Wisebe13b2d2014-03-21 20:40:33 +05301210static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001211{
1212 struct iw_cm_event event;
1213
1214 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1215 memset(&event, 0, sizeof(event));
1216 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301217 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001218 if (ep->com.cm_id) {
1219 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1220 ep, ep->com.cm_id, ep->hwtid);
1221 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301222 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001223 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001224 }
1225}
1226
Steve Wisecfdda9d2010-04-21 15:30:06 -07001227static void peer_close_upcall(struct c4iw_ep *ep)
1228{
1229 struct iw_cm_event event;
1230
1231 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1232 memset(&event, 0, sizeof(event));
1233 event.event = IW_CM_EVENT_DISCONNECT;
1234 if (ep->com.cm_id) {
1235 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1236 ep, ep->com.cm_id, ep->hwtid);
1237 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001238 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001239 }
1240}
1241
1242static void peer_abort_upcall(struct c4iw_ep *ep)
1243{
1244 struct iw_cm_event event;
1245
1246 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1247 memset(&event, 0, sizeof(event));
1248 event.event = IW_CM_EVENT_CLOSE;
1249 event.status = -ECONNRESET;
1250 if (ep->com.cm_id) {
1251 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1252 ep->com.cm_id, ep->hwtid);
1253 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301254 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001255 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256 }
1257}
1258
1259static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1260{
1261 struct iw_cm_event event;
1262
1263 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1264 memset(&event, 0, sizeof(event));
1265 event.event = IW_CM_EVENT_CONNECT_REPLY;
1266 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301267 memcpy(&event.local_addr, &ep->com.local_addr,
1268 sizeof(ep->com.local_addr));
1269 memcpy(&event.remote_addr, &ep->com.remote_addr,
1270 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001271
1272 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301273 if (!ep->tried_with_mpa_v1) {
1274 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301275 event.ord = ep->ird;
1276 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301277 event.private_data_len = ep->plen -
1278 sizeof(struct mpa_v2_conn_params);
1279 event.private_data = ep->mpa_pkt +
1280 sizeof(struct mpa_message) +
1281 sizeof(struct mpa_v2_conn_params);
1282 } else {
1283 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301284 event.ord = cur_max_read_depth(ep->com.dev);
1285 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301286 event.private_data_len = ep->plen;
1287 event.private_data = ep->mpa_pkt +
1288 sizeof(struct mpa_message);
1289 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001290 }
Roland Dreier85963e42010-07-19 13:13:09 -07001291
1292 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1293 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001294 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001295 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1296
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301297 if (status < 0)
1298 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001299}
1300
Steve Wisebe13b2d2014-03-21 20:40:33 +05301301static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001302{
1303 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301304 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001305
1306 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1307 memset(&event, 0, sizeof(event));
1308 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301309 memcpy(&event.local_addr, &ep->com.local_addr,
1310 sizeof(ep->com.local_addr));
1311 memcpy(&event.remote_addr, &ep->com.remote_addr,
1312 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001313 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301314 if (!ep->tried_with_mpa_v1) {
1315 /* this means MPA_v2 is used */
1316 event.ord = ep->ord;
1317 event.ird = ep->ird;
1318 event.private_data_len = ep->plen -
1319 sizeof(struct mpa_v2_conn_params);
1320 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1321 sizeof(struct mpa_v2_conn_params);
1322 } else {
1323 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301324 event.ord = cur_max_read_depth(ep->com.dev);
1325 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301326 event.private_data_len = ep->plen;
1327 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1328 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301329 c4iw_get_ep(&ep->com);
1330 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1331 &event);
1332 if (ret)
1333 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001334 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001335 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301336 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337}
1338
1339static void established_upcall(struct c4iw_ep *ep)
1340{
1341 struct iw_cm_event event;
1342
1343 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1344 memset(&event, 0, sizeof(event));
1345 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301346 event.ird = ep->ord;
1347 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001348 if (ep->com.cm_id) {
1349 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1350 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001351 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001352 }
1353}
1354
1355static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1356{
Steve Wisecfdda9d2010-04-21 15:30:06 -07001357 struct sk_buff *skb;
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301358 u32 wrlen = roundup(sizeof(struct cpl_rx_data_ack), 16);
1359 u32 credit_dack;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360
1361 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1362 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1363 if (!skb) {
1364 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1365 return 0;
1366 }
1367
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301368 /*
1369 * If we couldn't specify the entire rcv window at connection setup
1370 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1371 * then add the overage in to the credits returned.
1372 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001373 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1374 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301375
Varun Prakash6e3b6fc2016-09-13 21:24:06 +05301376 credit_dack = credits | RX_FORCE_ACK_F | RX_DACK_CHANGE_F |
1377 RX_DACK_MODE_V(dack_mode);
1378
1379 cxgb_mk_rx_data_ack(skb, wrlen, ep->hwtid, ep->ctrlq_idx,
1380 credit_dack);
1381
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1383 return credits;
1384}
1385
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301386#define RELAXED_IRD_NEGOTIATION 1
1387
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301388/*
1389 * process_mpa_reply - process streaming mode MPA reply
1390 *
1391 * Returns:
1392 *
1393 * 0 upon success indicating a connect request was delivered to the ULP
1394 * or the mpa request is incomplete but valid so far.
1395 *
1396 * 1 if a failure requires the caller to close the connection.
1397 *
1398 * 2 if a failure requires the caller to abort the connection.
1399 */
Steve Wisecc18b932014-04-24 14:31:53 -05001400static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001401{
1402 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301403 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001404 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301405 u16 resp_ird, resp_ord;
1406 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001407 struct c4iw_qp_attributes attrs;
1408 enum c4iw_qp_attr_mask mask;
1409 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001410 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001411
1412 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1413
1414 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001415 * If we get more than the supported amount of private data
1416 * then we must fail this connection.
1417 */
1418 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1419 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301420 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001421 }
1422
1423 /*
1424 * copy the new data into our accumulation buffer.
1425 */
1426 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1427 skb->len);
1428 ep->mpa_pkt_len += skb->len;
1429
1430 /*
1431 * if we don't even have the mpa message, then bail.
1432 */
1433 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001434 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001435 mpa = (struct mpa_message *) ep->mpa_pkt;
1436
1437 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301438 if (mpa->revision > mpa_rev) {
1439 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1440 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301442 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001443 }
1444 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1445 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301446 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001447 }
1448
1449 plen = ntohs(mpa->private_data_size);
1450
1451 /*
1452 * Fail if there's too much private data.
1453 */
1454 if (plen > MPA_MAX_PRIVATE_DATA) {
1455 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301456 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001457 }
1458
1459 /*
1460 * If plen does not account for pkt size
1461 */
1462 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
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 ep->plen = (u8) plen;
1468
1469 /*
1470 * If we don't have all the pdata yet, then bail.
1471 * We'll continue process when more data arrives.
1472 */
1473 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001474 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001475
1476 if (mpa->flags & MPA_REJECT) {
1477 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301478 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001479 }
1480
1481 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301482 * Stop mpa timer. If it expired, then
1483 * we ignore the MPA reply. process_timeout()
1484 * will abort the connection.
1485 */
1486 if (stop_ep_timer(ep))
1487 return 0;
1488
1489 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001490 * If we get here we have accumulated the entire mpa
1491 * start reply message including private data. And
1492 * the MPA header is valid.
1493 */
Steve Wisec529fb52014-03-21 20:40:37 +05301494 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001495 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001496 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301497 ep->mpa_attr.version = mpa->revision;
1498 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1499
1500 if (mpa->revision == 2) {
1501 ep->mpa_attr.enhanced_rdma_conn =
1502 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1503 if (ep->mpa_attr.enhanced_rdma_conn) {
1504 mpa_v2_params = (struct mpa_v2_conn_params *)
1505 (ep->mpa_pkt + sizeof(*mpa));
1506 resp_ird = ntohs(mpa_v2_params->ird) &
1507 MPA_V2_IRD_ORD_MASK;
1508 resp_ord = ntohs(mpa_v2_params->ord) &
1509 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301510 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1511 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301512
1513 /*
1514 * This is a double-check. Ideally, below checks are
1515 * not required since ird/ord stuff has been taken
1516 * care of in c4iw_accept_cr
1517 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301518 if (ep->ird < resp_ord) {
1519 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1520 ep->com.dev->rdev.lldi.max_ordird_qp)
1521 ep->ird = resp_ord;
1522 else
1523 insuff_ird = 1;
1524 } else if (ep->ird > resp_ord) {
1525 ep->ird = resp_ord;
1526 }
1527 if (ep->ord > resp_ird) {
1528 if (RELAXED_IRD_NEGOTIATION)
1529 ep->ord = resp_ird;
1530 else
1531 insuff_ird = 1;
1532 }
1533 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301534 err = -ENOMEM;
1535 ep->ird = resp_ord;
1536 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301537 }
1538
1539 if (ntohs(mpa_v2_params->ird) &
1540 MPA_V2_PEER2PEER_MODEL) {
1541 if (ntohs(mpa_v2_params->ord) &
1542 MPA_V2_RDMA_WRITE_RTR)
1543 ep->mpa_attr.p2p_type =
1544 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1545 else if (ntohs(mpa_v2_params->ord) &
1546 MPA_V2_RDMA_READ_RTR)
1547 ep->mpa_attr.p2p_type =
1548 FW_RI_INIT_P2PTYPE_READ_REQ;
1549 }
1550 }
1551 } else if (mpa->revision == 1)
1552 if (peer2peer)
1553 ep->mpa_attr.p2p_type = p2p_type;
1554
Steve Wisecfdda9d2010-04-21 15:30:06 -07001555 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301556 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1557 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1558 ep->mpa_attr.recv_marker_enabled,
1559 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1560 ep->mpa_attr.p2p_type, p2p_type);
1561
1562 /*
1563 * If responder's RTR does not match with that of initiator, assign
1564 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1565 * generated when moving QP to RTS state.
1566 * A TERM message will be sent after QP has moved to RTS state
1567 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001568 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301569 (ep->mpa_attr.p2p_type != p2p_type)) {
1570 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1571 rtr_mismatch = 1;
1572 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001573
1574 attrs.mpa_attr = ep->mpa_attr;
1575 attrs.max_ird = ep->ird;
1576 attrs.max_ord = ep->ord;
1577 attrs.llp_stream_handle = ep;
1578 attrs.next_state = C4IW_QP_STATE_RTS;
1579
1580 mask = C4IW_QP_ATTR_NEXT_STATE |
1581 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1582 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1583
1584 /* bind QP and TID with INIT_WR */
1585 err = c4iw_modify_qp(ep->com.qp->rhp,
1586 ep->com.qp, mask, &attrs, 1);
1587 if (err)
1588 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301589
1590 /*
1591 * If responder's RTR requirement did not match with what initiator
1592 * supports, generate TERM message
1593 */
1594 if (rtr_mismatch) {
1595 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1596 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1597 attrs.ecode = MPA_NOMATCH_RTR;
1598 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001599 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301600 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001601 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301602 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001603 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301604 goto out;
1605 }
1606
1607 /*
1608 * Generate TERM if initiator IRD is not sufficient for responder
1609 * provided ORD. Currently, we do the same behaviour even when
1610 * responder provided IRD is also not sufficient as regards to
1611 * initiator ORD.
1612 */
1613 if (insuff_ird) {
1614 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1615 __func__);
1616 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1617 attrs.ecode = MPA_INSUFF_IRD;
1618 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001619 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301620 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001621 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301622 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001623 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301624 goto out;
1625 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001626 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301627err_stop_timer:
1628 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301630 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001631out:
1632 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001633 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001634}
1635
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301636/*
1637 * process_mpa_request - process streaming mode MPA request
1638 *
1639 * Returns:
1640 *
1641 * 0 upon success indicating a connect request was delivered to the ULP
1642 * or the mpa request is incomplete but valid so far.
1643 *
1644 * 1 if a failure requires the caller to close the connection.
1645 *
1646 * 2 if a failure requires the caller to abort the connection.
1647 */
1648static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649{
1650 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301651 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001652 u16 plen;
1653
1654 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1655
Steve Wisecfdda9d2010-04-21 15:30:06 -07001656 /*
1657 * If we get more than the supported amount of private data
1658 * then we must fail this connection.
1659 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301660 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1661 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001662
1663 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1664
1665 /*
1666 * Copy the new data into our accumulation buffer.
1667 */
1668 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1669 skb->len);
1670 ep->mpa_pkt_len += skb->len;
1671
1672 /*
1673 * If we don't even have the mpa message, then bail.
1674 * We'll continue process when more data arrives.
1675 */
1676 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301677 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678
1679 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001680 mpa = (struct mpa_message *) ep->mpa_pkt;
1681
1682 /*
1683 * Validate MPA Header.
1684 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301685 if (mpa->revision > mpa_rev) {
1686 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1687 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301688 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001689 }
1690
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301691 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1692 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693
1694 plen = ntohs(mpa->private_data_size);
1695
1696 /*
1697 * Fail if there's too much private data.
1698 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301699 if (plen > MPA_MAX_PRIVATE_DATA)
1700 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001701
1702 /*
1703 * If plen does not account for pkt size
1704 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301705 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1706 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001707 ep->plen = (u8) plen;
1708
1709 /*
1710 * If we don't have all the pdata yet, then bail.
1711 */
1712 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301713 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001714
1715 /*
1716 * If we get here we have accumulated the entire mpa
1717 * start reply message including private data.
1718 */
1719 ep->mpa_attr.initiator = 0;
1720 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1721 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1722 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301723 ep->mpa_attr.version = mpa->revision;
1724 if (mpa->revision == 1)
1725 ep->tried_with_mpa_v1 = 1;
1726 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1727
1728 if (mpa->revision == 2) {
1729 ep->mpa_attr.enhanced_rdma_conn =
1730 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1731 if (ep->mpa_attr.enhanced_rdma_conn) {
1732 mpa_v2_params = (struct mpa_v2_conn_params *)
1733 (ep->mpa_pkt + sizeof(*mpa));
1734 ep->ird = ntohs(mpa_v2_params->ird) &
1735 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001736 ep->ird = min_t(u32, ep->ird,
1737 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301738 ep->ord = ntohs(mpa_v2_params->ord) &
1739 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001740 ep->ord = min_t(u32, ep->ord,
1741 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301742 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1743 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301744 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1745 if (peer2peer) {
1746 if (ntohs(mpa_v2_params->ord) &
1747 MPA_V2_RDMA_WRITE_RTR)
1748 ep->mpa_attr.p2p_type =
1749 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1750 else if (ntohs(mpa_v2_params->ord) &
1751 MPA_V2_RDMA_READ_RTR)
1752 ep->mpa_attr.p2p_type =
1753 FW_RI_INIT_P2PTYPE_READ_REQ;
1754 }
1755 }
1756 } else if (mpa->revision == 1)
1757 if (peer2peer)
1758 ep->mpa_attr.p2p_type = p2p_type;
1759
Steve Wisecfdda9d2010-04-21 15:30:06 -07001760 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1761 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1762 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1763 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1764 ep->mpa_attr.p2p_type);
1765
Hariprasad Se4b76a22016-05-06 22:17:59 +05301766 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001767
Hariprasad Se4b76a22016-05-06 22:17:59 +05301768 /* drive upcall */
1769 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1770 if (ep->parent_ep->com.state != DEAD) {
1771 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301772 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301773 } else {
1774 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301775 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301776 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301777 return 0;
1778
1779err_unlock_parent:
1780 mutex_unlock(&ep->parent_ep->com.mutex);
1781 goto err_out;
1782err_stop_timer:
1783 (void)stop_ep_timer(ep);
1784err_out:
1785 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001786}
1787
1788static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1789{
1790 struct c4iw_ep *ep;
1791 struct cpl_rx_data *hdr = cplhdr(skb);
1792 unsigned int dlen = ntohs(hdr->len);
1793 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001794 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001795 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796
Hariprasad S944661d2016-05-06 22:18:03 +05301797 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301798 if (!ep)
1799 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001800 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1801 skb_pull(skb, sizeof(*hdr));
1802 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301803 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804
Steve Wisecfdda9d2010-04-21 15:30:06 -07001805 /* update RX credits */
1806 update_rx_credits(ep, dlen);
1807
Steve Wisec529fb52014-03-21 20:40:37 +05301808 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001810 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001811 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001812 break;
1813 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001814 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301815 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001816 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001817 case FPDU_MODE: {
1818 struct c4iw_qp_attributes attrs;
1819 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001820 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001821 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001822 " qpid %u ep %p state %d tid %u status %d\n",
1823 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301824 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301825 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001826 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001827 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1828 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829 break;
1830 }
Vipul Pandya15579672013-01-07 13:11:52 +00001831 default:
1832 break;
1833 }
Steve Wisec529fb52014-03-21 20:40:37 +05301834 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001835 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301836 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301837 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001838 return 0;
1839}
1840
1841static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1842{
1843 struct c4iw_ep *ep;
1844 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845 int release = 0;
1846 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001847
Hariprasad S944661d2016-05-06 22:18:03 +05301848 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301849 if (!ep) {
1850 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1851 return 0;
1852 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001853 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001854 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855 switch (ep->com.state) {
1856 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001857 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858 __state_set(&ep->com, DEAD);
1859 release = 1;
1860 break;
1861 default:
1862 printk(KERN_ERR "%s ep %p state %d\n",
1863 __func__, ep, ep->com.state);
1864 break;
1865 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001866 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001867
1868 if (release)
1869 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301870 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001871 return 0;
1872}
1873
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301874static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001875{
1876 struct sk_buff *skb;
1877 struct fw_ofld_connection_wr *req;
1878 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301879 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301880 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301881 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001882
1883 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1884 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1885 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001886 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301887 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301888 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1889 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001890 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001891 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301892 req->le.lport = sin->sin_port;
1893 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001894 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301895 req->le.pport = sin->sin_port;
1896 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001897 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301898 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1899 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001900 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301901 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001902 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001903 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301904 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1905 enable_tcp_timestamps,
1906 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301907 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301908
1909 /*
1910 * Specify the largest window that will fit in opt0. The
1911 * remainder will be specified in the rx_data_ack.
1912 */
1913 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001914 if (win > RCV_BUFSIZ_M)
1915 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301916
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001917 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1918 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001919 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001920 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001921 WND_SCALE_V(wscale) |
1922 MSS_IDX_V(mtu_idx) |
1923 L2T_IDX_V(ep->l2t->idx) |
1924 TX_CHAN_V(ep->tx_chan) |
1925 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301926 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001927 ULP_MODE_V(ULP_MODE_TCPDDP) |
1928 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001929 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1930 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001931 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001932 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001933 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001934 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001935 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001936 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001937 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001938 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001939 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1940 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1941 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001942 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1943 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301944 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001945}
1946
Steve Wisecfdda9d2010-04-21 15:30:06 -07001947/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301948 * Some of the error codes above implicitly indicate that there is no TID
1949 * allocated with the result of an ACT_OPEN. We use this predicate to make
1950 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001951 */
1952static inline int act_open_has_tid(int status)
1953{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301954 return (status != CPL_ERR_TCAM_PARITY &&
1955 status != CPL_ERR_TCAM_MISS &&
1956 status != CPL_ERR_TCAM_FULL &&
1957 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1958 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001959}
1960
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301961static char *neg_adv_str(unsigned int status)
1962{
1963 switch (status) {
1964 case CPL_ERR_RTX_NEG_ADVICE:
1965 return "Retransmit timeout";
1966 case CPL_ERR_PERSIST_NEG_ADVICE:
1967 return "Persist timeout";
1968 case CPL_ERR_KEEPALV_NEG_ADVICE:
1969 return "Keepalive timeout";
1970 default:
1971 return "Unknown";
1972 }
1973}
1974
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301975static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1976{
1977 ep->snd_win = snd_win;
1978 ep->rcv_win = rcv_win;
1979 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1980}
1981
Vipul Pandya793dad92012-12-10 09:30:56 +00001982#define ACT_OPEN_RETRY_COUNT 2
1983
Vipul Pandya830662f2013-07-04 16:10:47 +05301984static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1985 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301986 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301987{
1988 struct neighbour *n;
1989 int err, step;
1990 struct net_device *pdev;
1991
1992 n = dst_neigh_lookup(dst, peer_ip);
1993 if (!n)
1994 return -ENODEV;
1995
1996 rcu_read_lock();
1997 err = -ENOMEM;
1998 if (n->dev->flags & IFF_LOOPBACK) {
1999 if (iptype == 4)
2000 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2001 else if (IS_ENABLED(CONFIG_IPV6))
2002 for_each_netdev(&init_net, pdev) {
2003 if (ipv6_chk_addr(&init_net,
2004 (struct in6_addr *)peer_ip,
2005 pdev, 1))
2006 break;
2007 }
2008 else
2009 pdev = NULL;
2010
2011 if (!pdev) {
2012 err = -ENODEV;
2013 goto out;
2014 }
2015 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302016 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302017 if (!ep->l2t)
2018 goto out;
2019 ep->mtu = pdev->mtu;
2020 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302021 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2022 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302023 step = cdev->rdev.lldi.ntxq /
2024 cdev->rdev.lldi.nchan;
2025 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2026 step = cdev->rdev.lldi.nrxq /
2027 cdev->rdev.lldi.nchan;
2028 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2029 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2030 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302031 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302032 dev_put(pdev);
2033 } else {
2034 pdev = get_real_dev(n->dev);
2035 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2036 n, pdev, 0);
2037 if (!ep->l2t)
2038 goto out;
2039 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002040 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302041 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2042 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302043 step = cdev->rdev.lldi.ntxq /
2044 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002045 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2046 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302047 step = cdev->rdev.lldi.nrxq /
2048 cdev->rdev.lldi.nchan;
2049 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002050 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302051 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302052
2053 if (clear_mpa_v1) {
2054 ep->retry_with_mpa_v1 = 0;
2055 ep->tried_with_mpa_v1 = 0;
2056 }
2057 }
2058 err = 0;
2059out:
2060 rcu_read_unlock();
2061
2062 neigh_release(n);
2063
2064 return err;
2065}
2066
Vipul Pandya793dad92012-12-10 09:30:56 +00002067static int c4iw_reconnect(struct c4iw_ep *ep)
2068{
2069 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302070 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302071 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002072 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302073 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002074 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302075 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002076 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302077 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002078 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302079 int iptype;
2080 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002081
2082 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2083 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302084 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002085
Hariprasad S4a740832016-06-10 01:05:15 +05302086 /* When MPA revision is different on nodes, the node with MPA_rev=2
2087 * tries to reconnect with MPA_rev 1 for the same EP through
2088 * c4iw_reconnect(), where the same EP is assigned with new tid for
2089 * further connection establishment. As we are using the same EP pointer
2090 * for reconnect, few skbs are used during the previous c4iw_connect(),
2091 * which leaves the EP with inadequate skbs for further
2092 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2093 * skb_list() during peer_abort(). Allocate skbs which is already used.
2094 */
2095 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2096 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2097 err = -ENOMEM;
2098 goto fail1;
2099 }
2100
Vipul Pandya793dad92012-12-10 09:30:56 +00002101 /*
2102 * Allocate an active TID to initiate a TCP connection.
2103 */
2104 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2105 if (ep->atid == -1) {
2106 pr_err("%s - cannot alloc atid.\n", __func__);
2107 err = -ENOMEM;
2108 goto fail2;
2109 }
2110 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2111
2112 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002113 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302114 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2115 laddr->sin_addr.s_addr,
2116 raddr->sin_addr.s_addr,
2117 laddr->sin_port,
2118 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302119 iptype = 4;
2120 ra = (__u8 *)&raddr->sin_addr;
2121 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302122 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2123 get_real_dev,
2124 laddr6->sin6_addr.s6_addr,
2125 raddr6->sin6_addr.s6_addr,
2126 laddr6->sin6_port,
2127 raddr6->sin6_port, 0,
2128 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302129 iptype = 6;
2130 ra = (__u8 *)&raddr6->sin6_addr;
2131 }
2132 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002133 pr_err("%s - cannot find route.\n", __func__);
2134 err = -EHOSTUNREACH;
2135 goto fail3;
2136 }
Hariprasad S963cab52015-09-23 17:19:27 +05302137 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302138 ep->com.dev->rdev.lldi.adapter_type,
2139 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302140 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002141 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002142 goto fail4;
2143 }
2144
2145 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2146 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2147 ep->l2t->idx);
2148
2149 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302150 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002151
2152 /* send connect request to rnic */
2153 err = send_connect(ep);
2154 if (!err)
2155 goto out;
2156
2157 cxgb4_l2t_release(ep->l2t);
2158fail4:
2159 dst_release(ep->dst);
2160fail3:
2161 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2162 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2163fail2:
2164 /*
2165 * remember to send notification to upper layer.
2166 * We are in here so the upper layer is not aware that this is
2167 * re-connect attempt and so, upper layer is still waiting for
2168 * response of 1st connect request.
2169 */
2170 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302171fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002172 c4iw_put_ep(&ep->com);
2173out:
2174 return err;
2175}
2176
Steve Wisecfdda9d2010-04-21 15:30:06 -07002177static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2178{
2179 struct c4iw_ep *ep;
2180 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002181 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2182 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002183 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002184 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302185 struct sockaddr_in *la;
2186 struct sockaddr_in *ra;
2187 struct sockaddr_in6 *la6;
2188 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302189 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002190
2191 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002192 la = (struct sockaddr_in *)&ep->com.local_addr;
2193 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2194 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2195 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002196
2197 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2198 status, status2errno(status));
2199
Varun Prakashb65eef02016-09-13 21:23:59 +05302200 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302201 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2202 __func__, atid, status, neg_adv_str(status));
2203 ep->stats.connect_neg_adv++;
2204 mutex_lock(&dev->rdev.stats.lock);
2205 dev->rdev.stats.neg_adv++;
2206 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002207 return 0;
2208 }
2209
Vipul Pandya793dad92012-12-10 09:30:56 +00002210 set_bit(ACT_OPEN_RPL, &ep->com.history);
2211
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302212 /*
2213 * Log interesting failures.
2214 */
2215 switch (status) {
2216 case CPL_ERR_CONN_RESET:
2217 case CPL_ERR_CONN_TIMEDOUT:
2218 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002219 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302220 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002221 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302222 mutex_unlock(&dev->rdev.stats.lock);
2223 if (ep->com.local_addr.ss_family == AF_INET &&
2224 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302225 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2226 ntohl(rpl->atid_status))));
2227 if (ret)
2228 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002229 return 0;
2230 }
2231 break;
2232 case CPL_ERR_CONN_EXIST:
2233 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2234 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302235 if (ep->com.remote_addr.ss_family == AF_INET6) {
2236 struct sockaddr_in6 *sin6 =
2237 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002238 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302239 cxgb4_clip_release(
2240 ep->com.dev->rdev.lldi.ports[0],
2241 (const u32 *)
2242 &sin6->sin6_addr.s6_addr, 1);
2243 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002244 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2245 atid);
2246 cxgb4_free_atid(t, atid);
2247 dst_release(ep->dst);
2248 cxgb4_l2t_release(ep->l2t);
2249 c4iw_reconnect(ep);
2250 return 0;
2251 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002252 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302253 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302254 if (ep->com.local_addr.ss_family == AF_INET) {
2255 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2256 atid, status, status2errno(status),
2257 &la->sin_addr.s_addr, ntohs(la->sin_port),
2258 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2259 } else {
2260 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2261 atid, status, status2errno(status),
2262 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2263 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2264 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302265 break;
2266 }
2267
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302268fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002269 connect_reply_upcall(ep, status2errno(status));
2270 state_set(&ep->com, DEAD);
2271
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302272 if (ep->com.remote_addr.ss_family == AF_INET6) {
2273 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002274 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302275 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2276 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2277 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002278 if (status && act_open_has_tid(status))
2279 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2280
Vipul Pandya793dad92012-12-10 09:30:56 +00002281 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 cxgb4_free_atid(t, atid);
2283 dst_release(ep->dst);
2284 cxgb4_l2t_release(ep->l2t);
2285 c4iw_put_ep(&ep->com);
2286
2287 return 0;
2288}
2289
2290static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2291{
2292 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302294 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295
2296 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002297 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2298 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002299 }
2300 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2301 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002302 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302303 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002304out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002305 return 0;
2306}
2307
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2309{
2310 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002311 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302312 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002313
2314 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002315 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302316 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002317 return 0;
2318}
2319
Hariprasad S9dec9002016-05-05 01:27:29 +05302320static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2321 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002322{
2323 struct cpl_pass_accept_rpl *rpl;
2324 unsigned int mtu_idx;
2325 u64 opt0;
2326 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302327 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302328 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302329 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302330 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331
2332 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2333 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302334
Steve Wisecfdda9d2010-04-21 15:30:06 -07002335 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302336 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302337 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302338 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2339 rpl5 = (void *)rpl;
2340 INIT_TP_WR(rpl5, ep->hwtid);
2341 } else {
2342 skb_trim(skb, sizeof(*rpl));
2343 INIT_TP_WR(rpl, ep->hwtid);
2344 }
2345 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2346 ep->hwtid));
2347
Varun Prakash44c6d062016-09-13 21:24:00 +05302348 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2349 enable_tcp_timestamps && req->tcpopt.tstamp,
2350 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302351 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302352
2353 /*
2354 * Specify the largest window that will fit in opt0. The
2355 * remainder will be specified in the rx_data_ack.
2356 */
2357 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002358 if (win > RCV_BUFSIZ_M)
2359 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002360 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002361 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002362 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002363 WND_SCALE_V(wscale) |
2364 MSS_IDX_V(mtu_idx) |
2365 L2T_IDX_V(ep->l2t->idx) |
2366 TX_CHAN_V(ep->tx_chan) |
2367 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002368 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002369 ULP_MODE_V(ULP_MODE_TCPDDP) |
2370 RCV_BUFSIZ_V(win);
2371 opt2 = RX_CHANNEL_V(0) |
2372 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373
2374 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002375 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002376 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002377 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002379 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002380 if (enable_ecn) {
2381 const struct tcphdr *tcph;
2382 u32 hlen = ntohl(req->hdr_len);
2383
Hariprasad S963cab52015-09-23 17:19:27 +05302384 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2385 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2386 IP_HDR_LEN_G(hlen);
2387 else
2388 tcph = (const void *)(req + 1) +
2389 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002390 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002391 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002392 }
Hariprasad S963cab52015-09-23 17:19:27 +05302393 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302394 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002395 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302396 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302397 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302398 rpl5 = (void *)rpl;
2399 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2400 if (peer2peer)
2401 isn += 4;
2402 rpl5->iss = cpu_to_be32(isn);
2403 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002404 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002405
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406 rpl->opt0 = cpu_to_be64(opt0);
2407 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002408 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302409 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410
Hariprasad S9dec9002016-05-05 01:27:29 +05302411 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002412}
2413
Vipul Pandya830662f2013-07-04 16:10:47 +05302414static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002415{
Vipul Pandya830662f2013-07-04 16:10:47 +05302416 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002417 BUG_ON(skb_cloned(skb));
2418 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002419 release_tid(&dev->rdev, hwtid, skb);
2420 return;
2421}
2422
Steve Wisecfdda9d2010-04-21 15:30:06 -07002423static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2424{
Vipul Pandya793dad92012-12-10 09:30:56 +00002425 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002427 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002428 struct tid_info *t = dev->rdev.lldi.tids;
2429 unsigned int hwtid = GET_TID(req);
2430 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302431 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302433 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002434 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002435 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302436 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302437 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302438 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002439
Hariprasad Sf86fac72016-05-06 22:18:07 +05302440 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002441 if (!parent_ep) {
2442 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2443 goto reject;
2444 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002445
Steve Wisecfdda9d2010-04-21 15:30:06 -07002446 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302447 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448 goto reject;
2449 }
2450
Varun Prakash85e42b02016-09-13 21:23:56 +05302451 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2452 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302453
Steve Wisecfdda9d2010-04-21 15:30:06 -07002454 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302455 if (iptype == 4) {
2456 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2457 , __func__, parent_ep, hwtid,
2458 local_ip, peer_ip, ntohs(local_port),
2459 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302460 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2461 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2462 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302463 } else {
2464 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 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 Prakash95554762016-09-13 21:23:58 +05302468 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2469 local_ip, peer_ip, local_port, peer_port,
2470 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2471 ((struct sockaddr_in6 *)
2472 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302473 }
2474 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2476 __func__);
2477 goto reject;
2478 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002479
2480 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2481 if (!child_ep) {
2482 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2483 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484 dst_release(dst);
2485 goto reject;
2486 }
David Miller3786cf12011-12-02 16:52:31 +00002487
Hariprasad S963cab52015-09-23 17:19:27 +05302488 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302489 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002490 if (err) {
2491 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2492 __func__);
2493 dst_release(dst);
2494 kfree(child_ep);
2495 goto reject;
2496 }
2497
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302498 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2499 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2500 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2501 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002502
Hariprasad S4a740832016-06-10 01:05:15 +05302503 skb_queue_head_init(&child_ep->com.ep_skb_list);
2504 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2505 goto fail;
2506
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 state_set(&child_ep->com, CONNECTING);
2508 child_ep->com.dev = dev;
2509 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002510
Vipul Pandya830662f2013-07-04 16:10:47 +05302511 if (iptype == 4) {
2512 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002513 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002514
Vipul Pandya830662f2013-07-04 16:10:47 +05302515 sin->sin_family = PF_INET;
2516 sin->sin_port = local_port;
2517 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002518
2519 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2520 sin->sin_family = PF_INET;
2521 sin->sin_port = ((struct sockaddr_in *)
2522 &parent_ep->com.local_addr)->sin_port;
2523 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2524
Steve Wise170003c2016-02-26 09:18:03 -06002525 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302526 sin->sin_family = PF_INET;
2527 sin->sin_port = peer_port;
2528 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2529 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002530 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302531 sin6->sin6_family = PF_INET6;
2532 sin6->sin6_port = local_port;
2533 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002534
2535 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2536 sin6->sin6_family = PF_INET6;
2537 sin6->sin6_port = ((struct sockaddr_in6 *)
2538 &parent_ep->com.local_addr)->sin6_port;
2539 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2540
Steve Wise170003c2016-02-26 09:18:03 -06002541 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302542 sin6->sin6_family = PF_INET6;
2543 sin6->sin6_port = peer_port;
2544 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2545 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002546
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547 c4iw_get_ep(&parent_ep->com);
2548 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302549 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550 child_ep->dst = dst;
2551 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002552
2553 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002554 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002555
2556 init_timer(&child_ep->timer);
2557 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302558 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302559 if (accept_cr(child_ep, skb, req)) {
2560 c4iw_put_ep(&parent_ep->com);
2561 release_ep_resources(child_ep);
2562 } else {
2563 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2564 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302565 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002566 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302567 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2568 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2569 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302571fail:
2572 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002573reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302574 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302575 if (parent_ep)
2576 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577out:
2578 return 0;
2579}
2580
2581static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2582{
2583 struct c4iw_ep *ep;
2584 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302586 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002587
Hariprasad S944661d2016-05-06 22:18:03 +05302588 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002589 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2590 ep->snd_seq = be32_to_cpu(req->snd_isn);
2591 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2592
Vipul Pandya1cab7752012-12-10 09:30:55 +00002593 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2594 ntohs(req->tcp_opt));
2595
Steve Wisecfdda9d2010-04-21 15:30:06 -07002596 set_emss(ep, ntohs(req->tcp_opt));
2597
2598 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302599 mutex_lock(&ep->com.mutex);
2600 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002601 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002602 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302603 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302604 mutex_unlock(&ep->com.mutex);
2605 if (ret)
2606 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302607 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608
2609 return 0;
2610}
2611
2612static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2613{
2614 struct cpl_peer_close *hdr = cplhdr(skb);
2615 struct c4iw_ep *ep;
2616 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617 int disconnect = 1;
2618 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002620 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621
Hariprasad S944661d2016-05-06 22:18:03 +05302622 ep = get_ep_from_tid(dev, tid);
2623 if (!ep)
2624 return 0;
2625
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2627 dst_confirm(ep->dst);
2628
Vipul Pandya793dad92012-12-10 09:30:56 +00002629 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002630 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002631 switch (ep->com.state) {
2632 case MPA_REQ_WAIT:
2633 __state_set(&ep->com, CLOSING);
2634 break;
2635 case MPA_REQ_SENT:
2636 __state_set(&ep->com, CLOSING);
2637 connect_reply_upcall(ep, -ECONNRESET);
2638 break;
2639 case MPA_REQ_RCVD:
2640
2641 /*
2642 * We're gonna mark this puppy DEAD, but keep
2643 * the reference on it until the ULP accepts or
2644 * rejects the CR. Also wake up anyone waiting
2645 * in rdma connection migration (see c4iw_accept_cr()).
2646 */
2647 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002649 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650 break;
2651 case MPA_REP_SENT:
2652 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002654 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 break;
2656 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002657 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002659 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002660 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002661 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002662 if (ret != -ECONNRESET) {
2663 peer_close_upcall(ep);
2664 disconnect = 1;
2665 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002666 break;
2667 case ABORTING:
2668 disconnect = 0;
2669 break;
2670 case CLOSING:
2671 __state_set(&ep->com, MORIBUND);
2672 disconnect = 0;
2673 break;
2674 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002675 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002676 if (ep->com.cm_id && ep->com.qp) {
2677 attrs.next_state = C4IW_QP_STATE_IDLE;
2678 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2679 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2680 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302681 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002682 __state_set(&ep->com, DEAD);
2683 release = 1;
2684 disconnect = 0;
2685 break;
2686 case DEAD:
2687 disconnect = 0;
2688 break;
2689 default:
2690 BUG_ON(1);
2691 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002692 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 if (disconnect)
2694 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2695 if (release)
2696 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302697 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698 return 0;
2699}
2700
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2702{
2703 struct cpl_abort_req_rss *req = cplhdr(skb);
2704 struct c4iw_ep *ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 struct sk_buff *rpl_skb;
2706 struct c4iw_qp_attributes attrs;
2707 int ret;
2708 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709 unsigned int tid = GET_TID(req);
Varun Prakash052f4732016-09-13 21:24:05 +05302710 u32 len = roundup(sizeof(struct cpl_abort_rpl), 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002711
Hariprasad S944661d2016-05-06 22:18:03 +05302712 ep = get_ep_from_tid(dev, tid);
2713 if (!ep)
2714 return 0;
2715
Varun Prakashb65eef02016-09-13 21:23:59 +05302716 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302717 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2718 __func__, ep->hwtid, req->status,
2719 neg_adv_str(req->status));
2720 ep->stats.abort_neg_adv++;
2721 mutex_lock(&dev->rdev.stats.lock);
2722 dev->rdev.stats.neg_adv++;
2723 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302724 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002726 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2727 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002728 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002729
2730 /*
2731 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302732 * However, this is not needed if com state is just
2733 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002734 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302735 if (ep->com.state != MPA_REQ_SENT)
2736 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002737
2738 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739 switch (ep->com.state) {
2740 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302741 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002742 break;
2743 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002744 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002745 break;
2746 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002747 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002748 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302749 connect_reply_upcall(ep, -ECONNRESET);
2750 else {
2751 /*
2752 * we just don't send notification upwards because we
2753 * want to retry with mpa_v1 without upper layers even
2754 * knowing it.
2755 *
2756 * do some housekeeping so as to re-initiate the
2757 * connection
2758 */
2759 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2760 mpa_rev);
2761 ep->retry_with_mpa_v1 = 1;
2762 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763 break;
2764 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002765 break;
2766 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002767 break;
2768 case MORIBUND:
2769 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002770 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002771 /*FALLTHROUGH*/
2772 case FPDU_MODE:
2773 if (ep->com.cm_id && ep->com.qp) {
2774 attrs.next_state = C4IW_QP_STATE_ERROR;
2775 ret = c4iw_modify_qp(ep->com.qp->rhp,
2776 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2777 &attrs, 1);
2778 if (ret)
2779 printk(KERN_ERR MOD
2780 "%s - qp <- error failed!\n",
2781 __func__);
2782 }
2783 peer_abort_upcall(ep);
2784 break;
2785 case ABORTING:
2786 break;
2787 case DEAD:
2788 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002789 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302790 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 default:
2792 BUG_ON(1);
2793 break;
2794 }
2795 dst_confirm(ep->dst);
2796 if (ep->com.state != ABORTING) {
2797 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302798 /* we don't release if we want to retry with mpa_v1 */
2799 if (!ep->retry_with_mpa_v1)
2800 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002801 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002802 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002803
Hariprasad S4a740832016-06-10 01:05:15 +05302804 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2805 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 release = 1;
2807 goto out;
2808 }
Varun Prakash052f4732016-09-13 21:24:05 +05302809
2810 cxgb_mk_abort_rpl(rpl_skb, len, ep->hwtid, ep->txq_idx);
2811
Steve Wisecfdda9d2010-04-21 15:30:06 -07002812 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2813out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002814 if (release)
2815 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002816 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302817 if (ep->com.remote_addr.ss_family == AF_INET6) {
2818 struct sockaddr_in6 *sin6 =
2819 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002820 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302821 cxgb4_clip_release(
2822 ep->com.dev->rdev.lldi.ports[0],
2823 (const u32 *)&sin6->sin6_addr.s6_addr,
2824 1);
2825 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002826 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302827 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2828 dst_release(ep->dst);
2829 cxgb4_l2t_release(ep->l2t);
2830 c4iw_reconnect(ep);
2831 }
2832
Hariprasad S944661d2016-05-06 22:18:03 +05302833deref_ep:
2834 c4iw_put_ep(&ep->com);
2835 /* Dereferencing ep, referenced in peer_abort_intr() */
2836 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 return 0;
2838}
2839
2840static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2841{
2842 struct c4iw_ep *ep;
2843 struct c4iw_qp_attributes attrs;
2844 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002846 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002847
Hariprasad S944661d2016-05-06 22:18:03 +05302848 ep = get_ep_from_tid(dev, tid);
2849 if (!ep)
2850 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002851
2852 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2853 BUG_ON(!ep);
2854
2855 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002856 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302857 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 switch (ep->com.state) {
2859 case CLOSING:
2860 __state_set(&ep->com, MORIBUND);
2861 break;
2862 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002863 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002864 if ((ep->com.cm_id) && (ep->com.qp)) {
2865 attrs.next_state = C4IW_QP_STATE_IDLE;
2866 c4iw_modify_qp(ep->com.qp->rhp,
2867 ep->com.qp,
2868 C4IW_QP_ATTR_NEXT_STATE,
2869 &attrs, 1);
2870 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302871 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002872 __state_set(&ep->com, DEAD);
2873 release = 1;
2874 break;
2875 case ABORTING:
2876 case DEAD:
2877 break;
2878 default:
2879 BUG_ON(1);
2880 break;
2881 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002882 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883 if (release)
2884 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302885 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002886 return 0;
2887}
2888
2889static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2890{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002891 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002892 unsigned int tid = GET_TID(rpl);
2893 struct c4iw_ep *ep;
2894 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895
Hariprasad S944661d2016-05-06 22:18:03 +05302896 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002897 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002898
Steve Wise30c95c22011-05-09 22:06:22 -07002899 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002900 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2901 ep->com.qp->wq.sq.qid);
2902 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2903 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2904 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2905 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002906 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302907 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002908
Steve Wisecfdda9d2010-04-21 15:30:06 -07002909 return 0;
2910}
2911
2912/*
2913 * Upcall from the adapter indicating data has been transmitted.
2914 * For us its just the single MPA request or reply. We can now free
2915 * the skb holding the mpa message.
2916 */
2917static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2918{
2919 struct c4iw_ep *ep;
2920 struct cpl_fw4_ack *hdr = cplhdr(skb);
2921 u8 credits = hdr->credits;
2922 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923
2924
Hariprasad S944661d2016-05-06 22:18:03 +05302925 ep = get_ep_from_tid(dev, tid);
2926 if (!ep)
2927 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002928 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2929 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002930 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2931 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302932 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002933 }
2934
2935 dst_confirm(ep->dst);
2936 if (ep->mpa_skb) {
2937 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2938 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2939 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002940 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002941 kfree_skb(ep->mpa_skb);
2942 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302943 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2944 stop_ep_timer(ep);
2945 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 }
Hariprasad S944661d2016-05-06 22:18:03 +05302947out:
2948 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 return 0;
2950}
2951
Steve Wisecfdda9d2010-04-21 15:30:06 -07002952int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2953{
Hariprasad Sbce28412016-06-10 01:05:13 +05302954 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002955 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302956
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2958
Steve Wisea7db89e2014-03-21 20:40:35 +05302959 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302960 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302961 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 c4iw_put_ep(&ep->com);
2963 return -ECONNRESET;
2964 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002965 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302967 abort = 1;
2968 else
2969 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302970 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302971
2972 stop_ep_timer(ep);
2973 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974 c4iw_put_ep(&ep->com);
2975 return 0;
2976}
2977
2978int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2979{
2980 int err;
2981 struct c4iw_qp_attributes attrs;
2982 enum c4iw_qp_attr_mask mask;
2983 struct c4iw_ep *ep = to_ep(cm_id);
2984 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2985 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302986 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002987
2988 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302989
2990 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302991 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302993 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002994 }
2995
Steve Wisecfdda9d2010-04-21 15:30:06 -07002996 BUG_ON(!qp);
2997
Vipul Pandya793dad92012-12-10 09:30:56 +00002998 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302999 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3000 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003001 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303002 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003003 }
3004
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303005 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3006 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303007 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003008 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303009 } else {
3010 ep->ird = conn_param->ird;
3011 ep->ord = conn_param->ord;
3012 send_mpa_reject(ep, conn_param->private_data,
3013 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303014 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303015 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303016 }
3017 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303018 if (conn_param->ird < ep->ord) {
3019 if (RELAXED_IRD_NEGOTIATION &&
3020 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3021 conn_param->ird = ep->ord;
3022 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303023 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303024 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303025 }
3026 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 ep->ird = conn_param->ird;
3029 ep->ord = conn_param->ord;
3030
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303031 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303032 if (peer2peer && ep->ird == 0)
3033 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303034 } else {
3035 if (peer2peer &&
3036 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303037 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303038 ep->ird = 1;
3039 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003040
3041 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3042
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303043 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303044 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303045 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003046 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303047
Steve Wisecfdda9d2010-04-21 15:30:06 -07003048 /* bind QP to EP and move to RTS */
3049 attrs.mpa_attr = ep->mpa_attr;
3050 attrs.max_ird = ep->ird;
3051 attrs.max_ord = ep->ord;
3052 attrs.llp_stream_handle = ep;
3053 attrs.next_state = C4IW_QP_STATE_RTS;
3054
3055 /* bind QP and TID with INIT_WR */
3056 mask = C4IW_QP_ATTR_NEXT_STATE |
3057 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3058 C4IW_QP_ATTR_MPA_ATTR |
3059 C4IW_QP_ATTR_MAX_IRD |
3060 C4IW_QP_ATTR_MAX_ORD;
3061
3062 err = c4iw_modify_qp(ep->com.qp->rhp,
3063 ep->com.qp, mask, &attrs, 1);
3064 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303065 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303066
3067 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 err = send_mpa_reply(ep, conn_param->private_data,
3069 conn_param->private_data_len);
3070 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303071 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003072
Steve Wisea7db89e2014-03-21 20:40:35 +05303073 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003074 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303075 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003076 c4iw_put_ep(&ep->com);
3077 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303078err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303079 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303080err_abort:
3081 abort = 1;
3082err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303083 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303084 if (abort)
3085 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003086 c4iw_put_ep(&ep->com);
3087 return err;
3088}
3089
Vipul Pandya830662f2013-07-04 16:10:47 +05303090static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3091{
3092 struct in_device *ind;
3093 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003094 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3095 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303096
3097 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3098 if (!ind)
3099 return -EADDRNOTAVAIL;
3100 for_primary_ifa(ind) {
3101 laddr->sin_addr.s_addr = ifa->ifa_address;
3102 raddr->sin_addr.s_addr = ifa->ifa_address;
3103 found = 1;
3104 break;
3105 }
3106 endfor_ifa(ind);
3107 in_dev_put(ind);
3108 return found ? 0 : -EADDRNOTAVAIL;
3109}
3110
3111static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3112 unsigned char banned_flags)
3113{
3114 struct inet6_dev *idev;
3115 int err = -EADDRNOTAVAIL;
3116
3117 rcu_read_lock();
3118 idev = __in6_dev_get(dev);
3119 if (idev != NULL) {
3120 struct inet6_ifaddr *ifp;
3121
3122 read_lock_bh(&idev->lock);
3123 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3124 if (ifp->scope == IFA_LINK &&
3125 !(ifp->flags & banned_flags)) {
3126 memcpy(addr, &ifp->addr, 16);
3127 err = 0;
3128 break;
3129 }
3130 }
3131 read_unlock_bh(&idev->lock);
3132 }
3133 rcu_read_unlock();
3134 return err;
3135}
3136
3137static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3138{
3139 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003140 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3141 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303142
Nicholas Krause54b9a962015-08-26 23:00:59 -04003143 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303144 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3145 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3146 return 0;
3147 }
3148 return -EADDRNOTAVAIL;
3149}
3150
Steve Wisecfdda9d2010-04-21 15:30:06 -07003151int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3152{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003153 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3154 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003155 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003156 struct sockaddr_in *laddr;
3157 struct sockaddr_in *raddr;
3158 struct sockaddr_in6 *laddr6;
3159 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303160 __u8 *ra;
3161 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003162
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303163 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3164 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003165 err = -EINVAL;
3166 goto out;
3167 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003168 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3169 if (!ep) {
3170 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3171 err = -ENOMEM;
3172 goto out;
3173 }
Hariprasad S4a740832016-06-10 01:05:15 +05303174
3175 skb_queue_head_init(&ep->com.ep_skb_list);
3176 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3177 err = -ENOMEM;
3178 goto fail1;
3179 }
3180
Steve Wisecfdda9d2010-04-21 15:30:06 -07003181 init_timer(&ep->timer);
3182 ep->plen = conn_param->private_data_len;
3183 if (ep->plen)
3184 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3185 conn_param->private_data, ep->plen);
3186 ep->ird = conn_param->ird;
3187 ep->ord = conn_param->ord;
3188
3189 if (peer2peer && ep->ord == 0)
3190 ep->ord = 1;
3191
Steve Wisecfdda9d2010-04-21 15:30:06 -07003192 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303193 ref_cm_id(&ep->com);
3194 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003195 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303196 if (!ep->com.qp) {
3197 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3198 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303199 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303200 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003201 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003202 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3203 ep->com.qp, cm_id);
3204
3205 /*
3206 * Allocate an active TID to initiate a TCP connection.
3207 */
3208 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3209 if (ep->atid == -1) {
3210 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3211 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303212 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003213 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003214 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003215
Steve Wise170003c2016-02-26 09:18:03 -06003216 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003217 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003218 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003219 sizeof(ep->com.remote_addr));
3220
Steve Wise170003c2016-02-26 09:18:03 -06003221 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3222 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3223 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3224 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003225
Steve Wise170003c2016-02-26 09:18:03 -06003226 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303227 iptype = 4;
3228 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003229
Vipul Pandya830662f2013-07-04 16:10:47 +05303230 /*
3231 * Handle loopback requests to INADDR_ANY.
3232 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003233 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303234 err = pick_local_ipaddrs(dev, cm_id);
3235 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303236 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303237 }
3238
3239 /* find a route */
3240 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3241 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3242 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303243 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3244 laddr->sin_addr.s_addr,
3245 raddr->sin_addr.s_addr,
3246 laddr->sin_port,
3247 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303248 } else {
3249 iptype = 6;
3250 ra = (__u8 *)&raddr6->sin6_addr;
3251
3252 /*
3253 * Handle loopback requests to INADDR_ANY.
3254 */
3255 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3256 err = pick_local_ip6addrs(dev, cm_id);
3257 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303258 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303259 }
3260
3261 /* find a route */
3262 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3263 __func__, laddr6->sin6_addr.s6_addr,
3264 ntohs(laddr6->sin6_port),
3265 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303266 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3267 laddr6->sin6_addr.s6_addr,
3268 raddr6->sin6_addr.s6_addr,
3269 laddr6->sin6_port,
3270 raddr6->sin6_port, 0,
3271 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303272 }
3273 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003274 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3275 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303276 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003277 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003278
Hariprasad S963cab52015-09-23 17:19:27 +05303279 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303280 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003281 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003282 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303283 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003284 }
3285
3286 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3287 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3288 ep->l2t->idx);
3289
3290 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303291 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292
3293 /* send connect request to rnic */
3294 err = send_connect(ep);
3295 if (!err)
3296 goto out;
3297
3298 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303299fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003300 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303301fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003302 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003303 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303304fail2:
3305 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303306 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303307fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003308 c4iw_put_ep(&ep->com);
3309out:
3310 return err;
3311}
3312
Vipul Pandya830662f2013-07-04 16:10:47 +05303313static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3314{
3315 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003316 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003317 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303318
Hariprasad S28de1f72016-01-13 10:03:14 +05303319 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3320 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3321 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3322 if (err)
3323 return err;
3324 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303325 c4iw_init_wr_wait(&ep->com.wr_wait);
3326 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3327 ep->stid, &sin6->sin6_addr,
3328 sin6->sin6_port,
3329 ep->com.dev->rdev.lldi.rxq_ids[0]);
3330 if (!err)
3331 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3332 &ep->com.wr_wait,
3333 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303334 else if (err > 0)
3335 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303336 if (err) {
3337 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3338 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303339 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3340 err, ep->stid,
3341 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303342 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303343 return err;
3344}
3345
3346static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3347{
3348 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003349 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003350 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303351
3352 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3353 do {
3354 err = cxgb4_create_server_filter(
3355 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3356 sin->sin_addr.s_addr, sin->sin_port, 0,
3357 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3358 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303359 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3360 err = -EIO;
3361 break;
3362 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303363 set_current_state(TASK_UNINTERRUPTIBLE);
3364 schedule_timeout(usecs_to_jiffies(100));
3365 }
3366 } while (err == -EBUSY);
3367 } else {
3368 c4iw_init_wr_wait(&ep->com.wr_wait);
3369 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3370 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3371 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3372 if (!err)
3373 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3374 &ep->com.wr_wait,
3375 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303376 else if (err > 0)
3377 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303378 }
3379 if (err)
3380 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3381 , err, ep->stid,
3382 &sin->sin_addr, ntohs(sin->sin_port));
3383 return err;
3384}
3385
Steve Wisecfdda9d2010-04-21 15:30:06 -07003386int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3387{
3388 int err = 0;
3389 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3390 struct c4iw_listen_ep *ep;
3391
Steve Wisecfdda9d2010-04-21 15:30:06 -07003392 might_sleep();
3393
3394 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3395 if (!ep) {
3396 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3397 err = -ENOMEM;
3398 goto fail1;
3399 }
Hariprasad S4a740832016-06-10 01:05:15 +05303400 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003401 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003402 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303403 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003404 ep->com.dev = dev;
3405 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003406 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303407 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003408
3409 /*
3410 * Allocate a server TID.
3411 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303412 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3413 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303414 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003415 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003416 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303417 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003418 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003419
Steve Wisecfdda9d2010-04-21 15:30:06 -07003420 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003421 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003422 err = -ENOMEM;
3423 goto fail2;
3424 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003425 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003426
Steve Wise170003c2016-02-26 09:18:03 -06003427 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3428 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003429
Steve Wisecfdda9d2010-04-21 15:30:06 -07003430 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303431 if (ep->com.local_addr.ss_family == AF_INET)
3432 err = create_server4(dev, ep);
3433 else
3434 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003435 if (!err) {
3436 cm_id->provider_data = ep;
3437 goto out;
3438 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003439
Vipul Pandya830662f2013-07-04 16:10:47 +05303440 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3441 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003442fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303443 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003444 c4iw_put_ep(&ep->com);
3445fail1:
3446out:
3447 return err;
3448}
3449
3450int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3451{
3452 int err;
3453 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3454
3455 PDBG("%s ep %p\n", __func__, ep);
3456
3457 might_sleep();
3458 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303459 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3460 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003461 err = cxgb4_remove_server_filter(
3462 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3463 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3464 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303465 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003466 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303467 err = cxgb4_remove_server(
3468 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3469 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003470 if (err)
3471 goto done;
3472 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3473 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003474 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303475 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3476 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003477 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003478 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303479 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3480 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003481done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303482 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003483 c4iw_put_ep(&ep->com);
3484 return err;
3485}
3486
3487int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3488{
3489 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003490 int close = 0;
3491 int fatal = 0;
3492 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003493
Steve Wise2f5b48c2010-09-10 11:15:36 -05003494 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003495
3496 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3497 states[ep->com.state], abrupt);
3498
Hariprasad S6e410d82016-05-05 01:27:31 +05303499 /*
3500 * Ref the ep here in case we have fatal errors causing the
3501 * ep to be released and freed.
3502 */
3503 c4iw_get_ep(&ep->com);
3504
Steve Wisecfdda9d2010-04-21 15:30:06 -07003505 rdev = &ep->com.dev->rdev;
3506 if (c4iw_fatal_error(rdev)) {
3507 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303508 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509 ep->com.state = DEAD;
3510 }
3511 switch (ep->com.state) {
3512 case MPA_REQ_WAIT:
3513 case MPA_REQ_SENT:
3514 case MPA_REQ_RCVD:
3515 case MPA_REP_SENT:
3516 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303517 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 close = 1;
3519 if (abrupt)
3520 ep->com.state = ABORTING;
3521 else {
3522 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003523
3524 /*
3525 * if we close before we see the fw4_ack() then we fix
3526 * up the timer state since we're reusing it.
3527 */
3528 if (ep->mpa_skb &&
3529 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3530 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3531 stop_ep_timer(ep);
3532 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003533 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003534 }
3535 set_bit(CLOSE_SENT, &ep->com.flags);
3536 break;
3537 case CLOSING:
3538 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3539 close = 1;
3540 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003541 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003542 ep->com.state = ABORTING;
3543 } else
3544 ep->com.state = MORIBUND;
3545 }
3546 break;
3547 case MORIBUND:
3548 case ABORTING:
3549 case DEAD:
3550 PDBG("%s ignoring disconnect ep %p state %u\n",
3551 __func__, ep, ep->com.state);
3552 break;
3553 default:
3554 BUG();
3555 break;
3556 }
3557
Steve Wisecfdda9d2010-04-21 15:30:06 -07003558 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003559 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003560 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303561 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303562 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003563 } else {
3564 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303565 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003566 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303567 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303568 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303569 if (!abrupt) {
3570 stop_ep_timer(ep);
3571 close_complete_upcall(ep, -EIO);
3572 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303573 if (ep->com.qp) {
3574 struct c4iw_qp_attributes attrs;
3575
3576 attrs.next_state = C4IW_QP_STATE_ERROR;
3577 ret = c4iw_modify_qp(ep->com.qp->rhp,
3578 ep->com.qp,
3579 C4IW_QP_ATTR_NEXT_STATE,
3580 &attrs, 1);
3581 if (ret)
3582 pr_err(MOD
3583 "%s - qp <- error failed!\n",
3584 __func__);
3585 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003586 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303587 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003588 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003589 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303590 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003591 if (fatal)
3592 release_ep_resources(ep);
3593 return ret;
3594}
3595
Vipul Pandya1cab7752012-12-10 09:30:55 +00003596static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3597 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3598{
3599 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003600 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003602 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3603 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003604 if (!ep)
3605 return;
3606
3607 switch (req->retval) {
3608 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003609 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3610 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3611 send_fw_act_open_req(ep, atid);
3612 return;
3613 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003614 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003615 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3616 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3617 send_fw_act_open_req(ep, atid);
3618 return;
3619 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003620 break;
3621 default:
3622 pr_info("%s unexpected ofld conn wr retval %d\n",
3623 __func__, req->retval);
3624 break;
3625 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003626 pr_err("active ofld_connect_wr failure %d atid %d\n",
3627 req->retval, atid);
3628 mutex_lock(&dev->rdev.stats.lock);
3629 dev->rdev.stats.act_ofld_conn_fails++;
3630 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003631 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003632 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303633 if (ep->com.remote_addr.ss_family == AF_INET6) {
3634 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003635 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303636 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3637 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3638 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003639 remove_handle(dev, &dev->atid_idr, atid);
3640 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3641 dst_release(ep->dst);
3642 cxgb4_l2t_release(ep->l2t);
3643 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003644}
3645
3646static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3647 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3648{
3649 struct sk_buff *rpl_skb;
3650 struct cpl_pass_accept_req *cpl;
3651 int ret;
3652
Paul Bolle710a3112013-02-05 20:51:30 +00003653 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654 BUG_ON(!rpl_skb);
3655 if (req->retval) {
3656 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003657 mutex_lock(&dev->rdev.stats.lock);
3658 dev->rdev.stats.pas_ofld_conn_fails++;
3659 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003660 kfree_skb(rpl_skb);
3661 } else {
3662 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3663 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003664 (__force u32) htonl(
3665 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003666 ret = pass_accept_req(dev, rpl_skb);
3667 if (!ret)
3668 kfree_skb(rpl_skb);
3669 }
3670 return;
3671}
3672
3673static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003674{
3675 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003676 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3677
3678 switch (rpl->type) {
3679 case FW6_TYPE_CQE:
3680 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3681 break;
3682 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3683 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3684 switch (req->t_state) {
3685 case TCP_SYN_SENT:
3686 active_ofld_conn_reply(dev, skb, req);
3687 break;
3688 case TCP_SYN_RECV:
3689 passive_ofld_conn_reply(dev, skb, req);
3690 break;
3691 default:
3692 pr_err("%s unexpected ofld conn wr state %d\n",
3693 __func__, req->t_state);
3694 break;
3695 }
3696 break;
3697 }
3698 return 0;
3699}
3700
3701static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3702{
Hariprasad S963cab52015-09-23 17:19:27 +05303703 __be32 l2info;
3704 __be16 hdr_len, vlantag, len;
3705 u16 eth_hdr_len;
3706 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003707 u8 intf;
3708 struct cpl_rx_pkt *cpl = cplhdr(skb);
3709 struct cpl_pass_accept_req *req;
3710 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003711 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303712 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003713
Vipul Pandyaf079af72013-03-14 05:08:58 +00003714 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003715 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303716 vlantag = cpl->vlan;
3717 len = cpl->len;
3718 l2info = cpl->l2info;
3719 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003720 intf = cpl->iff;
3721
3722 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3723
3724 /*
3725 * We need to parse the TCP options from SYN packet.
3726 * to generate cpl_pass_accept_req.
3727 */
3728 memset(&tmp_opt, 0, sizeof(tmp_opt));
3729 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003730 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003731
3732 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3733 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303734 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3735 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303736 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303737 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303738 type = dev->rdev.lldi.adapter_type;
3739 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3740 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3741 req->hdr_len =
3742 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3743 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3744 eth_hdr_len = is_t4(type) ?
3745 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3746 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3747 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3748 IP_HDR_LEN_V(ip_hdr_len) |
3749 ETH_HDR_LEN_V(eth_hdr_len));
3750 } else { /* T6 and later */
3751 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3752 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3753 T6_IP_HDR_LEN_V(ip_hdr_len) |
3754 T6_ETH_HDR_LEN_V(eth_hdr_len));
3755 }
3756 req->vlan = vlantag;
3757 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003758 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3759 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003760 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3761 if (tmp_opt.wscale_ok)
3762 req->tcpopt.wsf = tmp_opt.snd_wscale;
3763 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3764 if (tmp_opt.sack_ok)
3765 req->tcpopt.sack = 1;
3766 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3767 return;
3768}
3769
3770static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3771 __be32 laddr, __be16 lport,
3772 __be32 raddr, __be16 rport,
3773 u32 rcv_isn, u32 filter, u16 window,
3774 u32 rss_qid, u8 port_id)
3775{
3776 struct sk_buff *req_skb;
3777 struct fw_ofld_connection_wr *req;
3778 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303779 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003780
3781 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3782 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3783 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003784 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303785 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303786 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003787 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003788 req->le.lport = lport;
3789 req->le.pport = rport;
3790 req->le.u.ipv4.lip = laddr;
3791 req->le.u.ipv4.pip = raddr;
3792 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3793 req->tcb.rcv_adv = htons(window);
3794 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303795 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3796 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3797 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003798 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003799
3800 /*
3801 * We store the qid in opt2 which will be used by the firmware
3802 * to send us the wr response.
3803 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003804 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003805
3806 /*
3807 * We initialize the MSS index in TCB to 0xF.
3808 * So that when driver sends cpl_pass_accept_rpl
3809 * TCB picks up the correct value. If this was 0
3810 * TP will ignore any value > 0 for MSS index.
3811 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003812 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303813 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814
3815 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303816 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3817 if (ret < 0) {
3818 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3819 ret);
3820 kfree_skb(skb);
3821 kfree_skb(req_skb);
3822 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003823}
3824
3825/*
3826 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3827 * messages when a filter is being used instead of server to
3828 * redirect a syn packet. When packets hit filter they are redirected
3829 * to the offload queue and driver tries to establish the connection
3830 * using firmware work request.
3831 */
3832static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3833{
3834 int stid;
3835 unsigned int filter;
3836 struct ethhdr *eh = NULL;
3837 struct vlan_ethhdr *vlan_eh = NULL;
3838 struct iphdr *iph;
3839 struct tcphdr *tcph;
3840 struct rss_header *rss = (void *)skb->data;
3841 struct cpl_rx_pkt *cpl = (void *)skb->data;
3842 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3843 struct l2t_entry *e;
3844 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303845 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003846 u16 window;
3847 struct port_info *pi;
3848 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003849 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003850 int step;
3851 u32 tx_chan;
3852 struct neighbour *neigh;
3853
3854 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003855 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003856 goto reject;
3857
3858 /*
3859 * Drop all packets which did not hit the filter.
3860 * Unlikely to happen.
3861 */
3862 if (!(rss->filter_hit && rss->filter_tid))
3863 goto reject;
3864
3865 /*
3866 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3867 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303868 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003869
Hariprasad Sf86fac72016-05-06 22:18:07 +05303870 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003871 if (!lep) {
3872 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3873 goto reject;
3874 }
3875
Hariprasad S963cab52015-09-23 17:19:27 +05303876 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3877 case CHELSIO_T4:
3878 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3879 break;
3880 case CHELSIO_T5:
3881 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3882 break;
3883 case CHELSIO_T6:
3884 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3885 break;
3886 default:
3887 pr_err("T%d Chip is not supported\n",
3888 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3889 goto reject;
3890 }
3891
Vipul Pandyaf079af72013-03-14 05:08:58 +00003892 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003893 eh = (struct ethhdr *)(req + 1);
3894 iph = (struct iphdr *)(eh + 1);
3895 } else {
3896 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3897 iph = (struct iphdr *)(vlan_eh + 1);
3898 skb->vlan_tci = ntohs(cpl->vlan);
3899 }
3900
3901 if (iph->version != 0x4)
3902 goto reject;
3903
3904 tcph = (struct tcphdr *)(iph + 1);
3905 skb_set_network_header(skb, (void *)iph - (void *)rss);
3906 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3907 skb_get(skb);
3908
3909 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3910 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3911 ntohs(tcph->source), iph->tos);
3912
Varun Prakash804c2f32016-09-13 21:23:57 +05303913 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3914 iph->daddr, iph->saddr, tcph->dest,
3915 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303916 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003917 pr_err("%s - failed to find dst entry!\n",
3918 __func__);
3919 goto reject;
3920 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003921 neigh = dst_neigh_lookup_skb(dst, skb);
3922
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003923 if (!neigh) {
3924 pr_err("%s - failed to allocate neigh!\n",
3925 __func__);
3926 goto free_dst;
3927 }
3928
Vipul Pandya1cab7752012-12-10 09:30:55 +00003929 if (neigh->dev->flags & IFF_LOOPBACK) {
3930 pdev = ip_dev_find(&init_net, iph->daddr);
3931 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3932 pdev, 0);
3933 pi = (struct port_info *)netdev_priv(pdev);
3934 tx_chan = cxgb4_port_chan(pdev);
3935 dev_put(pdev);
3936 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303937 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003938 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303939 pdev, 0);
3940 pi = (struct port_info *)netdev_priv(pdev);
3941 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003942 }
Steve Wiseebf00062014-03-19 17:44:40 +05303943 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003944 if (!e) {
3945 pr_err("%s - failed to allocate l2t entry!\n",
3946 __func__);
3947 goto free_dst;
3948 }
3949
3950 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3951 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003952 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003953
3954 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303955 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3956 dev->rdev.lldi.ports[0],
3957 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003958
3959 /*
3960 * Synthesize the cpl_pass_accept_req. We have everything except the
3961 * TID. Once firmware sends a reply with TID we update the TID field
3962 * in cpl and pass it through the regular cpl_pass_accept_req path.
3963 */
3964 build_cpl_pass_accept_req(skb, stid, iph->tos);
3965 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3966 tcph->source, ntohl(tcph->seq), filter, window,
3967 rss_qid, pi->port_id);
3968 cxgb4_l2t_release(e);
3969free_dst:
3970 dst_release(dst);
3971reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303972 if (lep)
3973 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003974 return 0;
3975}
3976
Steve Wisecfdda9d2010-04-21 15:30:06 -07003977/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 * These are the real handlers that are called from a
3979 * work queue.
3980 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303981static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003982 [CPL_ACT_ESTABLISH] = act_establish,
3983 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3984 [CPL_RX_DATA] = rx_data,
3985 [CPL_ABORT_RPL_RSS] = abort_rpl,
3986 [CPL_ABORT_RPL] = abort_rpl,
3987 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3988 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3989 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3990 [CPL_PASS_ESTABLISH] = pass_establish,
3991 [CPL_PEER_CLOSE] = peer_close,
3992 [CPL_ABORT_REQ_RSS] = peer_abort,
3993 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3994 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003995 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003996 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303997 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05303998 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
3999 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004000};
4001
4002static void process_timeout(struct c4iw_ep *ep)
4003{
4004 struct c4iw_qp_attributes attrs;
4005 int abort = 1;
4006
Steve Wise2f5b48c2010-09-10 11:15:36 -05004007 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004008 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4009 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004010 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004011 switch (ep->com.state) {
4012 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004013 connect_reply_upcall(ep, -ETIMEDOUT);
4014 break;
4015 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304016 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304017 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304018 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004019 break;
4020 case CLOSING:
4021 case MORIBUND:
4022 if (ep->com.cm_id && ep->com.qp) {
4023 attrs.next_state = C4IW_QP_STATE_ERROR;
4024 c4iw_modify_qp(ep->com.qp->rhp,
4025 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4026 &attrs, 1);
4027 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304028 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004029 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004030 case ABORTING:
4031 case DEAD:
4032
4033 /*
4034 * These states are expected if the ep timed out at the same
4035 * time as another thread was calling stop_ep_timer().
4036 * So we silently do nothing for these states.
4037 */
4038 abort = 0;
4039 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004040 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004041 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004042 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004043 abort = 0;
4044 }
Steve Wisecc18b932014-04-24 14:31:53 -05004045 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304046 if (abort)
4047 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004048 c4iw_put_ep(&ep->com);
4049}
4050
4051static void process_timedout_eps(void)
4052{
4053 struct c4iw_ep *ep;
4054
4055 spin_lock_irq(&timeout_lock);
4056 while (!list_empty(&timeout_list)) {
4057 struct list_head *tmp;
4058
4059 tmp = timeout_list.next;
4060 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004061 tmp->next = NULL;
4062 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004063 spin_unlock_irq(&timeout_lock);
4064 ep = list_entry(tmp, struct c4iw_ep, entry);
4065 process_timeout(ep);
4066 spin_lock_irq(&timeout_lock);
4067 }
4068 spin_unlock_irq(&timeout_lock);
4069}
4070
4071static void process_work(struct work_struct *work)
4072{
4073 struct sk_buff *skb = NULL;
4074 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004075 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004076 unsigned int opcode;
4077 int ret;
4078
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004079 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004080 while ((skb = skb_dequeue(&rxq))) {
4081 rpl = cplhdr(skb);
4082 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4083 opcode = rpl->ot.opcode;
4084
4085 BUG_ON(!work_handlers[opcode]);
4086 ret = work_handlers[opcode](dev, skb);
4087 if (!ret)
4088 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004089 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004090 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004091}
4092
4093static DECLARE_WORK(skb_work, process_work);
4094
4095static void ep_timeout(unsigned long arg)
4096{
4097 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004098 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004099
4100 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004101 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004102 /*
4103 * Only insert if it is not already on the list.
4104 */
4105 if (!ep->entry.next) {
4106 list_add_tail(&ep->entry, &timeout_list);
4107 kickit = 1;
4108 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004109 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004110 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004111 if (kickit)
4112 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004113}
4114
4115/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004116 * All the CM events are handled on a work queue to have a safe context.
4117 */
4118static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4119{
4120
4121 /*
4122 * Save dev in the skb->cb area.
4123 */
4124 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4125
4126 /*
4127 * Queue the skb and schedule the worker thread.
4128 */
4129 skb_queue_tail(&rxq, skb);
4130 queue_work(workq, &skb_work);
4131 return 0;
4132}
4133
4134static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4135{
4136 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4137
4138 if (rpl->status != CPL_ERR_NONE) {
4139 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4140 "for tid %u\n", rpl->status, GET_TID(rpl));
4141 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004142 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004143 return 0;
4144}
4145
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004146static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4147{
4148 struct cpl_fw6_msg *rpl = cplhdr(skb);
4149 struct c4iw_wr_wait *wr_waitp;
4150 int ret;
4151
4152 PDBG("%s type %u\n", __func__, rpl->type);
4153
4154 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004155 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004156 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004157 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004158 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004159 if (wr_waitp)
4160 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004161 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004162 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004163 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004164 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004165 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004166 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004167 default:
4168 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4169 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004170 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004171 break;
4172 }
4173 return 0;
4174}
4175
Steve Wise8da7e7a2011-06-14 20:59:27 +00004176static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4177{
4178 struct cpl_abort_req_rss *req = cplhdr(skb);
4179 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004180 unsigned int tid = GET_TID(req);
4181
Hariprasad S944661d2016-05-06 22:18:03 +05304182 ep = get_ep_from_tid(dev, tid);
4183 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004184 if (!ep) {
4185 printk(KERN_WARNING MOD
4186 "Abort on non-existent endpoint, tid %d\n", tid);
4187 kfree_skb(skb);
4188 return 0;
4189 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304190 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304191 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4192 __func__, ep->hwtid, req->status,
4193 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304194 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004195 }
4196 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4197 ep->com.state);
4198
Hariprasad S093108c2016-05-06 22:18:09 +05304199 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304200out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004201 sched(dev, skb);
4202 return 0;
4203}
4204
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004205/*
4206 * Most upcalls from the T4 Core go to sched() to
4207 * schedule the processing on a work queue.
4208 */
4209c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4210 [CPL_ACT_ESTABLISH] = sched,
4211 [CPL_ACT_OPEN_RPL] = sched,
4212 [CPL_RX_DATA] = sched,
4213 [CPL_ABORT_RPL_RSS] = sched,
4214 [CPL_ABORT_RPL] = sched,
4215 [CPL_PASS_OPEN_RPL] = sched,
4216 [CPL_CLOSE_LISTSRV_RPL] = sched,
4217 [CPL_PASS_ACCEPT_REQ] = sched,
4218 [CPL_PASS_ESTABLISH] = sched,
4219 [CPL_PEER_CLOSE] = sched,
4220 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004221 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004222 [CPL_RDMA_TERMINATE] = sched,
4223 [CPL_FW4_ACK] = sched,
4224 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004225 [CPL_FW6_MSG] = fw6_msg,
4226 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004227};
4228
Steve Wisecfdda9d2010-04-21 15:30:06 -07004229int __init c4iw_cm_init(void)
4230{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004231 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004232 skb_queue_head_init(&rxq);
4233
4234 workq = create_singlethread_workqueue("iw_cxgb4");
4235 if (!workq)
4236 return -ENOMEM;
4237
Steve Wisecfdda9d2010-04-21 15:30:06 -07004238 return 0;
4239}
4240
Steve Wise46c13762014-06-20 14:26:25 -05004241void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004242{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004243 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004244 flush_workqueue(workq);
4245 destroy_workqueue(workq);
4246}