blob: 02f5e20cd3a34565f91722c75d1ae594bd834a02 [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
468static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
469{
470 int i;
471
472 egress_dev = get_real_dev(egress_dev);
473 for (i = 0; i < dev->rdev.lldi.nports; i++)
474 if (dev->rdev.lldi.ports[i] == egress_dev)
475 return 1;
476 return 0;
477}
478
479static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
480 __u8 *peer_ip, __be16 local_port,
481 __be16 peer_port, u8 tos,
482 __u32 sin6_scope_id)
483{
484 struct dst_entry *dst = NULL;
485
486 if (IS_ENABLED(CONFIG_IPV6)) {
487 struct flowi6 fl6;
488
489 memset(&fl6, 0, sizeof(fl6));
490 memcpy(&fl6.daddr, peer_ip, 16);
491 memcpy(&fl6.saddr, local_ip, 16);
492 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
493 fl6.flowi6_oif = sin6_scope_id;
494 dst = ip6_route_output(&init_net, NULL, &fl6);
495 if (!dst)
496 goto out;
497 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
498 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
499 dst_release(dst);
500 dst = NULL;
501 }
502 }
503
504out:
505 return dst;
506}
507
Steve Wisecfdda9d2010-04-21 15:30:06 -0700508static void arp_failure_discard(void *handle, struct sk_buff *skb)
509{
Hariprasad S9dec9002016-05-05 01:27:29 +0530510 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700511 kfree_skb(skb);
512}
513
Hariprasad S64bec742016-05-06 22:18:10 +0530514static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
515{
516 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
517}
518
Hariprasad S9dec9002016-05-05 01:27:29 +0530519enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530520 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530521 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530522 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530523};
524
525static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
526{
527 struct c4iw_ep *ep;
528
529 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
530 release_ep_resources(ep);
531 return 0;
532}
533
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530534static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
535{
536 struct c4iw_ep *ep;
537
538 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
539 c4iw_put_ep(&ep->parent_ep->com);
540 release_ep_resources(ep);
541 return 0;
542}
543
Hariprasad S9dec9002016-05-05 01:27:29 +0530544/*
545 * Fake up a special CPL opcode and call sched() so process_work() will call
546 * _put_ep_safe() in a safe context to free the ep resources. This is needed
547 * because ARP error handlers are called in an ATOMIC context, and
548 * _c4iw_free_ep() needs to block.
549 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530550static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
551 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530552{
553 struct cpl_act_establish *rpl = cplhdr(skb);
554
555 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530556 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530557
558 /*
559 * Save ep in the skb->cb area, after where sched() will save the dev
560 * ptr.
561 */
562 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
563 sched(ep->com.dev, skb);
564}
565
566/* Handle an ARP failure for an accept */
567static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
568{
569 struct c4iw_ep *ep = handle;
570
571 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
572 ep->hwtid);
573
574 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530575 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530576}
577
Steve Wisecfdda9d2010-04-21 15:30:06 -0700578/*
579 * Handle an ARP failure for an active open.
580 */
581static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
582{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530583 struct c4iw_ep *ep = handle;
584
Masanari Iidae3d132d2015-10-16 21:14:29 +0900585 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530586 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530587 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530588 if (ep->com.remote_addr.ss_family == AF_INET6) {
589 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600590 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530591 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
592 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
593 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530594 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
595 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530596 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700597}
598
599/*
600 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
601 * and send it along.
602 */
603static void abort_arp_failure(void *handle, struct sk_buff *skb)
604{
Hariprasad S761e19a2016-05-06 22:18:02 +0530605 int ret;
606 struct c4iw_ep *ep = handle;
607 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700608 struct cpl_abort_req *req = cplhdr(skb);
609
610 PDBG("%s rdev %p\n", __func__, rdev);
611 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530612 ret = c4iw_ofld_send(rdev, skb);
613 if (ret) {
614 __state_set(&ep->com, DEAD);
615 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
616 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700617}
618
Hariprasad S4a740832016-06-10 01:05:15 +0530619static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700620{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700621 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530622 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700623 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530624 u16 vlan = ep->l2t->vlan;
625 int nparams;
626
Hariprasad S4a740832016-06-10 01:05:15 +0530627 if (WARN_ON(!skb))
628 return -ENOMEM;
629
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530630 if (vlan == CPL_L2T_VLAN_NONE)
631 nparams = 8;
632 else
633 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700634
Hariprasad S4a740832016-06-10 01:05:15 +0530635 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700636
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530637 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530638 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530639 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530640 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641
642 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530643 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530644 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700645 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
646 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
647 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
648 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
649 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
650 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
651 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
652 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
653 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
654 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
655 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530656 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700657 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
658 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530659 if (nparams == 9) {
660 u16 pri;
661
662 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
663 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
664 flowc->mnemval[8].val = cpu_to_be32(pri);
665 } else {
666 /* Pad WR to 16 byte boundary */
667 flowc->mnemval[8].mnemonic = 0;
668 flowc->mnemval[8].val = 0;
669 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700670 for (i = 0; i < 9; i++) {
671 flowc->mnemval[i].r4[0] = 0;
672 flowc->mnemval[i].r4[1] = 0;
673 flowc->mnemval[i].r4[2] = 0;
674 }
675
676 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530677 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700678}
679
Hariprasad S4a740832016-06-10 01:05:15 +0530680static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700681{
682 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530683 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700684 int wrlen = roundup(sizeof *req, 16);
685
686 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530687 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700688 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530689
Steve Wisecfdda9d2010-04-21 15:30:06 -0700690 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
691 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
692 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
693 memset(req, 0, wrlen);
694 INIT_TP_WR(req, ep->hwtid);
695 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
696 ep->hwtid));
697 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
698}
699
Hariprasad S4a740832016-06-10 01:05:15 +0530700static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700701{
702 struct cpl_abort_req *req;
703 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530704 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700705
706 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530707 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700708 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530709
710 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
711 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
712 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700713 memset(req, 0, wrlen);
714 INIT_TP_WR(req, ep->hwtid);
715 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
716 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530717 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700718}
719
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530720static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530721 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530722{
Hariprasad S04524a42014-09-24 03:53:41 +0530723 unsigned short hdr_size = (ipv6 ?
724 sizeof(struct ipv6hdr) :
725 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530726 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530727 (use_ts ?
728 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530729 unsigned short data_size = mtu - hdr_size;
730
731 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
732}
733
Steve Wisecfdda9d2010-04-21 15:30:06 -0700734static int send_connect(struct c4iw_ep *ep)
735{
Hariprasad S963cab52015-09-23 17:19:27 +0530736 struct cpl_act_open_req *req = NULL;
737 struct cpl_t5_act_open_req *t5req = NULL;
738 struct cpl_t6_act_open_req *t6req = NULL;
739 struct cpl_act_open_req6 *req6 = NULL;
740 struct cpl_t5_act_open_req6 *t5req6 = NULL;
741 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700742 struct sk_buff *skb;
743 u64 opt0;
744 u32 opt2;
745 unsigned int mtu_idx;
746 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530747 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500748 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600749 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500750 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600751 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500752 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600753 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500754 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600755 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530756 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530757 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
758 u32 isn = (prandom_u32() & ~7UL) - 1;
759
760 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
761 case CHELSIO_T4:
762 sizev4 = sizeof(struct cpl_act_open_req);
763 sizev6 = sizeof(struct cpl_act_open_req6);
764 break;
765 case CHELSIO_T5:
766 sizev4 = sizeof(struct cpl_t5_act_open_req);
767 sizev6 = sizeof(struct cpl_t5_act_open_req6);
768 break;
769 case CHELSIO_T6:
770 sizev4 = sizeof(struct cpl_t6_act_open_req);
771 sizev6 = sizeof(struct cpl_t6_act_open_req6);
772 break;
773 default:
774 pr_err("T%d Chip is not supported\n",
775 CHELSIO_CHIP_VERSION(adapter_type));
776 return -EINVAL;
777 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530778
779 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
780 roundup(sizev4, 16) :
781 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700782
783 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
784
785 skb = get_skb(NULL, wrlen, GFP_KERNEL);
786 if (!skb) {
787 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
788 __func__);
789 return -ENOMEM;
790 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000791 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700792
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530793 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530794 enable_tcp_timestamps,
795 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700796 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530797
798 /*
799 * Specify the largest window that will fit in opt0. The
800 * remainder will be specified in the rx_data_ack.
801 */
802 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800803 if (win > RCV_BUFSIZ_M)
804 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530805
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800806 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800807 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800808 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800809 WND_SCALE_V(wscale) |
810 MSS_IDX_V(mtu_idx) |
811 L2T_IDX_V(ep->l2t->idx) |
812 TX_CHAN_V(ep->tx_chan) |
813 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530814 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800815 ULP_MODE_V(ULP_MODE_TCPDDP) |
816 RCV_BUFSIZ_V(win);
817 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800818 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800819 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700820 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800821 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700822 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800823 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700824 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800825 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530826 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
827 if (peer2peer)
828 isn += 4;
829
Anish Bhattd7990b02014-11-12 17:15:57 -0800830 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530831 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530832 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500833 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530834
835 if (ep->com.remote_addr.ss_family == AF_INET6)
836 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
837 (const u32 *)&la6->sin6_addr.s6_addr, 1);
838
Hariprasad S5dab6d32014-06-23 19:12:36 +0530839 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700840
Hariprasad S963cab52015-09-23 17:19:27 +0530841 if (ep->com.remote_addr.ss_family == AF_INET) {
842 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
843 case CHELSIO_T4:
844 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530845 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530846 break;
847 case CHELSIO_T5:
848 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
849 wrlen);
850 INIT_TP_WR(t5req, 0);
851 req = (struct cpl_act_open_req *)t5req;
852 break;
853 case CHELSIO_T6:
854 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
855 wrlen);
856 INIT_TP_WR(t6req, 0);
857 req = (struct cpl_act_open_req *)t6req;
858 t5req = (struct cpl_t5_act_open_req *)t6req;
859 break;
860 default:
861 pr_err("T%d Chip is not supported\n",
862 CHELSIO_CHIP_VERSION(adapter_type));
863 ret = -EINVAL;
864 goto clip_release;
865 }
866
867 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
868 ((ep->rss_qid<<14) | ep->atid)));
869 req->local_port = la->sin_port;
870 req->peer_port = ra->sin_port;
871 req->local_ip = la->sin_addr.s_addr;
872 req->peer_ip = ra->sin_addr.s_addr;
873 req->opt0 = cpu_to_be64(opt0);
874
875 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530876 req->params = cpu_to_be32(cxgb4_select_ntuple(
877 ep->com.dev->rdev.lldi.ports[0],
878 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530879 req->opt2 = cpu_to_be32(opt2);
880 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530881 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
882 cxgb4_select_ntuple(
883 ep->com.dev->rdev.lldi.ports[0],
884 ep->l2t)));
885 t5req->rsvd = cpu_to_be32(isn);
886 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
887 t5req->opt2 = cpu_to_be32(opt2);
888 }
889 } else {
890 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
891 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530892 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530893 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530894 break;
895 case CHELSIO_T5:
896 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
897 wrlen);
898 INIT_TP_WR(t5req6, 0);
899 req6 = (struct cpl_act_open_req6 *)t5req6;
900 break;
901 case CHELSIO_T6:
902 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
903 wrlen);
904 INIT_TP_WR(t6req6, 0);
905 req6 = (struct cpl_act_open_req6 *)t6req6;
906 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
907 break;
908 default:
909 pr_err("T%d Chip is not supported\n",
910 CHELSIO_CHIP_VERSION(adapter_type));
911 ret = -EINVAL;
912 goto clip_release;
913 }
914
915 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
916 ((ep->rss_qid<<14)|ep->atid)));
917 req6->local_port = la6->sin6_port;
918 req6->peer_port = ra6->sin6_port;
919 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
920 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
921 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
922 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
923 req6->opt0 = cpu_to_be64(opt0);
924
925 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530926 req6->params = cpu_to_be32(cxgb4_select_ntuple(
927 ep->com.dev->rdev.lldi.ports[0],
928 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530929 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530930 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530931 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
932 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530933 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530934 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530935 t5req6->rsvd = cpu_to_be32(isn);
936 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
937 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530938 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000939 }
940
Vipul Pandya793dad92012-12-10 09:30:56 +0000941 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530942 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530943clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530944 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
945 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
946 (const u32 *)&la6->sin6_addr.s6_addr, 1);
947 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700948}
949
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530950static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
951 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700952{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530953 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700954 struct fw_ofld_tx_data_wr *req;
955 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530956 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700957
958 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
959
960 BUG_ON(skb_cloned(skb));
961
962 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530963 if (mpa_rev_to_use == 2)
964 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700965 wrlen = roundup(mpalen + sizeof *req, 16);
966 skb = get_skb(skb, wrlen, GFP_KERNEL);
967 if (!skb) {
968 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530969 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700970 }
971 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
972
973 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
974 memset(req, 0, wrlen);
975 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530976 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
977 FW_WR_COMPL_F |
978 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530980 FW_WR_FLOWID_V(ep->hwtid) |
981 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982 req->plen = cpu_to_be32(mpalen);
983 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530984 FW_OFLD_TX_DATA_WR_FLUSH_F |
985 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700986
987 mpa = (struct mpa_message *)(req + 1);
988 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530989
990 mpa->flags = 0;
991 if (crc_enabled)
992 mpa->flags |= MPA_CRC;
993 if (markers_enabled) {
994 mpa->flags |= MPA_MARKERS;
995 ep->mpa_attr.recv_marker_enabled = 1;
996 } else {
997 ep->mpa_attr.recv_marker_enabled = 0;
998 }
999 if (mpa_rev_to_use == 2)
1000 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1001
Steve Wisecfdda9d2010-04-21 15:30:06 -07001002 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301003 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301004 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301005 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301006 ep->retry_with_mpa_v1 = 0;
1007 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001008
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301009 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001010 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1011 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301012 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1013 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301014 mpa_v2_params.ird = htons((u16)ep->ird);
1015 mpa_v2_params.ord = htons((u16)ep->ord);
1016
1017 if (peer2peer) {
1018 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1019 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1020 mpa_v2_params.ord |=
1021 htons(MPA_V2_RDMA_WRITE_RTR);
1022 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1023 mpa_v2_params.ord |=
1024 htons(MPA_V2_RDMA_READ_RTR);
1025 }
1026 memcpy(mpa->private_data, &mpa_v2_params,
1027 sizeof(struct mpa_v2_conn_params));
1028
1029 if (ep->plen)
1030 memcpy(mpa->private_data +
1031 sizeof(struct mpa_v2_conn_params),
1032 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1033 } else
1034 if (ep->plen)
1035 memcpy(mpa->private_data,
1036 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001037
1038 /*
1039 * Reference the mpa skb. This ensures the data area
1040 * will remain in memory until the hw acks the tx.
1041 * Function fw4_ack() will deref it.
1042 */
1043 skb_get(skb);
1044 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1045 BUG_ON(ep->mpa_skb);
1046 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301047 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1048 if (ret)
1049 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001050 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301051 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301053 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301054 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001055}
1056
1057static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1058{
1059 int mpalen, wrlen;
1060 struct fw_ofld_tx_data_wr *req;
1061 struct mpa_message *mpa;
1062 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301063 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001064
1065 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1066
1067 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301068 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1069 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001070 wrlen = roundup(mpalen + sizeof *req, 16);
1071
1072 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1073 if (!skb) {
1074 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1075 return -ENOMEM;
1076 }
1077 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1078
1079 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1080 memset(req, 0, wrlen);
1081 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301082 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1083 FW_WR_COMPL_F |
1084 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001085 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301086 FW_WR_FLOWID_V(ep->hwtid) |
1087 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088 req->plen = cpu_to_be32(mpalen);
1089 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301090 FW_OFLD_TX_DATA_WR_FLUSH_F |
1091 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001092
1093 mpa = (struct mpa_message *)(req + 1);
1094 memset(mpa, 0, sizeof(*mpa));
1095 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1096 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001097 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001098 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301099
1100 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1101 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001102 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1103 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301104 mpa_v2_params.ird = htons(((u16)ep->ird) |
1105 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1106 0));
1107 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1108 (p2p_type ==
1109 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1110 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1111 FW_RI_INIT_P2PTYPE_READ_REQ ?
1112 MPA_V2_RDMA_READ_RTR : 0) : 0));
1113 memcpy(mpa->private_data, &mpa_v2_params,
1114 sizeof(struct mpa_v2_conn_params));
1115
1116 if (ep->plen)
1117 memcpy(mpa->private_data +
1118 sizeof(struct mpa_v2_conn_params), pdata, plen);
1119 } else
1120 if (plen)
1121 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001122
1123 /*
1124 * Reference the mpa skb again. This ensures the data area
1125 * will remain in memory until the hw acks the tx.
1126 * Function fw4_ack() will deref it.
1127 */
1128 skb_get(skb);
1129 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301130 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001131 BUG_ON(ep->mpa_skb);
1132 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301133 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001134 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1135}
1136
1137static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1138{
1139 int mpalen, wrlen;
1140 struct fw_ofld_tx_data_wr *req;
1141 struct mpa_message *mpa;
1142 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301143 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001144
1145 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1146
1147 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301148 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1149 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001150 wrlen = roundup(mpalen + sizeof *req, 16);
1151
1152 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1153 if (!skb) {
1154 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1155 return -ENOMEM;
1156 }
1157 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1158
1159 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1160 memset(req, 0, wrlen);
1161 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301162 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1163 FW_WR_COMPL_F |
1164 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301166 FW_WR_FLOWID_V(ep->hwtid) |
1167 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001168 req->plen = cpu_to_be32(mpalen);
1169 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301170 FW_OFLD_TX_DATA_WR_FLUSH_F |
1171 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001172
1173 mpa = (struct mpa_message *)(req + 1);
1174 memset(mpa, 0, sizeof(*mpa));
1175 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301176 mpa->flags = 0;
1177 if (ep->mpa_attr.crc_enabled)
1178 mpa->flags |= MPA_CRC;
1179 if (ep->mpa_attr.recv_marker_enabled)
1180 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301181 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301183
1184 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1185 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001186 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1187 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301188 mpa_v2_params.ird = htons((u16)ep->ird);
1189 mpa_v2_params.ord = htons((u16)ep->ord);
1190 if (peer2peer && (ep->mpa_attr.p2p_type !=
1191 FW_RI_INIT_P2PTYPE_DISABLED)) {
1192 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1193
1194 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1195 mpa_v2_params.ord |=
1196 htons(MPA_V2_RDMA_WRITE_RTR);
1197 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1198 mpa_v2_params.ord |=
1199 htons(MPA_V2_RDMA_READ_RTR);
1200 }
1201
1202 memcpy(mpa->private_data, &mpa_v2_params,
1203 sizeof(struct mpa_v2_conn_params));
1204
1205 if (ep->plen)
1206 memcpy(mpa->private_data +
1207 sizeof(struct mpa_v2_conn_params), pdata, plen);
1208 } else
1209 if (plen)
1210 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001211
1212 /*
1213 * Reference the mpa skb. This ensures the data area
1214 * will remain in memory until the hw acks the tx.
1215 * Function fw4_ack() will deref it.
1216 */
1217 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301218 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001219 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301220 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301221 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001222 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1223}
1224
1225static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1226{
1227 struct c4iw_ep *ep;
1228 struct cpl_act_establish *req = cplhdr(skb);
1229 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001230 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001231 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301232 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001233
1234 ep = lookup_atid(t, atid);
1235
1236 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1237 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1238
Steve Wisea7db89e2014-03-21 20:40:35 +05301239 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001240 dst_confirm(ep->dst);
1241
1242 /* setup the hwtid for this connection */
1243 ep->hwtid = tid;
1244 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301245 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001246
1247 ep->snd_seq = be32_to_cpu(req->snd_isn);
1248 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1249
1250 set_emss(ep, ntohs(req->tcp_opt));
1251
1252 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001253 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001254 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001255 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256
1257 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301258 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301259 if (ret)
1260 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301261 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301262 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301263 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301264 ret = send_mpa_req(ep, skb, mpa_rev);
1265 if (ret)
1266 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301267 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001268 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301269err:
1270 mutex_unlock(&ep->com.mutex);
1271 connect_reply_upcall(ep, -ENOMEM);
1272 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1273 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001274}
1275
Steve Wisebe13b2d2014-03-21 20:40:33 +05301276static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001277{
1278 struct iw_cm_event event;
1279
1280 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1281 memset(&event, 0, sizeof(event));
1282 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301283 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001284 if (ep->com.cm_id) {
1285 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1286 ep, ep->com.cm_id, ep->hwtid);
1287 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301288 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001289 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001290 }
1291}
1292
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293static void peer_close_upcall(struct c4iw_ep *ep)
1294{
1295 struct iw_cm_event event;
1296
1297 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1298 memset(&event, 0, sizeof(event));
1299 event.event = IW_CM_EVENT_DISCONNECT;
1300 if (ep->com.cm_id) {
1301 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1302 ep, ep->com.cm_id, ep->hwtid);
1303 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001304 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001305 }
1306}
1307
1308static void peer_abort_upcall(struct c4iw_ep *ep)
1309{
1310 struct iw_cm_event event;
1311
1312 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1313 memset(&event, 0, sizeof(event));
1314 event.event = IW_CM_EVENT_CLOSE;
1315 event.status = -ECONNRESET;
1316 if (ep->com.cm_id) {
1317 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1318 ep->com.cm_id, ep->hwtid);
1319 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301320 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001321 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001322 }
1323}
1324
1325static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1326{
1327 struct iw_cm_event event;
1328
1329 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1330 memset(&event, 0, sizeof(event));
1331 event.event = IW_CM_EVENT_CONNECT_REPLY;
1332 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301333 memcpy(&event.local_addr, &ep->com.local_addr,
1334 sizeof(ep->com.local_addr));
1335 memcpy(&event.remote_addr, &ep->com.remote_addr,
1336 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337
1338 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301339 if (!ep->tried_with_mpa_v1) {
1340 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301341 event.ord = ep->ird;
1342 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301343 event.private_data_len = ep->plen -
1344 sizeof(struct mpa_v2_conn_params);
1345 event.private_data = ep->mpa_pkt +
1346 sizeof(struct mpa_message) +
1347 sizeof(struct mpa_v2_conn_params);
1348 } else {
1349 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301350 event.ord = cur_max_read_depth(ep->com.dev);
1351 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301352 event.private_data_len = ep->plen;
1353 event.private_data = ep->mpa_pkt +
1354 sizeof(struct mpa_message);
1355 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001356 }
Roland Dreier85963e42010-07-19 13:13:09 -07001357
1358 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1359 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001360 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001361 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1362
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301363 if (status < 0)
1364 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001365}
1366
Steve Wisebe13b2d2014-03-21 20:40:33 +05301367static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001368{
1369 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301370 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001371
1372 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1373 memset(&event, 0, sizeof(event));
1374 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301375 memcpy(&event.local_addr, &ep->com.local_addr,
1376 sizeof(ep->com.local_addr));
1377 memcpy(&event.remote_addr, &ep->com.remote_addr,
1378 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001379 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301380 if (!ep->tried_with_mpa_v1) {
1381 /* this means MPA_v2 is used */
1382 event.ord = ep->ord;
1383 event.ird = ep->ird;
1384 event.private_data_len = ep->plen -
1385 sizeof(struct mpa_v2_conn_params);
1386 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1387 sizeof(struct mpa_v2_conn_params);
1388 } else {
1389 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301390 event.ord = cur_max_read_depth(ep->com.dev);
1391 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301392 event.private_data_len = ep->plen;
1393 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1394 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301395 c4iw_get_ep(&ep->com);
1396 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1397 &event);
1398 if (ret)
1399 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001400 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001401 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301402 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403}
1404
1405static void established_upcall(struct c4iw_ep *ep)
1406{
1407 struct iw_cm_event event;
1408
1409 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1410 memset(&event, 0, sizeof(event));
1411 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301412 event.ird = ep->ord;
1413 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001414 if (ep->com.cm_id) {
1415 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1416 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001417 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001418 }
1419}
1420
1421static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1422{
1423 struct cpl_rx_data_ack *req;
1424 struct sk_buff *skb;
1425 int wrlen = roundup(sizeof *req, 16);
1426
1427 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1428 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1429 if (!skb) {
1430 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1431 return 0;
1432 }
1433
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301434 /*
1435 * If we couldn't specify the entire rcv window at connection setup
1436 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1437 * then add the overage in to the credits returned.
1438 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001439 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1440 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301441
Steve Wisecfdda9d2010-04-21 15:30:06 -07001442 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1443 memset(req, 0, wrlen);
1444 INIT_TP_WR(req, ep->hwtid);
1445 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1446 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001447 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301448 RX_DACK_CHANGE_F |
1449 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001450 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001451 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1452 return credits;
1453}
1454
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301455#define RELAXED_IRD_NEGOTIATION 1
1456
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301457/*
1458 * process_mpa_reply - process streaming mode MPA reply
1459 *
1460 * Returns:
1461 *
1462 * 0 upon success indicating a connect request was delivered to the ULP
1463 * or the mpa request is incomplete but valid so far.
1464 *
1465 * 1 if a failure requires the caller to close the connection.
1466 *
1467 * 2 if a failure requires the caller to abort the connection.
1468 */
Steve Wisecc18b932014-04-24 14:31:53 -05001469static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001470{
1471 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301472 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301474 u16 resp_ird, resp_ord;
1475 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001476 struct c4iw_qp_attributes attrs;
1477 enum c4iw_qp_attr_mask mask;
1478 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001479 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001480
1481 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1482
1483 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001484 * If we get more than the supported amount of private data
1485 * then we must fail this connection.
1486 */
1487 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1488 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301489 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001490 }
1491
1492 /*
1493 * copy the new data into our accumulation buffer.
1494 */
1495 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1496 skb->len);
1497 ep->mpa_pkt_len += skb->len;
1498
1499 /*
1500 * if we don't even have the mpa message, then bail.
1501 */
1502 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001503 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001504 mpa = (struct mpa_message *) ep->mpa_pkt;
1505
1506 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301507 if (mpa->revision > mpa_rev) {
1508 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1509 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301511 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001512 }
1513 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1514 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301515 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001516 }
1517
1518 plen = ntohs(mpa->private_data_size);
1519
1520 /*
1521 * Fail if there's too much private data.
1522 */
1523 if (plen > MPA_MAX_PRIVATE_DATA) {
1524 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301525 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001526 }
1527
1528 /*
1529 * If plen does not account for pkt size
1530 */
1531 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1532 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301533 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001534 }
1535
1536 ep->plen = (u8) plen;
1537
1538 /*
1539 * If we don't have all the pdata yet, then bail.
1540 * We'll continue process when more data arrives.
1541 */
1542 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001543 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001544
1545 if (mpa->flags & MPA_REJECT) {
1546 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301547 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001548 }
1549
1550 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301551 * Stop mpa timer. If it expired, then
1552 * we ignore the MPA reply. process_timeout()
1553 * will abort the connection.
1554 */
1555 if (stop_ep_timer(ep))
1556 return 0;
1557
1558 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001559 * If we get here we have accumulated the entire mpa
1560 * start reply message including private data. And
1561 * the MPA header is valid.
1562 */
Steve Wisec529fb52014-03-21 20:40:37 +05301563 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001564 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001565 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301566 ep->mpa_attr.version = mpa->revision;
1567 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1568
1569 if (mpa->revision == 2) {
1570 ep->mpa_attr.enhanced_rdma_conn =
1571 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1572 if (ep->mpa_attr.enhanced_rdma_conn) {
1573 mpa_v2_params = (struct mpa_v2_conn_params *)
1574 (ep->mpa_pkt + sizeof(*mpa));
1575 resp_ird = ntohs(mpa_v2_params->ird) &
1576 MPA_V2_IRD_ORD_MASK;
1577 resp_ord = ntohs(mpa_v2_params->ord) &
1578 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301579 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1580 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301581
1582 /*
1583 * This is a double-check. Ideally, below checks are
1584 * not required since ird/ord stuff has been taken
1585 * care of in c4iw_accept_cr
1586 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301587 if (ep->ird < resp_ord) {
1588 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1589 ep->com.dev->rdev.lldi.max_ordird_qp)
1590 ep->ird = resp_ord;
1591 else
1592 insuff_ird = 1;
1593 } else if (ep->ird > resp_ord) {
1594 ep->ird = resp_ord;
1595 }
1596 if (ep->ord > resp_ird) {
1597 if (RELAXED_IRD_NEGOTIATION)
1598 ep->ord = resp_ird;
1599 else
1600 insuff_ird = 1;
1601 }
1602 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301603 err = -ENOMEM;
1604 ep->ird = resp_ord;
1605 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301606 }
1607
1608 if (ntohs(mpa_v2_params->ird) &
1609 MPA_V2_PEER2PEER_MODEL) {
1610 if (ntohs(mpa_v2_params->ord) &
1611 MPA_V2_RDMA_WRITE_RTR)
1612 ep->mpa_attr.p2p_type =
1613 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1614 else if (ntohs(mpa_v2_params->ord) &
1615 MPA_V2_RDMA_READ_RTR)
1616 ep->mpa_attr.p2p_type =
1617 FW_RI_INIT_P2PTYPE_READ_REQ;
1618 }
1619 }
1620 } else if (mpa->revision == 1)
1621 if (peer2peer)
1622 ep->mpa_attr.p2p_type = p2p_type;
1623
Steve Wisecfdda9d2010-04-21 15:30:06 -07001624 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301625 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1626 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1627 ep->mpa_attr.recv_marker_enabled,
1628 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1629 ep->mpa_attr.p2p_type, p2p_type);
1630
1631 /*
1632 * If responder's RTR does not match with that of initiator, assign
1633 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1634 * generated when moving QP to RTS state.
1635 * A TERM message will be sent after QP has moved to RTS state
1636 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001637 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301638 (ep->mpa_attr.p2p_type != p2p_type)) {
1639 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1640 rtr_mismatch = 1;
1641 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001642
1643 attrs.mpa_attr = ep->mpa_attr;
1644 attrs.max_ird = ep->ird;
1645 attrs.max_ord = ep->ord;
1646 attrs.llp_stream_handle = ep;
1647 attrs.next_state = C4IW_QP_STATE_RTS;
1648
1649 mask = C4IW_QP_ATTR_NEXT_STATE |
1650 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1651 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1652
1653 /* bind QP and TID with INIT_WR */
1654 err = c4iw_modify_qp(ep->com.qp->rhp,
1655 ep->com.qp, mask, &attrs, 1);
1656 if (err)
1657 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301658
1659 /*
1660 * If responder's RTR requirement did not match with what initiator
1661 * supports, generate TERM message
1662 */
1663 if (rtr_mismatch) {
1664 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1665 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1666 attrs.ecode = MPA_NOMATCH_RTR;
1667 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001668 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301669 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001670 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301671 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001672 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301673 goto out;
1674 }
1675
1676 /*
1677 * Generate TERM if initiator IRD is not sufficient for responder
1678 * provided ORD. Currently, we do the same behaviour even when
1679 * responder provided IRD is also not sufficient as regards to
1680 * initiator ORD.
1681 */
1682 if (insuff_ird) {
1683 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1684 __func__);
1685 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1686 attrs.ecode = MPA_INSUFF_IRD;
1687 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001688 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301689 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001690 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301691 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001692 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301693 goto out;
1694 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001695 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301696err_stop_timer:
1697 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001698err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301699 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001700out:
1701 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001702 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001703}
1704
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301705/*
1706 * process_mpa_request - process streaming mode MPA request
1707 *
1708 * Returns:
1709 *
1710 * 0 upon success indicating a connect request was delivered to the ULP
1711 * or the mpa request is incomplete but valid so far.
1712 *
1713 * 1 if a failure requires the caller to close the connection.
1714 *
1715 * 2 if a failure requires the caller to abort the connection.
1716 */
1717static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718{
1719 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301720 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001721 u16 plen;
1722
1723 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1724
Steve Wisecfdda9d2010-04-21 15:30:06 -07001725 /*
1726 * If we get more than the supported amount of private data
1727 * then we must fail this connection.
1728 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301729 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1730 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001731
1732 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1733
1734 /*
1735 * Copy the new data into our accumulation buffer.
1736 */
1737 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1738 skb->len);
1739 ep->mpa_pkt_len += skb->len;
1740
1741 /*
1742 * If we don't even have the mpa message, then bail.
1743 * We'll continue process when more data arrives.
1744 */
1745 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301746 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001747
1748 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001749 mpa = (struct mpa_message *) ep->mpa_pkt;
1750
1751 /*
1752 * Validate MPA Header.
1753 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301754 if (mpa->revision > mpa_rev) {
1755 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1756 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301757 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001758 }
1759
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301760 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1761 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001762
1763 plen = ntohs(mpa->private_data_size);
1764
1765 /*
1766 * Fail if there's too much private data.
1767 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301768 if (plen > MPA_MAX_PRIVATE_DATA)
1769 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001770
1771 /*
1772 * If plen does not account for pkt size
1773 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301774 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1775 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001776 ep->plen = (u8) plen;
1777
1778 /*
1779 * If we don't have all the pdata yet, then bail.
1780 */
1781 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301782 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001783
1784 /*
1785 * If we get here we have accumulated the entire mpa
1786 * start reply message including private data.
1787 */
1788 ep->mpa_attr.initiator = 0;
1789 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1790 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1791 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301792 ep->mpa_attr.version = mpa->revision;
1793 if (mpa->revision == 1)
1794 ep->tried_with_mpa_v1 = 1;
1795 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1796
1797 if (mpa->revision == 2) {
1798 ep->mpa_attr.enhanced_rdma_conn =
1799 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1800 if (ep->mpa_attr.enhanced_rdma_conn) {
1801 mpa_v2_params = (struct mpa_v2_conn_params *)
1802 (ep->mpa_pkt + sizeof(*mpa));
1803 ep->ird = ntohs(mpa_v2_params->ird) &
1804 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001805 ep->ird = min_t(u32, ep->ird,
1806 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301807 ep->ord = ntohs(mpa_v2_params->ord) &
1808 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001809 ep->ord = min_t(u32, ep->ord,
1810 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301811 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1812 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301813 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1814 if (peer2peer) {
1815 if (ntohs(mpa_v2_params->ord) &
1816 MPA_V2_RDMA_WRITE_RTR)
1817 ep->mpa_attr.p2p_type =
1818 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1819 else if (ntohs(mpa_v2_params->ord) &
1820 MPA_V2_RDMA_READ_RTR)
1821 ep->mpa_attr.p2p_type =
1822 FW_RI_INIT_P2PTYPE_READ_REQ;
1823 }
1824 }
1825 } else if (mpa->revision == 1)
1826 if (peer2peer)
1827 ep->mpa_attr.p2p_type = p2p_type;
1828
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1830 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1831 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1832 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1833 ep->mpa_attr.p2p_type);
1834
Hariprasad Se4b76a22016-05-06 22:17:59 +05301835 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001836
Hariprasad Se4b76a22016-05-06 22:17:59 +05301837 /* drive upcall */
1838 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1839 if (ep->parent_ep->com.state != DEAD) {
1840 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301841 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301842 } else {
1843 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301844 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301845 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301846 return 0;
1847
1848err_unlock_parent:
1849 mutex_unlock(&ep->parent_ep->com.mutex);
1850 goto err_out;
1851err_stop_timer:
1852 (void)stop_ep_timer(ep);
1853err_out:
1854 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855}
1856
1857static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1858{
1859 struct c4iw_ep *ep;
1860 struct cpl_rx_data *hdr = cplhdr(skb);
1861 unsigned int dlen = ntohs(hdr->len);
1862 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001863 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001864 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001865
Hariprasad S944661d2016-05-06 22:18:03 +05301866 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301867 if (!ep)
1868 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001869 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1870 skb_pull(skb, sizeof(*hdr));
1871 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301872 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001873
Steve Wisecfdda9d2010-04-21 15:30:06 -07001874 /* update RX credits */
1875 update_rx_credits(ep, dlen);
1876
Steve Wisec529fb52014-03-21 20:40:37 +05301877 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001878 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001879 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001880 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001881 break;
1882 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001883 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301884 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001885 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001886 case FPDU_MODE: {
1887 struct c4iw_qp_attributes attrs;
1888 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001889 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001890 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001891 " qpid %u ep %p state %d tid %u status %d\n",
1892 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301893 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301894 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001895 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001896 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1897 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001898 break;
1899 }
Vipul Pandya15579672013-01-07 13:11:52 +00001900 default:
1901 break;
1902 }
Steve Wisec529fb52014-03-21 20:40:37 +05301903 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001904 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301905 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301906 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001907 return 0;
1908}
1909
1910static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1911{
1912 struct c4iw_ep *ep;
1913 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001914 int release = 0;
1915 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001916
Hariprasad S944661d2016-05-06 22:18:03 +05301917 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301918 if (!ep) {
1919 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1920 return 0;
1921 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001922 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001923 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001924 switch (ep->com.state) {
1925 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001926 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001927 __state_set(&ep->com, DEAD);
1928 release = 1;
1929 break;
1930 default:
1931 printk(KERN_ERR "%s ep %p state %d\n",
1932 __func__, ep, ep->com.state);
1933 break;
1934 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001935 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001936
1937 if (release)
1938 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301939 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001940 return 0;
1941}
1942
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301943static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001944{
1945 struct sk_buff *skb;
1946 struct fw_ofld_connection_wr *req;
1947 unsigned int mtu_idx;
1948 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301949 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301950 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001951
1952 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1953 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1954 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001955 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301956 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301957 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1958 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001959 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001960 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301961 req->le.lport = sin->sin_port;
1962 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001963 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301964 req->le.pport = sin->sin_port;
1965 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001966 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301967 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1968 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001969 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301970 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001971 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001972 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301973 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301974 enable_tcp_timestamps,
1975 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001976 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301977
1978 /*
1979 * Specify the largest window that will fit in opt0. The
1980 * remainder will be specified in the rx_data_ack.
1981 */
1982 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001983 if (win > RCV_BUFSIZ_M)
1984 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301985
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001986 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1987 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001988 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001989 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001990 WND_SCALE_V(wscale) |
1991 MSS_IDX_V(mtu_idx) |
1992 L2T_IDX_V(ep->l2t->idx) |
1993 TX_CHAN_V(ep->tx_chan) |
1994 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301995 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001996 ULP_MODE_V(ULP_MODE_TCPDDP) |
1997 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001998 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1999 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002000 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002001 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002002 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002003 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002004 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002005 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002006 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002007 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002008 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
2009 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2010 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00002011 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2012 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302013 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002014}
2015
Steve Wisecfdda9d2010-04-21 15:30:06 -07002016/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05302017 * Some of the error codes above implicitly indicate that there is no TID
2018 * allocated with the result of an ACT_OPEN. We use this predicate to make
2019 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07002020 */
2021static inline int act_open_has_tid(int status)
2022{
Hariprasad S4c72efe2016-06-10 01:05:14 +05302023 return (status != CPL_ERR_TCAM_PARITY &&
2024 status != CPL_ERR_TCAM_MISS &&
2025 status != CPL_ERR_TCAM_FULL &&
2026 status != CPL_ERR_CONN_EXIST_SYNRECV &&
2027 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002028}
2029
Steve Wise7a2cea22014-03-14 21:52:07 +05302030/* Returns whether a CPL status conveys negative advice.
2031 */
2032static int is_neg_adv(unsigned int status)
2033{
2034 return status == CPL_ERR_RTX_NEG_ADVICE ||
2035 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2036 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2037}
2038
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302039static char *neg_adv_str(unsigned int status)
2040{
2041 switch (status) {
2042 case CPL_ERR_RTX_NEG_ADVICE:
2043 return "Retransmit timeout";
2044 case CPL_ERR_PERSIST_NEG_ADVICE:
2045 return "Persist timeout";
2046 case CPL_ERR_KEEPALV_NEG_ADVICE:
2047 return "Keepalive timeout";
2048 default:
2049 return "Unknown";
2050 }
2051}
2052
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302053static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2054{
2055 ep->snd_win = snd_win;
2056 ep->rcv_win = rcv_win;
2057 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2058}
2059
Vipul Pandya793dad92012-12-10 09:30:56 +00002060#define ACT_OPEN_RETRY_COUNT 2
2061
Vipul Pandya830662f2013-07-04 16:10:47 +05302062static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2063 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302064 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302065{
2066 struct neighbour *n;
2067 int err, step;
2068 struct net_device *pdev;
2069
2070 n = dst_neigh_lookup(dst, peer_ip);
2071 if (!n)
2072 return -ENODEV;
2073
2074 rcu_read_lock();
2075 err = -ENOMEM;
2076 if (n->dev->flags & IFF_LOOPBACK) {
2077 if (iptype == 4)
2078 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2079 else if (IS_ENABLED(CONFIG_IPV6))
2080 for_each_netdev(&init_net, pdev) {
2081 if (ipv6_chk_addr(&init_net,
2082 (struct in6_addr *)peer_ip,
2083 pdev, 1))
2084 break;
2085 }
2086 else
2087 pdev = NULL;
2088
2089 if (!pdev) {
2090 err = -ENODEV;
2091 goto out;
2092 }
2093 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302094 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302095 if (!ep->l2t)
2096 goto out;
2097 ep->mtu = pdev->mtu;
2098 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302099 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2100 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302101 step = cdev->rdev.lldi.ntxq /
2102 cdev->rdev.lldi.nchan;
2103 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2104 step = cdev->rdev.lldi.nrxq /
2105 cdev->rdev.lldi.nchan;
2106 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2107 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2108 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302109 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302110 dev_put(pdev);
2111 } else {
2112 pdev = get_real_dev(n->dev);
2113 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2114 n, pdev, 0);
2115 if (!ep->l2t)
2116 goto out;
2117 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002118 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302119 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2120 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302121 step = cdev->rdev.lldi.ntxq /
2122 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002123 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2124 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302125 step = cdev->rdev.lldi.nrxq /
2126 cdev->rdev.lldi.nchan;
2127 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002128 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302129 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302130
2131 if (clear_mpa_v1) {
2132 ep->retry_with_mpa_v1 = 0;
2133 ep->tried_with_mpa_v1 = 0;
2134 }
2135 }
2136 err = 0;
2137out:
2138 rcu_read_unlock();
2139
2140 neigh_release(n);
2141
2142 return err;
2143}
2144
Vipul Pandya793dad92012-12-10 09:30:56 +00002145static int c4iw_reconnect(struct c4iw_ep *ep)
2146{
2147 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302148 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302149 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002150 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302151 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002152 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302153 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002154 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302155 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002156 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302157 int iptype;
2158 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002159
2160 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2161 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302162 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002163
Hariprasad S4a740832016-06-10 01:05:15 +05302164 /* When MPA revision is different on nodes, the node with MPA_rev=2
2165 * tries to reconnect with MPA_rev 1 for the same EP through
2166 * c4iw_reconnect(), where the same EP is assigned with new tid for
2167 * further connection establishment. As we are using the same EP pointer
2168 * for reconnect, few skbs are used during the previous c4iw_connect(),
2169 * which leaves the EP with inadequate skbs for further
2170 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2171 * skb_list() during peer_abort(). Allocate skbs which is already used.
2172 */
2173 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2174 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2175 err = -ENOMEM;
2176 goto fail1;
2177 }
2178
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 /*
2180 * Allocate an active TID to initiate a TCP connection.
2181 */
2182 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2183 if (ep->atid == -1) {
2184 pr_err("%s - cannot alloc atid.\n", __func__);
2185 err = -ENOMEM;
2186 goto fail2;
2187 }
2188 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2189
2190 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002191 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302192 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2193 laddr->sin_addr.s_addr,
2194 raddr->sin_addr.s_addr,
2195 laddr->sin_port,
2196 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302197 iptype = 4;
2198 ra = (__u8 *)&raddr->sin_addr;
2199 } else {
2200 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2201 raddr6->sin6_addr.s6_addr,
2202 laddr6->sin6_port, raddr6->sin6_port, 0,
2203 raddr6->sin6_scope_id);
2204 iptype = 6;
2205 ra = (__u8 *)&raddr6->sin6_addr;
2206 }
2207 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002208 pr_err("%s - cannot find route.\n", __func__);
2209 err = -EHOSTUNREACH;
2210 goto fail3;
2211 }
Hariprasad S963cab52015-09-23 17:19:27 +05302212 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302213 ep->com.dev->rdev.lldi.adapter_type,
2214 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302215 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002216 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002217 goto fail4;
2218 }
2219
2220 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2221 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2222 ep->l2t->idx);
2223
2224 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302225 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002226
2227 /* send connect request to rnic */
2228 err = send_connect(ep);
2229 if (!err)
2230 goto out;
2231
2232 cxgb4_l2t_release(ep->l2t);
2233fail4:
2234 dst_release(ep->dst);
2235fail3:
2236 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2237 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2238fail2:
2239 /*
2240 * remember to send notification to upper layer.
2241 * We are in here so the upper layer is not aware that this is
2242 * re-connect attempt and so, upper layer is still waiting for
2243 * response of 1st connect request.
2244 */
2245 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302246fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002247 c4iw_put_ep(&ep->com);
2248out:
2249 return err;
2250}
2251
Steve Wisecfdda9d2010-04-21 15:30:06 -07002252static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2253{
2254 struct c4iw_ep *ep;
2255 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002256 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2257 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002258 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002259 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302260 struct sockaddr_in *la;
2261 struct sockaddr_in *ra;
2262 struct sockaddr_in6 *la6;
2263 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302264 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002265
2266 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002267 la = (struct sockaddr_in *)&ep->com.local_addr;
2268 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2269 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2270 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002271
2272 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2273 status, status2errno(status));
2274
Steve Wise7a2cea22014-03-14 21:52:07 +05302275 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302276 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2277 __func__, atid, status, neg_adv_str(status));
2278 ep->stats.connect_neg_adv++;
2279 mutex_lock(&dev->rdev.stats.lock);
2280 dev->rdev.stats.neg_adv++;
2281 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 return 0;
2283 }
2284
Vipul Pandya793dad92012-12-10 09:30:56 +00002285 set_bit(ACT_OPEN_RPL, &ep->com.history);
2286
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302287 /*
2288 * Log interesting failures.
2289 */
2290 switch (status) {
2291 case CPL_ERR_CONN_RESET:
2292 case CPL_ERR_CONN_TIMEDOUT:
2293 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002294 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302295 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002296 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302297 mutex_unlock(&dev->rdev.stats.lock);
2298 if (ep->com.local_addr.ss_family == AF_INET &&
2299 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302300 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2301 ntohl(rpl->atid_status))));
2302 if (ret)
2303 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002304 return 0;
2305 }
2306 break;
2307 case CPL_ERR_CONN_EXIST:
2308 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2309 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302310 if (ep->com.remote_addr.ss_family == AF_INET6) {
2311 struct sockaddr_in6 *sin6 =
2312 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002313 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302314 cxgb4_clip_release(
2315 ep->com.dev->rdev.lldi.ports[0],
2316 (const u32 *)
2317 &sin6->sin6_addr.s6_addr, 1);
2318 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002319 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2320 atid);
2321 cxgb4_free_atid(t, atid);
2322 dst_release(ep->dst);
2323 cxgb4_l2t_release(ep->l2t);
2324 c4iw_reconnect(ep);
2325 return 0;
2326 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002327 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302328 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302329 if (ep->com.local_addr.ss_family == AF_INET) {
2330 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2331 atid, status, status2errno(status),
2332 &la->sin_addr.s_addr, ntohs(la->sin_port),
2333 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2334 } else {
2335 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2336 atid, status, status2errno(status),
2337 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2338 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2339 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302340 break;
2341 }
2342
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302343fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002344 connect_reply_upcall(ep, status2errno(status));
2345 state_set(&ep->com, DEAD);
2346
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302347 if (ep->com.remote_addr.ss_family == AF_INET6) {
2348 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002349 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302350 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2351 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2352 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002353 if (status && act_open_has_tid(status))
2354 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2355
Vipul Pandya793dad92012-12-10 09:30:56 +00002356 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002357 cxgb4_free_atid(t, atid);
2358 dst_release(ep->dst);
2359 cxgb4_l2t_release(ep->l2t);
2360 c4iw_put_ep(&ep->com);
2361
2362 return 0;
2363}
2364
2365static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2366{
2367 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302369 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002370
2371 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002372 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2373 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002374 }
2375 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2376 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002377 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302378 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002379out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002380 return 0;
2381}
2382
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2384{
2385 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002386 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302387 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388
2389 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002390 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302391 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392 return 0;
2393}
2394
Hariprasad S9dec9002016-05-05 01:27:29 +05302395static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2396 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002397{
2398 struct cpl_pass_accept_rpl *rpl;
2399 unsigned int mtu_idx;
2400 u64 opt0;
2401 u32 opt2;
2402 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302403 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302404 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302405 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406
2407 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2408 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302409
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302411 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302412 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302413 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2414 rpl5 = (void *)rpl;
2415 INIT_TP_WR(rpl5, ep->hwtid);
2416 } else {
2417 skb_trim(skb, sizeof(*rpl));
2418 INIT_TP_WR(rpl, ep->hwtid);
2419 }
2420 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2421 ep->hwtid));
2422
2423 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302424 enable_tcp_timestamps && req->tcpopt.tstamp,
2425 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302427
2428 /*
2429 * Specify the largest window that will fit in opt0. The
2430 * remainder will be specified in the rx_data_ack.
2431 */
2432 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002433 if (win > RCV_BUFSIZ_M)
2434 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002435 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002436 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002437 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002438 WND_SCALE_V(wscale) |
2439 MSS_IDX_V(mtu_idx) |
2440 L2T_IDX_V(ep->l2t->idx) |
2441 TX_CHAN_V(ep->tx_chan) |
2442 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002443 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002444 ULP_MODE_V(ULP_MODE_TCPDDP) |
2445 RCV_BUFSIZ_V(win);
2446 opt2 = RX_CHANNEL_V(0) |
2447 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448
2449 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002450 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002452 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002454 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002455 if (enable_ecn) {
2456 const struct tcphdr *tcph;
2457 u32 hlen = ntohl(req->hdr_len);
2458
Hariprasad S963cab52015-09-23 17:19:27 +05302459 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2460 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2461 IP_HDR_LEN_G(hlen);
2462 else
2463 tcph = (const void *)(req + 1) +
2464 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002465 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002466 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002467 }
Hariprasad S963cab52015-09-23 17:19:27 +05302468 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302469 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002470 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302471 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302472 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302473 rpl5 = (void *)rpl;
2474 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2475 if (peer2peer)
2476 isn += 4;
2477 rpl5->iss = cpu_to_be32(isn);
2478 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002479 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002480
Steve Wisecfdda9d2010-04-21 15:30:06 -07002481 rpl->opt0 = cpu_to_be64(opt0);
2482 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002483 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302484 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002485
Hariprasad S9dec9002016-05-05 01:27:29 +05302486 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002487}
2488
Vipul Pandya830662f2013-07-04 16:10:47 +05302489static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002490{
Vipul Pandya830662f2013-07-04 16:10:47 +05302491 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 BUG_ON(skb_cloned(skb));
2493 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002494 release_tid(&dev->rdev, hwtid, skb);
2495 return;
2496}
2497
Steve Wisecfdda9d2010-04-21 15:30:06 -07002498static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2499{
Vipul Pandya793dad92012-12-10 09:30:56 +00002500 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002501 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002502 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002503 struct tid_info *t = dev->rdev.lldi.tids;
2504 unsigned int hwtid = GET_TID(req);
2505 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302506 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002507 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302508 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002509 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002510 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302511 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302512 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302513 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002514
Hariprasad Sf86fac72016-05-06 22:18:07 +05302515 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002516 if (!parent_ep) {
2517 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2518 goto reject;
2519 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002520
Steve Wisecfdda9d2010-04-21 15:30:06 -07002521 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302522 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002523 goto reject;
2524 }
2525
Varun Prakash85e42b02016-09-13 21:23:56 +05302526 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2527 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302528
Steve Wisecfdda9d2010-04-21 15:30:06 -07002529 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 if (iptype == 4) {
2531 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2532 , __func__, parent_ep, hwtid,
2533 local_ip, peer_ip, ntohs(local_port),
2534 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302535 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2536 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2537 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302538 } else {
2539 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2540 , __func__, parent_ep, hwtid,
2541 local_ip, peer_ip, ntohs(local_port),
2542 ntohs(peer_port), peer_mss);
2543 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002544 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302545 ((struct sockaddr_in6 *)
2546 &parent_ep->com.local_addr)->sin6_scope_id);
2547 }
2548 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002549 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2550 __func__);
2551 goto reject;
2552 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553
2554 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2555 if (!child_ep) {
2556 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2557 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002558 dst_release(dst);
2559 goto reject;
2560 }
David Miller3786cf12011-12-02 16:52:31 +00002561
Hariprasad S963cab52015-09-23 17:19:27 +05302562 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302563 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002564 if (err) {
2565 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2566 __func__);
2567 dst_release(dst);
2568 kfree(child_ep);
2569 goto reject;
2570 }
2571
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302572 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2573 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2574 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2575 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002576
Hariprasad S4a740832016-06-10 01:05:15 +05302577 skb_queue_head_init(&child_ep->com.ep_skb_list);
2578 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2579 goto fail;
2580
Steve Wisecfdda9d2010-04-21 15:30:06 -07002581 state_set(&child_ep->com, CONNECTING);
2582 child_ep->com.dev = dev;
2583 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002584
Vipul Pandya830662f2013-07-04 16:10:47 +05302585 if (iptype == 4) {
2586 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002587 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002588
Vipul Pandya830662f2013-07-04 16:10:47 +05302589 sin->sin_family = PF_INET;
2590 sin->sin_port = local_port;
2591 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002592
2593 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2594 sin->sin_family = PF_INET;
2595 sin->sin_port = ((struct sockaddr_in *)
2596 &parent_ep->com.local_addr)->sin_port;
2597 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2598
Steve Wise170003c2016-02-26 09:18:03 -06002599 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302600 sin->sin_family = PF_INET;
2601 sin->sin_port = peer_port;
2602 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2603 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002604 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302605 sin6->sin6_family = PF_INET6;
2606 sin6->sin6_port = local_port;
2607 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002608
2609 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2610 sin6->sin6_family = PF_INET6;
2611 sin6->sin6_port = ((struct sockaddr_in6 *)
2612 &parent_ep->com.local_addr)->sin6_port;
2613 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2614
Steve Wise170003c2016-02-26 09:18:03 -06002615 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302616 sin6->sin6_family = PF_INET6;
2617 sin6->sin6_port = peer_port;
2618 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2619 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002620
Steve Wisecfdda9d2010-04-21 15:30:06 -07002621 c4iw_get_ep(&parent_ep->com);
2622 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302623 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002624 child_ep->dst = dst;
2625 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002626
2627 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002628 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629
2630 init_timer(&child_ep->timer);
2631 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302632 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302633 if (accept_cr(child_ep, skb, req)) {
2634 c4iw_put_ep(&parent_ep->com);
2635 release_ep_resources(child_ep);
2636 } else {
2637 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2638 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302639 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002640 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302641 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2642 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2643 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002644 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302645fail:
2646 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302648 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302649 if (parent_ep)
2650 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651out:
2652 return 0;
2653}
2654
2655static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2656{
2657 struct c4iw_ep *ep;
2658 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302660 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002661
Hariprasad S944661d2016-05-06 22:18:03 +05302662 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002663 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2664 ep->snd_seq = be32_to_cpu(req->snd_isn);
2665 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2666
Vipul Pandya1cab7752012-12-10 09:30:55 +00002667 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2668 ntohs(req->tcp_opt));
2669
Steve Wisecfdda9d2010-04-21 15:30:06 -07002670 set_emss(ep, ntohs(req->tcp_opt));
2671
2672 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302673 mutex_lock(&ep->com.mutex);
2674 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002676 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302677 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302678 mutex_unlock(&ep->com.mutex);
2679 if (ret)
2680 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302681 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002682
2683 return 0;
2684}
2685
2686static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2687{
2688 struct cpl_peer_close *hdr = cplhdr(skb);
2689 struct c4iw_ep *ep;
2690 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 int disconnect = 1;
2692 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002694 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002695
Hariprasad S944661d2016-05-06 22:18:03 +05302696 ep = get_ep_from_tid(dev, tid);
2697 if (!ep)
2698 return 0;
2699
Steve Wisecfdda9d2010-04-21 15:30:06 -07002700 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2701 dst_confirm(ep->dst);
2702
Vipul Pandya793dad92012-12-10 09:30:56 +00002703 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002704 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002705 switch (ep->com.state) {
2706 case MPA_REQ_WAIT:
2707 __state_set(&ep->com, CLOSING);
2708 break;
2709 case MPA_REQ_SENT:
2710 __state_set(&ep->com, CLOSING);
2711 connect_reply_upcall(ep, -ECONNRESET);
2712 break;
2713 case MPA_REQ_RCVD:
2714
2715 /*
2716 * We're gonna mark this puppy DEAD, but keep
2717 * the reference on it until the ULP accepts or
2718 * rejects the CR. Also wake up anyone waiting
2719 * in rdma connection migration (see c4iw_accept_cr()).
2720 */
2721 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002722 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002723 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724 break;
2725 case MPA_REP_SENT:
2726 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002727 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002728 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 break;
2730 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002731 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002732 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002733 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002734 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002735 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002736 if (ret != -ECONNRESET) {
2737 peer_close_upcall(ep);
2738 disconnect = 1;
2739 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 break;
2741 case ABORTING:
2742 disconnect = 0;
2743 break;
2744 case CLOSING:
2745 __state_set(&ep->com, MORIBUND);
2746 disconnect = 0;
2747 break;
2748 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002749 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002750 if (ep->com.cm_id && ep->com.qp) {
2751 attrs.next_state = C4IW_QP_STATE_IDLE;
2752 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2753 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2754 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302755 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 __state_set(&ep->com, DEAD);
2757 release = 1;
2758 disconnect = 0;
2759 break;
2760 case DEAD:
2761 disconnect = 0;
2762 break;
2763 default:
2764 BUG_ON(1);
2765 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002766 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002767 if (disconnect)
2768 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2769 if (release)
2770 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302771 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002772 return 0;
2773}
2774
Steve Wisecfdda9d2010-04-21 15:30:06 -07002775static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2776{
2777 struct cpl_abort_req_rss *req = cplhdr(skb);
2778 struct c4iw_ep *ep;
2779 struct cpl_abort_rpl *rpl;
2780 struct sk_buff *rpl_skb;
2781 struct c4iw_qp_attributes attrs;
2782 int ret;
2783 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002784 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785
Hariprasad S944661d2016-05-06 22:18:03 +05302786 ep = get_ep_from_tid(dev, tid);
2787 if (!ep)
2788 return 0;
2789
Steve Wise7a2cea22014-03-14 21:52:07 +05302790 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302791 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2792 __func__, ep->hwtid, req->status,
2793 neg_adv_str(req->status));
2794 ep->stats.abort_neg_adv++;
2795 mutex_lock(&dev->rdev.stats.lock);
2796 dev->rdev.stats.neg_adv++;
2797 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302798 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002800 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2801 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002802 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002803
2804 /*
2805 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302806 * However, this is not needed if com state is just
2807 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002808 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302809 if (ep->com.state != MPA_REQ_SENT)
2810 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002811
2812 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 switch (ep->com.state) {
2814 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302815 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002816 break;
2817 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002818 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002819 break;
2820 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002821 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002822 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302823 connect_reply_upcall(ep, -ECONNRESET);
2824 else {
2825 /*
2826 * we just don't send notification upwards because we
2827 * want to retry with mpa_v1 without upper layers even
2828 * knowing it.
2829 *
2830 * do some housekeeping so as to re-initiate the
2831 * connection
2832 */
2833 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2834 mpa_rev);
2835 ep->retry_with_mpa_v1 = 1;
2836 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 break;
2838 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 break;
2840 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002841 break;
2842 case MORIBUND:
2843 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002844 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002845 /*FALLTHROUGH*/
2846 case FPDU_MODE:
2847 if (ep->com.cm_id && ep->com.qp) {
2848 attrs.next_state = C4IW_QP_STATE_ERROR;
2849 ret = c4iw_modify_qp(ep->com.qp->rhp,
2850 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2851 &attrs, 1);
2852 if (ret)
2853 printk(KERN_ERR MOD
2854 "%s - qp <- error failed!\n",
2855 __func__);
2856 }
2857 peer_abort_upcall(ep);
2858 break;
2859 case ABORTING:
2860 break;
2861 case DEAD:
2862 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002863 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302864 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865 default:
2866 BUG_ON(1);
2867 break;
2868 }
2869 dst_confirm(ep->dst);
2870 if (ep->com.state != ABORTING) {
2871 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302872 /* we don't release if we want to retry with mpa_v1 */
2873 if (!ep->retry_with_mpa_v1)
2874 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002875 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002876 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877
Hariprasad S4a740832016-06-10 01:05:15 +05302878 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2879 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002880 release = 1;
2881 goto out;
2882 }
2883 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2884 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2885 INIT_TP_WR(rpl, ep->hwtid);
2886 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2887 rpl->cmd = CPL_ABORT_NO_RST;
2888 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2889out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002890 if (release)
2891 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002892 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302893 if (ep->com.remote_addr.ss_family == AF_INET6) {
2894 struct sockaddr_in6 *sin6 =
2895 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002896 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302897 cxgb4_clip_release(
2898 ep->com.dev->rdev.lldi.ports[0],
2899 (const u32 *)&sin6->sin6_addr.s6_addr,
2900 1);
2901 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002902 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302903 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2904 dst_release(ep->dst);
2905 cxgb4_l2t_release(ep->l2t);
2906 c4iw_reconnect(ep);
2907 }
2908
Hariprasad S944661d2016-05-06 22:18:03 +05302909deref_ep:
2910 c4iw_put_ep(&ep->com);
2911 /* Dereferencing ep, referenced in peer_abort_intr() */
2912 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002913 return 0;
2914}
2915
2916static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2917{
2918 struct c4iw_ep *ep;
2919 struct c4iw_qp_attributes attrs;
2920 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002921 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002922 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923
Hariprasad S944661d2016-05-06 22:18:03 +05302924 ep = get_ep_from_tid(dev, tid);
2925 if (!ep)
2926 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002927
2928 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2929 BUG_ON(!ep);
2930
2931 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002932 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302933 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002934 switch (ep->com.state) {
2935 case CLOSING:
2936 __state_set(&ep->com, MORIBUND);
2937 break;
2938 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002939 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002940 if ((ep->com.cm_id) && (ep->com.qp)) {
2941 attrs.next_state = C4IW_QP_STATE_IDLE;
2942 c4iw_modify_qp(ep->com.qp->rhp,
2943 ep->com.qp,
2944 C4IW_QP_ATTR_NEXT_STATE,
2945 &attrs, 1);
2946 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302947 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948 __state_set(&ep->com, DEAD);
2949 release = 1;
2950 break;
2951 case ABORTING:
2952 case DEAD:
2953 break;
2954 default:
2955 BUG_ON(1);
2956 break;
2957 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002958 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 if (release)
2960 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302961 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 return 0;
2963}
2964
2965static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2966{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002967 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002968 unsigned int tid = GET_TID(rpl);
2969 struct c4iw_ep *ep;
2970 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002971
Hariprasad S944661d2016-05-06 22:18:03 +05302972 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002973 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002974
Steve Wise30c95c22011-05-09 22:06:22 -07002975 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002976 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2977 ep->com.qp->wq.sq.qid);
2978 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2979 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2980 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2981 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002982 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302983 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002984
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985 return 0;
2986}
2987
2988/*
2989 * Upcall from the adapter indicating data has been transmitted.
2990 * For us its just the single MPA request or reply. We can now free
2991 * the skb holding the mpa message.
2992 */
2993static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2994{
2995 struct c4iw_ep *ep;
2996 struct cpl_fw4_ack *hdr = cplhdr(skb);
2997 u8 credits = hdr->credits;
2998 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002999
3000
Hariprasad S944661d2016-05-06 22:18:03 +05303001 ep = get_ep_from_tid(dev, tid);
3002 if (!ep)
3003 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003004 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
3005 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07003006 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3007 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05303008 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 }
3010
3011 dst_confirm(ep->dst);
3012 if (ep->mpa_skb) {
3013 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3014 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3015 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07003016 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003017 kfree_skb(ep->mpa_skb);
3018 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303019 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3020 stop_ep_timer(ep);
3021 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003022 }
Hariprasad S944661d2016-05-06 22:18:03 +05303023out:
3024 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003025 return 0;
3026}
3027
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3029{
Hariprasad Sbce28412016-06-10 01:05:13 +05303030 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003031 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05303032
Steve Wisecfdda9d2010-04-21 15:30:06 -07003033 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3034
Steve Wisea7db89e2014-03-21 20:40:35 +05303035 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303036 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303037 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003038 c4iw_put_ep(&ep->com);
3039 return -ECONNRESET;
3040 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003041 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003042 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05303043 abort = 1;
3044 else
3045 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303046 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05303047
3048 stop_ep_timer(ep);
3049 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003050 c4iw_put_ep(&ep->com);
3051 return 0;
3052}
3053
3054int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3055{
3056 int err;
3057 struct c4iw_qp_attributes attrs;
3058 enum c4iw_qp_attr_mask mask;
3059 struct c4iw_ep *ep = to_ep(cm_id);
3060 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3061 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303062 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063
3064 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303065
3066 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303067 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303069 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003070 }
3071
Steve Wisecfdda9d2010-04-21 15:30:06 -07003072 BUG_ON(!qp);
3073
Vipul Pandya793dad92012-12-10 09:30:56 +00003074 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303075 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3076 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003077 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303078 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003079 }
3080
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303081 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3082 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303083 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003084 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303085 } else {
3086 ep->ird = conn_param->ird;
3087 ep->ord = conn_param->ord;
3088 send_mpa_reject(ep, conn_param->private_data,
3089 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303090 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303091 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303092 }
3093 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303094 if (conn_param->ird < ep->ord) {
3095 if (RELAXED_IRD_NEGOTIATION &&
3096 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3097 conn_param->ird = ep->ord;
3098 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303099 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303100 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303101 }
3102 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303103 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003104 ep->ird = conn_param->ird;
3105 ep->ord = conn_param->ord;
3106
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303107 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303108 if (peer2peer && ep->ird == 0)
3109 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303110 } else {
3111 if (peer2peer &&
3112 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303113 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303114 ep->ird = 1;
3115 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003116
3117 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3118
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303119 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303120 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303121 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003122 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303123
Steve Wisecfdda9d2010-04-21 15:30:06 -07003124 /* bind QP to EP and move to RTS */
3125 attrs.mpa_attr = ep->mpa_attr;
3126 attrs.max_ird = ep->ird;
3127 attrs.max_ord = ep->ord;
3128 attrs.llp_stream_handle = ep;
3129 attrs.next_state = C4IW_QP_STATE_RTS;
3130
3131 /* bind QP and TID with INIT_WR */
3132 mask = C4IW_QP_ATTR_NEXT_STATE |
3133 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3134 C4IW_QP_ATTR_MPA_ATTR |
3135 C4IW_QP_ATTR_MAX_IRD |
3136 C4IW_QP_ATTR_MAX_ORD;
3137
3138 err = c4iw_modify_qp(ep->com.qp->rhp,
3139 ep->com.qp, mask, &attrs, 1);
3140 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303141 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303142
3143 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003144 err = send_mpa_reply(ep, conn_param->private_data,
3145 conn_param->private_data_len);
3146 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303147 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003148
Steve Wisea7db89e2014-03-21 20:40:35 +05303149 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003150 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303151 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003152 c4iw_put_ep(&ep->com);
3153 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303154err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303155 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303156err_abort:
3157 abort = 1;
3158err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303159 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303160 if (abort)
3161 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003162 c4iw_put_ep(&ep->com);
3163 return err;
3164}
3165
Vipul Pandya830662f2013-07-04 16:10:47 +05303166static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3167{
3168 struct in_device *ind;
3169 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003170 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3171 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303172
3173 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3174 if (!ind)
3175 return -EADDRNOTAVAIL;
3176 for_primary_ifa(ind) {
3177 laddr->sin_addr.s_addr = ifa->ifa_address;
3178 raddr->sin_addr.s_addr = ifa->ifa_address;
3179 found = 1;
3180 break;
3181 }
3182 endfor_ifa(ind);
3183 in_dev_put(ind);
3184 return found ? 0 : -EADDRNOTAVAIL;
3185}
3186
3187static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3188 unsigned char banned_flags)
3189{
3190 struct inet6_dev *idev;
3191 int err = -EADDRNOTAVAIL;
3192
3193 rcu_read_lock();
3194 idev = __in6_dev_get(dev);
3195 if (idev != NULL) {
3196 struct inet6_ifaddr *ifp;
3197
3198 read_lock_bh(&idev->lock);
3199 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3200 if (ifp->scope == IFA_LINK &&
3201 !(ifp->flags & banned_flags)) {
3202 memcpy(addr, &ifp->addr, 16);
3203 err = 0;
3204 break;
3205 }
3206 }
3207 read_unlock_bh(&idev->lock);
3208 }
3209 rcu_read_unlock();
3210 return err;
3211}
3212
3213static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3214{
3215 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003216 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3217 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303218
Nicholas Krause54b9a962015-08-26 23:00:59 -04003219 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303220 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3221 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3222 return 0;
3223 }
3224 return -EADDRNOTAVAIL;
3225}
3226
Steve Wisecfdda9d2010-04-21 15:30:06 -07003227int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3228{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003229 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3230 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003231 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003232 struct sockaddr_in *laddr;
3233 struct sockaddr_in *raddr;
3234 struct sockaddr_in6 *laddr6;
3235 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303236 __u8 *ra;
3237 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003238
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303239 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3240 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003241 err = -EINVAL;
3242 goto out;
3243 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003244 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3245 if (!ep) {
3246 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3247 err = -ENOMEM;
3248 goto out;
3249 }
Hariprasad S4a740832016-06-10 01:05:15 +05303250
3251 skb_queue_head_init(&ep->com.ep_skb_list);
3252 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3253 err = -ENOMEM;
3254 goto fail1;
3255 }
3256
Steve Wisecfdda9d2010-04-21 15:30:06 -07003257 init_timer(&ep->timer);
3258 ep->plen = conn_param->private_data_len;
3259 if (ep->plen)
3260 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3261 conn_param->private_data, ep->plen);
3262 ep->ird = conn_param->ird;
3263 ep->ord = conn_param->ord;
3264
3265 if (peer2peer && ep->ord == 0)
3266 ep->ord = 1;
3267
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303269 ref_cm_id(&ep->com);
3270 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003271 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303272 if (!ep->com.qp) {
3273 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3274 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303275 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303276 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003277 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003278 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3279 ep->com.qp, cm_id);
3280
3281 /*
3282 * Allocate an active TID to initiate a TCP connection.
3283 */
3284 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3285 if (ep->atid == -1) {
3286 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3287 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303288 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003289 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003290 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003291
Steve Wise170003c2016-02-26 09:18:03 -06003292 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003293 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003294 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003295 sizeof(ep->com.remote_addr));
3296
Steve Wise170003c2016-02-26 09:18:03 -06003297 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3298 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3299 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3300 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003301
Steve Wise170003c2016-02-26 09:18:03 -06003302 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303303 iptype = 4;
3304 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003305
Vipul Pandya830662f2013-07-04 16:10:47 +05303306 /*
3307 * Handle loopback requests to INADDR_ANY.
3308 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003309 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303310 err = pick_local_ipaddrs(dev, cm_id);
3311 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303312 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303313 }
3314
3315 /* find a route */
3316 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3317 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3318 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303319 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3320 laddr->sin_addr.s_addr,
3321 raddr->sin_addr.s_addr,
3322 laddr->sin_port,
3323 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303324 } else {
3325 iptype = 6;
3326 ra = (__u8 *)&raddr6->sin6_addr;
3327
3328 /*
3329 * Handle loopback requests to INADDR_ANY.
3330 */
3331 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3332 err = pick_local_ip6addrs(dev, cm_id);
3333 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303334 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303335 }
3336
3337 /* find a route */
3338 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3339 __func__, laddr6->sin6_addr.s6_addr,
3340 ntohs(laddr6->sin6_port),
3341 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3342 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3343 raddr6->sin6_addr.s6_addr,
3344 laddr6->sin6_port, raddr6->sin6_port, 0,
3345 raddr6->sin6_scope_id);
3346 }
3347 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003348 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3349 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303350 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003351 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003352
Hariprasad S963cab52015-09-23 17:19:27 +05303353 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303354 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003355 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003356 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303357 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003358 }
3359
3360 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3361 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3362 ep->l2t->idx);
3363
3364 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303365 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003366
3367 /* send connect request to rnic */
3368 err = send_connect(ep);
3369 if (!err)
3370 goto out;
3371
3372 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303373fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003374 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303375fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003376 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003377 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303378fail2:
3379 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303380 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303381fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003382 c4iw_put_ep(&ep->com);
3383out:
3384 return err;
3385}
3386
Vipul Pandya830662f2013-07-04 16:10:47 +05303387static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3388{
3389 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003390 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003391 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303392
Hariprasad S28de1f72016-01-13 10:03:14 +05303393 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3394 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3395 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3396 if (err)
3397 return err;
3398 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303399 c4iw_init_wr_wait(&ep->com.wr_wait);
3400 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3401 ep->stid, &sin6->sin6_addr,
3402 sin6->sin6_port,
3403 ep->com.dev->rdev.lldi.rxq_ids[0]);
3404 if (!err)
3405 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3406 &ep->com.wr_wait,
3407 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303408 else if (err > 0)
3409 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303410 if (err) {
3411 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3412 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303413 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3414 err, ep->stid,
3415 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303416 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303417 return err;
3418}
3419
3420static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3421{
3422 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003423 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003424 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303425
3426 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3427 do {
3428 err = cxgb4_create_server_filter(
3429 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3430 sin->sin_addr.s_addr, sin->sin_port, 0,
3431 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3432 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303433 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3434 err = -EIO;
3435 break;
3436 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303437 set_current_state(TASK_UNINTERRUPTIBLE);
3438 schedule_timeout(usecs_to_jiffies(100));
3439 }
3440 } while (err == -EBUSY);
3441 } else {
3442 c4iw_init_wr_wait(&ep->com.wr_wait);
3443 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3444 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3445 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3446 if (!err)
3447 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3448 &ep->com.wr_wait,
3449 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303450 else if (err > 0)
3451 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303452 }
3453 if (err)
3454 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3455 , err, ep->stid,
3456 &sin->sin_addr, ntohs(sin->sin_port));
3457 return err;
3458}
3459
Steve Wisecfdda9d2010-04-21 15:30:06 -07003460int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3461{
3462 int err = 0;
3463 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3464 struct c4iw_listen_ep *ep;
3465
Steve Wisecfdda9d2010-04-21 15:30:06 -07003466 might_sleep();
3467
3468 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3469 if (!ep) {
3470 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3471 err = -ENOMEM;
3472 goto fail1;
3473 }
Hariprasad S4a740832016-06-10 01:05:15 +05303474 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003476 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303477 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003478 ep->com.dev = dev;
3479 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003480 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303481 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482
3483 /*
3484 * Allocate a server TID.
3485 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303486 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3487 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303488 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003489 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003490 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303491 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003492 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003493
Steve Wisecfdda9d2010-04-21 15:30:06 -07003494 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003495 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003496 err = -ENOMEM;
3497 goto fail2;
3498 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003499 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003500
Steve Wise170003c2016-02-26 09:18:03 -06003501 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3502 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003503
Steve Wisecfdda9d2010-04-21 15:30:06 -07003504 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303505 if (ep->com.local_addr.ss_family == AF_INET)
3506 err = create_server4(dev, ep);
3507 else
3508 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003509 if (!err) {
3510 cm_id->provider_data = ep;
3511 goto out;
3512 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003513
Vipul Pandya830662f2013-07-04 16:10:47 +05303514 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3515 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003516fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303517 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 c4iw_put_ep(&ep->com);
3519fail1:
3520out:
3521 return err;
3522}
3523
3524int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3525{
3526 int err;
3527 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3528
3529 PDBG("%s ep %p\n", __func__, ep);
3530
3531 might_sleep();
3532 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303533 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3534 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003535 err = cxgb4_remove_server_filter(
3536 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3537 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3538 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303539 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003540 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303541 err = cxgb4_remove_server(
3542 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3543 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003544 if (err)
3545 goto done;
3546 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3547 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003548 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303549 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3550 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003551 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003552 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303553 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3554 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003555done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303556 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003557 c4iw_put_ep(&ep->com);
3558 return err;
3559}
3560
3561int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3562{
3563 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003564 int close = 0;
3565 int fatal = 0;
3566 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003567
Steve Wise2f5b48c2010-09-10 11:15:36 -05003568 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003569
3570 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3571 states[ep->com.state], abrupt);
3572
Hariprasad S6e410d82016-05-05 01:27:31 +05303573 /*
3574 * Ref the ep here in case we have fatal errors causing the
3575 * ep to be released and freed.
3576 */
3577 c4iw_get_ep(&ep->com);
3578
Steve Wisecfdda9d2010-04-21 15:30:06 -07003579 rdev = &ep->com.dev->rdev;
3580 if (c4iw_fatal_error(rdev)) {
3581 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303582 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003583 ep->com.state = DEAD;
3584 }
3585 switch (ep->com.state) {
3586 case MPA_REQ_WAIT:
3587 case MPA_REQ_SENT:
3588 case MPA_REQ_RCVD:
3589 case MPA_REP_SENT:
3590 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303591 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003592 close = 1;
3593 if (abrupt)
3594 ep->com.state = ABORTING;
3595 else {
3596 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003597
3598 /*
3599 * if we close before we see the fw4_ack() then we fix
3600 * up the timer state since we're reusing it.
3601 */
3602 if (ep->mpa_skb &&
3603 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3604 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3605 stop_ep_timer(ep);
3606 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003607 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003608 }
3609 set_bit(CLOSE_SENT, &ep->com.flags);
3610 break;
3611 case CLOSING:
3612 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3613 close = 1;
3614 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003615 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003616 ep->com.state = ABORTING;
3617 } else
3618 ep->com.state = MORIBUND;
3619 }
3620 break;
3621 case MORIBUND:
3622 case ABORTING:
3623 case DEAD:
3624 PDBG("%s ignoring disconnect ep %p state %u\n",
3625 __func__, ep, ep->com.state);
3626 break;
3627 default:
3628 BUG();
3629 break;
3630 }
3631
Steve Wisecfdda9d2010-04-21 15:30:06 -07003632 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003633 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003634 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303635 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303636 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003637 } else {
3638 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303639 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003640 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303641 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303642 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303643 if (!abrupt) {
3644 stop_ep_timer(ep);
3645 close_complete_upcall(ep, -EIO);
3646 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303647 if (ep->com.qp) {
3648 struct c4iw_qp_attributes attrs;
3649
3650 attrs.next_state = C4IW_QP_STATE_ERROR;
3651 ret = c4iw_modify_qp(ep->com.qp->rhp,
3652 ep->com.qp,
3653 C4IW_QP_ATTR_NEXT_STATE,
3654 &attrs, 1);
3655 if (ret)
3656 pr_err(MOD
3657 "%s - qp <- error failed!\n",
3658 __func__);
3659 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003660 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303661 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003662 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003663 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303664 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003665 if (fatal)
3666 release_ep_resources(ep);
3667 return ret;
3668}
3669
Vipul Pandya1cab7752012-12-10 09:30:55 +00003670static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3671 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3672{
3673 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003674 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003675
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003676 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3677 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003678 if (!ep)
3679 return;
3680
3681 switch (req->retval) {
3682 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003683 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3684 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3685 send_fw_act_open_req(ep, atid);
3686 return;
3687 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003688 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003689 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3690 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3691 send_fw_act_open_req(ep, atid);
3692 return;
3693 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003694 break;
3695 default:
3696 pr_info("%s unexpected ofld conn wr retval %d\n",
3697 __func__, req->retval);
3698 break;
3699 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003700 pr_err("active ofld_connect_wr failure %d atid %d\n",
3701 req->retval, atid);
3702 mutex_lock(&dev->rdev.stats.lock);
3703 dev->rdev.stats.act_ofld_conn_fails++;
3704 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003705 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003706 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303707 if (ep->com.remote_addr.ss_family == AF_INET6) {
3708 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003709 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303710 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3711 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3712 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003713 remove_handle(dev, &dev->atid_idr, atid);
3714 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3715 dst_release(ep->dst);
3716 cxgb4_l2t_release(ep->l2t);
3717 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003718}
3719
3720static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3721 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3722{
3723 struct sk_buff *rpl_skb;
3724 struct cpl_pass_accept_req *cpl;
3725 int ret;
3726
Paul Bolle710a3112013-02-05 20:51:30 +00003727 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003728 BUG_ON(!rpl_skb);
3729 if (req->retval) {
3730 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003731 mutex_lock(&dev->rdev.stats.lock);
3732 dev->rdev.stats.pas_ofld_conn_fails++;
3733 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003734 kfree_skb(rpl_skb);
3735 } else {
3736 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3737 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003738 (__force u32) htonl(
3739 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003740 ret = pass_accept_req(dev, rpl_skb);
3741 if (!ret)
3742 kfree_skb(rpl_skb);
3743 }
3744 return;
3745}
3746
3747static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003748{
3749 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003750 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3751
3752 switch (rpl->type) {
3753 case FW6_TYPE_CQE:
3754 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3755 break;
3756 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3757 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3758 switch (req->t_state) {
3759 case TCP_SYN_SENT:
3760 active_ofld_conn_reply(dev, skb, req);
3761 break;
3762 case TCP_SYN_RECV:
3763 passive_ofld_conn_reply(dev, skb, req);
3764 break;
3765 default:
3766 pr_err("%s unexpected ofld conn wr state %d\n",
3767 __func__, req->t_state);
3768 break;
3769 }
3770 break;
3771 }
3772 return 0;
3773}
3774
3775static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3776{
Hariprasad S963cab52015-09-23 17:19:27 +05303777 __be32 l2info;
3778 __be16 hdr_len, vlantag, len;
3779 u16 eth_hdr_len;
3780 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003781 u8 intf;
3782 struct cpl_rx_pkt *cpl = cplhdr(skb);
3783 struct cpl_pass_accept_req *req;
3784 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003785 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303786 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003787
Vipul Pandyaf079af72013-03-14 05:08:58 +00003788 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003789 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303790 vlantag = cpl->vlan;
3791 len = cpl->len;
3792 l2info = cpl->l2info;
3793 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003794 intf = cpl->iff;
3795
3796 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3797
3798 /*
3799 * We need to parse the TCP options from SYN packet.
3800 * to generate cpl_pass_accept_req.
3801 */
3802 memset(&tmp_opt, 0, sizeof(tmp_opt));
3803 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003804 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003805
3806 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3807 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303808 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3809 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303810 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303811 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303812 type = dev->rdev.lldi.adapter_type;
3813 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3814 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3815 req->hdr_len =
3816 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3817 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3818 eth_hdr_len = is_t4(type) ?
3819 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3820 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3821 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3822 IP_HDR_LEN_V(ip_hdr_len) |
3823 ETH_HDR_LEN_V(eth_hdr_len));
3824 } else { /* T6 and later */
3825 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3826 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3827 T6_IP_HDR_LEN_V(ip_hdr_len) |
3828 T6_ETH_HDR_LEN_V(eth_hdr_len));
3829 }
3830 req->vlan = vlantag;
3831 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003832 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3833 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003834 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3835 if (tmp_opt.wscale_ok)
3836 req->tcpopt.wsf = tmp_opt.snd_wscale;
3837 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3838 if (tmp_opt.sack_ok)
3839 req->tcpopt.sack = 1;
3840 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3841 return;
3842}
3843
3844static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3845 __be32 laddr, __be16 lport,
3846 __be32 raddr, __be16 rport,
3847 u32 rcv_isn, u32 filter, u16 window,
3848 u32 rss_qid, u8 port_id)
3849{
3850 struct sk_buff *req_skb;
3851 struct fw_ofld_connection_wr *req;
3852 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303853 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003854
3855 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3856 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3857 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003858 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303859 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303860 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003861 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003862 req->le.lport = lport;
3863 req->le.pport = rport;
3864 req->le.u.ipv4.lip = laddr;
3865 req->le.u.ipv4.pip = raddr;
3866 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3867 req->tcb.rcv_adv = htons(window);
3868 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303869 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3870 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3871 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003872 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003873
3874 /*
3875 * We store the qid in opt2 which will be used by the firmware
3876 * to send us the wr response.
3877 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003878 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003879
3880 /*
3881 * We initialize the MSS index in TCB to 0xF.
3882 * So that when driver sends cpl_pass_accept_rpl
3883 * TCB picks up the correct value. If this was 0
3884 * TP will ignore any value > 0 for MSS index.
3885 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003886 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303887 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003888
3889 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303890 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3891 if (ret < 0) {
3892 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3893 ret);
3894 kfree_skb(skb);
3895 kfree_skb(req_skb);
3896 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003897}
3898
3899/*
3900 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3901 * messages when a filter is being used instead of server to
3902 * redirect a syn packet. When packets hit filter they are redirected
3903 * to the offload queue and driver tries to establish the connection
3904 * using firmware work request.
3905 */
3906static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3907{
3908 int stid;
3909 unsigned int filter;
3910 struct ethhdr *eh = NULL;
3911 struct vlan_ethhdr *vlan_eh = NULL;
3912 struct iphdr *iph;
3913 struct tcphdr *tcph;
3914 struct rss_header *rss = (void *)skb->data;
3915 struct cpl_rx_pkt *cpl = (void *)skb->data;
3916 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3917 struct l2t_entry *e;
3918 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303919 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003920 u16 window;
3921 struct port_info *pi;
3922 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003923 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003924 int step;
3925 u32 tx_chan;
3926 struct neighbour *neigh;
3927
3928 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003929 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003930 goto reject;
3931
3932 /*
3933 * Drop all packets which did not hit the filter.
3934 * Unlikely to happen.
3935 */
3936 if (!(rss->filter_hit && rss->filter_tid))
3937 goto reject;
3938
3939 /*
3940 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3941 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303942 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003943
Hariprasad Sf86fac72016-05-06 22:18:07 +05303944 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003945 if (!lep) {
3946 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3947 goto reject;
3948 }
3949
Hariprasad S963cab52015-09-23 17:19:27 +05303950 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3951 case CHELSIO_T4:
3952 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3953 break;
3954 case CHELSIO_T5:
3955 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3956 break;
3957 case CHELSIO_T6:
3958 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3959 break;
3960 default:
3961 pr_err("T%d Chip is not supported\n",
3962 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3963 goto reject;
3964 }
3965
Vipul Pandyaf079af72013-03-14 05:08:58 +00003966 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003967 eh = (struct ethhdr *)(req + 1);
3968 iph = (struct iphdr *)(eh + 1);
3969 } else {
3970 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3971 iph = (struct iphdr *)(vlan_eh + 1);
3972 skb->vlan_tci = ntohs(cpl->vlan);
3973 }
3974
3975 if (iph->version != 0x4)
3976 goto reject;
3977
3978 tcph = (struct tcphdr *)(iph + 1);
3979 skb_set_network_header(skb, (void *)iph - (void *)rss);
3980 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3981 skb_get(skb);
3982
3983 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3984 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3985 ntohs(tcph->source), iph->tos);
3986
Varun Prakash804c2f32016-09-13 21:23:57 +05303987 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3988 iph->daddr, iph->saddr, tcph->dest,
3989 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303990 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003991 pr_err("%s - failed to find dst entry!\n",
3992 __func__);
3993 goto reject;
3994 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003995 neigh = dst_neigh_lookup_skb(dst, skb);
3996
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003997 if (!neigh) {
3998 pr_err("%s - failed to allocate neigh!\n",
3999 __func__);
4000 goto free_dst;
4001 }
4002
Vipul Pandya1cab7752012-12-10 09:30:55 +00004003 if (neigh->dev->flags & IFF_LOOPBACK) {
4004 pdev = ip_dev_find(&init_net, iph->daddr);
4005 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
4006 pdev, 0);
4007 pi = (struct port_info *)netdev_priv(pdev);
4008 tx_chan = cxgb4_port_chan(pdev);
4009 dev_put(pdev);
4010 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05304011 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004012 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05304013 pdev, 0);
4014 pi = (struct port_info *)netdev_priv(pdev);
4015 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004016 }
Steve Wiseebf00062014-03-19 17:44:40 +05304017 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004018 if (!e) {
4019 pr_err("%s - failed to allocate l2t entry!\n",
4020 __func__);
4021 goto free_dst;
4022 }
4023
4024 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4025 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00004026 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004027
4028 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05304029 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4030 dev->rdev.lldi.ports[0],
4031 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004032
4033 /*
4034 * Synthesize the cpl_pass_accept_req. We have everything except the
4035 * TID. Once firmware sends a reply with TID we update the TID field
4036 * in cpl and pass it through the regular cpl_pass_accept_req path.
4037 */
4038 build_cpl_pass_accept_req(skb, stid, iph->tos);
4039 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4040 tcph->source, ntohl(tcph->seq), filter, window,
4041 rss_qid, pi->port_id);
4042 cxgb4_l2t_release(e);
4043free_dst:
4044 dst_release(dst);
4045reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304046 if (lep)
4047 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004048 return 0;
4049}
4050
Steve Wisecfdda9d2010-04-21 15:30:06 -07004051/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004052 * These are the real handlers that are called from a
4053 * work queue.
4054 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304055static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004056 [CPL_ACT_ESTABLISH] = act_establish,
4057 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4058 [CPL_RX_DATA] = rx_data,
4059 [CPL_ABORT_RPL_RSS] = abort_rpl,
4060 [CPL_ABORT_RPL] = abort_rpl,
4061 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4062 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4063 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4064 [CPL_PASS_ESTABLISH] = pass_establish,
4065 [CPL_PEER_CLOSE] = peer_close,
4066 [CPL_ABORT_REQ_RSS] = peer_abort,
4067 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4068 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004069 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004070 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304071 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304072 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4073 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004074};
4075
4076static void process_timeout(struct c4iw_ep *ep)
4077{
4078 struct c4iw_qp_attributes attrs;
4079 int abort = 1;
4080
Steve Wise2f5b48c2010-09-10 11:15:36 -05004081 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004082 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4083 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004084 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004085 switch (ep->com.state) {
4086 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004087 connect_reply_upcall(ep, -ETIMEDOUT);
4088 break;
4089 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304090 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304091 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304092 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004093 break;
4094 case CLOSING:
4095 case MORIBUND:
4096 if (ep->com.cm_id && ep->com.qp) {
4097 attrs.next_state = C4IW_QP_STATE_ERROR;
4098 c4iw_modify_qp(ep->com.qp->rhp,
4099 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4100 &attrs, 1);
4101 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304102 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004104 case ABORTING:
4105 case DEAD:
4106
4107 /*
4108 * These states are expected if the ep timed out at the same
4109 * time as another thread was calling stop_ep_timer().
4110 * So we silently do nothing for these states.
4111 */
4112 abort = 0;
4113 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004114 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004115 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004116 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004117 abort = 0;
4118 }
Steve Wisecc18b932014-04-24 14:31:53 -05004119 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304120 if (abort)
4121 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004122 c4iw_put_ep(&ep->com);
4123}
4124
4125static void process_timedout_eps(void)
4126{
4127 struct c4iw_ep *ep;
4128
4129 spin_lock_irq(&timeout_lock);
4130 while (!list_empty(&timeout_list)) {
4131 struct list_head *tmp;
4132
4133 tmp = timeout_list.next;
4134 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004135 tmp->next = NULL;
4136 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004137 spin_unlock_irq(&timeout_lock);
4138 ep = list_entry(tmp, struct c4iw_ep, entry);
4139 process_timeout(ep);
4140 spin_lock_irq(&timeout_lock);
4141 }
4142 spin_unlock_irq(&timeout_lock);
4143}
4144
4145static void process_work(struct work_struct *work)
4146{
4147 struct sk_buff *skb = NULL;
4148 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004149 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004150 unsigned int opcode;
4151 int ret;
4152
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004153 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004154 while ((skb = skb_dequeue(&rxq))) {
4155 rpl = cplhdr(skb);
4156 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4157 opcode = rpl->ot.opcode;
4158
4159 BUG_ON(!work_handlers[opcode]);
4160 ret = work_handlers[opcode](dev, skb);
4161 if (!ret)
4162 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004163 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004164 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004165}
4166
4167static DECLARE_WORK(skb_work, process_work);
4168
4169static void ep_timeout(unsigned long arg)
4170{
4171 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004172 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004173
4174 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004175 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004176 /*
4177 * Only insert if it is not already on the list.
4178 */
4179 if (!ep->entry.next) {
4180 list_add_tail(&ep->entry, &timeout_list);
4181 kickit = 1;
4182 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004183 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004184 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004185 if (kickit)
4186 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004187}
4188
4189/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004190 * All the CM events are handled on a work queue to have a safe context.
4191 */
4192static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4193{
4194
4195 /*
4196 * Save dev in the skb->cb area.
4197 */
4198 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4199
4200 /*
4201 * Queue the skb and schedule the worker thread.
4202 */
4203 skb_queue_tail(&rxq, skb);
4204 queue_work(workq, &skb_work);
4205 return 0;
4206}
4207
4208static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4209{
4210 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4211
4212 if (rpl->status != CPL_ERR_NONE) {
4213 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4214 "for tid %u\n", rpl->status, GET_TID(rpl));
4215 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004216 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004217 return 0;
4218}
4219
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004220static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4221{
4222 struct cpl_fw6_msg *rpl = cplhdr(skb);
4223 struct c4iw_wr_wait *wr_waitp;
4224 int ret;
4225
4226 PDBG("%s type %u\n", __func__, rpl->type);
4227
4228 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004229 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004230 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004231 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004232 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004233 if (wr_waitp)
4234 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004235 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004236 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004237 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004238 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004239 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004240 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004241 default:
4242 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4243 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004244 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004245 break;
4246 }
4247 return 0;
4248}
4249
Steve Wise8da7e7a2011-06-14 20:59:27 +00004250static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4251{
4252 struct cpl_abort_req_rss *req = cplhdr(skb);
4253 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004254 unsigned int tid = GET_TID(req);
4255
Hariprasad S944661d2016-05-06 22:18:03 +05304256 ep = get_ep_from_tid(dev, tid);
4257 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004258 if (!ep) {
4259 printk(KERN_WARNING MOD
4260 "Abort on non-existent endpoint, tid %d\n", tid);
4261 kfree_skb(skb);
4262 return 0;
4263 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304264 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304265 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4266 __func__, ep->hwtid, req->status,
4267 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304268 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004269 }
4270 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4271 ep->com.state);
4272
Hariprasad S093108c2016-05-06 22:18:09 +05304273 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304274out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004275 sched(dev, skb);
4276 return 0;
4277}
4278
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004279/*
4280 * Most upcalls from the T4 Core go to sched() to
4281 * schedule the processing on a work queue.
4282 */
4283c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4284 [CPL_ACT_ESTABLISH] = sched,
4285 [CPL_ACT_OPEN_RPL] = sched,
4286 [CPL_RX_DATA] = sched,
4287 [CPL_ABORT_RPL_RSS] = sched,
4288 [CPL_ABORT_RPL] = sched,
4289 [CPL_PASS_OPEN_RPL] = sched,
4290 [CPL_CLOSE_LISTSRV_RPL] = sched,
4291 [CPL_PASS_ACCEPT_REQ] = sched,
4292 [CPL_PASS_ESTABLISH] = sched,
4293 [CPL_PEER_CLOSE] = sched,
4294 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004295 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004296 [CPL_RDMA_TERMINATE] = sched,
4297 [CPL_FW4_ACK] = sched,
4298 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004299 [CPL_FW6_MSG] = fw6_msg,
4300 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004301};
4302
Steve Wisecfdda9d2010-04-21 15:30:06 -07004303int __init c4iw_cm_init(void)
4304{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004305 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004306 skb_queue_head_init(&rxq);
4307
4308 workq = create_singlethread_workqueue("iw_cxgb4");
4309 if (!workq)
4310 return -ENOMEM;
4311
Steve Wisecfdda9d2010-04-21 15:30:06 -07004312 return 0;
4313}
4314
Steve Wise46c13762014-06-20 14:26:25 -05004315void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004316{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004317 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004318 flush_workqueue(workq);
4319 destroy_workqueue(workq);
4320}