blob: b9d77df0a2f65428c1ed247f29a009d7cff2ee41 [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{
243 struct cpl_tid_release *req;
244
245 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
246 if (!skb)
247 return;
248 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
249 INIT_TP_WR(req, hwtid);
250 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
251 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
252 c4iw_ofld_send(rdev, skb);
253 return;
254}
255
256static void set_emss(struct c4iw_ep *ep, u16 opt)
257{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800258 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530259 ((AF_INET == ep->com.remote_addr.ss_family) ?
260 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
261 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800263 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530264 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700265 if (ep->emss < 128)
266 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530267 if (ep->emss & 7)
268 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800269 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
270 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700271 ep->mss, ep->emss);
272}
273
274static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
275{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 enum c4iw_ep_state state;
277
Steve Wise2f5b48c2010-09-10 11:15:36 -0500278 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500280 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700281 return state;
282}
283
284static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
285{
286 epc->state = new;
287}
288
289static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
290{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500291 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700292 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
293 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500294 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700295 return;
296}
297
Hariprasad S4a740832016-06-10 01:05:15 +0530298static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
299{
300 struct sk_buff *skb;
301 unsigned int i;
302 size_t len;
303
304 len = roundup(sizeof(union cpl_wr_size), 16);
305 for (i = 0; i < size; i++) {
306 skb = alloc_skb(len, GFP_KERNEL);
307 if (!skb)
308 goto fail;
309 skb_queue_tail(ep_skb_list, skb);
310 }
311 return 0;
312fail:
313 skb_queue_purge(ep_skb_list);
314 return -ENOMEM;
315}
316
Steve Wisecfdda9d2010-04-21 15:30:06 -0700317static void *alloc_ep(int size, gfp_t gfp)
318{
319 struct c4iw_ep_common *epc;
320
321 epc = kzalloc(size, gfp);
322 if (epc) {
323 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500324 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500325 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700326 }
327 PDBG("%s alloc ep %p\n", __func__, epc);
328 return epc;
329}
330
Hariprasad S944661d2016-05-06 22:18:03 +0530331static void remove_ep_tid(struct c4iw_ep *ep)
332{
333 unsigned long flags;
334
335 spin_lock_irqsave(&ep->com.dev->lock, flags);
336 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
337 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
338}
339
340static void insert_ep_tid(struct c4iw_ep *ep)
341{
342 unsigned long flags;
343
344 spin_lock_irqsave(&ep->com.dev->lock, flags);
345 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
346 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
347}
348
349/*
350 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
351 */
352static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
353{
354 struct c4iw_ep *ep;
355 unsigned long flags;
356
357 spin_lock_irqsave(&dev->lock, flags);
358 ep = idr_find(&dev->hwtid_idr, tid);
359 if (ep)
360 c4iw_get_ep(&ep->com);
361 spin_unlock_irqrestore(&dev->lock, flags);
362 return ep;
363}
364
Hariprasad Sf86fac72016-05-06 22:18:07 +0530365/*
366 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
367 */
368static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
369 unsigned int stid)
370{
371 struct c4iw_listen_ep *ep;
372 unsigned long flags;
373
374 spin_lock_irqsave(&dev->lock, flags);
375 ep = idr_find(&dev->stid_idr, stid);
376 if (ep)
377 c4iw_get_ep(&ep->com);
378 spin_unlock_irqrestore(&dev->lock, flags);
379 return ep;
380}
381
Steve Wisecfdda9d2010-04-21 15:30:06 -0700382void _c4iw_free_ep(struct kref *kref)
383{
384 struct c4iw_ep *ep;
385
386 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530387 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000388 if (test_bit(QP_REFERENCED, &ep->com.flags))
389 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700390 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530391 if (ep->com.remote_addr.ss_family == AF_INET6) {
392 struct sockaddr_in6 *sin6 =
393 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600394 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530395
396 cxgb4_clip_release(
397 ep->com.dev->rdev.lldi.ports[0],
398 (const u32 *)&sin6->sin6_addr.s6_addr,
399 1);
400 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700401 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
402 dst_release(ep->dst);
403 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530404 if (ep->mpa_skb)
405 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700406 }
Hariprasad S4a740832016-06-10 01:05:15 +0530407 if (!skb_queue_empty(&ep->com.ep_skb_list))
408 skb_queue_purge(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700409 kfree(ep);
410}
411
412static void release_ep_resources(struct c4iw_ep *ep)
413{
414 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530415
416 /*
417 * If we have a hwtid, then remove it from the idr table
418 * so lookups will no longer find this endpoint. Otherwise
419 * we have a race where one thread finds the ep ptr just
420 * before the other thread is freeing the ep memory.
421 */
422 if (ep->hwtid != -1)
423 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700424 c4iw_put_ep(&ep->com);
425}
426
Steve Wisecfdda9d2010-04-21 15:30:06 -0700427static int status2errno(int status)
428{
429 switch (status) {
430 case CPL_ERR_NONE:
431 return 0;
432 case CPL_ERR_CONN_RESET:
433 return -ECONNRESET;
434 case CPL_ERR_ARP_MISS:
435 return -EHOSTUNREACH;
436 case CPL_ERR_CONN_TIMEDOUT:
437 return -ETIMEDOUT;
438 case CPL_ERR_TCAM_FULL:
439 return -ENOMEM;
440 case CPL_ERR_CONN_EXIST:
441 return -EADDRINUSE;
442 default:
443 return -EIO;
444 }
445}
446
447/*
448 * Try and reuse skbs already allocated...
449 */
450static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
451{
452 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
453 skb_trim(skb, 0);
454 skb_get(skb);
455 skb_reset_transport_header(skb);
456 } else {
457 skb = alloc_skb(len, gfp);
458 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530459 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700460 return skb;
461}
462
Vipul Pandya830662f2013-07-04 16:10:47 +0530463static struct net_device *get_real_dev(struct net_device *egress_dev)
464{
Steve Wise11b8e222014-05-16 12:42:46 -0500465 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530466}
467
Steve Wisecfdda9d2010-04-21 15:30:06 -0700468static void arp_failure_discard(void *handle, struct sk_buff *skb)
469{
Hariprasad S9dec9002016-05-05 01:27:29 +0530470 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700471 kfree_skb(skb);
472}
473
Hariprasad S64bec742016-05-06 22:18:10 +0530474static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
475{
476 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
477}
478
Hariprasad S9dec9002016-05-05 01:27:29 +0530479enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530480 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530481 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530482 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530483};
484
485static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
486{
487 struct c4iw_ep *ep;
488
489 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
490 release_ep_resources(ep);
491 return 0;
492}
493
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530494static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
495{
496 struct c4iw_ep *ep;
497
498 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
499 c4iw_put_ep(&ep->parent_ep->com);
500 release_ep_resources(ep);
501 return 0;
502}
503
Hariprasad S9dec9002016-05-05 01:27:29 +0530504/*
505 * Fake up a special CPL opcode and call sched() so process_work() will call
506 * _put_ep_safe() in a safe context to free the ep resources. This is needed
507 * because ARP error handlers are called in an ATOMIC context, and
508 * _c4iw_free_ep() needs to block.
509 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530510static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
511 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530512{
513 struct cpl_act_establish *rpl = cplhdr(skb);
514
515 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530516 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530517
518 /*
519 * Save ep in the skb->cb area, after where sched() will save the dev
520 * ptr.
521 */
522 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
523 sched(ep->com.dev, skb);
524}
525
526/* Handle an ARP failure for an accept */
527static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
528{
529 struct c4iw_ep *ep = handle;
530
531 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
532 ep->hwtid);
533
534 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530535 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530536}
537
Steve Wisecfdda9d2010-04-21 15:30:06 -0700538/*
539 * Handle an ARP failure for an active open.
540 */
541static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
542{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530543 struct c4iw_ep *ep = handle;
544
Masanari Iidae3d132d2015-10-16 21:14:29 +0900545 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530546 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530547 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530548 if (ep->com.remote_addr.ss_family == AF_INET6) {
549 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600550 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530551 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
552 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
553 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530554 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
555 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530556 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557}
558
559/*
560 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
561 * and send it along.
562 */
563static void abort_arp_failure(void *handle, struct sk_buff *skb)
564{
Hariprasad S761e19a2016-05-06 22:18:02 +0530565 int ret;
566 struct c4iw_ep *ep = handle;
567 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700568 struct cpl_abort_req *req = cplhdr(skb);
569
570 PDBG("%s rdev %p\n", __func__, rdev);
571 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530572 ret = c4iw_ofld_send(rdev, skb);
573 if (ret) {
574 __state_set(&ep->com, DEAD);
575 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
576 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577}
578
Hariprasad S4a740832016-06-10 01:05:15 +0530579static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700580{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530582 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700583 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530584 u16 vlan = ep->l2t->vlan;
585 int nparams;
586
Hariprasad S4a740832016-06-10 01:05:15 +0530587 if (WARN_ON(!skb))
588 return -ENOMEM;
589
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530590 if (vlan == CPL_L2T_VLAN_NONE)
591 nparams = 8;
592 else
593 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700594
Hariprasad S4a740832016-06-10 01:05:15 +0530595 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530597 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530598 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530599 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530600 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700601
602 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530603 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530604 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700605 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
606 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
607 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
608 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
609 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
610 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
611 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
612 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
613 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
614 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
615 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530616 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700617 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
618 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530619 if (nparams == 9) {
620 u16 pri;
621
622 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
623 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
624 flowc->mnemval[8].val = cpu_to_be32(pri);
625 } else {
626 /* Pad WR to 16 byte boundary */
627 flowc->mnemval[8].mnemonic = 0;
628 flowc->mnemval[8].val = 0;
629 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700630 for (i = 0; i < 9; i++) {
631 flowc->mnemval[i].r4[0] = 0;
632 flowc->mnemval[i].r4[1] = 0;
633 flowc->mnemval[i].r4[2] = 0;
634 }
635
636 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530637 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700638}
639
Hariprasad S4a740832016-06-10 01:05:15 +0530640static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641{
642 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530643 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700644 int wrlen = roundup(sizeof *req, 16);
645
646 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530647 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530649
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
651 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
652 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
653 memset(req, 0, wrlen);
654 INIT_TP_WR(req, ep->hwtid);
655 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
656 ep->hwtid));
657 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
658}
659
Hariprasad S4a740832016-06-10 01:05:15 +0530660static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661{
662 struct cpl_abort_req *req;
663 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530664 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700665
666 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530667 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530669
670 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
671 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
672 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700673 memset(req, 0, wrlen);
674 INIT_TP_WR(req, ep->hwtid);
675 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
676 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530677 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700678}
679
680static int send_connect(struct c4iw_ep *ep)
681{
Hariprasad S963cab52015-09-23 17:19:27 +0530682 struct cpl_act_open_req *req = NULL;
683 struct cpl_t5_act_open_req *t5req = NULL;
684 struct cpl_t6_act_open_req *t6req = NULL;
685 struct cpl_act_open_req6 *req6 = NULL;
686 struct cpl_t5_act_open_req6 *t5req6 = NULL;
687 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700688 struct sk_buff *skb;
689 u64 opt0;
690 u32 opt2;
691 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +0530692 u32 wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530693 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500694 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600695 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500696 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600697 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500698 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600699 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500700 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600701 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530702 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530703 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
704 u32 isn = (prandom_u32() & ~7UL) - 1;
705
706 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
707 case CHELSIO_T4:
708 sizev4 = sizeof(struct cpl_act_open_req);
709 sizev6 = sizeof(struct cpl_act_open_req6);
710 break;
711 case CHELSIO_T5:
712 sizev4 = sizeof(struct cpl_t5_act_open_req);
713 sizev6 = sizeof(struct cpl_t5_act_open_req6);
714 break;
715 case CHELSIO_T6:
716 sizev4 = sizeof(struct cpl_t6_act_open_req);
717 sizev6 = sizeof(struct cpl_t6_act_open_req6);
718 break;
719 default:
720 pr_err("T%d Chip is not supported\n",
721 CHELSIO_CHIP_VERSION(adapter_type));
722 return -EINVAL;
723 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530724
725 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
726 roundup(sizev4, 16) :
727 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700728
729 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
730
731 skb = get_skb(NULL, wrlen, GFP_KERNEL);
732 if (!skb) {
733 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
734 __func__);
735 return -ENOMEM;
736 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000737 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700738
Varun Prakash44c6d062016-09-13 21:24:00 +0530739 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
740 enable_tcp_timestamps,
741 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +0530742 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530743
744 /*
745 * Specify the largest window that will fit in opt0. The
746 * remainder will be specified in the rx_data_ack.
747 */
748 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800749 if (win > RCV_BUFSIZ_M)
750 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530751
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800752 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800753 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800754 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800755 WND_SCALE_V(wscale) |
756 MSS_IDX_V(mtu_idx) |
757 L2T_IDX_V(ep->l2t->idx) |
758 TX_CHAN_V(ep->tx_chan) |
759 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530760 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800761 ULP_MODE_V(ULP_MODE_TCPDDP) |
762 RCV_BUFSIZ_V(win);
763 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800764 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800765 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700766 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800767 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700768 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800769 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700770 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800771 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530772 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
773 if (peer2peer)
774 isn += 4;
775
Anish Bhattd7990b02014-11-12 17:15:57 -0800776 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530777 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530778 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500779 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530780
781 if (ep->com.remote_addr.ss_family == AF_INET6)
782 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
783 (const u32 *)&la6->sin6_addr.s6_addr, 1);
784
Hariprasad S5dab6d32014-06-23 19:12:36 +0530785 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700786
Hariprasad S963cab52015-09-23 17:19:27 +0530787 if (ep->com.remote_addr.ss_family == AF_INET) {
788 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
789 case CHELSIO_T4:
790 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530791 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530792 break;
793 case CHELSIO_T5:
794 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
795 wrlen);
796 INIT_TP_WR(t5req, 0);
797 req = (struct cpl_act_open_req *)t5req;
798 break;
799 case CHELSIO_T6:
800 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
801 wrlen);
802 INIT_TP_WR(t6req, 0);
803 req = (struct cpl_act_open_req *)t6req;
804 t5req = (struct cpl_t5_act_open_req *)t6req;
805 break;
806 default:
807 pr_err("T%d Chip is not supported\n",
808 CHELSIO_CHIP_VERSION(adapter_type));
809 ret = -EINVAL;
810 goto clip_release;
811 }
812
813 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
814 ((ep->rss_qid<<14) | ep->atid)));
815 req->local_port = la->sin_port;
816 req->peer_port = ra->sin_port;
817 req->local_ip = la->sin_addr.s_addr;
818 req->peer_ip = ra->sin_addr.s_addr;
819 req->opt0 = cpu_to_be64(opt0);
820
821 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530822 req->params = cpu_to_be32(cxgb4_select_ntuple(
823 ep->com.dev->rdev.lldi.ports[0],
824 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530825 req->opt2 = cpu_to_be32(opt2);
826 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530827 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
828 cxgb4_select_ntuple(
829 ep->com.dev->rdev.lldi.ports[0],
830 ep->l2t)));
831 t5req->rsvd = cpu_to_be32(isn);
832 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
833 t5req->opt2 = cpu_to_be32(opt2);
834 }
835 } else {
836 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
837 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530838 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530839 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530840 break;
841 case CHELSIO_T5:
842 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
843 wrlen);
844 INIT_TP_WR(t5req6, 0);
845 req6 = (struct cpl_act_open_req6 *)t5req6;
846 break;
847 case CHELSIO_T6:
848 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
849 wrlen);
850 INIT_TP_WR(t6req6, 0);
851 req6 = (struct cpl_act_open_req6 *)t6req6;
852 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
853 break;
854 default:
855 pr_err("T%d Chip is not supported\n",
856 CHELSIO_CHIP_VERSION(adapter_type));
857 ret = -EINVAL;
858 goto clip_release;
859 }
860
861 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
862 ((ep->rss_qid<<14)|ep->atid)));
863 req6->local_port = la6->sin6_port;
864 req6->peer_port = ra6->sin6_port;
865 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
866 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
867 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
868 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
869 req6->opt0 = cpu_to_be64(opt0);
870
871 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530872 req6->params = cpu_to_be32(cxgb4_select_ntuple(
873 ep->com.dev->rdev.lldi.ports[0],
874 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530875 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530876 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530877 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
878 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530879 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530880 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530881 t5req6->rsvd = cpu_to_be32(isn);
882 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
883 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530884 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000885 }
886
Vipul Pandya793dad92012-12-10 09:30:56 +0000887 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530888 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530889clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530890 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
891 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
892 (const u32 *)&la6->sin6_addr.s6_addr, 1);
893 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700894}
895
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530896static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
897 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700898{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530899 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700900 struct fw_ofld_tx_data_wr *req;
901 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530902 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700903
904 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
905
906 BUG_ON(skb_cloned(skb));
907
908 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530909 if (mpa_rev_to_use == 2)
910 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700911 wrlen = roundup(mpalen + sizeof *req, 16);
912 skb = get_skb(skb, wrlen, GFP_KERNEL);
913 if (!skb) {
914 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530915 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700916 }
917 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
918
919 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
920 memset(req, 0, wrlen);
921 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530922 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
923 FW_WR_COMPL_F |
924 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700925 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530926 FW_WR_FLOWID_V(ep->hwtid) |
927 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700928 req->plen = cpu_to_be32(mpalen);
929 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530930 FW_OFLD_TX_DATA_WR_FLUSH_F |
931 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932
933 mpa = (struct mpa_message *)(req + 1);
934 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530935
936 mpa->flags = 0;
937 if (crc_enabled)
938 mpa->flags |= MPA_CRC;
939 if (markers_enabled) {
940 mpa->flags |= MPA_MARKERS;
941 ep->mpa_attr.recv_marker_enabled = 1;
942 } else {
943 ep->mpa_attr.recv_marker_enabled = 0;
944 }
945 if (mpa_rev_to_use == 2)
946 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
947
Steve Wisecfdda9d2010-04-21 15:30:06 -0700948 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530949 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530950 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530951 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530952 ep->retry_with_mpa_v1 = 0;
953 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530955 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700956 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
957 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530958 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
959 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530960 mpa_v2_params.ird = htons((u16)ep->ird);
961 mpa_v2_params.ord = htons((u16)ep->ord);
962
963 if (peer2peer) {
964 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
965 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
966 mpa_v2_params.ord |=
967 htons(MPA_V2_RDMA_WRITE_RTR);
968 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
969 mpa_v2_params.ord |=
970 htons(MPA_V2_RDMA_READ_RTR);
971 }
972 memcpy(mpa->private_data, &mpa_v2_params,
973 sizeof(struct mpa_v2_conn_params));
974
975 if (ep->plen)
976 memcpy(mpa->private_data +
977 sizeof(struct mpa_v2_conn_params),
978 ep->mpa_pkt + sizeof(*mpa), ep->plen);
979 } else
980 if (ep->plen)
981 memcpy(mpa->private_data,
982 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700983
984 /*
985 * Reference the mpa skb. This ensures the data area
986 * will remain in memory until the hw acks the tx.
987 * Function fw4_ack() will deref it.
988 */
989 skb_get(skb);
990 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
991 BUG_ON(ep->mpa_skb);
992 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530993 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
994 if (ret)
995 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530997 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700998 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530999 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301000 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001001}
1002
1003static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1004{
1005 int mpalen, wrlen;
1006 struct fw_ofld_tx_data_wr *req;
1007 struct mpa_message *mpa;
1008 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301009 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001010
1011 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1012
1013 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301014 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1015 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001016 wrlen = roundup(mpalen + sizeof *req, 16);
1017
1018 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1019 if (!skb) {
1020 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1021 return -ENOMEM;
1022 }
1023 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1024
1025 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1026 memset(req, 0, wrlen);
1027 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301028 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1029 FW_WR_COMPL_F |
1030 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001031 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301032 FW_WR_FLOWID_V(ep->hwtid) |
1033 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001034 req->plen = cpu_to_be32(mpalen);
1035 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301036 FW_OFLD_TX_DATA_WR_FLUSH_F |
1037 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001038
1039 mpa = (struct mpa_message *)(req + 1);
1040 memset(mpa, 0, sizeof(*mpa));
1041 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1042 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001043 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001044 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301045
1046 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1047 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001048 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1049 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301050 mpa_v2_params.ird = htons(((u16)ep->ird) |
1051 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1052 0));
1053 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1054 (p2p_type ==
1055 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1056 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1057 FW_RI_INIT_P2PTYPE_READ_REQ ?
1058 MPA_V2_RDMA_READ_RTR : 0) : 0));
1059 memcpy(mpa->private_data, &mpa_v2_params,
1060 sizeof(struct mpa_v2_conn_params));
1061
1062 if (ep->plen)
1063 memcpy(mpa->private_data +
1064 sizeof(struct mpa_v2_conn_params), pdata, plen);
1065 } else
1066 if (plen)
1067 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001068
1069 /*
1070 * Reference the mpa skb again. This ensures the data area
1071 * will remain in memory until the hw acks the tx.
1072 * Function fw4_ack() will deref it.
1073 */
1074 skb_get(skb);
1075 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301076 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001077 BUG_ON(ep->mpa_skb);
1078 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301079 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001080 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1081}
1082
1083static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1084{
1085 int mpalen, wrlen;
1086 struct fw_ofld_tx_data_wr *req;
1087 struct mpa_message *mpa;
1088 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301089 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001090
1091 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1092
1093 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301094 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1095 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001096 wrlen = roundup(mpalen + sizeof *req, 16);
1097
1098 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1099 if (!skb) {
1100 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1101 return -ENOMEM;
1102 }
1103 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1104
1105 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1106 memset(req, 0, wrlen);
1107 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301108 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1109 FW_WR_COMPL_F |
1110 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001111 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301112 FW_WR_FLOWID_V(ep->hwtid) |
1113 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001114 req->plen = cpu_to_be32(mpalen);
1115 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301116 FW_OFLD_TX_DATA_WR_FLUSH_F |
1117 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001118
1119 mpa = (struct mpa_message *)(req + 1);
1120 memset(mpa, 0, sizeof(*mpa));
1121 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301122 mpa->flags = 0;
1123 if (ep->mpa_attr.crc_enabled)
1124 mpa->flags |= MPA_CRC;
1125 if (ep->mpa_attr.recv_marker_enabled)
1126 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301127 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001128 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301129
1130 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1131 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001132 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1133 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301134 mpa_v2_params.ird = htons((u16)ep->ird);
1135 mpa_v2_params.ord = htons((u16)ep->ord);
1136 if (peer2peer && (ep->mpa_attr.p2p_type !=
1137 FW_RI_INIT_P2PTYPE_DISABLED)) {
1138 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1139
1140 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1141 mpa_v2_params.ord |=
1142 htons(MPA_V2_RDMA_WRITE_RTR);
1143 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1144 mpa_v2_params.ord |=
1145 htons(MPA_V2_RDMA_READ_RTR);
1146 }
1147
1148 memcpy(mpa->private_data, &mpa_v2_params,
1149 sizeof(struct mpa_v2_conn_params));
1150
1151 if (ep->plen)
1152 memcpy(mpa->private_data +
1153 sizeof(struct mpa_v2_conn_params), pdata, plen);
1154 } else
1155 if (plen)
1156 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157
1158 /*
1159 * Reference the mpa skb. This ensures the data area
1160 * will remain in memory until the hw acks the tx.
1161 * Function fw4_ack() will deref it.
1162 */
1163 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301164 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301166 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301167 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001168 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1169}
1170
1171static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1172{
1173 struct c4iw_ep *ep;
1174 struct cpl_act_establish *req = cplhdr(skb);
1175 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001176 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001177 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301178 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179
1180 ep = lookup_atid(t, atid);
1181
1182 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1183 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1184
Steve Wisea7db89e2014-03-21 20:40:35 +05301185 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001186 dst_confirm(ep->dst);
1187
1188 /* setup the hwtid for this connection */
1189 ep->hwtid = tid;
1190 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301191 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001192
1193 ep->snd_seq = be32_to_cpu(req->snd_isn);
1194 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1195
1196 set_emss(ep, ntohs(req->tcp_opt));
1197
1198 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001199 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001201 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202
1203 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301204 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301205 if (ret)
1206 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301207 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301208 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301209 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301210 ret = send_mpa_req(ep, skb, mpa_rev);
1211 if (ret)
1212 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301213 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001214 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301215err:
1216 mutex_unlock(&ep->com.mutex);
1217 connect_reply_upcall(ep, -ENOMEM);
1218 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1219 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001220}
1221
Steve Wisebe13b2d2014-03-21 20:40:33 +05301222static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001223{
1224 struct iw_cm_event event;
1225
1226 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1227 memset(&event, 0, sizeof(event));
1228 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301229 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001230 if (ep->com.cm_id) {
1231 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1232 ep, ep->com.cm_id, ep->hwtid);
1233 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301234 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001235 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001236 }
1237}
1238
Steve Wisecfdda9d2010-04-21 15:30:06 -07001239static void peer_close_upcall(struct c4iw_ep *ep)
1240{
1241 struct iw_cm_event event;
1242
1243 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1244 memset(&event, 0, sizeof(event));
1245 event.event = IW_CM_EVENT_DISCONNECT;
1246 if (ep->com.cm_id) {
1247 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1248 ep, ep->com.cm_id, ep->hwtid);
1249 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001250 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001251 }
1252}
1253
1254static void peer_abort_upcall(struct c4iw_ep *ep)
1255{
1256 struct iw_cm_event event;
1257
1258 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1259 memset(&event, 0, sizeof(event));
1260 event.event = IW_CM_EVENT_CLOSE;
1261 event.status = -ECONNRESET;
1262 if (ep->com.cm_id) {
1263 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1264 ep->com.cm_id, ep->hwtid);
1265 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301266 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001267 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001268 }
1269}
1270
1271static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1272{
1273 struct iw_cm_event event;
1274
1275 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1276 memset(&event, 0, sizeof(event));
1277 event.event = IW_CM_EVENT_CONNECT_REPLY;
1278 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301279 memcpy(&event.local_addr, &ep->com.local_addr,
1280 sizeof(ep->com.local_addr));
1281 memcpy(&event.remote_addr, &ep->com.remote_addr,
1282 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001283
1284 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301285 if (!ep->tried_with_mpa_v1) {
1286 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301287 event.ord = ep->ird;
1288 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301289 event.private_data_len = ep->plen -
1290 sizeof(struct mpa_v2_conn_params);
1291 event.private_data = ep->mpa_pkt +
1292 sizeof(struct mpa_message) +
1293 sizeof(struct mpa_v2_conn_params);
1294 } else {
1295 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301296 event.ord = cur_max_read_depth(ep->com.dev);
1297 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301298 event.private_data_len = ep->plen;
1299 event.private_data = ep->mpa_pkt +
1300 sizeof(struct mpa_message);
1301 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001302 }
Roland Dreier85963e42010-07-19 13:13:09 -07001303
1304 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1305 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001306 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001307 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1308
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301309 if (status < 0)
1310 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001311}
1312
Steve Wisebe13b2d2014-03-21 20:40:33 +05301313static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001314{
1315 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301316 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001317
1318 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1319 memset(&event, 0, sizeof(event));
1320 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301321 memcpy(&event.local_addr, &ep->com.local_addr,
1322 sizeof(ep->com.local_addr));
1323 memcpy(&event.remote_addr, &ep->com.remote_addr,
1324 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001325 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301326 if (!ep->tried_with_mpa_v1) {
1327 /* this means MPA_v2 is used */
1328 event.ord = ep->ord;
1329 event.ird = ep->ird;
1330 event.private_data_len = ep->plen -
1331 sizeof(struct mpa_v2_conn_params);
1332 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1333 sizeof(struct mpa_v2_conn_params);
1334 } else {
1335 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301336 event.ord = cur_max_read_depth(ep->com.dev);
1337 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301338 event.private_data_len = ep->plen;
1339 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1340 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301341 c4iw_get_ep(&ep->com);
1342 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1343 &event);
1344 if (ret)
1345 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001346 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001347 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301348 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001349}
1350
1351static void established_upcall(struct c4iw_ep *ep)
1352{
1353 struct iw_cm_event event;
1354
1355 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1356 memset(&event, 0, sizeof(event));
1357 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301358 event.ird = ep->ord;
1359 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001360 if (ep->com.cm_id) {
1361 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1362 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001363 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001364 }
1365}
1366
1367static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1368{
1369 struct cpl_rx_data_ack *req;
1370 struct sk_buff *skb;
1371 int wrlen = roundup(sizeof *req, 16);
1372
1373 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1374 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1375 if (!skb) {
1376 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1377 return 0;
1378 }
1379
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301380 /*
1381 * If we couldn't specify the entire rcv window at connection setup
1382 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1383 * then add the overage in to the credits returned.
1384 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001385 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1386 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301387
Steve Wisecfdda9d2010-04-21 15:30:06 -07001388 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1389 memset(req, 0, wrlen);
1390 INIT_TP_WR(req, ep->hwtid);
1391 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1392 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001393 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301394 RX_DACK_CHANGE_F |
1395 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001396 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001397 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1398 return credits;
1399}
1400
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301401#define RELAXED_IRD_NEGOTIATION 1
1402
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301403/*
1404 * process_mpa_reply - process streaming mode MPA reply
1405 *
1406 * Returns:
1407 *
1408 * 0 upon success indicating a connect request was delivered to the ULP
1409 * or the mpa request is incomplete but valid so far.
1410 *
1411 * 1 if a failure requires the caller to close the connection.
1412 *
1413 * 2 if a failure requires the caller to abort the connection.
1414 */
Steve Wisecc18b932014-04-24 14:31:53 -05001415static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001416{
1417 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301418 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001419 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301420 u16 resp_ird, resp_ord;
1421 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001422 struct c4iw_qp_attributes attrs;
1423 enum c4iw_qp_attr_mask mask;
1424 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001425 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001426
1427 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1428
1429 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430 * If we get more than the supported amount of private data
1431 * then we must fail this connection.
1432 */
1433 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1434 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301435 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001436 }
1437
1438 /*
1439 * copy the new data into our accumulation buffer.
1440 */
1441 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1442 skb->len);
1443 ep->mpa_pkt_len += skb->len;
1444
1445 /*
1446 * if we don't even have the mpa message, then bail.
1447 */
1448 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001449 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001450 mpa = (struct mpa_message *) ep->mpa_pkt;
1451
1452 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301453 if (mpa->revision > mpa_rev) {
1454 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1455 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001456 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301457 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001458 }
1459 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1460 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301461 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001462 }
1463
1464 plen = ntohs(mpa->private_data_size);
1465
1466 /*
1467 * Fail if there's too much private data.
1468 */
1469 if (plen > MPA_MAX_PRIVATE_DATA) {
1470 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301471 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001472 }
1473
1474 /*
1475 * If plen does not account for pkt size
1476 */
1477 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1478 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301479 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001480 }
1481
1482 ep->plen = (u8) plen;
1483
1484 /*
1485 * If we don't have all the pdata yet, then bail.
1486 * We'll continue process when more data arrives.
1487 */
1488 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001489 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001490
1491 if (mpa->flags & MPA_REJECT) {
1492 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301493 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001494 }
1495
1496 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301497 * Stop mpa timer. If it expired, then
1498 * we ignore the MPA reply. process_timeout()
1499 * will abort the connection.
1500 */
1501 if (stop_ep_timer(ep))
1502 return 0;
1503
1504 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001505 * If we get here we have accumulated the entire mpa
1506 * start reply message including private data. And
1507 * the MPA header is valid.
1508 */
Steve Wisec529fb52014-03-21 20:40:37 +05301509 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001511 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301512 ep->mpa_attr.version = mpa->revision;
1513 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1514
1515 if (mpa->revision == 2) {
1516 ep->mpa_attr.enhanced_rdma_conn =
1517 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1518 if (ep->mpa_attr.enhanced_rdma_conn) {
1519 mpa_v2_params = (struct mpa_v2_conn_params *)
1520 (ep->mpa_pkt + sizeof(*mpa));
1521 resp_ird = ntohs(mpa_v2_params->ird) &
1522 MPA_V2_IRD_ORD_MASK;
1523 resp_ord = ntohs(mpa_v2_params->ord) &
1524 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301525 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1526 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301527
1528 /*
1529 * This is a double-check. Ideally, below checks are
1530 * not required since ird/ord stuff has been taken
1531 * care of in c4iw_accept_cr
1532 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301533 if (ep->ird < resp_ord) {
1534 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1535 ep->com.dev->rdev.lldi.max_ordird_qp)
1536 ep->ird = resp_ord;
1537 else
1538 insuff_ird = 1;
1539 } else if (ep->ird > resp_ord) {
1540 ep->ird = resp_ord;
1541 }
1542 if (ep->ord > resp_ird) {
1543 if (RELAXED_IRD_NEGOTIATION)
1544 ep->ord = resp_ird;
1545 else
1546 insuff_ird = 1;
1547 }
1548 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301549 err = -ENOMEM;
1550 ep->ird = resp_ord;
1551 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301552 }
1553
1554 if (ntohs(mpa_v2_params->ird) &
1555 MPA_V2_PEER2PEER_MODEL) {
1556 if (ntohs(mpa_v2_params->ord) &
1557 MPA_V2_RDMA_WRITE_RTR)
1558 ep->mpa_attr.p2p_type =
1559 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1560 else if (ntohs(mpa_v2_params->ord) &
1561 MPA_V2_RDMA_READ_RTR)
1562 ep->mpa_attr.p2p_type =
1563 FW_RI_INIT_P2PTYPE_READ_REQ;
1564 }
1565 }
1566 } else if (mpa->revision == 1)
1567 if (peer2peer)
1568 ep->mpa_attr.p2p_type = p2p_type;
1569
Steve Wisecfdda9d2010-04-21 15:30:06 -07001570 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301571 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1572 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1573 ep->mpa_attr.recv_marker_enabled,
1574 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1575 ep->mpa_attr.p2p_type, p2p_type);
1576
1577 /*
1578 * If responder's RTR does not match with that of initiator, assign
1579 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1580 * generated when moving QP to RTS state.
1581 * A TERM message will be sent after QP has moved to RTS state
1582 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001583 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301584 (ep->mpa_attr.p2p_type != p2p_type)) {
1585 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1586 rtr_mismatch = 1;
1587 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001588
1589 attrs.mpa_attr = ep->mpa_attr;
1590 attrs.max_ird = ep->ird;
1591 attrs.max_ord = ep->ord;
1592 attrs.llp_stream_handle = ep;
1593 attrs.next_state = C4IW_QP_STATE_RTS;
1594
1595 mask = C4IW_QP_ATTR_NEXT_STATE |
1596 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1597 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1598
1599 /* bind QP and TID with INIT_WR */
1600 err = c4iw_modify_qp(ep->com.qp->rhp,
1601 ep->com.qp, mask, &attrs, 1);
1602 if (err)
1603 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301604
1605 /*
1606 * If responder's RTR requirement did not match with what initiator
1607 * supports, generate TERM message
1608 */
1609 if (rtr_mismatch) {
1610 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1611 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1612 attrs.ecode = MPA_NOMATCH_RTR;
1613 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001614 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301615 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001616 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301617 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001618 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 goto out;
1620 }
1621
1622 /*
1623 * Generate TERM if initiator IRD is not sufficient for responder
1624 * provided ORD. Currently, we do the same behaviour even when
1625 * responder provided IRD is also not sufficient as regards to
1626 * initiator ORD.
1627 */
1628 if (insuff_ird) {
1629 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1630 __func__);
1631 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1632 attrs.ecode = MPA_INSUFF_IRD;
1633 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001634 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301635 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001636 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301637 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001638 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301639 goto out;
1640 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001641 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301642err_stop_timer:
1643 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001644err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301645 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001646out:
1647 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001648 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001649}
1650
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301651/*
1652 * process_mpa_request - process streaming mode MPA request
1653 *
1654 * Returns:
1655 *
1656 * 0 upon success indicating a connect request was delivered to the ULP
1657 * or the mpa request is incomplete but valid so far.
1658 *
1659 * 1 if a failure requires the caller to close the connection.
1660 *
1661 * 2 if a failure requires the caller to abort the connection.
1662 */
1663static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001664{
1665 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301666 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001667 u16 plen;
1668
1669 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1670
Steve Wisecfdda9d2010-04-21 15:30:06 -07001671 /*
1672 * If we get more than the supported amount of private data
1673 * then we must fail this connection.
1674 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301675 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1676 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001677
1678 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1679
1680 /*
1681 * Copy the new data into our accumulation buffer.
1682 */
1683 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1684 skb->len);
1685 ep->mpa_pkt_len += skb->len;
1686
1687 /*
1688 * If we don't even have the mpa message, then bail.
1689 * We'll continue process when more data arrives.
1690 */
1691 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301692 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001693
1694 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001695 mpa = (struct mpa_message *) ep->mpa_pkt;
1696
1697 /*
1698 * Validate MPA Header.
1699 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301700 if (mpa->revision > mpa_rev) {
1701 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1702 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301703 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001704 }
1705
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301706 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1707 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001708
1709 plen = ntohs(mpa->private_data_size);
1710
1711 /*
1712 * Fail if there's too much private data.
1713 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301714 if (plen > MPA_MAX_PRIVATE_DATA)
1715 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001716
1717 /*
1718 * If plen does not account for pkt size
1719 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301720 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1721 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001722 ep->plen = (u8) plen;
1723
1724 /*
1725 * If we don't have all the pdata yet, then bail.
1726 */
1727 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301728 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001729
1730 /*
1731 * If we get here we have accumulated the entire mpa
1732 * start reply message including private data.
1733 */
1734 ep->mpa_attr.initiator = 0;
1735 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1736 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1737 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301738 ep->mpa_attr.version = mpa->revision;
1739 if (mpa->revision == 1)
1740 ep->tried_with_mpa_v1 = 1;
1741 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1742
1743 if (mpa->revision == 2) {
1744 ep->mpa_attr.enhanced_rdma_conn =
1745 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1746 if (ep->mpa_attr.enhanced_rdma_conn) {
1747 mpa_v2_params = (struct mpa_v2_conn_params *)
1748 (ep->mpa_pkt + sizeof(*mpa));
1749 ep->ird = ntohs(mpa_v2_params->ird) &
1750 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001751 ep->ird = min_t(u32, ep->ird,
1752 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301753 ep->ord = ntohs(mpa_v2_params->ord) &
1754 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001755 ep->ord = min_t(u32, ep->ord,
1756 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301757 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1758 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301759 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1760 if (peer2peer) {
1761 if (ntohs(mpa_v2_params->ord) &
1762 MPA_V2_RDMA_WRITE_RTR)
1763 ep->mpa_attr.p2p_type =
1764 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1765 else if (ntohs(mpa_v2_params->ord) &
1766 MPA_V2_RDMA_READ_RTR)
1767 ep->mpa_attr.p2p_type =
1768 FW_RI_INIT_P2PTYPE_READ_REQ;
1769 }
1770 }
1771 } else if (mpa->revision == 1)
1772 if (peer2peer)
1773 ep->mpa_attr.p2p_type = p2p_type;
1774
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1776 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1777 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1778 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1779 ep->mpa_attr.p2p_type);
1780
Hariprasad Se4b76a22016-05-06 22:17:59 +05301781 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001782
Hariprasad Se4b76a22016-05-06 22:17:59 +05301783 /* drive upcall */
1784 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1785 if (ep->parent_ep->com.state != DEAD) {
1786 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301787 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301788 } else {
1789 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301790 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301791 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301792 return 0;
1793
1794err_unlock_parent:
1795 mutex_unlock(&ep->parent_ep->com.mutex);
1796 goto err_out;
1797err_stop_timer:
1798 (void)stop_ep_timer(ep);
1799err_out:
1800 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801}
1802
1803static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1804{
1805 struct c4iw_ep *ep;
1806 struct cpl_rx_data *hdr = cplhdr(skb);
1807 unsigned int dlen = ntohs(hdr->len);
1808 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001809 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001810 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001811
Hariprasad S944661d2016-05-06 22:18:03 +05301812 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301813 if (!ep)
1814 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1816 skb_pull(skb, sizeof(*hdr));
1817 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301818 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001819
Steve Wisecfdda9d2010-04-21 15:30:06 -07001820 /* update RX credits */
1821 update_rx_credits(ep, dlen);
1822
Steve Wisec529fb52014-03-21 20:40:37 +05301823 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001824 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001825 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001826 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001827 break;
1828 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001829 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301830 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001831 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001832 case FPDU_MODE: {
1833 struct c4iw_qp_attributes attrs;
1834 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001835 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001836 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001837 " qpid %u ep %p state %d tid %u status %d\n",
1838 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301839 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301840 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001841 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001842 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1843 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001844 break;
1845 }
Vipul Pandya15579672013-01-07 13:11:52 +00001846 default:
1847 break;
1848 }
Steve Wisec529fb52014-03-21 20:40:37 +05301849 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001850 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301851 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301852 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001853 return 0;
1854}
1855
1856static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1857{
1858 struct c4iw_ep *ep;
1859 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001860 int release = 0;
1861 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001862
Hariprasad S944661d2016-05-06 22:18:03 +05301863 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301864 if (!ep) {
1865 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1866 return 0;
1867 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001868 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001869 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001870 switch (ep->com.state) {
1871 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001872 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873 __state_set(&ep->com, DEAD);
1874 release = 1;
1875 break;
1876 default:
1877 printk(KERN_ERR "%s ep %p state %d\n",
1878 __func__, ep, ep->com.state);
1879 break;
1880 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001881 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001882
1883 if (release)
1884 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301885 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001886 return 0;
1887}
1888
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301889static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001890{
1891 struct sk_buff *skb;
1892 struct fw_ofld_connection_wr *req;
1893 unsigned int mtu_idx;
Varun Prakashcc516702016-09-13 21:24:01 +05301894 u32 wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301895 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301896 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001897
1898 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1899 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1900 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001901 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301902 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301903 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1904 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001905 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001906 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301907 req->le.lport = sin->sin_port;
1908 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001909 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301910 req->le.pport = sin->sin_port;
1911 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001912 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301913 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1914 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001915 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301916 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001917 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001918 req->tcb.rcv_adv = htons(1);
Varun Prakash44c6d062016-09-13 21:24:00 +05301919 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
1920 enable_tcp_timestamps,
1921 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05301922 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301923
1924 /*
1925 * Specify the largest window that will fit in opt0. The
1926 * remainder will be specified in the rx_data_ack.
1927 */
1928 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001929 if (win > RCV_BUFSIZ_M)
1930 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301931
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001932 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1933 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001934 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001935 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001936 WND_SCALE_V(wscale) |
1937 MSS_IDX_V(mtu_idx) |
1938 L2T_IDX_V(ep->l2t->idx) |
1939 TX_CHAN_V(ep->tx_chan) |
1940 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301941 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001942 ULP_MODE_V(ULP_MODE_TCPDDP) |
1943 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001944 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1945 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001946 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001947 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001948 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001949 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001950 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001951 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001952 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001953 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001954 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1955 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1956 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001957 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1958 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301959 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001960}
1961
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301963 * Some of the error codes above implicitly indicate that there is no TID
1964 * allocated with the result of an ACT_OPEN. We use this predicate to make
1965 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001966 */
1967static inline int act_open_has_tid(int status)
1968{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301969 return (status != CPL_ERR_TCAM_PARITY &&
1970 status != CPL_ERR_TCAM_MISS &&
1971 status != CPL_ERR_TCAM_FULL &&
1972 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1973 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001974}
1975
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301976static char *neg_adv_str(unsigned int status)
1977{
1978 switch (status) {
1979 case CPL_ERR_RTX_NEG_ADVICE:
1980 return "Retransmit timeout";
1981 case CPL_ERR_PERSIST_NEG_ADVICE:
1982 return "Persist timeout";
1983 case CPL_ERR_KEEPALV_NEG_ADVICE:
1984 return "Keepalive timeout";
1985 default:
1986 return "Unknown";
1987 }
1988}
1989
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301990static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1991{
1992 ep->snd_win = snd_win;
1993 ep->rcv_win = rcv_win;
1994 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1995}
1996
Vipul Pandya793dad92012-12-10 09:30:56 +00001997#define ACT_OPEN_RETRY_COUNT 2
1998
Vipul Pandya830662f2013-07-04 16:10:47 +05301999static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2000 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302001 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302002{
2003 struct neighbour *n;
2004 int err, step;
2005 struct net_device *pdev;
2006
2007 n = dst_neigh_lookup(dst, peer_ip);
2008 if (!n)
2009 return -ENODEV;
2010
2011 rcu_read_lock();
2012 err = -ENOMEM;
2013 if (n->dev->flags & IFF_LOOPBACK) {
2014 if (iptype == 4)
2015 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2016 else if (IS_ENABLED(CONFIG_IPV6))
2017 for_each_netdev(&init_net, pdev) {
2018 if (ipv6_chk_addr(&init_net,
2019 (struct in6_addr *)peer_ip,
2020 pdev, 1))
2021 break;
2022 }
2023 else
2024 pdev = NULL;
2025
2026 if (!pdev) {
2027 err = -ENODEV;
2028 goto out;
2029 }
2030 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302031 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302032 if (!ep->l2t)
2033 goto out;
2034 ep->mtu = pdev->mtu;
2035 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302036 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2037 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302038 step = cdev->rdev.lldi.ntxq /
2039 cdev->rdev.lldi.nchan;
2040 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2041 step = cdev->rdev.lldi.nrxq /
2042 cdev->rdev.lldi.nchan;
2043 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2044 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2045 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302046 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302047 dev_put(pdev);
2048 } else {
2049 pdev = get_real_dev(n->dev);
2050 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2051 n, pdev, 0);
2052 if (!ep->l2t)
2053 goto out;
2054 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002055 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302056 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2057 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302058 step = cdev->rdev.lldi.ntxq /
2059 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002060 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2061 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302062 step = cdev->rdev.lldi.nrxq /
2063 cdev->rdev.lldi.nchan;
2064 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002065 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302066 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302067
2068 if (clear_mpa_v1) {
2069 ep->retry_with_mpa_v1 = 0;
2070 ep->tried_with_mpa_v1 = 0;
2071 }
2072 }
2073 err = 0;
2074out:
2075 rcu_read_unlock();
2076
2077 neigh_release(n);
2078
2079 return err;
2080}
2081
Vipul Pandya793dad92012-12-10 09:30:56 +00002082static int c4iw_reconnect(struct c4iw_ep *ep)
2083{
2084 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302085 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302086 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002087 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302088 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002089 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302090 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002091 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302092 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002093 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302094 int iptype;
2095 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002096
2097 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2098 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302099 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002100
Hariprasad S4a740832016-06-10 01:05:15 +05302101 /* When MPA revision is different on nodes, the node with MPA_rev=2
2102 * tries to reconnect with MPA_rev 1 for the same EP through
2103 * c4iw_reconnect(), where the same EP is assigned with new tid for
2104 * further connection establishment. As we are using the same EP pointer
2105 * for reconnect, few skbs are used during the previous c4iw_connect(),
2106 * which leaves the EP with inadequate skbs for further
2107 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2108 * skb_list() during peer_abort(). Allocate skbs which is already used.
2109 */
2110 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2111 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2112 err = -ENOMEM;
2113 goto fail1;
2114 }
2115
Vipul Pandya793dad92012-12-10 09:30:56 +00002116 /*
2117 * Allocate an active TID to initiate a TCP connection.
2118 */
2119 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2120 if (ep->atid == -1) {
2121 pr_err("%s - cannot alloc atid.\n", __func__);
2122 err = -ENOMEM;
2123 goto fail2;
2124 }
2125 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2126
2127 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002128 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302129 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2130 laddr->sin_addr.s_addr,
2131 raddr->sin_addr.s_addr,
2132 laddr->sin_port,
2133 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302134 iptype = 4;
2135 ra = (__u8 *)&raddr->sin_addr;
2136 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302137 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2138 get_real_dev,
2139 laddr6->sin6_addr.s6_addr,
2140 raddr6->sin6_addr.s6_addr,
2141 laddr6->sin6_port,
2142 raddr6->sin6_port, 0,
2143 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302144 iptype = 6;
2145 ra = (__u8 *)&raddr6->sin6_addr;
2146 }
2147 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002148 pr_err("%s - cannot find route.\n", __func__);
2149 err = -EHOSTUNREACH;
2150 goto fail3;
2151 }
Hariprasad S963cab52015-09-23 17:19:27 +05302152 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302153 ep->com.dev->rdev.lldi.adapter_type,
2154 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302155 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002156 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002157 goto fail4;
2158 }
2159
2160 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2161 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2162 ep->l2t->idx);
2163
2164 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302165 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002166
2167 /* send connect request to rnic */
2168 err = send_connect(ep);
2169 if (!err)
2170 goto out;
2171
2172 cxgb4_l2t_release(ep->l2t);
2173fail4:
2174 dst_release(ep->dst);
2175fail3:
2176 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2177 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2178fail2:
2179 /*
2180 * remember to send notification to upper layer.
2181 * We are in here so the upper layer is not aware that this is
2182 * re-connect attempt and so, upper layer is still waiting for
2183 * response of 1st connect request.
2184 */
2185 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302186fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002187 c4iw_put_ep(&ep->com);
2188out:
2189 return err;
2190}
2191
Steve Wisecfdda9d2010-04-21 15:30:06 -07002192static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2193{
2194 struct c4iw_ep *ep;
2195 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002196 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2197 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002198 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002199 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302200 struct sockaddr_in *la;
2201 struct sockaddr_in *ra;
2202 struct sockaddr_in6 *la6;
2203 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302204 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002205
2206 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002207 la = (struct sockaddr_in *)&ep->com.local_addr;
2208 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2209 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2210 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002211
2212 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2213 status, status2errno(status));
2214
Varun Prakashb65eef02016-09-13 21:23:59 +05302215 if (cxgb_is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302216 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2217 __func__, atid, status, neg_adv_str(status));
2218 ep->stats.connect_neg_adv++;
2219 mutex_lock(&dev->rdev.stats.lock);
2220 dev->rdev.stats.neg_adv++;
2221 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002222 return 0;
2223 }
2224
Vipul Pandya793dad92012-12-10 09:30:56 +00002225 set_bit(ACT_OPEN_RPL, &ep->com.history);
2226
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302227 /*
2228 * Log interesting failures.
2229 */
2230 switch (status) {
2231 case CPL_ERR_CONN_RESET:
2232 case CPL_ERR_CONN_TIMEDOUT:
2233 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002234 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302235 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002236 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302237 mutex_unlock(&dev->rdev.stats.lock);
2238 if (ep->com.local_addr.ss_family == AF_INET &&
2239 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302240 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2241 ntohl(rpl->atid_status))));
2242 if (ret)
2243 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002244 return 0;
2245 }
2246 break;
2247 case CPL_ERR_CONN_EXIST:
2248 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2249 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302250 if (ep->com.remote_addr.ss_family == AF_INET6) {
2251 struct sockaddr_in6 *sin6 =
2252 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002253 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302254 cxgb4_clip_release(
2255 ep->com.dev->rdev.lldi.ports[0],
2256 (const u32 *)
2257 &sin6->sin6_addr.s6_addr, 1);
2258 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002259 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2260 atid);
2261 cxgb4_free_atid(t, atid);
2262 dst_release(ep->dst);
2263 cxgb4_l2t_release(ep->l2t);
2264 c4iw_reconnect(ep);
2265 return 0;
2266 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002267 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302268 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302269 if (ep->com.local_addr.ss_family == AF_INET) {
2270 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2271 atid, status, status2errno(status),
2272 &la->sin_addr.s_addr, ntohs(la->sin_port),
2273 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2274 } else {
2275 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2276 atid, status, status2errno(status),
2277 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2278 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2279 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302280 break;
2281 }
2282
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302283fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002284 connect_reply_upcall(ep, status2errno(status));
2285 state_set(&ep->com, DEAD);
2286
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302287 if (ep->com.remote_addr.ss_family == AF_INET6) {
2288 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002289 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302290 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2291 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2292 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002293 if (status && act_open_has_tid(status))
2294 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2295
Vipul Pandya793dad92012-12-10 09:30:56 +00002296 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002297 cxgb4_free_atid(t, atid);
2298 dst_release(ep->dst);
2299 cxgb4_l2t_release(ep->l2t);
2300 c4iw_put_ep(&ep->com);
2301
2302 return 0;
2303}
2304
2305static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2306{
2307 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302309 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002310
2311 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002312 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2313 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002314 }
2315 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2316 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002317 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302318 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002319out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 return 0;
2321}
2322
Steve Wisecfdda9d2010-04-21 15:30:06 -07002323static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2324{
2325 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002326 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302327 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002328
2329 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002330 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302331 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002332 return 0;
2333}
2334
Hariprasad S9dec9002016-05-05 01:27:29 +05302335static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2336 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002337{
2338 struct cpl_pass_accept_rpl *rpl;
2339 unsigned int mtu_idx;
2340 u64 opt0;
2341 u32 opt2;
Varun Prakashcc516702016-09-13 21:24:01 +05302342 u32 wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302343 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302344 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302345 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346
2347 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2348 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302349
Steve Wisecfdda9d2010-04-21 15:30:06 -07002350 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302351 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302352 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302353 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2354 rpl5 = (void *)rpl;
2355 INIT_TP_WR(rpl5, ep->hwtid);
2356 } else {
2357 skb_trim(skb, sizeof(*rpl));
2358 INIT_TP_WR(rpl, ep->hwtid);
2359 }
2360 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2361 ep->hwtid));
2362
Varun Prakash44c6d062016-09-13 21:24:00 +05302363 cxgb_best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
2364 enable_tcp_timestamps && req->tcpopt.tstamp,
2365 (ep->com.remote_addr.ss_family == AF_INET) ? 0 : 1);
Varun Prakashcc516702016-09-13 21:24:01 +05302366 wscale = cxgb_compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302367
2368 /*
2369 * Specify the largest window that will fit in opt0. The
2370 * remainder will be specified in the rx_data_ack.
2371 */
2372 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002373 if (win > RCV_BUFSIZ_M)
2374 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002375 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002376 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002377 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002378 WND_SCALE_V(wscale) |
2379 MSS_IDX_V(mtu_idx) |
2380 L2T_IDX_V(ep->l2t->idx) |
2381 TX_CHAN_V(ep->tx_chan) |
2382 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002383 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002384 ULP_MODE_V(ULP_MODE_TCPDDP) |
2385 RCV_BUFSIZ_V(win);
2386 opt2 = RX_CHANNEL_V(0) |
2387 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388
2389 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002390 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002391 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002392 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002393 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002394 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002395 if (enable_ecn) {
2396 const struct tcphdr *tcph;
2397 u32 hlen = ntohl(req->hdr_len);
2398
Hariprasad S963cab52015-09-23 17:19:27 +05302399 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2400 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2401 IP_HDR_LEN_G(hlen);
2402 else
2403 tcph = (const void *)(req + 1) +
2404 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002405 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002406 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002407 }
Hariprasad S963cab52015-09-23 17:19:27 +05302408 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302409 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002410 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302411 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302412 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302413 rpl5 = (void *)rpl;
2414 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2415 if (peer2peer)
2416 isn += 4;
2417 rpl5->iss = cpu_to_be32(isn);
2418 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002419 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421 rpl->opt0 = cpu_to_be64(opt0);
2422 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002423 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302424 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002425
Hariprasad S9dec9002016-05-05 01:27:29 +05302426 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002427}
2428
Vipul Pandya830662f2013-07-04 16:10:47 +05302429static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430{
Vipul Pandya830662f2013-07-04 16:10:47 +05302431 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002432 BUG_ON(skb_cloned(skb));
2433 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 release_tid(&dev->rdev, hwtid, skb);
2435 return;
2436}
2437
Steve Wisecfdda9d2010-04-21 15:30:06 -07002438static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2439{
Vipul Pandya793dad92012-12-10 09:30:56 +00002440 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002442 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443 struct tid_info *t = dev->rdev.lldi.tids;
2444 unsigned int hwtid = GET_TID(req);
2445 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302446 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002447 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302448 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002449 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002450 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302451 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302452 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302453 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002454
Hariprasad Sf86fac72016-05-06 22:18:07 +05302455 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002456 if (!parent_ep) {
2457 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2458 goto reject;
2459 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002460
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302462 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002463 goto reject;
2464 }
2465
Varun Prakash85e42b02016-09-13 21:23:56 +05302466 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2467 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302468
Steve Wisecfdda9d2010-04-21 15:30:06 -07002469 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302470 if (iptype == 4) {
2471 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2472 , __func__, parent_ep, hwtid,
2473 local_ip, peer_ip, ntohs(local_port),
2474 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302475 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2476 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2477 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302478 } else {
2479 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2480 , __func__, parent_ep, hwtid,
2481 local_ip, peer_ip, ntohs(local_port),
2482 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302483 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2484 local_ip, peer_ip, local_port, peer_port,
2485 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2486 ((struct sockaddr_in6 *)
2487 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302488 }
2489 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2491 __func__);
2492 goto reject;
2493 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002494
2495 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2496 if (!child_ep) {
2497 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2498 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002499 dst_release(dst);
2500 goto reject;
2501 }
David Miller3786cf12011-12-02 16:52:31 +00002502
Hariprasad S963cab52015-09-23 17:19:27 +05302503 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302504 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002505 if (err) {
2506 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2507 __func__);
2508 dst_release(dst);
2509 kfree(child_ep);
2510 goto reject;
2511 }
2512
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302513 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2514 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2515 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2516 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002517
Hariprasad S4a740832016-06-10 01:05:15 +05302518 skb_queue_head_init(&child_ep->com.ep_skb_list);
2519 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2520 goto fail;
2521
Steve Wisecfdda9d2010-04-21 15:30:06 -07002522 state_set(&child_ep->com, CONNECTING);
2523 child_ep->com.dev = dev;
2524 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002525
Vipul Pandya830662f2013-07-04 16:10:47 +05302526 if (iptype == 4) {
2527 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002528 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002529
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 sin->sin_family = PF_INET;
2531 sin->sin_port = local_port;
2532 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002533
2534 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2535 sin->sin_family = PF_INET;
2536 sin->sin_port = ((struct sockaddr_in *)
2537 &parent_ep->com.local_addr)->sin_port;
2538 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2539
Steve Wise170003c2016-02-26 09:18:03 -06002540 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302541 sin->sin_family = PF_INET;
2542 sin->sin_port = peer_port;
2543 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2544 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002545 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302546 sin6->sin6_family = PF_INET6;
2547 sin6->sin6_port = local_port;
2548 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002549
2550 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2551 sin6->sin6_family = PF_INET6;
2552 sin6->sin6_port = ((struct sockaddr_in6 *)
2553 &parent_ep->com.local_addr)->sin6_port;
2554 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2555
Steve Wise170003c2016-02-26 09:18:03 -06002556 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302557 sin6->sin6_family = PF_INET6;
2558 sin6->sin6_port = peer_port;
2559 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2560 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002561
Steve Wisecfdda9d2010-04-21 15:30:06 -07002562 c4iw_get_ep(&parent_ep->com);
2563 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302564 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002565 child_ep->dst = dst;
2566 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002567
2568 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002569 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002570
2571 init_timer(&child_ep->timer);
2572 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302573 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302574 if (accept_cr(child_ep, skb, req)) {
2575 c4iw_put_ep(&parent_ep->com);
2576 release_ep_resources(child_ep);
2577 } else {
2578 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2579 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302580 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002581 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302582 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2583 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2584 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302586fail:
2587 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302589 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302590 if (parent_ep)
2591 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002592out:
2593 return 0;
2594}
2595
2596static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2597{
2598 struct c4iw_ep *ep;
2599 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002600 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302601 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602
Hariprasad S944661d2016-05-06 22:18:03 +05302603 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002604 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2605 ep->snd_seq = be32_to_cpu(req->snd_isn);
2606 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2607
Vipul Pandya1cab7752012-12-10 09:30:55 +00002608 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2609 ntohs(req->tcp_opt));
2610
Steve Wisecfdda9d2010-04-21 15:30:06 -07002611 set_emss(ep, ntohs(req->tcp_opt));
2612
2613 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302614 mutex_lock(&ep->com.mutex);
2615 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002617 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302618 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302619 mutex_unlock(&ep->com.mutex);
2620 if (ret)
2621 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302622 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623
2624 return 0;
2625}
2626
2627static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2628{
2629 struct cpl_peer_close *hdr = cplhdr(skb);
2630 struct c4iw_ep *ep;
2631 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002632 int disconnect = 1;
2633 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002635 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002636
Hariprasad S944661d2016-05-06 22:18:03 +05302637 ep = get_ep_from_tid(dev, tid);
2638 if (!ep)
2639 return 0;
2640
Steve Wisecfdda9d2010-04-21 15:30:06 -07002641 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2642 dst_confirm(ep->dst);
2643
Vipul Pandya793dad92012-12-10 09:30:56 +00002644 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002645 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 switch (ep->com.state) {
2647 case MPA_REQ_WAIT:
2648 __state_set(&ep->com, CLOSING);
2649 break;
2650 case MPA_REQ_SENT:
2651 __state_set(&ep->com, CLOSING);
2652 connect_reply_upcall(ep, -ECONNRESET);
2653 break;
2654 case MPA_REQ_RCVD:
2655
2656 /*
2657 * We're gonna mark this puppy DEAD, but keep
2658 * the reference on it until the ULP accepts or
2659 * rejects the CR. Also wake up anyone waiting
2660 * in rdma connection migration (see c4iw_accept_cr()).
2661 */
2662 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002664 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002665 break;
2666 case MPA_REP_SENT:
2667 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002669 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 break;
2671 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002672 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002673 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002674 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002675 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002676 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002677 if (ret != -ECONNRESET) {
2678 peer_close_upcall(ep);
2679 disconnect = 1;
2680 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002681 break;
2682 case ABORTING:
2683 disconnect = 0;
2684 break;
2685 case CLOSING:
2686 __state_set(&ep->com, MORIBUND);
2687 disconnect = 0;
2688 break;
2689 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002690 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 if (ep->com.cm_id && ep->com.qp) {
2692 attrs.next_state = C4IW_QP_STATE_IDLE;
2693 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2694 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2695 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302696 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002697 __state_set(&ep->com, DEAD);
2698 release = 1;
2699 disconnect = 0;
2700 break;
2701 case DEAD:
2702 disconnect = 0;
2703 break;
2704 default:
2705 BUG_ON(1);
2706 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002707 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002708 if (disconnect)
2709 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2710 if (release)
2711 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302712 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002713 return 0;
2714}
2715
Steve Wisecfdda9d2010-04-21 15:30:06 -07002716static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2717{
2718 struct cpl_abort_req_rss *req = cplhdr(skb);
2719 struct c4iw_ep *ep;
2720 struct cpl_abort_rpl *rpl;
2721 struct sk_buff *rpl_skb;
2722 struct c4iw_qp_attributes attrs;
2723 int ret;
2724 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002725 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002726
Hariprasad S944661d2016-05-06 22:18:03 +05302727 ep = get_ep_from_tid(dev, tid);
2728 if (!ep)
2729 return 0;
2730
Varun Prakashb65eef02016-09-13 21:23:59 +05302731 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302732 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2733 __func__, ep->hwtid, req->status,
2734 neg_adv_str(req->status));
2735 ep->stats.abort_neg_adv++;
2736 mutex_lock(&dev->rdev.stats.lock);
2737 dev->rdev.stats.neg_adv++;
2738 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302739 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002741 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2742 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002743 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002744
2745 /*
2746 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302747 * However, this is not needed if com state is just
2748 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002749 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302750 if (ep->com.state != MPA_REQ_SENT)
2751 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002752
2753 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 switch (ep->com.state) {
2755 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302756 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002757 break;
2758 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002759 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760 break;
2761 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002762 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002763 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302764 connect_reply_upcall(ep, -ECONNRESET);
2765 else {
2766 /*
2767 * we just don't send notification upwards because we
2768 * want to retry with mpa_v1 without upper layers even
2769 * knowing it.
2770 *
2771 * do some housekeeping so as to re-initiate the
2772 * connection
2773 */
2774 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2775 mpa_rev);
2776 ep->retry_with_mpa_v1 = 1;
2777 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002778 break;
2779 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 break;
2781 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002782 break;
2783 case MORIBUND:
2784 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002785 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002786 /*FALLTHROUGH*/
2787 case FPDU_MODE:
2788 if (ep->com.cm_id && ep->com.qp) {
2789 attrs.next_state = C4IW_QP_STATE_ERROR;
2790 ret = c4iw_modify_qp(ep->com.qp->rhp,
2791 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2792 &attrs, 1);
2793 if (ret)
2794 printk(KERN_ERR MOD
2795 "%s - qp <- error failed!\n",
2796 __func__);
2797 }
2798 peer_abort_upcall(ep);
2799 break;
2800 case ABORTING:
2801 break;
2802 case DEAD:
2803 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002804 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302805 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002806 default:
2807 BUG_ON(1);
2808 break;
2809 }
2810 dst_confirm(ep->dst);
2811 if (ep->com.state != ABORTING) {
2812 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302813 /* we don't release if we want to retry with mpa_v1 */
2814 if (!ep->retry_with_mpa_v1)
2815 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002817 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002818
Hariprasad S4a740832016-06-10 01:05:15 +05302819 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2820 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002821 release = 1;
2822 goto out;
2823 }
2824 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2825 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2826 INIT_TP_WR(rpl, ep->hwtid);
2827 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2828 rpl->cmd = CPL_ABORT_NO_RST;
2829 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2830out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002831 if (release)
2832 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002833 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302834 if (ep->com.remote_addr.ss_family == AF_INET6) {
2835 struct sockaddr_in6 *sin6 =
2836 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002837 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302838 cxgb4_clip_release(
2839 ep->com.dev->rdev.lldi.ports[0],
2840 (const u32 *)&sin6->sin6_addr.s6_addr,
2841 1);
2842 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002843 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302844 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2845 dst_release(ep->dst);
2846 cxgb4_l2t_release(ep->l2t);
2847 c4iw_reconnect(ep);
2848 }
2849
Hariprasad S944661d2016-05-06 22:18:03 +05302850deref_ep:
2851 c4iw_put_ep(&ep->com);
2852 /* Dereferencing ep, referenced in peer_abort_intr() */
2853 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002854 return 0;
2855}
2856
2857static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2858{
2859 struct c4iw_ep *ep;
2860 struct c4iw_qp_attributes attrs;
2861 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002862 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002864
Hariprasad S944661d2016-05-06 22:18:03 +05302865 ep = get_ep_from_tid(dev, tid);
2866 if (!ep)
2867 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002868
2869 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2870 BUG_ON(!ep);
2871
2872 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002873 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302874 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002875 switch (ep->com.state) {
2876 case CLOSING:
2877 __state_set(&ep->com, MORIBUND);
2878 break;
2879 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002880 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002881 if ((ep->com.cm_id) && (ep->com.qp)) {
2882 attrs.next_state = C4IW_QP_STATE_IDLE;
2883 c4iw_modify_qp(ep->com.qp->rhp,
2884 ep->com.qp,
2885 C4IW_QP_ATTR_NEXT_STATE,
2886 &attrs, 1);
2887 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302888 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889 __state_set(&ep->com, DEAD);
2890 release = 1;
2891 break;
2892 case ABORTING:
2893 case DEAD:
2894 break;
2895 default:
2896 BUG_ON(1);
2897 break;
2898 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002899 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002900 if (release)
2901 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302902 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002903 return 0;
2904}
2905
2906static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2907{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002908 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002909 unsigned int tid = GET_TID(rpl);
2910 struct c4iw_ep *ep;
2911 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002912
Hariprasad S944661d2016-05-06 22:18:03 +05302913 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002914 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002915
Steve Wise30c95c22011-05-09 22:06:22 -07002916 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002917 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2918 ep->com.qp->wq.sq.qid);
2919 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2920 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2921 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2922 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002923 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302924 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002925
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926 return 0;
2927}
2928
2929/*
2930 * Upcall from the adapter indicating data has been transmitted.
2931 * For us its just the single MPA request or reply. We can now free
2932 * the skb holding the mpa message.
2933 */
2934static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2935{
2936 struct c4iw_ep *ep;
2937 struct cpl_fw4_ack *hdr = cplhdr(skb);
2938 u8 credits = hdr->credits;
2939 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002940
2941
Hariprasad S944661d2016-05-06 22:18:03 +05302942 ep = get_ep_from_tid(dev, tid);
2943 if (!ep)
2944 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002945 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2946 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002947 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2948 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302949 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002950 }
2951
2952 dst_confirm(ep->dst);
2953 if (ep->mpa_skb) {
2954 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2955 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2956 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002957 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002958 kfree_skb(ep->mpa_skb);
2959 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302960 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2961 stop_ep_timer(ep);
2962 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002963 }
Hariprasad S944661d2016-05-06 22:18:03 +05302964out:
2965 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002966 return 0;
2967}
2968
Steve Wisecfdda9d2010-04-21 15:30:06 -07002969int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2970{
Hariprasad Sbce28412016-06-10 01:05:13 +05302971 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302973
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2975
Steve Wisea7db89e2014-03-21 20:40:35 +05302976 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05302977 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05302978 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002979 c4iw_put_ep(&ep->com);
2980 return -ECONNRESET;
2981 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002982 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002983 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05302984 abort = 1;
2985 else
2986 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302987 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05302988
2989 stop_ep_timer(ep);
2990 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002991 c4iw_put_ep(&ep->com);
2992 return 0;
2993}
2994
2995int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2996{
2997 int err;
2998 struct c4iw_qp_attributes attrs;
2999 enum c4iw_qp_attr_mask mask;
3000 struct c4iw_ep *ep = to_ep(cm_id);
3001 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3002 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303003 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003004
3005 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303006
3007 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303008 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303010 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003011 }
3012
Steve Wisecfdda9d2010-04-21 15:30:06 -07003013 BUG_ON(!qp);
3014
Vipul Pandya793dad92012-12-10 09:30:56 +00003015 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303016 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3017 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003018 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303019 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003020 }
3021
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303022 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3023 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303024 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003025 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303026 } else {
3027 ep->ird = conn_param->ird;
3028 ep->ord = conn_param->ord;
3029 send_mpa_reject(ep, conn_param->private_data,
3030 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303031 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303032 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303033 }
3034 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303035 if (conn_param->ird < ep->ord) {
3036 if (RELAXED_IRD_NEGOTIATION &&
3037 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3038 conn_param->ird = ep->ord;
3039 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303040 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303041 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303042 }
3043 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303044 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003045 ep->ird = conn_param->ird;
3046 ep->ord = conn_param->ord;
3047
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303048 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303049 if (peer2peer && ep->ird == 0)
3050 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303051 } else {
3052 if (peer2peer &&
3053 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303054 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303055 ep->ird = 1;
3056 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003057
3058 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3059
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303060 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303061 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303062 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003063 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303064
Steve Wisecfdda9d2010-04-21 15:30:06 -07003065 /* bind QP to EP and move to RTS */
3066 attrs.mpa_attr = ep->mpa_attr;
3067 attrs.max_ird = ep->ird;
3068 attrs.max_ord = ep->ord;
3069 attrs.llp_stream_handle = ep;
3070 attrs.next_state = C4IW_QP_STATE_RTS;
3071
3072 /* bind QP and TID with INIT_WR */
3073 mask = C4IW_QP_ATTR_NEXT_STATE |
3074 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3075 C4IW_QP_ATTR_MPA_ATTR |
3076 C4IW_QP_ATTR_MAX_IRD |
3077 C4IW_QP_ATTR_MAX_ORD;
3078
3079 err = c4iw_modify_qp(ep->com.qp->rhp,
3080 ep->com.qp, mask, &attrs, 1);
3081 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303082 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303083
3084 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003085 err = send_mpa_reply(ep, conn_param->private_data,
3086 conn_param->private_data_len);
3087 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303088 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003089
Steve Wisea7db89e2014-03-21 20:40:35 +05303090 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003091 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303092 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003093 c4iw_put_ep(&ep->com);
3094 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303095err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303096 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303097err_abort:
3098 abort = 1;
3099err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303100 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303101 if (abort)
3102 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003103 c4iw_put_ep(&ep->com);
3104 return err;
3105}
3106
Vipul Pandya830662f2013-07-04 16:10:47 +05303107static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3108{
3109 struct in_device *ind;
3110 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003111 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3112 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303113
3114 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3115 if (!ind)
3116 return -EADDRNOTAVAIL;
3117 for_primary_ifa(ind) {
3118 laddr->sin_addr.s_addr = ifa->ifa_address;
3119 raddr->sin_addr.s_addr = ifa->ifa_address;
3120 found = 1;
3121 break;
3122 }
3123 endfor_ifa(ind);
3124 in_dev_put(ind);
3125 return found ? 0 : -EADDRNOTAVAIL;
3126}
3127
3128static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3129 unsigned char banned_flags)
3130{
3131 struct inet6_dev *idev;
3132 int err = -EADDRNOTAVAIL;
3133
3134 rcu_read_lock();
3135 idev = __in6_dev_get(dev);
3136 if (idev != NULL) {
3137 struct inet6_ifaddr *ifp;
3138
3139 read_lock_bh(&idev->lock);
3140 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3141 if (ifp->scope == IFA_LINK &&
3142 !(ifp->flags & banned_flags)) {
3143 memcpy(addr, &ifp->addr, 16);
3144 err = 0;
3145 break;
3146 }
3147 }
3148 read_unlock_bh(&idev->lock);
3149 }
3150 rcu_read_unlock();
3151 return err;
3152}
3153
3154static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3155{
3156 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003157 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3158 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303159
Nicholas Krause54b9a962015-08-26 23:00:59 -04003160 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303161 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3162 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3163 return 0;
3164 }
3165 return -EADDRNOTAVAIL;
3166}
3167
Steve Wisecfdda9d2010-04-21 15:30:06 -07003168int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3169{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003170 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3171 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003172 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003173 struct sockaddr_in *laddr;
3174 struct sockaddr_in *raddr;
3175 struct sockaddr_in6 *laddr6;
3176 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303177 __u8 *ra;
3178 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003179
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303180 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3181 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003182 err = -EINVAL;
3183 goto out;
3184 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003185 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3186 if (!ep) {
3187 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3188 err = -ENOMEM;
3189 goto out;
3190 }
Hariprasad S4a740832016-06-10 01:05:15 +05303191
3192 skb_queue_head_init(&ep->com.ep_skb_list);
3193 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3194 err = -ENOMEM;
3195 goto fail1;
3196 }
3197
Steve Wisecfdda9d2010-04-21 15:30:06 -07003198 init_timer(&ep->timer);
3199 ep->plen = conn_param->private_data_len;
3200 if (ep->plen)
3201 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3202 conn_param->private_data, ep->plen);
3203 ep->ird = conn_param->ird;
3204 ep->ord = conn_param->ord;
3205
3206 if (peer2peer && ep->ord == 0)
3207 ep->ord = 1;
3208
Steve Wisecfdda9d2010-04-21 15:30:06 -07003209 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303210 ref_cm_id(&ep->com);
3211 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003212 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303213 if (!ep->com.qp) {
3214 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3215 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303216 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303217 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003218 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003219 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3220 ep->com.qp, cm_id);
3221
3222 /*
3223 * Allocate an active TID to initiate a TCP connection.
3224 */
3225 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3226 if (ep->atid == -1) {
3227 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3228 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303229 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003230 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003231 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232
Steve Wise170003c2016-02-26 09:18:03 -06003233 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003234 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003235 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003236 sizeof(ep->com.remote_addr));
3237
Steve Wise170003c2016-02-26 09:18:03 -06003238 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3239 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3240 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3241 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003242
Steve Wise170003c2016-02-26 09:18:03 -06003243 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303244 iptype = 4;
3245 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003246
Vipul Pandya830662f2013-07-04 16:10:47 +05303247 /*
3248 * Handle loopback requests to INADDR_ANY.
3249 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003250 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303251 err = pick_local_ipaddrs(dev, cm_id);
3252 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303253 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303254 }
3255
3256 /* find a route */
3257 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3258 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3259 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303260 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3261 laddr->sin_addr.s_addr,
3262 raddr->sin_addr.s_addr,
3263 laddr->sin_port,
3264 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303265 } else {
3266 iptype = 6;
3267 ra = (__u8 *)&raddr6->sin6_addr;
3268
3269 /*
3270 * Handle loopback requests to INADDR_ANY.
3271 */
3272 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3273 err = pick_local_ip6addrs(dev, cm_id);
3274 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303275 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303276 }
3277
3278 /* find a route */
3279 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3280 __func__, laddr6->sin6_addr.s6_addr,
3281 ntohs(laddr6->sin6_port),
3282 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303283 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3284 laddr6->sin6_addr.s6_addr,
3285 raddr6->sin6_addr.s6_addr,
3286 laddr6->sin6_port,
3287 raddr6->sin6_port, 0,
3288 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303289 }
3290 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3292 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303293 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003294 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003295
Hariprasad S963cab52015-09-23 17:19:27 +05303296 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303297 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003298 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003299 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303300 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003301 }
3302
3303 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3304 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3305 ep->l2t->idx);
3306
3307 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303308 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003309
3310 /* send connect request to rnic */
3311 err = send_connect(ep);
3312 if (!err)
3313 goto out;
3314
3315 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303316fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003317 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303318fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003319 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003320 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303321fail2:
3322 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303323 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303324fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003325 c4iw_put_ep(&ep->com);
3326out:
3327 return err;
3328}
3329
Vipul Pandya830662f2013-07-04 16:10:47 +05303330static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3331{
3332 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003333 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003334 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303335
Hariprasad S28de1f72016-01-13 10:03:14 +05303336 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3337 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3338 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3339 if (err)
3340 return err;
3341 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303342 c4iw_init_wr_wait(&ep->com.wr_wait);
3343 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3344 ep->stid, &sin6->sin6_addr,
3345 sin6->sin6_port,
3346 ep->com.dev->rdev.lldi.rxq_ids[0]);
3347 if (!err)
3348 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3349 &ep->com.wr_wait,
3350 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303351 else if (err > 0)
3352 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303353 if (err) {
3354 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3355 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303356 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3357 err, ep->stid,
3358 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303359 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303360 return err;
3361}
3362
3363static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3364{
3365 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003366 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003367 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303368
3369 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3370 do {
3371 err = cxgb4_create_server_filter(
3372 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3373 sin->sin_addr.s_addr, sin->sin_port, 0,
3374 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3375 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303376 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3377 err = -EIO;
3378 break;
3379 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303380 set_current_state(TASK_UNINTERRUPTIBLE);
3381 schedule_timeout(usecs_to_jiffies(100));
3382 }
3383 } while (err == -EBUSY);
3384 } else {
3385 c4iw_init_wr_wait(&ep->com.wr_wait);
3386 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3387 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3388 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3389 if (!err)
3390 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3391 &ep->com.wr_wait,
3392 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303393 else if (err > 0)
3394 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303395 }
3396 if (err)
3397 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3398 , err, ep->stid,
3399 &sin->sin_addr, ntohs(sin->sin_port));
3400 return err;
3401}
3402
Steve Wisecfdda9d2010-04-21 15:30:06 -07003403int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3404{
3405 int err = 0;
3406 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3407 struct c4iw_listen_ep *ep;
3408
Steve Wisecfdda9d2010-04-21 15:30:06 -07003409 might_sleep();
3410
3411 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3412 if (!ep) {
3413 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3414 err = -ENOMEM;
3415 goto fail1;
3416 }
Hariprasad S4a740832016-06-10 01:05:15 +05303417 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003418 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003419 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303420 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003421 ep->com.dev = dev;
3422 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003423 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303424 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425
3426 /*
3427 * Allocate a server TID.
3428 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303429 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3430 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303431 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003432 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003433 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303434 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003435 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003436
Steve Wisecfdda9d2010-04-21 15:30:06 -07003437 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003438 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003439 err = -ENOMEM;
3440 goto fail2;
3441 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003442 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003443
Steve Wise170003c2016-02-26 09:18:03 -06003444 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3445 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003446
Steve Wisecfdda9d2010-04-21 15:30:06 -07003447 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303448 if (ep->com.local_addr.ss_family == AF_INET)
3449 err = create_server4(dev, ep);
3450 else
3451 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003452 if (!err) {
3453 cm_id->provider_data = ep;
3454 goto out;
3455 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003456
Vipul Pandya830662f2013-07-04 16:10:47 +05303457 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3458 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003459fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303460 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003461 c4iw_put_ep(&ep->com);
3462fail1:
3463out:
3464 return err;
3465}
3466
3467int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3468{
3469 int err;
3470 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3471
3472 PDBG("%s ep %p\n", __func__, ep);
3473
3474 might_sleep();
3475 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303476 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3477 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003478 err = cxgb4_remove_server_filter(
3479 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3480 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3481 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303482 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003483 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303484 err = cxgb4_remove_server(
3485 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3486 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003487 if (err)
3488 goto done;
3489 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3490 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003491 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303492 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3493 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003494 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003495 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303496 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3497 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303499 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003500 c4iw_put_ep(&ep->com);
3501 return err;
3502}
3503
3504int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3505{
3506 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003507 int close = 0;
3508 int fatal = 0;
3509 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003510
Steve Wise2f5b48c2010-09-10 11:15:36 -05003511 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003512
3513 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3514 states[ep->com.state], abrupt);
3515
Hariprasad S6e410d82016-05-05 01:27:31 +05303516 /*
3517 * Ref the ep here in case we have fatal errors causing the
3518 * ep to be released and freed.
3519 */
3520 c4iw_get_ep(&ep->com);
3521
Steve Wisecfdda9d2010-04-21 15:30:06 -07003522 rdev = &ep->com.dev->rdev;
3523 if (c4iw_fatal_error(rdev)) {
3524 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303525 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003526 ep->com.state = DEAD;
3527 }
3528 switch (ep->com.state) {
3529 case MPA_REQ_WAIT:
3530 case MPA_REQ_SENT:
3531 case MPA_REQ_RCVD:
3532 case MPA_REP_SENT:
3533 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303534 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535 close = 1;
3536 if (abrupt)
3537 ep->com.state = ABORTING;
3538 else {
3539 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003540
3541 /*
3542 * if we close before we see the fw4_ack() then we fix
3543 * up the timer state since we're reusing it.
3544 */
3545 if (ep->mpa_skb &&
3546 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3547 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3548 stop_ep_timer(ep);
3549 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003550 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003551 }
3552 set_bit(CLOSE_SENT, &ep->com.flags);
3553 break;
3554 case CLOSING:
3555 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3556 close = 1;
3557 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003558 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003559 ep->com.state = ABORTING;
3560 } else
3561 ep->com.state = MORIBUND;
3562 }
3563 break;
3564 case MORIBUND:
3565 case ABORTING:
3566 case DEAD:
3567 PDBG("%s ignoring disconnect ep %p state %u\n",
3568 __func__, ep, ep->com.state);
3569 break;
3570 default:
3571 BUG();
3572 break;
3573 }
3574
Steve Wisecfdda9d2010-04-21 15:30:06 -07003575 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003576 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003577 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303578 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303579 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003580 } else {
3581 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303582 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003583 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303584 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303585 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303586 if (!abrupt) {
3587 stop_ep_timer(ep);
3588 close_complete_upcall(ep, -EIO);
3589 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303590 if (ep->com.qp) {
3591 struct c4iw_qp_attributes attrs;
3592
3593 attrs.next_state = C4IW_QP_STATE_ERROR;
3594 ret = c4iw_modify_qp(ep->com.qp->rhp,
3595 ep->com.qp,
3596 C4IW_QP_ATTR_NEXT_STATE,
3597 &attrs, 1);
3598 if (ret)
3599 pr_err(MOD
3600 "%s - qp <- error failed!\n",
3601 __func__);
3602 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003603 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303604 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003605 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003606 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303607 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003608 if (fatal)
3609 release_ep_resources(ep);
3610 return ret;
3611}
3612
Vipul Pandya1cab7752012-12-10 09:30:55 +00003613static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3614 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3615{
3616 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003617 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003618
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003619 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3620 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003621 if (!ep)
3622 return;
3623
3624 switch (req->retval) {
3625 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003626 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3627 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3628 send_fw_act_open_req(ep, atid);
3629 return;
3630 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003631 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003632 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3633 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3634 send_fw_act_open_req(ep, atid);
3635 return;
3636 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003637 break;
3638 default:
3639 pr_info("%s unexpected ofld conn wr retval %d\n",
3640 __func__, req->retval);
3641 break;
3642 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003643 pr_err("active ofld_connect_wr failure %d atid %d\n",
3644 req->retval, atid);
3645 mutex_lock(&dev->rdev.stats.lock);
3646 dev->rdev.stats.act_ofld_conn_fails++;
3647 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003648 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003649 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303650 if (ep->com.remote_addr.ss_family == AF_INET6) {
3651 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003652 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303653 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3654 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3655 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003656 remove_handle(dev, &dev->atid_idr, atid);
3657 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3658 dst_release(ep->dst);
3659 cxgb4_l2t_release(ep->l2t);
3660 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003661}
3662
3663static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3664 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3665{
3666 struct sk_buff *rpl_skb;
3667 struct cpl_pass_accept_req *cpl;
3668 int ret;
3669
Paul Bolle710a3112013-02-05 20:51:30 +00003670 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 BUG_ON(!rpl_skb);
3672 if (req->retval) {
3673 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003674 mutex_lock(&dev->rdev.stats.lock);
3675 dev->rdev.stats.pas_ofld_conn_fails++;
3676 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677 kfree_skb(rpl_skb);
3678 } else {
3679 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3680 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003681 (__force u32) htonl(
3682 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003683 ret = pass_accept_req(dev, rpl_skb);
3684 if (!ret)
3685 kfree_skb(rpl_skb);
3686 }
3687 return;
3688}
3689
3690static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003691{
3692 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003693 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3694
3695 switch (rpl->type) {
3696 case FW6_TYPE_CQE:
3697 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3698 break;
3699 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3700 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3701 switch (req->t_state) {
3702 case TCP_SYN_SENT:
3703 active_ofld_conn_reply(dev, skb, req);
3704 break;
3705 case TCP_SYN_RECV:
3706 passive_ofld_conn_reply(dev, skb, req);
3707 break;
3708 default:
3709 pr_err("%s unexpected ofld conn wr state %d\n",
3710 __func__, req->t_state);
3711 break;
3712 }
3713 break;
3714 }
3715 return 0;
3716}
3717
3718static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3719{
Hariprasad S963cab52015-09-23 17:19:27 +05303720 __be32 l2info;
3721 __be16 hdr_len, vlantag, len;
3722 u16 eth_hdr_len;
3723 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003724 u8 intf;
3725 struct cpl_rx_pkt *cpl = cplhdr(skb);
3726 struct cpl_pass_accept_req *req;
3727 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003728 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303729 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730
Vipul Pandyaf079af72013-03-14 05:08:58 +00003731 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003732 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303733 vlantag = cpl->vlan;
3734 len = cpl->len;
3735 l2info = cpl->l2info;
3736 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003737 intf = cpl->iff;
3738
3739 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3740
3741 /*
3742 * We need to parse the TCP options from SYN packet.
3743 * to generate cpl_pass_accept_req.
3744 */
3745 memset(&tmp_opt, 0, sizeof(tmp_opt));
3746 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003747 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003748
3749 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3750 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303751 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3752 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303753 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303754 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303755 type = dev->rdev.lldi.adapter_type;
3756 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3757 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3758 req->hdr_len =
3759 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3760 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3761 eth_hdr_len = is_t4(type) ?
3762 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3763 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3764 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3765 IP_HDR_LEN_V(ip_hdr_len) |
3766 ETH_HDR_LEN_V(eth_hdr_len));
3767 } else { /* T6 and later */
3768 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3769 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3770 T6_IP_HDR_LEN_V(ip_hdr_len) |
3771 T6_ETH_HDR_LEN_V(eth_hdr_len));
3772 }
3773 req->vlan = vlantag;
3774 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003775 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3776 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003777 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3778 if (tmp_opt.wscale_ok)
3779 req->tcpopt.wsf = tmp_opt.snd_wscale;
3780 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3781 if (tmp_opt.sack_ok)
3782 req->tcpopt.sack = 1;
3783 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3784 return;
3785}
3786
3787static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3788 __be32 laddr, __be16 lport,
3789 __be32 raddr, __be16 rport,
3790 u32 rcv_isn, u32 filter, u16 window,
3791 u32 rss_qid, u8 port_id)
3792{
3793 struct sk_buff *req_skb;
3794 struct fw_ofld_connection_wr *req;
3795 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303796 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003797
3798 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3799 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3800 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003801 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303802 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303803 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003804 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003805 req->le.lport = lport;
3806 req->le.pport = rport;
3807 req->le.u.ipv4.lip = laddr;
3808 req->le.u.ipv4.pip = raddr;
3809 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3810 req->tcb.rcv_adv = htons(window);
3811 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303812 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3813 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3814 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003815 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003816
3817 /*
3818 * We store the qid in opt2 which will be used by the firmware
3819 * to send us the wr response.
3820 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003821 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003822
3823 /*
3824 * We initialize the MSS index in TCB to 0xF.
3825 * So that when driver sends cpl_pass_accept_rpl
3826 * TCB picks up the correct value. If this was 0
3827 * TP will ignore any value > 0 for MSS index.
3828 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003829 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303830 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003831
3832 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303833 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3834 if (ret < 0) {
3835 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3836 ret);
3837 kfree_skb(skb);
3838 kfree_skb(req_skb);
3839 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003840}
3841
3842/*
3843 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3844 * messages when a filter is being used instead of server to
3845 * redirect a syn packet. When packets hit filter they are redirected
3846 * to the offload queue and driver tries to establish the connection
3847 * using firmware work request.
3848 */
3849static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3850{
3851 int stid;
3852 unsigned int filter;
3853 struct ethhdr *eh = NULL;
3854 struct vlan_ethhdr *vlan_eh = NULL;
3855 struct iphdr *iph;
3856 struct tcphdr *tcph;
3857 struct rss_header *rss = (void *)skb->data;
3858 struct cpl_rx_pkt *cpl = (void *)skb->data;
3859 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3860 struct l2t_entry *e;
3861 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303862 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863 u16 window;
3864 struct port_info *pi;
3865 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003866 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003867 int step;
3868 u32 tx_chan;
3869 struct neighbour *neigh;
3870
3871 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003872 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003873 goto reject;
3874
3875 /*
3876 * Drop all packets which did not hit the filter.
3877 * Unlikely to happen.
3878 */
3879 if (!(rss->filter_hit && rss->filter_tid))
3880 goto reject;
3881
3882 /*
3883 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3884 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303885 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003886
Hariprasad Sf86fac72016-05-06 22:18:07 +05303887 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003888 if (!lep) {
3889 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3890 goto reject;
3891 }
3892
Hariprasad S963cab52015-09-23 17:19:27 +05303893 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3894 case CHELSIO_T4:
3895 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3896 break;
3897 case CHELSIO_T5:
3898 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3899 break;
3900 case CHELSIO_T6:
3901 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3902 break;
3903 default:
3904 pr_err("T%d Chip is not supported\n",
3905 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3906 goto reject;
3907 }
3908
Vipul Pandyaf079af72013-03-14 05:08:58 +00003909 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003910 eh = (struct ethhdr *)(req + 1);
3911 iph = (struct iphdr *)(eh + 1);
3912 } else {
3913 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3914 iph = (struct iphdr *)(vlan_eh + 1);
3915 skb->vlan_tci = ntohs(cpl->vlan);
3916 }
3917
3918 if (iph->version != 0x4)
3919 goto reject;
3920
3921 tcph = (struct tcphdr *)(iph + 1);
3922 skb_set_network_header(skb, (void *)iph - (void *)rss);
3923 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3924 skb_get(skb);
3925
3926 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3927 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3928 ntohs(tcph->source), iph->tos);
3929
Varun Prakash804c2f32016-09-13 21:23:57 +05303930 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3931 iph->daddr, iph->saddr, tcph->dest,
3932 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303933 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003934 pr_err("%s - failed to find dst entry!\n",
3935 __func__);
3936 goto reject;
3937 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003938 neigh = dst_neigh_lookup_skb(dst, skb);
3939
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003940 if (!neigh) {
3941 pr_err("%s - failed to allocate neigh!\n",
3942 __func__);
3943 goto free_dst;
3944 }
3945
Vipul Pandya1cab7752012-12-10 09:30:55 +00003946 if (neigh->dev->flags & IFF_LOOPBACK) {
3947 pdev = ip_dev_find(&init_net, iph->daddr);
3948 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3949 pdev, 0);
3950 pi = (struct port_info *)netdev_priv(pdev);
3951 tx_chan = cxgb4_port_chan(pdev);
3952 dev_put(pdev);
3953 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303954 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003955 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303956 pdev, 0);
3957 pi = (struct port_info *)netdev_priv(pdev);
3958 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003959 }
Steve Wiseebf00062014-03-19 17:44:40 +05303960 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003961 if (!e) {
3962 pr_err("%s - failed to allocate l2t entry!\n",
3963 __func__);
3964 goto free_dst;
3965 }
3966
3967 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3968 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003969 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003970
3971 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303972 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3973 dev->rdev.lldi.ports[0],
3974 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003975
3976 /*
3977 * Synthesize the cpl_pass_accept_req. We have everything except the
3978 * TID. Once firmware sends a reply with TID we update the TID field
3979 * in cpl and pass it through the regular cpl_pass_accept_req path.
3980 */
3981 build_cpl_pass_accept_req(skb, stid, iph->tos);
3982 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3983 tcph->source, ntohl(tcph->seq), filter, window,
3984 rss_qid, pi->port_id);
3985 cxgb4_l2t_release(e);
3986free_dst:
3987 dst_release(dst);
3988reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05303989 if (lep)
3990 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05003991 return 0;
3992}
3993
Steve Wisecfdda9d2010-04-21 15:30:06 -07003994/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003995 * These are the real handlers that are called from a
3996 * work queue.
3997 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303998static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003999 [CPL_ACT_ESTABLISH] = act_establish,
4000 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4001 [CPL_RX_DATA] = rx_data,
4002 [CPL_ABORT_RPL_RSS] = abort_rpl,
4003 [CPL_ABORT_RPL] = abort_rpl,
4004 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4005 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4006 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4007 [CPL_PASS_ESTABLISH] = pass_establish,
4008 [CPL_PEER_CLOSE] = peer_close,
4009 [CPL_ABORT_REQ_RSS] = peer_abort,
4010 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4011 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004012 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004013 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304014 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304015 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4016 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004017};
4018
4019static void process_timeout(struct c4iw_ep *ep)
4020{
4021 struct c4iw_qp_attributes attrs;
4022 int abort = 1;
4023
Steve Wise2f5b48c2010-09-10 11:15:36 -05004024 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004025 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4026 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004027 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028 switch (ep->com.state) {
4029 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004030 connect_reply_upcall(ep, -ETIMEDOUT);
4031 break;
4032 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304033 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304034 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304035 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004036 break;
4037 case CLOSING:
4038 case MORIBUND:
4039 if (ep->com.cm_id && ep->com.qp) {
4040 attrs.next_state = C4IW_QP_STATE_ERROR;
4041 c4iw_modify_qp(ep->com.qp->rhp,
4042 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4043 &attrs, 1);
4044 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304045 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004046 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004047 case ABORTING:
4048 case DEAD:
4049
4050 /*
4051 * These states are expected if the ep timed out at the same
4052 * time as another thread was calling stop_ep_timer().
4053 * So we silently do nothing for these states.
4054 */
4055 abort = 0;
4056 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004057 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004058 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004059 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004060 abort = 0;
4061 }
Steve Wisecc18b932014-04-24 14:31:53 -05004062 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304063 if (abort)
4064 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004065 c4iw_put_ep(&ep->com);
4066}
4067
4068static void process_timedout_eps(void)
4069{
4070 struct c4iw_ep *ep;
4071
4072 spin_lock_irq(&timeout_lock);
4073 while (!list_empty(&timeout_list)) {
4074 struct list_head *tmp;
4075
4076 tmp = timeout_list.next;
4077 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004078 tmp->next = NULL;
4079 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004080 spin_unlock_irq(&timeout_lock);
4081 ep = list_entry(tmp, struct c4iw_ep, entry);
4082 process_timeout(ep);
4083 spin_lock_irq(&timeout_lock);
4084 }
4085 spin_unlock_irq(&timeout_lock);
4086}
4087
4088static void process_work(struct work_struct *work)
4089{
4090 struct sk_buff *skb = NULL;
4091 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004092 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004093 unsigned int opcode;
4094 int ret;
4095
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004096 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004097 while ((skb = skb_dequeue(&rxq))) {
4098 rpl = cplhdr(skb);
4099 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4100 opcode = rpl->ot.opcode;
4101
4102 BUG_ON(!work_handlers[opcode]);
4103 ret = work_handlers[opcode](dev, skb);
4104 if (!ret)
4105 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004106 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004107 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004108}
4109
4110static DECLARE_WORK(skb_work, process_work);
4111
4112static void ep_timeout(unsigned long arg)
4113{
4114 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004115 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004116
4117 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004118 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004119 /*
4120 * Only insert if it is not already on the list.
4121 */
4122 if (!ep->entry.next) {
4123 list_add_tail(&ep->entry, &timeout_list);
4124 kickit = 1;
4125 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004126 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004127 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004128 if (kickit)
4129 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004130}
4131
4132/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004133 * All the CM events are handled on a work queue to have a safe context.
4134 */
4135static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4136{
4137
4138 /*
4139 * Save dev in the skb->cb area.
4140 */
4141 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4142
4143 /*
4144 * Queue the skb and schedule the worker thread.
4145 */
4146 skb_queue_tail(&rxq, skb);
4147 queue_work(workq, &skb_work);
4148 return 0;
4149}
4150
4151static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4152{
4153 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4154
4155 if (rpl->status != CPL_ERR_NONE) {
4156 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4157 "for tid %u\n", rpl->status, GET_TID(rpl));
4158 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004159 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004160 return 0;
4161}
4162
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004163static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4164{
4165 struct cpl_fw6_msg *rpl = cplhdr(skb);
4166 struct c4iw_wr_wait *wr_waitp;
4167 int ret;
4168
4169 PDBG("%s type %u\n", __func__, rpl->type);
4170
4171 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004172 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004173 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004174 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004175 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004176 if (wr_waitp)
4177 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004178 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004179 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004180 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004181 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004182 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004183 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004184 default:
4185 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4186 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004187 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004188 break;
4189 }
4190 return 0;
4191}
4192
Steve Wise8da7e7a2011-06-14 20:59:27 +00004193static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4194{
4195 struct cpl_abort_req_rss *req = cplhdr(skb);
4196 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004197 unsigned int tid = GET_TID(req);
4198
Hariprasad S944661d2016-05-06 22:18:03 +05304199 ep = get_ep_from_tid(dev, tid);
4200 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004201 if (!ep) {
4202 printk(KERN_WARNING MOD
4203 "Abort on non-existent endpoint, tid %d\n", tid);
4204 kfree_skb(skb);
4205 return 0;
4206 }
Varun Prakashb65eef02016-09-13 21:23:59 +05304207 if (cxgb_is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304208 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4209 __func__, ep->hwtid, req->status,
4210 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304211 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004212 }
4213 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4214 ep->com.state);
4215
Hariprasad S093108c2016-05-06 22:18:09 +05304216 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304217out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004218 sched(dev, skb);
4219 return 0;
4220}
4221
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004222/*
4223 * Most upcalls from the T4 Core go to sched() to
4224 * schedule the processing on a work queue.
4225 */
4226c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4227 [CPL_ACT_ESTABLISH] = sched,
4228 [CPL_ACT_OPEN_RPL] = sched,
4229 [CPL_RX_DATA] = sched,
4230 [CPL_ABORT_RPL_RSS] = sched,
4231 [CPL_ABORT_RPL] = sched,
4232 [CPL_PASS_OPEN_RPL] = sched,
4233 [CPL_CLOSE_LISTSRV_RPL] = sched,
4234 [CPL_PASS_ACCEPT_REQ] = sched,
4235 [CPL_PASS_ESTABLISH] = sched,
4236 [CPL_PEER_CLOSE] = sched,
4237 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004238 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004239 [CPL_RDMA_TERMINATE] = sched,
4240 [CPL_FW4_ACK] = sched,
4241 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004242 [CPL_FW6_MSG] = fw6_msg,
4243 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004244};
4245
Steve Wisecfdda9d2010-04-21 15:30:06 -07004246int __init c4iw_cm_init(void)
4247{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004248 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004249 skb_queue_head_init(&rxq);
4250
4251 workq = create_singlethread_workqueue("iw_cxgb4");
4252 if (!workq)
4253 return -ENOMEM;
4254
Steve Wisecfdda9d2010-04-21 15:30:06 -07004255 return 0;
4256}
4257
Steve Wise46c13762014-06-20 14:26:25 -05004258void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004259{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004260 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004261 flush_workqueue(workq);
4262 destroy_workqueue(workq);
4263}