blob: e591f61c5601176beca2598ff57d9448785ae90f [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
508static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700509 __be32 peer_ip, __be16 local_port,
510 __be16 peer_port, u8 tos)
511{
512 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700513 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530514 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700515
David S. Miller31e4543d2011-05-03 20:25:42 -0700516 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500517 peer_port, local_port, IPPROTO_TCP,
518 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800519 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700520 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530521 n = dst_neigh_lookup(&rt->dst, &peer_ip);
522 if (!n)
523 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530524 if (!our_interface(dev, n->dev) &&
525 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530526 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530527 dst_release(&rt->dst);
528 return NULL;
529 }
530 neigh_release(n);
531 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700532}
533
534static void arp_failure_discard(void *handle, struct sk_buff *skb)
535{
Hariprasad S9dec9002016-05-05 01:27:29 +0530536 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700537 kfree_skb(skb);
538}
539
Hariprasad S64bec742016-05-06 22:18:10 +0530540static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
541{
542 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
543}
544
Hariprasad S9dec9002016-05-05 01:27:29 +0530545enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530546 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530547 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530548 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530549};
550
551static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
552{
553 struct c4iw_ep *ep;
554
555 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
556 release_ep_resources(ep);
557 return 0;
558}
559
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530560static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
561{
562 struct c4iw_ep *ep;
563
564 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
565 c4iw_put_ep(&ep->parent_ep->com);
566 release_ep_resources(ep);
567 return 0;
568}
569
Hariprasad S9dec9002016-05-05 01:27:29 +0530570/*
571 * Fake up a special CPL opcode and call sched() so process_work() will call
572 * _put_ep_safe() in a safe context to free the ep resources. This is needed
573 * because ARP error handlers are called in an ATOMIC context, and
574 * _c4iw_free_ep() needs to block.
575 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530576static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
577 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530578{
579 struct cpl_act_establish *rpl = cplhdr(skb);
580
581 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530582 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530583
584 /*
585 * Save ep in the skb->cb area, after where sched() will save the dev
586 * ptr.
587 */
588 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
589 sched(ep->com.dev, skb);
590}
591
592/* Handle an ARP failure for an accept */
593static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
594{
595 struct c4iw_ep *ep = handle;
596
597 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
598 ep->hwtid);
599
600 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530601 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530602}
603
Steve Wisecfdda9d2010-04-21 15:30:06 -0700604/*
605 * Handle an ARP failure for an active open.
606 */
607static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
608{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530609 struct c4iw_ep *ep = handle;
610
Masanari Iidae3d132d2015-10-16 21:14:29 +0900611 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530612 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530613 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530614 if (ep->com.remote_addr.ss_family == AF_INET6) {
615 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600616 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530617 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
618 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
619 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530620 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
621 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530622 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700623}
624
625/*
626 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
627 * and send it along.
628 */
629static void abort_arp_failure(void *handle, struct sk_buff *skb)
630{
Hariprasad S761e19a2016-05-06 22:18:02 +0530631 int ret;
632 struct c4iw_ep *ep = handle;
633 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700634 struct cpl_abort_req *req = cplhdr(skb);
635
636 PDBG("%s rdev %p\n", __func__, rdev);
637 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530638 ret = c4iw_ofld_send(rdev, skb);
639 if (ret) {
640 __state_set(&ep->com, DEAD);
641 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
642 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700643}
644
Hariprasad S4a740832016-06-10 01:05:15 +0530645static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700646{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700647 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530648 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700649 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530650 u16 vlan = ep->l2t->vlan;
651 int nparams;
652
Hariprasad S4a740832016-06-10 01:05:15 +0530653 if (WARN_ON(!skb))
654 return -ENOMEM;
655
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530656 if (vlan == CPL_L2T_VLAN_NONE)
657 nparams = 8;
658 else
659 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700660
Hariprasad S4a740832016-06-10 01:05:15 +0530661 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700662
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530663 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530664 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530665 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530666 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700667
668 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530669 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530670 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700671 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
672 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
673 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
674 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
675 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
676 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
677 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
678 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
679 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
680 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
681 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530682 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700683 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
684 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530685 if (nparams == 9) {
686 u16 pri;
687
688 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
689 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
690 flowc->mnemval[8].val = cpu_to_be32(pri);
691 } else {
692 /* Pad WR to 16 byte boundary */
693 flowc->mnemval[8].mnemonic = 0;
694 flowc->mnemval[8].val = 0;
695 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700696 for (i = 0; i < 9; i++) {
697 flowc->mnemval[i].r4[0] = 0;
698 flowc->mnemval[i].r4[1] = 0;
699 flowc->mnemval[i].r4[2] = 0;
700 }
701
702 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530703 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700704}
705
Hariprasad S4a740832016-06-10 01:05:15 +0530706static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700707{
708 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530709 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700710 int wrlen = roundup(sizeof *req, 16);
711
712 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530713 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700714 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530715
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
717 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
718 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
719 memset(req, 0, wrlen);
720 INIT_TP_WR(req, ep->hwtid);
721 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
722 ep->hwtid));
723 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
724}
725
Hariprasad S4a740832016-06-10 01:05:15 +0530726static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700727{
728 struct cpl_abort_req *req;
729 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530730 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700731
732 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530733 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700734 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530735
736 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
737 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
738 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700739 memset(req, 0, wrlen);
740 INIT_TP_WR(req, ep->hwtid);
741 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
742 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530743 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700744}
745
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530746static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530747 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530748{
Hariprasad S04524a42014-09-24 03:53:41 +0530749 unsigned short hdr_size = (ipv6 ?
750 sizeof(struct ipv6hdr) :
751 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530752 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530753 (use_ts ?
754 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530755 unsigned short data_size = mtu - hdr_size;
756
757 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
758}
759
Steve Wisecfdda9d2010-04-21 15:30:06 -0700760static int send_connect(struct c4iw_ep *ep)
761{
Hariprasad S963cab52015-09-23 17:19:27 +0530762 struct cpl_act_open_req *req = NULL;
763 struct cpl_t5_act_open_req *t5req = NULL;
764 struct cpl_t6_act_open_req *t6req = NULL;
765 struct cpl_act_open_req6 *req6 = NULL;
766 struct cpl_t5_act_open_req6 *t5req6 = NULL;
767 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700768 struct sk_buff *skb;
769 u64 opt0;
770 u32 opt2;
771 unsigned int mtu_idx;
772 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530773 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500774 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600775 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500776 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600777 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500778 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600779 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500780 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600781 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530782 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530783 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
784 u32 isn = (prandom_u32() & ~7UL) - 1;
785
786 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
787 case CHELSIO_T4:
788 sizev4 = sizeof(struct cpl_act_open_req);
789 sizev6 = sizeof(struct cpl_act_open_req6);
790 break;
791 case CHELSIO_T5:
792 sizev4 = sizeof(struct cpl_t5_act_open_req);
793 sizev6 = sizeof(struct cpl_t5_act_open_req6);
794 break;
795 case CHELSIO_T6:
796 sizev4 = sizeof(struct cpl_t6_act_open_req);
797 sizev6 = sizeof(struct cpl_t6_act_open_req6);
798 break;
799 default:
800 pr_err("T%d Chip is not supported\n",
801 CHELSIO_CHIP_VERSION(adapter_type));
802 return -EINVAL;
803 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530804
805 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
806 roundup(sizev4, 16) :
807 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700808
809 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
810
811 skb = get_skb(NULL, wrlen, GFP_KERNEL);
812 if (!skb) {
813 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
814 __func__);
815 return -ENOMEM;
816 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000817 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700818
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530819 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530820 enable_tcp_timestamps,
821 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700822 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530823
824 /*
825 * Specify the largest window that will fit in opt0. The
826 * remainder will be specified in the rx_data_ack.
827 */
828 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800829 if (win > RCV_BUFSIZ_M)
830 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530831
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800832 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800833 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800834 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800835 WND_SCALE_V(wscale) |
836 MSS_IDX_V(mtu_idx) |
837 L2T_IDX_V(ep->l2t->idx) |
838 TX_CHAN_V(ep->tx_chan) |
839 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530840 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800841 ULP_MODE_V(ULP_MODE_TCPDDP) |
842 RCV_BUFSIZ_V(win);
843 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800844 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800845 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700846 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800847 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700848 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800849 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700850 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800851 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530852 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
853 if (peer2peer)
854 isn += 4;
855
Anish Bhattd7990b02014-11-12 17:15:57 -0800856 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530857 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530858 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500859 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530860
861 if (ep->com.remote_addr.ss_family == AF_INET6)
862 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
863 (const u32 *)&la6->sin6_addr.s6_addr, 1);
864
Hariprasad S5dab6d32014-06-23 19:12:36 +0530865 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700866
Hariprasad S963cab52015-09-23 17:19:27 +0530867 if (ep->com.remote_addr.ss_family == AF_INET) {
868 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
869 case CHELSIO_T4:
870 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530871 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530872 break;
873 case CHELSIO_T5:
874 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
875 wrlen);
876 INIT_TP_WR(t5req, 0);
877 req = (struct cpl_act_open_req *)t5req;
878 break;
879 case CHELSIO_T6:
880 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
881 wrlen);
882 INIT_TP_WR(t6req, 0);
883 req = (struct cpl_act_open_req *)t6req;
884 t5req = (struct cpl_t5_act_open_req *)t6req;
885 break;
886 default:
887 pr_err("T%d Chip is not supported\n",
888 CHELSIO_CHIP_VERSION(adapter_type));
889 ret = -EINVAL;
890 goto clip_release;
891 }
892
893 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
894 ((ep->rss_qid<<14) | ep->atid)));
895 req->local_port = la->sin_port;
896 req->peer_port = ra->sin_port;
897 req->local_ip = la->sin_addr.s_addr;
898 req->peer_ip = ra->sin_addr.s_addr;
899 req->opt0 = cpu_to_be64(opt0);
900
901 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530902 req->params = cpu_to_be32(cxgb4_select_ntuple(
903 ep->com.dev->rdev.lldi.ports[0],
904 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530905 req->opt2 = cpu_to_be32(opt2);
906 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530907 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
908 cxgb4_select_ntuple(
909 ep->com.dev->rdev.lldi.ports[0],
910 ep->l2t)));
911 t5req->rsvd = cpu_to_be32(isn);
912 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
913 t5req->opt2 = cpu_to_be32(opt2);
914 }
915 } else {
916 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
917 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530918 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530919 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530920 break;
921 case CHELSIO_T5:
922 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
923 wrlen);
924 INIT_TP_WR(t5req6, 0);
925 req6 = (struct cpl_act_open_req6 *)t5req6;
926 break;
927 case CHELSIO_T6:
928 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
929 wrlen);
930 INIT_TP_WR(t6req6, 0);
931 req6 = (struct cpl_act_open_req6 *)t6req6;
932 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
933 break;
934 default:
935 pr_err("T%d Chip is not supported\n",
936 CHELSIO_CHIP_VERSION(adapter_type));
937 ret = -EINVAL;
938 goto clip_release;
939 }
940
941 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
942 ((ep->rss_qid<<14)|ep->atid)));
943 req6->local_port = la6->sin6_port;
944 req6->peer_port = ra6->sin6_port;
945 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
946 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
947 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
948 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
949 req6->opt0 = cpu_to_be64(opt0);
950
951 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530952 req6->params = cpu_to_be32(cxgb4_select_ntuple(
953 ep->com.dev->rdev.lldi.ports[0],
954 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530955 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530956 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530957 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
958 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530959 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530960 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530961 t5req6->rsvd = cpu_to_be32(isn);
962 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
963 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530964 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000965 }
966
Vipul Pandya793dad92012-12-10 09:30:56 +0000967 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530968 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530969clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530970 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
971 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
972 (const u32 *)&la6->sin6_addr.s6_addr, 1);
973 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700974}
975
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530976static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
977 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700978{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530979 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700980 struct fw_ofld_tx_data_wr *req;
981 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530982 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700983
984 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
985
986 BUG_ON(skb_cloned(skb));
987
988 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530989 if (mpa_rev_to_use == 2)
990 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700991 wrlen = roundup(mpalen + sizeof *req, 16);
992 skb = get_skb(skb, wrlen, GFP_KERNEL);
993 if (!skb) {
994 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530995 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700996 }
997 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
998
999 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1000 memset(req, 0, wrlen);
1001 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301002 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1003 FW_WR_COMPL_F |
1004 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001005 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301006 FW_WR_FLOWID_V(ep->hwtid) |
1007 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001008 req->plen = cpu_to_be32(mpalen);
1009 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301010 FW_OFLD_TX_DATA_WR_FLUSH_F |
1011 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001012
1013 mpa = (struct mpa_message *)(req + 1);
1014 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301015
1016 mpa->flags = 0;
1017 if (crc_enabled)
1018 mpa->flags |= MPA_CRC;
1019 if (markers_enabled) {
1020 mpa->flags |= MPA_MARKERS;
1021 ep->mpa_attr.recv_marker_enabled = 1;
1022 } else {
1023 ep->mpa_attr.recv_marker_enabled = 0;
1024 }
1025 if (mpa_rev_to_use == 2)
1026 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
1027
Steve Wisecfdda9d2010-04-21 15:30:06 -07001028 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301029 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301030 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301031 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +05301032 ep->retry_with_mpa_v1 = 0;
1033 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001034
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301035 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -07001036 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1037 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301038 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1039 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301040 mpa_v2_params.ird = htons((u16)ep->ird);
1041 mpa_v2_params.ord = htons((u16)ep->ord);
1042
1043 if (peer2peer) {
1044 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1045 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1046 mpa_v2_params.ord |=
1047 htons(MPA_V2_RDMA_WRITE_RTR);
1048 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1049 mpa_v2_params.ord |=
1050 htons(MPA_V2_RDMA_READ_RTR);
1051 }
1052 memcpy(mpa->private_data, &mpa_v2_params,
1053 sizeof(struct mpa_v2_conn_params));
1054
1055 if (ep->plen)
1056 memcpy(mpa->private_data +
1057 sizeof(struct mpa_v2_conn_params),
1058 ep->mpa_pkt + sizeof(*mpa), ep->plen);
1059 } else
1060 if (ep->plen)
1061 memcpy(mpa->private_data,
1062 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001063
1064 /*
1065 * Reference the mpa skb. This ensures the data area
1066 * will remain in memory until the hw acks the tx.
1067 * Function fw4_ack() will deref it.
1068 */
1069 skb_get(skb);
1070 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1071 BUG_ON(ep->mpa_skb);
1072 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301073 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1074 if (ret)
1075 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001076 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301077 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001078 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301079 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301080 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001081}
1082
1083static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1084{
1085 int mpalen, wrlen;
1086 struct fw_ofld_tx_data_wr *req;
1087 struct mpa_message *mpa;
1088 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301089 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001090
1091 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1092
1093 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301094 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1095 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001096 wrlen = roundup(mpalen + sizeof *req, 16);
1097
1098 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1099 if (!skb) {
1100 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1101 return -ENOMEM;
1102 }
1103 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1104
1105 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1106 memset(req, 0, wrlen);
1107 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301108 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1109 FW_WR_COMPL_F |
1110 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001111 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301112 FW_WR_FLOWID_V(ep->hwtid) |
1113 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001114 req->plen = cpu_to_be32(mpalen);
1115 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301116 FW_OFLD_TX_DATA_WR_FLUSH_F |
1117 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001118
1119 mpa = (struct mpa_message *)(req + 1);
1120 memset(mpa, 0, sizeof(*mpa));
1121 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1122 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001123 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001124 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301125
1126 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1127 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001128 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1129 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301130 mpa_v2_params.ird = htons(((u16)ep->ird) |
1131 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1132 0));
1133 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1134 (p2p_type ==
1135 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1136 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1137 FW_RI_INIT_P2PTYPE_READ_REQ ?
1138 MPA_V2_RDMA_READ_RTR : 0) : 0));
1139 memcpy(mpa->private_data, &mpa_v2_params,
1140 sizeof(struct mpa_v2_conn_params));
1141
1142 if (ep->plen)
1143 memcpy(mpa->private_data +
1144 sizeof(struct mpa_v2_conn_params), pdata, plen);
1145 } else
1146 if (plen)
1147 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001148
1149 /*
1150 * Reference the mpa skb again. This ensures the data area
1151 * will remain in memory until the hw acks the tx.
1152 * Function fw4_ack() will deref it.
1153 */
1154 skb_get(skb);
1155 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301156 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001157 BUG_ON(ep->mpa_skb);
1158 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301159 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001160 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1161}
1162
1163static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1164{
1165 int mpalen, wrlen;
1166 struct fw_ofld_tx_data_wr *req;
1167 struct mpa_message *mpa;
1168 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301169 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001170
1171 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1172
1173 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301174 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1175 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001176 wrlen = roundup(mpalen + sizeof *req, 16);
1177
1178 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1179 if (!skb) {
1180 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1181 return -ENOMEM;
1182 }
1183 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1184
1185 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1186 memset(req, 0, wrlen);
1187 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301188 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1189 FW_WR_COMPL_F |
1190 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001191 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301192 FW_WR_FLOWID_V(ep->hwtid) |
1193 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001194 req->plen = cpu_to_be32(mpalen);
1195 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301196 FW_OFLD_TX_DATA_WR_FLUSH_F |
1197 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001198
1199 mpa = (struct mpa_message *)(req + 1);
1200 memset(mpa, 0, sizeof(*mpa));
1201 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301202 mpa->flags = 0;
1203 if (ep->mpa_attr.crc_enabled)
1204 mpa->flags |= MPA_CRC;
1205 if (ep->mpa_attr.recv_marker_enabled)
1206 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301207 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001208 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301209
1210 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1211 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001212 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1213 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301214 mpa_v2_params.ird = htons((u16)ep->ird);
1215 mpa_v2_params.ord = htons((u16)ep->ord);
1216 if (peer2peer && (ep->mpa_attr.p2p_type !=
1217 FW_RI_INIT_P2PTYPE_DISABLED)) {
1218 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1219
1220 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1221 mpa_v2_params.ord |=
1222 htons(MPA_V2_RDMA_WRITE_RTR);
1223 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1224 mpa_v2_params.ord |=
1225 htons(MPA_V2_RDMA_READ_RTR);
1226 }
1227
1228 memcpy(mpa->private_data, &mpa_v2_params,
1229 sizeof(struct mpa_v2_conn_params));
1230
1231 if (ep->plen)
1232 memcpy(mpa->private_data +
1233 sizeof(struct mpa_v2_conn_params), pdata, plen);
1234 } else
1235 if (plen)
1236 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237
1238 /*
1239 * Reference the mpa skb. This ensures the data area
1240 * will remain in memory until the hw acks the tx.
1241 * Function fw4_ack() will deref it.
1242 */
1243 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301244 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001245 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301246 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301247 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001248 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1249}
1250
1251static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1252{
1253 struct c4iw_ep *ep;
1254 struct cpl_act_establish *req = cplhdr(skb);
1255 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001256 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001257 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301258 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001259
1260 ep = lookup_atid(t, atid);
1261
1262 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1263 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1264
Steve Wisea7db89e2014-03-21 20:40:35 +05301265 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001266 dst_confirm(ep->dst);
1267
1268 /* setup the hwtid for this connection */
1269 ep->hwtid = tid;
1270 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301271 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001272
1273 ep->snd_seq = be32_to_cpu(req->snd_isn);
1274 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1275
1276 set_emss(ep, ntohs(req->tcp_opt));
1277
1278 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001279 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001280 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001281 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001282
1283 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301284 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301285 if (ret)
1286 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301287 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301288 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301289 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301290 ret = send_mpa_req(ep, skb, mpa_rev);
1291 if (ret)
1292 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301293 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001294 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301295err:
1296 mutex_unlock(&ep->com.mutex);
1297 connect_reply_upcall(ep, -ENOMEM);
1298 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1299 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001300}
1301
Steve Wisebe13b2d2014-03-21 20:40:33 +05301302static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001303{
1304 struct iw_cm_event event;
1305
1306 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1307 memset(&event, 0, sizeof(event));
1308 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301309 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001310 if (ep->com.cm_id) {
1311 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1312 ep, ep->com.cm_id, ep->hwtid);
1313 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301314 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001315 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001316 }
1317}
1318
Steve Wisecfdda9d2010-04-21 15:30:06 -07001319static void peer_close_upcall(struct c4iw_ep *ep)
1320{
1321 struct iw_cm_event event;
1322
1323 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1324 memset(&event, 0, sizeof(event));
1325 event.event = IW_CM_EVENT_DISCONNECT;
1326 if (ep->com.cm_id) {
1327 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1328 ep, ep->com.cm_id, ep->hwtid);
1329 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001330 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001331 }
1332}
1333
1334static void peer_abort_upcall(struct c4iw_ep *ep)
1335{
1336 struct iw_cm_event event;
1337
1338 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1339 memset(&event, 0, sizeof(event));
1340 event.event = IW_CM_EVENT_CLOSE;
1341 event.status = -ECONNRESET;
1342 if (ep->com.cm_id) {
1343 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1344 ep->com.cm_id, ep->hwtid);
1345 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301346 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001347 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001348 }
1349}
1350
1351static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1352{
1353 struct iw_cm_event event;
1354
1355 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1356 memset(&event, 0, sizeof(event));
1357 event.event = IW_CM_EVENT_CONNECT_REPLY;
1358 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301359 memcpy(&event.local_addr, &ep->com.local_addr,
1360 sizeof(ep->com.local_addr));
1361 memcpy(&event.remote_addr, &ep->com.remote_addr,
1362 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001363
1364 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301365 if (!ep->tried_with_mpa_v1) {
1366 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301367 event.ord = ep->ird;
1368 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301369 event.private_data_len = ep->plen -
1370 sizeof(struct mpa_v2_conn_params);
1371 event.private_data = ep->mpa_pkt +
1372 sizeof(struct mpa_message) +
1373 sizeof(struct mpa_v2_conn_params);
1374 } else {
1375 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301376 event.ord = cur_max_read_depth(ep->com.dev);
1377 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301378 event.private_data_len = ep->plen;
1379 event.private_data = ep->mpa_pkt +
1380 sizeof(struct mpa_message);
1381 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001382 }
Roland Dreier85963e42010-07-19 13:13:09 -07001383
1384 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1385 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001386 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001387 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1388
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301389 if (status < 0)
1390 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001391}
1392
Steve Wisebe13b2d2014-03-21 20:40:33 +05301393static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001394{
1395 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301396 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001397
1398 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1399 memset(&event, 0, sizeof(event));
1400 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301401 memcpy(&event.local_addr, &ep->com.local_addr,
1402 sizeof(ep->com.local_addr));
1403 memcpy(&event.remote_addr, &ep->com.remote_addr,
1404 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001405 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301406 if (!ep->tried_with_mpa_v1) {
1407 /* this means MPA_v2 is used */
1408 event.ord = ep->ord;
1409 event.ird = ep->ird;
1410 event.private_data_len = ep->plen -
1411 sizeof(struct mpa_v2_conn_params);
1412 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1413 sizeof(struct mpa_v2_conn_params);
1414 } else {
1415 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301416 event.ord = cur_max_read_depth(ep->com.dev);
1417 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301418 event.private_data_len = ep->plen;
1419 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1420 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301421 c4iw_get_ep(&ep->com);
1422 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1423 &event);
1424 if (ret)
1425 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001426 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001427 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301428 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429}
1430
1431static void established_upcall(struct c4iw_ep *ep)
1432{
1433 struct iw_cm_event event;
1434
1435 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1436 memset(&event, 0, sizeof(event));
1437 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301438 event.ird = ep->ord;
1439 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001440 if (ep->com.cm_id) {
1441 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1442 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001443 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444 }
1445}
1446
1447static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1448{
1449 struct cpl_rx_data_ack *req;
1450 struct sk_buff *skb;
1451 int wrlen = roundup(sizeof *req, 16);
1452
1453 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1454 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1455 if (!skb) {
1456 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1457 return 0;
1458 }
1459
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301460 /*
1461 * If we couldn't specify the entire rcv window at connection setup
1462 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1463 * then add the overage in to the credits returned.
1464 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001465 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1466 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301467
Steve Wisecfdda9d2010-04-21 15:30:06 -07001468 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1469 memset(req, 0, wrlen);
1470 INIT_TP_WR(req, ep->hwtid);
1471 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1472 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001473 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301474 RX_DACK_CHANGE_F |
1475 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001476 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001477 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1478 return credits;
1479}
1480
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301481#define RELAXED_IRD_NEGOTIATION 1
1482
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301483/*
1484 * process_mpa_reply - process streaming mode MPA reply
1485 *
1486 * Returns:
1487 *
1488 * 0 upon success indicating a connect request was delivered to the ULP
1489 * or the mpa request is incomplete but valid so far.
1490 *
1491 * 1 if a failure requires the caller to close the connection.
1492 *
1493 * 2 if a failure requires the caller to abort the connection.
1494 */
Steve Wisecc18b932014-04-24 14:31:53 -05001495static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001496{
1497 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301498 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001499 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301500 u16 resp_ird, resp_ord;
1501 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001502 struct c4iw_qp_attributes attrs;
1503 enum c4iw_qp_attr_mask mask;
1504 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001505 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001506
1507 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1508
1509 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001510 * If we get more than the supported amount of private data
1511 * then we must fail this connection.
1512 */
1513 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1514 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301515 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001516 }
1517
1518 /*
1519 * copy the new data into our accumulation buffer.
1520 */
1521 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1522 skb->len);
1523 ep->mpa_pkt_len += skb->len;
1524
1525 /*
1526 * if we don't even have the mpa message, then bail.
1527 */
1528 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001529 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001530 mpa = (struct mpa_message *) ep->mpa_pkt;
1531
1532 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301533 if (mpa->revision > mpa_rev) {
1534 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1535 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001536 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301537 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001538 }
1539 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1540 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301541 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001542 }
1543
1544 plen = ntohs(mpa->private_data_size);
1545
1546 /*
1547 * Fail if there's too much private data.
1548 */
1549 if (plen > MPA_MAX_PRIVATE_DATA) {
1550 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301551 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001552 }
1553
1554 /*
1555 * If plen does not account for pkt size
1556 */
1557 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1558 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301559 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001560 }
1561
1562 ep->plen = (u8) plen;
1563
1564 /*
1565 * If we don't have all the pdata yet, then bail.
1566 * We'll continue process when more data arrives.
1567 */
1568 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001569 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001570
1571 if (mpa->flags & MPA_REJECT) {
1572 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301573 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001574 }
1575
1576 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301577 * Stop mpa timer. If it expired, then
1578 * we ignore the MPA reply. process_timeout()
1579 * will abort the connection.
1580 */
1581 if (stop_ep_timer(ep))
1582 return 0;
1583
1584 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001585 * If we get here we have accumulated the entire mpa
1586 * start reply message including private data. And
1587 * the MPA header is valid.
1588 */
Steve Wisec529fb52014-03-21 20:40:37 +05301589 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001590 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001591 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301592 ep->mpa_attr.version = mpa->revision;
1593 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1594
1595 if (mpa->revision == 2) {
1596 ep->mpa_attr.enhanced_rdma_conn =
1597 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1598 if (ep->mpa_attr.enhanced_rdma_conn) {
1599 mpa_v2_params = (struct mpa_v2_conn_params *)
1600 (ep->mpa_pkt + sizeof(*mpa));
1601 resp_ird = ntohs(mpa_v2_params->ird) &
1602 MPA_V2_IRD_ORD_MASK;
1603 resp_ord = ntohs(mpa_v2_params->ord) &
1604 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301605 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1606 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301607
1608 /*
1609 * This is a double-check. Ideally, below checks are
1610 * not required since ird/ord stuff has been taken
1611 * care of in c4iw_accept_cr
1612 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301613 if (ep->ird < resp_ord) {
1614 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1615 ep->com.dev->rdev.lldi.max_ordird_qp)
1616 ep->ird = resp_ord;
1617 else
1618 insuff_ird = 1;
1619 } else if (ep->ird > resp_ord) {
1620 ep->ird = resp_ord;
1621 }
1622 if (ep->ord > resp_ird) {
1623 if (RELAXED_IRD_NEGOTIATION)
1624 ep->ord = resp_ird;
1625 else
1626 insuff_ird = 1;
1627 }
1628 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301629 err = -ENOMEM;
1630 ep->ird = resp_ord;
1631 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301632 }
1633
1634 if (ntohs(mpa_v2_params->ird) &
1635 MPA_V2_PEER2PEER_MODEL) {
1636 if (ntohs(mpa_v2_params->ord) &
1637 MPA_V2_RDMA_WRITE_RTR)
1638 ep->mpa_attr.p2p_type =
1639 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1640 else if (ntohs(mpa_v2_params->ord) &
1641 MPA_V2_RDMA_READ_RTR)
1642 ep->mpa_attr.p2p_type =
1643 FW_RI_INIT_P2PTYPE_READ_REQ;
1644 }
1645 }
1646 } else if (mpa->revision == 1)
1647 if (peer2peer)
1648 ep->mpa_attr.p2p_type = p2p_type;
1649
Steve Wisecfdda9d2010-04-21 15:30:06 -07001650 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301651 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1652 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1653 ep->mpa_attr.recv_marker_enabled,
1654 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1655 ep->mpa_attr.p2p_type, p2p_type);
1656
1657 /*
1658 * If responder's RTR does not match with that of initiator, assign
1659 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1660 * generated when moving QP to RTS state.
1661 * A TERM message will be sent after QP has moved to RTS state
1662 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001663 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301664 (ep->mpa_attr.p2p_type != p2p_type)) {
1665 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1666 rtr_mismatch = 1;
1667 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001668
1669 attrs.mpa_attr = ep->mpa_attr;
1670 attrs.max_ird = ep->ird;
1671 attrs.max_ord = ep->ord;
1672 attrs.llp_stream_handle = ep;
1673 attrs.next_state = C4IW_QP_STATE_RTS;
1674
1675 mask = C4IW_QP_ATTR_NEXT_STATE |
1676 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1677 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1678
1679 /* bind QP and TID with INIT_WR */
1680 err = c4iw_modify_qp(ep->com.qp->rhp,
1681 ep->com.qp, mask, &attrs, 1);
1682 if (err)
1683 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301684
1685 /*
1686 * If responder's RTR requirement did not match with what initiator
1687 * supports, generate TERM message
1688 */
1689 if (rtr_mismatch) {
1690 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1691 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1692 attrs.ecode = MPA_NOMATCH_RTR;
1693 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001694 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301695 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001696 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301697 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001698 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301699 goto out;
1700 }
1701
1702 /*
1703 * Generate TERM if initiator IRD is not sufficient for responder
1704 * provided ORD. Currently, we do the same behaviour even when
1705 * responder provided IRD is also not sufficient as regards to
1706 * initiator ORD.
1707 */
1708 if (insuff_ird) {
1709 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1710 __func__);
1711 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1712 attrs.ecode = MPA_INSUFF_IRD;
1713 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001714 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301715 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001716 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301717 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001718 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301719 goto out;
1720 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001721 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301722err_stop_timer:
1723 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001724err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301725 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001726out:
1727 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001728 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001729}
1730
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301731/*
1732 * process_mpa_request - process streaming mode MPA request
1733 *
1734 * Returns:
1735 *
1736 * 0 upon success indicating a connect request was delivered to the ULP
1737 * or the mpa request is incomplete but valid so far.
1738 *
1739 * 1 if a failure requires the caller to close the connection.
1740 *
1741 * 2 if a failure requires the caller to abort the connection.
1742 */
1743static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001744{
1745 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301746 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001747 u16 plen;
1748
1749 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1750
Steve Wisecfdda9d2010-04-21 15:30:06 -07001751 /*
1752 * If we get more than the supported amount of private data
1753 * then we must fail this connection.
1754 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301755 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1756 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001757
1758 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1759
1760 /*
1761 * Copy the new data into our accumulation buffer.
1762 */
1763 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1764 skb->len);
1765 ep->mpa_pkt_len += skb->len;
1766
1767 /*
1768 * If we don't even have the mpa message, then bail.
1769 * We'll continue process when more data arrives.
1770 */
1771 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301772 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001773
1774 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001775 mpa = (struct mpa_message *) ep->mpa_pkt;
1776
1777 /*
1778 * Validate MPA Header.
1779 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301780 if (mpa->revision > mpa_rev) {
1781 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1782 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301783 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001784 }
1785
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301786 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1787 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788
1789 plen = ntohs(mpa->private_data_size);
1790
1791 /*
1792 * Fail if there's too much private data.
1793 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301794 if (plen > MPA_MAX_PRIVATE_DATA)
1795 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796
1797 /*
1798 * If plen does not account for pkt size
1799 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301800 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1801 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001802 ep->plen = (u8) plen;
1803
1804 /*
1805 * If we don't have all the pdata yet, then bail.
1806 */
1807 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301808 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001809
1810 /*
1811 * If we get here we have accumulated the entire mpa
1812 * start reply message including private data.
1813 */
1814 ep->mpa_attr.initiator = 0;
1815 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1816 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1817 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301818 ep->mpa_attr.version = mpa->revision;
1819 if (mpa->revision == 1)
1820 ep->tried_with_mpa_v1 = 1;
1821 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1822
1823 if (mpa->revision == 2) {
1824 ep->mpa_attr.enhanced_rdma_conn =
1825 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1826 if (ep->mpa_attr.enhanced_rdma_conn) {
1827 mpa_v2_params = (struct mpa_v2_conn_params *)
1828 (ep->mpa_pkt + sizeof(*mpa));
1829 ep->ird = ntohs(mpa_v2_params->ird) &
1830 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001831 ep->ird = min_t(u32, ep->ird,
1832 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301833 ep->ord = ntohs(mpa_v2_params->ord) &
1834 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001835 ep->ord = min_t(u32, ep->ord,
1836 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301837 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1838 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301839 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1840 if (peer2peer) {
1841 if (ntohs(mpa_v2_params->ord) &
1842 MPA_V2_RDMA_WRITE_RTR)
1843 ep->mpa_attr.p2p_type =
1844 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1845 else if (ntohs(mpa_v2_params->ord) &
1846 MPA_V2_RDMA_READ_RTR)
1847 ep->mpa_attr.p2p_type =
1848 FW_RI_INIT_P2PTYPE_READ_REQ;
1849 }
1850 }
1851 } else if (mpa->revision == 1)
1852 if (peer2peer)
1853 ep->mpa_attr.p2p_type = p2p_type;
1854
Steve Wisecfdda9d2010-04-21 15:30:06 -07001855 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1856 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1857 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1858 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1859 ep->mpa_attr.p2p_type);
1860
Hariprasad Se4b76a22016-05-06 22:17:59 +05301861 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001862
Hariprasad Se4b76a22016-05-06 22:17:59 +05301863 /* drive upcall */
1864 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1865 if (ep->parent_ep->com.state != DEAD) {
1866 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301867 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301868 } else {
1869 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301870 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301871 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301872 return 0;
1873
1874err_unlock_parent:
1875 mutex_unlock(&ep->parent_ep->com.mutex);
1876 goto err_out;
1877err_stop_timer:
1878 (void)stop_ep_timer(ep);
1879err_out:
1880 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001881}
1882
1883static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1884{
1885 struct c4iw_ep *ep;
1886 struct cpl_rx_data *hdr = cplhdr(skb);
1887 unsigned int dlen = ntohs(hdr->len);
1888 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001889 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001890 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001891
Hariprasad S944661d2016-05-06 22:18:03 +05301892 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301893 if (!ep)
1894 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001895 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1896 skb_pull(skb, sizeof(*hdr));
1897 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301898 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001899
Steve Wisecfdda9d2010-04-21 15:30:06 -07001900 /* update RX credits */
1901 update_rx_credits(ep, dlen);
1902
Steve Wisec529fb52014-03-21 20:40:37 +05301903 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001904 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001905 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001906 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001907 break;
1908 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001909 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301910 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001911 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001912 case FPDU_MODE: {
1913 struct c4iw_qp_attributes attrs;
1914 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001915 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001916 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001917 " qpid %u ep %p state %d tid %u status %d\n",
1918 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301919 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301920 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001921 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001922 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1923 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001924 break;
1925 }
Vipul Pandya15579672013-01-07 13:11:52 +00001926 default:
1927 break;
1928 }
Steve Wisec529fb52014-03-21 20:40:37 +05301929 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001930 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301931 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301932 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001933 return 0;
1934}
1935
1936static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1937{
1938 struct c4iw_ep *ep;
1939 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001940 int release = 0;
1941 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001942
Hariprasad S944661d2016-05-06 22:18:03 +05301943 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301944 if (!ep) {
1945 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1946 return 0;
1947 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001948 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001949 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001950 switch (ep->com.state) {
1951 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001952 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001953 __state_set(&ep->com, DEAD);
1954 release = 1;
1955 break;
1956 default:
1957 printk(KERN_ERR "%s ep %p state %d\n",
1958 __func__, ep, ep->com.state);
1959 break;
1960 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001961 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001962
1963 if (release)
1964 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301965 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001966 return 0;
1967}
1968
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301969static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001970{
1971 struct sk_buff *skb;
1972 struct fw_ofld_connection_wr *req;
1973 unsigned int mtu_idx;
1974 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301975 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301976 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001977
1978 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1979 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1980 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001981 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301982 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301983 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1984 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001985 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001986 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301987 req->le.lport = sin->sin_port;
1988 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001989 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301990 req->le.pport = sin->sin_port;
1991 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001992 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301993 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1994 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001995 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301996 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001997 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001998 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301999 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302000 enable_tcp_timestamps,
2001 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002002 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302003
2004 /*
2005 * Specify the largest window that will fit in opt0. The
2006 * remainder will be specified in the rx_data_ack.
2007 */
2008 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002009 if (win > RCV_BUFSIZ_M)
2010 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302011
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002012 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
2013 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002014 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002015 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002016 WND_SCALE_V(wscale) |
2017 MSS_IDX_V(mtu_idx) |
2018 L2T_IDX_V(ep->l2t->idx) |
2019 TX_CHAN_V(ep->tx_chan) |
2020 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302021 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002022 ULP_MODE_V(ULP_MODE_TCPDDP) |
2023 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002024 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
2025 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002026 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002027 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002028 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002029 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002030 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002031 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002032 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002033 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002034 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
2035 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
2036 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00002037 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
2038 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302039 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002040}
2041
Steve Wisecfdda9d2010-04-21 15:30:06 -07002042/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05302043 * Some of the error codes above implicitly indicate that there is no TID
2044 * allocated with the result of an ACT_OPEN. We use this predicate to make
2045 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07002046 */
2047static inline int act_open_has_tid(int status)
2048{
Hariprasad S4c72efe2016-06-10 01:05:14 +05302049 return (status != CPL_ERR_TCAM_PARITY &&
2050 status != CPL_ERR_TCAM_MISS &&
2051 status != CPL_ERR_TCAM_FULL &&
2052 status != CPL_ERR_CONN_EXIST_SYNRECV &&
2053 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002054}
2055
Steve Wise7a2cea22014-03-14 21:52:07 +05302056/* Returns whether a CPL status conveys negative advice.
2057 */
2058static int is_neg_adv(unsigned int status)
2059{
2060 return status == CPL_ERR_RTX_NEG_ADVICE ||
2061 status == CPL_ERR_PERSIST_NEG_ADVICE ||
2062 status == CPL_ERR_KEEPALV_NEG_ADVICE;
2063}
2064
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05302065static char *neg_adv_str(unsigned int status)
2066{
2067 switch (status) {
2068 case CPL_ERR_RTX_NEG_ADVICE:
2069 return "Retransmit timeout";
2070 case CPL_ERR_PERSIST_NEG_ADVICE:
2071 return "Persist timeout";
2072 case CPL_ERR_KEEPALV_NEG_ADVICE:
2073 return "Keepalive timeout";
2074 default:
2075 return "Unknown";
2076 }
2077}
2078
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302079static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2080{
2081 ep->snd_win = snd_win;
2082 ep->rcv_win = rcv_win;
2083 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2084}
2085
Vipul Pandya793dad92012-12-10 09:30:56 +00002086#define ACT_OPEN_RETRY_COUNT 2
2087
Vipul Pandya830662f2013-07-04 16:10:47 +05302088static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2089 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302090 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302091{
2092 struct neighbour *n;
2093 int err, step;
2094 struct net_device *pdev;
2095
2096 n = dst_neigh_lookup(dst, peer_ip);
2097 if (!n)
2098 return -ENODEV;
2099
2100 rcu_read_lock();
2101 err = -ENOMEM;
2102 if (n->dev->flags & IFF_LOOPBACK) {
2103 if (iptype == 4)
2104 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2105 else if (IS_ENABLED(CONFIG_IPV6))
2106 for_each_netdev(&init_net, pdev) {
2107 if (ipv6_chk_addr(&init_net,
2108 (struct in6_addr *)peer_ip,
2109 pdev, 1))
2110 break;
2111 }
2112 else
2113 pdev = NULL;
2114
2115 if (!pdev) {
2116 err = -ENODEV;
2117 goto out;
2118 }
2119 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302120 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302121 if (!ep->l2t)
2122 goto out;
2123 ep->mtu = pdev->mtu;
2124 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302125 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2126 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302127 step = cdev->rdev.lldi.ntxq /
2128 cdev->rdev.lldi.nchan;
2129 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2130 step = cdev->rdev.lldi.nrxq /
2131 cdev->rdev.lldi.nchan;
2132 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2133 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2134 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302135 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302136 dev_put(pdev);
2137 } else {
2138 pdev = get_real_dev(n->dev);
2139 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2140 n, pdev, 0);
2141 if (!ep->l2t)
2142 goto out;
2143 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002144 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302145 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2146 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302147 step = cdev->rdev.lldi.ntxq /
2148 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002149 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2150 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302151 step = cdev->rdev.lldi.nrxq /
2152 cdev->rdev.lldi.nchan;
2153 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002154 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302155 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302156
2157 if (clear_mpa_v1) {
2158 ep->retry_with_mpa_v1 = 0;
2159 ep->tried_with_mpa_v1 = 0;
2160 }
2161 }
2162 err = 0;
2163out:
2164 rcu_read_unlock();
2165
2166 neigh_release(n);
2167
2168 return err;
2169}
2170
Vipul Pandya793dad92012-12-10 09:30:56 +00002171static int c4iw_reconnect(struct c4iw_ep *ep)
2172{
2173 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302174 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302175 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002176 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302177 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002178 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302179 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002180 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302181 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002182 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302183 int iptype;
2184 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002185
2186 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2187 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302188 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002189
Hariprasad S4a740832016-06-10 01:05:15 +05302190 /* When MPA revision is different on nodes, the node with MPA_rev=2
2191 * tries to reconnect with MPA_rev 1 for the same EP through
2192 * c4iw_reconnect(), where the same EP is assigned with new tid for
2193 * further connection establishment. As we are using the same EP pointer
2194 * for reconnect, few skbs are used during the previous c4iw_connect(),
2195 * which leaves the EP with inadequate skbs for further
2196 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2197 * skb_list() during peer_abort(). Allocate skbs which is already used.
2198 */
2199 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2200 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2201 err = -ENOMEM;
2202 goto fail1;
2203 }
2204
Vipul Pandya793dad92012-12-10 09:30:56 +00002205 /*
2206 * Allocate an active TID to initiate a TCP connection.
2207 */
2208 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2209 if (ep->atid == -1) {
2210 pr_err("%s - cannot alloc atid.\n", __func__);
2211 err = -ENOMEM;
2212 goto fail2;
2213 }
2214 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2215
2216 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002217 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302218 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2219 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302220 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302221 iptype = 4;
2222 ra = (__u8 *)&raddr->sin_addr;
2223 } else {
2224 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2225 raddr6->sin6_addr.s6_addr,
2226 laddr6->sin6_port, raddr6->sin6_port, 0,
2227 raddr6->sin6_scope_id);
2228 iptype = 6;
2229 ra = (__u8 *)&raddr6->sin6_addr;
2230 }
2231 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002232 pr_err("%s - cannot find route.\n", __func__);
2233 err = -EHOSTUNREACH;
2234 goto fail3;
2235 }
Hariprasad S963cab52015-09-23 17:19:27 +05302236 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302237 ep->com.dev->rdev.lldi.adapter_type,
2238 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302239 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002240 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002241 goto fail4;
2242 }
2243
2244 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2245 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2246 ep->l2t->idx);
2247
2248 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302249 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002250
2251 /* send connect request to rnic */
2252 err = send_connect(ep);
2253 if (!err)
2254 goto out;
2255
2256 cxgb4_l2t_release(ep->l2t);
2257fail4:
2258 dst_release(ep->dst);
2259fail3:
2260 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2261 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2262fail2:
2263 /*
2264 * remember to send notification to upper layer.
2265 * We are in here so the upper layer is not aware that this is
2266 * re-connect attempt and so, upper layer is still waiting for
2267 * response of 1st connect request.
2268 */
2269 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302270fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002271 c4iw_put_ep(&ep->com);
2272out:
2273 return err;
2274}
2275
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2277{
2278 struct c4iw_ep *ep;
2279 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002280 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2281 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002282 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002283 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302284 struct sockaddr_in *la;
2285 struct sockaddr_in *ra;
2286 struct sockaddr_in6 *la6;
2287 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302288 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289
2290 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002291 la = (struct sockaddr_in *)&ep->com.local_addr;
2292 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2293 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2294 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295
2296 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2297 status, status2errno(status));
2298
Steve Wise7a2cea22014-03-14 21:52:07 +05302299 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302300 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2301 __func__, atid, status, neg_adv_str(status));
2302 ep->stats.connect_neg_adv++;
2303 mutex_lock(&dev->rdev.stats.lock);
2304 dev->rdev.stats.neg_adv++;
2305 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002306 return 0;
2307 }
2308
Vipul Pandya793dad92012-12-10 09:30:56 +00002309 set_bit(ACT_OPEN_RPL, &ep->com.history);
2310
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302311 /*
2312 * Log interesting failures.
2313 */
2314 switch (status) {
2315 case CPL_ERR_CONN_RESET:
2316 case CPL_ERR_CONN_TIMEDOUT:
2317 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002318 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302319 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002320 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302321 mutex_unlock(&dev->rdev.stats.lock);
2322 if (ep->com.local_addr.ss_family == AF_INET &&
2323 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302324 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2325 ntohl(rpl->atid_status))));
2326 if (ret)
2327 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002328 return 0;
2329 }
2330 break;
2331 case CPL_ERR_CONN_EXIST:
2332 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2333 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302334 if (ep->com.remote_addr.ss_family == AF_INET6) {
2335 struct sockaddr_in6 *sin6 =
2336 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002337 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302338 cxgb4_clip_release(
2339 ep->com.dev->rdev.lldi.ports[0],
2340 (const u32 *)
2341 &sin6->sin6_addr.s6_addr, 1);
2342 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002343 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2344 atid);
2345 cxgb4_free_atid(t, atid);
2346 dst_release(ep->dst);
2347 cxgb4_l2t_release(ep->l2t);
2348 c4iw_reconnect(ep);
2349 return 0;
2350 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002351 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302352 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302353 if (ep->com.local_addr.ss_family == AF_INET) {
2354 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2355 atid, status, status2errno(status),
2356 &la->sin_addr.s_addr, ntohs(la->sin_port),
2357 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2358 } else {
2359 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2360 atid, status, status2errno(status),
2361 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2362 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2363 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302364 break;
2365 }
2366
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302367fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002368 connect_reply_upcall(ep, status2errno(status));
2369 state_set(&ep->com, DEAD);
2370
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302371 if (ep->com.remote_addr.ss_family == AF_INET6) {
2372 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002373 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302374 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2375 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2376 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002377 if (status && act_open_has_tid(status))
2378 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2379
Vipul Pandya793dad92012-12-10 09:30:56 +00002380 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002381 cxgb4_free_atid(t, atid);
2382 dst_release(ep->dst);
2383 cxgb4_l2t_release(ep->l2t);
2384 c4iw_put_ep(&ep->com);
2385
2386 return 0;
2387}
2388
2389static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2390{
2391 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302393 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002394
2395 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002396 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2397 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002398 }
2399 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2400 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002401 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302402 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002403out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002404 return 0;
2405}
2406
Steve Wisecfdda9d2010-04-21 15:30:06 -07002407static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2408{
2409 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002410 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302411 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002412
2413 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002414 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302415 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 return 0;
2417}
2418
Hariprasad S9dec9002016-05-05 01:27:29 +05302419static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2420 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002421{
2422 struct cpl_pass_accept_rpl *rpl;
2423 unsigned int mtu_idx;
2424 u64 opt0;
2425 u32 opt2;
2426 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302427 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302428 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302429 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002430
2431 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2432 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302433
Steve Wisecfdda9d2010-04-21 15:30:06 -07002434 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302435 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302436 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302437 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2438 rpl5 = (void *)rpl;
2439 INIT_TP_WR(rpl5, ep->hwtid);
2440 } else {
2441 skb_trim(skb, sizeof(*rpl));
2442 INIT_TP_WR(rpl, ep->hwtid);
2443 }
2444 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2445 ep->hwtid));
2446
2447 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302448 enable_tcp_timestamps && req->tcpopt.tstamp,
2449 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302451
2452 /*
2453 * Specify the largest window that will fit in opt0. The
2454 * remainder will be specified in the rx_data_ack.
2455 */
2456 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002457 if (win > RCV_BUFSIZ_M)
2458 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002459 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002460 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002461 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002462 WND_SCALE_V(wscale) |
2463 MSS_IDX_V(mtu_idx) |
2464 L2T_IDX_V(ep->l2t->idx) |
2465 TX_CHAN_V(ep->tx_chan) |
2466 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002467 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002468 ULP_MODE_V(ULP_MODE_TCPDDP) |
2469 RCV_BUFSIZ_V(win);
2470 opt2 = RX_CHANNEL_V(0) |
2471 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002472
2473 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002474 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002475 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002476 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002478 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002479 if (enable_ecn) {
2480 const struct tcphdr *tcph;
2481 u32 hlen = ntohl(req->hdr_len);
2482
Hariprasad S963cab52015-09-23 17:19:27 +05302483 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2484 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2485 IP_HDR_LEN_G(hlen);
2486 else
2487 tcph = (const void *)(req + 1) +
2488 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002489 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002490 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002491 }
Hariprasad S963cab52015-09-23 17:19:27 +05302492 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302493 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002494 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302495 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302496 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302497 rpl5 = (void *)rpl;
2498 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2499 if (peer2peer)
2500 isn += 4;
2501 rpl5->iss = cpu_to_be32(isn);
2502 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002503 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002504
Steve Wisecfdda9d2010-04-21 15:30:06 -07002505 rpl->opt0 = cpu_to_be64(opt0);
2506 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002507 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302508 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002509
Hariprasad S9dec9002016-05-05 01:27:29 +05302510 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002511}
2512
Vipul Pandya830662f2013-07-04 16:10:47 +05302513static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002514{
Vipul Pandya830662f2013-07-04 16:10:47 +05302515 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002516 BUG_ON(skb_cloned(skb));
2517 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002518 release_tid(&dev->rdev, hwtid, skb);
2519 return;
2520}
2521
Steve Wisecfdda9d2010-04-21 15:30:06 -07002522static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2523{
Vipul Pandya793dad92012-12-10 09:30:56 +00002524 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002525 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002526 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002527 struct tid_info *t = dev->rdev.lldi.tids;
2528 unsigned int hwtid = GET_TID(req);
2529 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002531 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302532 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002533 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002534 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302535 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302536 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302537 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002538
Hariprasad Sf86fac72016-05-06 22:18:07 +05302539 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002540 if (!parent_ep) {
2541 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2542 goto reject;
2543 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002544
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302546 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002547 goto reject;
2548 }
2549
Varun Prakash85e42b02016-09-13 21:23:56 +05302550 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2551 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302552
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302554 if (iptype == 4) {
2555 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2556 , __func__, parent_ep, hwtid,
2557 local_ip, peer_ip, ntohs(local_port),
2558 ntohs(peer_port), peer_mss);
2559 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2560 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302561 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302562 } else {
2563 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2564 , __func__, parent_ep, hwtid,
2565 local_ip, peer_ip, ntohs(local_port),
2566 ntohs(peer_port), peer_mss);
2567 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002568 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302569 ((struct sockaddr_in6 *)
2570 &parent_ep->com.local_addr)->sin6_scope_id);
2571 }
2572 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002573 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2574 __func__);
2575 goto reject;
2576 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577
2578 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2579 if (!child_ep) {
2580 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2581 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582 dst_release(dst);
2583 goto reject;
2584 }
David Miller3786cf12011-12-02 16:52:31 +00002585
Hariprasad S963cab52015-09-23 17:19:27 +05302586 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302587 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002588 if (err) {
2589 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2590 __func__);
2591 dst_release(dst);
2592 kfree(child_ep);
2593 goto reject;
2594 }
2595
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302596 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2597 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2598 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2599 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002600
Hariprasad S4a740832016-06-10 01:05:15 +05302601 skb_queue_head_init(&child_ep->com.ep_skb_list);
2602 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2603 goto fail;
2604
Steve Wisecfdda9d2010-04-21 15:30:06 -07002605 state_set(&child_ep->com, CONNECTING);
2606 child_ep->com.dev = dev;
2607 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002608
Vipul Pandya830662f2013-07-04 16:10:47 +05302609 if (iptype == 4) {
2610 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002611 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002612
Vipul Pandya830662f2013-07-04 16:10:47 +05302613 sin->sin_family = PF_INET;
2614 sin->sin_port = local_port;
2615 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002616
2617 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2618 sin->sin_family = PF_INET;
2619 sin->sin_port = ((struct sockaddr_in *)
2620 &parent_ep->com.local_addr)->sin_port;
2621 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2622
Steve Wise170003c2016-02-26 09:18:03 -06002623 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302624 sin->sin_family = PF_INET;
2625 sin->sin_port = peer_port;
2626 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2627 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002628 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302629 sin6->sin6_family = PF_INET6;
2630 sin6->sin6_port = local_port;
2631 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002632
2633 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2634 sin6->sin6_family = PF_INET6;
2635 sin6->sin6_port = ((struct sockaddr_in6 *)
2636 &parent_ep->com.local_addr)->sin6_port;
2637 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2638
Steve Wise170003c2016-02-26 09:18:03 -06002639 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302640 sin6->sin6_family = PF_INET6;
2641 sin6->sin6_port = peer_port;
2642 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2643 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002644
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 c4iw_get_ep(&parent_ep->com);
2646 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302647 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 child_ep->dst = dst;
2649 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650
2651 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002652 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653
2654 init_timer(&child_ep->timer);
2655 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302656 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302657 if (accept_cr(child_ep, skb, req)) {
2658 c4iw_put_ep(&parent_ep->com);
2659 release_ep_resources(child_ep);
2660 } else {
2661 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2662 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302663 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002664 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302665 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2666 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2667 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302669fail:
2670 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002671reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302672 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302673 if (parent_ep)
2674 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002675out:
2676 return 0;
2677}
2678
2679static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2680{
2681 struct c4iw_ep *ep;
2682 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002683 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302684 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685
Hariprasad S944661d2016-05-06 22:18:03 +05302686 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002687 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2688 ep->snd_seq = be32_to_cpu(req->snd_isn);
2689 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2690
Vipul Pandya1cab7752012-12-10 09:30:55 +00002691 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2692 ntohs(req->tcp_opt));
2693
Steve Wisecfdda9d2010-04-21 15:30:06 -07002694 set_emss(ep, ntohs(req->tcp_opt));
2695
2696 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302697 mutex_lock(&ep->com.mutex);
2698 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002699 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002700 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302701 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302702 mutex_unlock(&ep->com.mutex);
2703 if (ret)
2704 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302705 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002706
2707 return 0;
2708}
2709
2710static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2711{
2712 struct cpl_peer_close *hdr = cplhdr(skb);
2713 struct c4iw_ep *ep;
2714 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 int disconnect = 1;
2716 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002717 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002718 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719
Hariprasad S944661d2016-05-06 22:18:03 +05302720 ep = get_ep_from_tid(dev, tid);
2721 if (!ep)
2722 return 0;
2723
Steve Wisecfdda9d2010-04-21 15:30:06 -07002724 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2725 dst_confirm(ep->dst);
2726
Vipul Pandya793dad92012-12-10 09:30:56 +00002727 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002728 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002729 switch (ep->com.state) {
2730 case MPA_REQ_WAIT:
2731 __state_set(&ep->com, CLOSING);
2732 break;
2733 case MPA_REQ_SENT:
2734 __state_set(&ep->com, CLOSING);
2735 connect_reply_upcall(ep, -ECONNRESET);
2736 break;
2737 case MPA_REQ_RCVD:
2738
2739 /*
2740 * We're gonna mark this puppy DEAD, but keep
2741 * the reference on it until the ULP accepts or
2742 * rejects the CR. Also wake up anyone waiting
2743 * in rdma connection migration (see c4iw_accept_cr()).
2744 */
2745 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002746 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002747 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748 break;
2749 case MPA_REP_SENT:
2750 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002751 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002752 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002753 break;
2754 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002755 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002757 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002758 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002759 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002760 if (ret != -ECONNRESET) {
2761 peer_close_upcall(ep);
2762 disconnect = 1;
2763 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002764 break;
2765 case ABORTING:
2766 disconnect = 0;
2767 break;
2768 case CLOSING:
2769 __state_set(&ep->com, MORIBUND);
2770 disconnect = 0;
2771 break;
2772 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002773 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002774 if (ep->com.cm_id && ep->com.qp) {
2775 attrs.next_state = C4IW_QP_STATE_IDLE;
2776 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2777 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2778 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302779 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 __state_set(&ep->com, DEAD);
2781 release = 1;
2782 disconnect = 0;
2783 break;
2784 case DEAD:
2785 disconnect = 0;
2786 break;
2787 default:
2788 BUG_ON(1);
2789 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002790 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002791 if (disconnect)
2792 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2793 if (release)
2794 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302795 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002796 return 0;
2797}
2798
Steve Wisecfdda9d2010-04-21 15:30:06 -07002799static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2800{
2801 struct cpl_abort_req_rss *req = cplhdr(skb);
2802 struct c4iw_ep *ep;
2803 struct cpl_abort_rpl *rpl;
2804 struct sk_buff *rpl_skb;
2805 struct c4iw_qp_attributes attrs;
2806 int ret;
2807 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002808 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809
Hariprasad S944661d2016-05-06 22:18:03 +05302810 ep = get_ep_from_tid(dev, tid);
2811 if (!ep)
2812 return 0;
2813
Steve Wise7a2cea22014-03-14 21:52:07 +05302814 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302815 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2816 __func__, ep->hwtid, req->status,
2817 neg_adv_str(req->status));
2818 ep->stats.abort_neg_adv++;
2819 mutex_lock(&dev->rdev.stats.lock);
2820 dev->rdev.stats.neg_adv++;
2821 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302822 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002823 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002824 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2825 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002826 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002827
2828 /*
2829 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302830 * However, this is not needed if com state is just
2831 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002832 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302833 if (ep->com.state != MPA_REQ_SENT)
2834 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002835
2836 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837 switch (ep->com.state) {
2838 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302839 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002840 break;
2841 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002842 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843 break;
2844 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002845 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002846 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302847 connect_reply_upcall(ep, -ECONNRESET);
2848 else {
2849 /*
2850 * we just don't send notification upwards because we
2851 * want to retry with mpa_v1 without upper layers even
2852 * knowing it.
2853 *
2854 * do some housekeeping so as to re-initiate the
2855 * connection
2856 */
2857 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2858 mpa_rev);
2859 ep->retry_with_mpa_v1 = 1;
2860 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002861 break;
2862 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002863 break;
2864 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002865 break;
2866 case MORIBUND:
2867 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002868 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002869 /*FALLTHROUGH*/
2870 case FPDU_MODE:
2871 if (ep->com.cm_id && ep->com.qp) {
2872 attrs.next_state = C4IW_QP_STATE_ERROR;
2873 ret = c4iw_modify_qp(ep->com.qp->rhp,
2874 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2875 &attrs, 1);
2876 if (ret)
2877 printk(KERN_ERR MOD
2878 "%s - qp <- error failed!\n",
2879 __func__);
2880 }
2881 peer_abort_upcall(ep);
2882 break;
2883 case ABORTING:
2884 break;
2885 case DEAD:
2886 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002887 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302888 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889 default:
2890 BUG_ON(1);
2891 break;
2892 }
2893 dst_confirm(ep->dst);
2894 if (ep->com.state != ABORTING) {
2895 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302896 /* we don't release if we want to retry with mpa_v1 */
2897 if (!ep->retry_with_mpa_v1)
2898 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002899 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002900 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002901
Hariprasad S4a740832016-06-10 01:05:15 +05302902 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2903 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002904 release = 1;
2905 goto out;
2906 }
2907 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2908 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2909 INIT_TP_WR(rpl, ep->hwtid);
2910 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2911 rpl->cmd = CPL_ABORT_NO_RST;
2912 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2913out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002914 if (release)
2915 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002916 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302917 if (ep->com.remote_addr.ss_family == AF_INET6) {
2918 struct sockaddr_in6 *sin6 =
2919 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002920 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302921 cxgb4_clip_release(
2922 ep->com.dev->rdev.lldi.ports[0],
2923 (const u32 *)&sin6->sin6_addr.s6_addr,
2924 1);
2925 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002926 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302927 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2928 dst_release(ep->dst);
2929 cxgb4_l2t_release(ep->l2t);
2930 c4iw_reconnect(ep);
2931 }
2932
Hariprasad S944661d2016-05-06 22:18:03 +05302933deref_ep:
2934 c4iw_put_ep(&ep->com);
2935 /* Dereferencing ep, referenced in peer_abort_intr() */
2936 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002937 return 0;
2938}
2939
2940static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2941{
2942 struct c4iw_ep *ep;
2943 struct c4iw_qp_attributes attrs;
2944 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002945 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002947
Hariprasad S944661d2016-05-06 22:18:03 +05302948 ep = get_ep_from_tid(dev, tid);
2949 if (!ep)
2950 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951
2952 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2953 BUG_ON(!ep);
2954
2955 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002956 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302957 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002958 switch (ep->com.state) {
2959 case CLOSING:
2960 __state_set(&ep->com, MORIBUND);
2961 break;
2962 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002963 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002964 if ((ep->com.cm_id) && (ep->com.qp)) {
2965 attrs.next_state = C4IW_QP_STATE_IDLE;
2966 c4iw_modify_qp(ep->com.qp->rhp,
2967 ep->com.qp,
2968 C4IW_QP_ATTR_NEXT_STATE,
2969 &attrs, 1);
2970 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302971 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002972 __state_set(&ep->com, DEAD);
2973 release = 1;
2974 break;
2975 case ABORTING:
2976 case DEAD:
2977 break;
2978 default:
2979 BUG_ON(1);
2980 break;
2981 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002982 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002983 if (release)
2984 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302985 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 return 0;
2987}
2988
2989static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2990{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002991 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002992 unsigned int tid = GET_TID(rpl);
2993 struct c4iw_ep *ep;
2994 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002995
Hariprasad S944661d2016-05-06 22:18:03 +05302996 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002997 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002998
Steve Wise30c95c22011-05-09 22:06:22 -07002999 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05003000 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
3001 ep->com.qp->wq.sq.qid);
3002 attrs.next_state = C4IW_QP_STATE_TERMINATE;
3003 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
3004 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
3005 } else
Steve Wise30c95c22011-05-09 22:06:22 -07003006 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05303007 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003008
Steve Wisecfdda9d2010-04-21 15:30:06 -07003009 return 0;
3010}
3011
3012/*
3013 * Upcall from the adapter indicating data has been transmitted.
3014 * For us its just the single MPA request or reply. We can now free
3015 * the skb holding the mpa message.
3016 */
3017static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
3018{
3019 struct c4iw_ep *ep;
3020 struct cpl_fw4_ack *hdr = cplhdr(skb);
3021 u8 credits = hdr->credits;
3022 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003023
3024
Hariprasad S944661d2016-05-06 22:18:03 +05303025 ep = get_ep_from_tid(dev, tid);
3026 if (!ep)
3027 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003028 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
3029 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07003030 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
3031 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05303032 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003033 }
3034
3035 dst_confirm(ep->dst);
3036 if (ep->mpa_skb) {
3037 PDBG("%s last streaming msg ack ep %p tid %u state %u "
3038 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
3039 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07003040 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003041 kfree_skb(ep->mpa_skb);
3042 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303043 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
3044 stop_ep_timer(ep);
3045 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003046 }
Hariprasad S944661d2016-05-06 22:18:03 +05303047out:
3048 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003049 return 0;
3050}
3051
Steve Wisecfdda9d2010-04-21 15:30:06 -07003052int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
3053{
Hariprasad Sbce28412016-06-10 01:05:13 +05303054 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003055 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05303056
Steve Wisecfdda9d2010-04-21 15:30:06 -07003057 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
3058
Steve Wisea7db89e2014-03-21 20:40:35 +05303059 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303060 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303061 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003062 c4iw_put_ep(&ep->com);
3063 return -ECONNRESET;
3064 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003065 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003066 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05303067 abort = 1;
3068 else
3069 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303070 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05303071
3072 stop_ep_timer(ep);
3073 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003074 c4iw_put_ep(&ep->com);
3075 return 0;
3076}
3077
3078int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3079{
3080 int err;
3081 struct c4iw_qp_attributes attrs;
3082 enum c4iw_qp_attr_mask mask;
3083 struct c4iw_ep *ep = to_ep(cm_id);
3084 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3085 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303086 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003087
3088 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303089
3090 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303091 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003092 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303093 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003094 }
3095
Steve Wisecfdda9d2010-04-21 15:30:06 -07003096 BUG_ON(!qp);
3097
Vipul Pandya793dad92012-12-10 09:30:56 +00003098 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303099 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3100 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003101 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303102 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003103 }
3104
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303105 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3106 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303107 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003108 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303109 } else {
3110 ep->ird = conn_param->ird;
3111 ep->ord = conn_param->ord;
3112 send_mpa_reject(ep, conn_param->private_data,
3113 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303114 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303115 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303116 }
3117 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303118 if (conn_param->ird < ep->ord) {
3119 if (RELAXED_IRD_NEGOTIATION &&
3120 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3121 conn_param->ird = ep->ord;
3122 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303123 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303124 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303125 }
3126 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303127 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003128 ep->ird = conn_param->ird;
3129 ep->ord = conn_param->ord;
3130
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303131 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303132 if (peer2peer && ep->ird == 0)
3133 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303134 } else {
3135 if (peer2peer &&
3136 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303137 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303138 ep->ird = 1;
3139 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003140
3141 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3142
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303143 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303144 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303145 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003146 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303147
Steve Wisecfdda9d2010-04-21 15:30:06 -07003148 /* bind QP to EP and move to RTS */
3149 attrs.mpa_attr = ep->mpa_attr;
3150 attrs.max_ird = ep->ird;
3151 attrs.max_ord = ep->ord;
3152 attrs.llp_stream_handle = ep;
3153 attrs.next_state = C4IW_QP_STATE_RTS;
3154
3155 /* bind QP and TID with INIT_WR */
3156 mask = C4IW_QP_ATTR_NEXT_STATE |
3157 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3158 C4IW_QP_ATTR_MPA_ATTR |
3159 C4IW_QP_ATTR_MAX_IRD |
3160 C4IW_QP_ATTR_MAX_ORD;
3161
3162 err = c4iw_modify_qp(ep->com.qp->rhp,
3163 ep->com.qp, mask, &attrs, 1);
3164 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303165 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303166
3167 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003168 err = send_mpa_reply(ep, conn_param->private_data,
3169 conn_param->private_data_len);
3170 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303171 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003172
Steve Wisea7db89e2014-03-21 20:40:35 +05303173 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003174 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303175 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003176 c4iw_put_ep(&ep->com);
3177 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303178err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303179 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303180err_abort:
3181 abort = 1;
3182err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303183 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303184 if (abort)
3185 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003186 c4iw_put_ep(&ep->com);
3187 return err;
3188}
3189
Vipul Pandya830662f2013-07-04 16:10:47 +05303190static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3191{
3192 struct in_device *ind;
3193 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003194 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3195 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303196
3197 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3198 if (!ind)
3199 return -EADDRNOTAVAIL;
3200 for_primary_ifa(ind) {
3201 laddr->sin_addr.s_addr = ifa->ifa_address;
3202 raddr->sin_addr.s_addr = ifa->ifa_address;
3203 found = 1;
3204 break;
3205 }
3206 endfor_ifa(ind);
3207 in_dev_put(ind);
3208 return found ? 0 : -EADDRNOTAVAIL;
3209}
3210
3211static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3212 unsigned char banned_flags)
3213{
3214 struct inet6_dev *idev;
3215 int err = -EADDRNOTAVAIL;
3216
3217 rcu_read_lock();
3218 idev = __in6_dev_get(dev);
3219 if (idev != NULL) {
3220 struct inet6_ifaddr *ifp;
3221
3222 read_lock_bh(&idev->lock);
3223 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3224 if (ifp->scope == IFA_LINK &&
3225 !(ifp->flags & banned_flags)) {
3226 memcpy(addr, &ifp->addr, 16);
3227 err = 0;
3228 break;
3229 }
3230 }
3231 read_unlock_bh(&idev->lock);
3232 }
3233 rcu_read_unlock();
3234 return err;
3235}
3236
3237static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3238{
3239 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003240 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3241 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303242
Nicholas Krause54b9a962015-08-26 23:00:59 -04003243 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303244 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3245 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3246 return 0;
3247 }
3248 return -EADDRNOTAVAIL;
3249}
3250
Steve Wisecfdda9d2010-04-21 15:30:06 -07003251int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3252{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3254 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003255 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003256 struct sockaddr_in *laddr;
3257 struct sockaddr_in *raddr;
3258 struct sockaddr_in6 *laddr6;
3259 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303260 __u8 *ra;
3261 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003262
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303263 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3264 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003265 err = -EINVAL;
3266 goto out;
3267 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3269 if (!ep) {
3270 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3271 err = -ENOMEM;
3272 goto out;
3273 }
Hariprasad S4a740832016-06-10 01:05:15 +05303274
3275 skb_queue_head_init(&ep->com.ep_skb_list);
3276 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3277 err = -ENOMEM;
3278 goto fail1;
3279 }
3280
Steve Wisecfdda9d2010-04-21 15:30:06 -07003281 init_timer(&ep->timer);
3282 ep->plen = conn_param->private_data_len;
3283 if (ep->plen)
3284 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3285 conn_param->private_data, ep->plen);
3286 ep->ird = conn_param->ird;
3287 ep->ord = conn_param->ord;
3288
3289 if (peer2peer && ep->ord == 0)
3290 ep->ord = 1;
3291
Steve Wisecfdda9d2010-04-21 15:30:06 -07003292 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303293 ref_cm_id(&ep->com);
3294 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003295 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303296 if (!ep->com.qp) {
3297 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3298 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303299 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303300 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003301 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003302 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3303 ep->com.qp, cm_id);
3304
3305 /*
3306 * Allocate an active TID to initiate a TCP connection.
3307 */
3308 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3309 if (ep->atid == -1) {
3310 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3311 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303312 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003313 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003314 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003315
Steve Wise170003c2016-02-26 09:18:03 -06003316 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003317 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003318 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003319 sizeof(ep->com.remote_addr));
3320
Steve Wise170003c2016-02-26 09:18:03 -06003321 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3322 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3323 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3324 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003325
Steve Wise170003c2016-02-26 09:18:03 -06003326 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303327 iptype = 4;
3328 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003329
Vipul Pandya830662f2013-07-04 16:10:47 +05303330 /*
3331 * Handle loopback requests to INADDR_ANY.
3332 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003333 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303334 err = pick_local_ipaddrs(dev, cm_id);
3335 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303336 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303337 }
3338
3339 /* find a route */
3340 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3341 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3342 ra, ntohs(raddr->sin_port));
3343 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3344 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303345 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303346 } else {
3347 iptype = 6;
3348 ra = (__u8 *)&raddr6->sin6_addr;
3349
3350 /*
3351 * Handle loopback requests to INADDR_ANY.
3352 */
3353 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3354 err = pick_local_ip6addrs(dev, cm_id);
3355 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303356 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303357 }
3358
3359 /* find a route */
3360 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3361 __func__, laddr6->sin6_addr.s6_addr,
3362 ntohs(laddr6->sin6_port),
3363 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3364 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3365 raddr6->sin6_addr.s6_addr,
3366 laddr6->sin6_port, raddr6->sin6_port, 0,
3367 raddr6->sin6_scope_id);
3368 }
3369 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003370 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3371 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303372 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003373 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374
Hariprasad S963cab52015-09-23 17:19:27 +05303375 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303376 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003377 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003378 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303379 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003380 }
3381
3382 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3383 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3384 ep->l2t->idx);
3385
3386 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303387 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003388
3389 /* send connect request to rnic */
3390 err = send_connect(ep);
3391 if (!err)
3392 goto out;
3393
3394 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303395fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003396 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303397fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003398 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003399 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303400fail2:
3401 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303402 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303403fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003404 c4iw_put_ep(&ep->com);
3405out:
3406 return err;
3407}
3408
Vipul Pandya830662f2013-07-04 16:10:47 +05303409static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3410{
3411 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003412 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003413 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303414
Hariprasad S28de1f72016-01-13 10:03:14 +05303415 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3416 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3417 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3418 if (err)
3419 return err;
3420 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303421 c4iw_init_wr_wait(&ep->com.wr_wait);
3422 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3423 ep->stid, &sin6->sin6_addr,
3424 sin6->sin6_port,
3425 ep->com.dev->rdev.lldi.rxq_ids[0]);
3426 if (!err)
3427 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3428 &ep->com.wr_wait,
3429 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303430 else if (err > 0)
3431 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303432 if (err) {
3433 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3434 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303435 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3436 err, ep->stid,
3437 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303438 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303439 return err;
3440}
3441
3442static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3443{
3444 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003445 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003446 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303447
3448 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3449 do {
3450 err = cxgb4_create_server_filter(
3451 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3452 sin->sin_addr.s_addr, sin->sin_port, 0,
3453 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3454 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303455 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3456 err = -EIO;
3457 break;
3458 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303459 set_current_state(TASK_UNINTERRUPTIBLE);
3460 schedule_timeout(usecs_to_jiffies(100));
3461 }
3462 } while (err == -EBUSY);
3463 } else {
3464 c4iw_init_wr_wait(&ep->com.wr_wait);
3465 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3466 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3467 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3468 if (!err)
3469 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3470 &ep->com.wr_wait,
3471 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303472 else if (err > 0)
3473 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303474 }
3475 if (err)
3476 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3477 , err, ep->stid,
3478 &sin->sin_addr, ntohs(sin->sin_port));
3479 return err;
3480}
3481
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3483{
3484 int err = 0;
3485 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3486 struct c4iw_listen_ep *ep;
3487
Steve Wisecfdda9d2010-04-21 15:30:06 -07003488 might_sleep();
3489
3490 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3491 if (!ep) {
3492 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3493 err = -ENOMEM;
3494 goto fail1;
3495 }
Hariprasad S4a740832016-06-10 01:05:15 +05303496 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003497 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303499 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003500 ep->com.dev = dev;
3501 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003502 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303503 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003504
3505 /*
3506 * Allocate a server TID.
3507 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303508 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3509 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303510 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003511 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003512 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303513 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003514 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003515
Steve Wisecfdda9d2010-04-21 15:30:06 -07003516 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003517 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003518 err = -ENOMEM;
3519 goto fail2;
3520 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003521 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003522
Steve Wise170003c2016-02-26 09:18:03 -06003523 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3524 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003525
Steve Wisecfdda9d2010-04-21 15:30:06 -07003526 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303527 if (ep->com.local_addr.ss_family == AF_INET)
3528 err = create_server4(dev, ep);
3529 else
3530 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003531 if (!err) {
3532 cm_id->provider_data = ep;
3533 goto out;
3534 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003535
Vipul Pandya830662f2013-07-04 16:10:47 +05303536 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3537 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003538fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303539 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003540 c4iw_put_ep(&ep->com);
3541fail1:
3542out:
3543 return err;
3544}
3545
3546int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3547{
3548 int err;
3549 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3550
3551 PDBG("%s ep %p\n", __func__, ep);
3552
3553 might_sleep();
3554 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303555 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3556 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003557 err = cxgb4_remove_server_filter(
3558 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3559 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3560 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303561 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003562 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303563 err = cxgb4_remove_server(
3564 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3565 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003566 if (err)
3567 goto done;
3568 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3569 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003570 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303571 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3572 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003573 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003574 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303575 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3576 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003577done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303578 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003579 c4iw_put_ep(&ep->com);
3580 return err;
3581}
3582
3583int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3584{
3585 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003586 int close = 0;
3587 int fatal = 0;
3588 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003589
Steve Wise2f5b48c2010-09-10 11:15:36 -05003590 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003591
3592 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3593 states[ep->com.state], abrupt);
3594
Hariprasad S6e410d82016-05-05 01:27:31 +05303595 /*
3596 * Ref the ep here in case we have fatal errors causing the
3597 * ep to be released and freed.
3598 */
3599 c4iw_get_ep(&ep->com);
3600
Steve Wisecfdda9d2010-04-21 15:30:06 -07003601 rdev = &ep->com.dev->rdev;
3602 if (c4iw_fatal_error(rdev)) {
3603 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303604 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003605 ep->com.state = DEAD;
3606 }
3607 switch (ep->com.state) {
3608 case MPA_REQ_WAIT:
3609 case MPA_REQ_SENT:
3610 case MPA_REQ_RCVD:
3611 case MPA_REP_SENT:
3612 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303613 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003614 close = 1;
3615 if (abrupt)
3616 ep->com.state = ABORTING;
3617 else {
3618 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003619
3620 /*
3621 * if we close before we see the fw4_ack() then we fix
3622 * up the timer state since we're reusing it.
3623 */
3624 if (ep->mpa_skb &&
3625 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3626 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3627 stop_ep_timer(ep);
3628 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003629 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003630 }
3631 set_bit(CLOSE_SENT, &ep->com.flags);
3632 break;
3633 case CLOSING:
3634 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3635 close = 1;
3636 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003637 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003638 ep->com.state = ABORTING;
3639 } else
3640 ep->com.state = MORIBUND;
3641 }
3642 break;
3643 case MORIBUND:
3644 case ABORTING:
3645 case DEAD:
3646 PDBG("%s ignoring disconnect ep %p state %u\n",
3647 __func__, ep, ep->com.state);
3648 break;
3649 default:
3650 BUG();
3651 break;
3652 }
3653
Steve Wisecfdda9d2010-04-21 15:30:06 -07003654 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003655 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003656 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303657 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303658 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003659 } else {
3660 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303661 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003662 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303663 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303664 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303665 if (!abrupt) {
3666 stop_ep_timer(ep);
3667 close_complete_upcall(ep, -EIO);
3668 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303669 if (ep->com.qp) {
3670 struct c4iw_qp_attributes attrs;
3671
3672 attrs.next_state = C4IW_QP_STATE_ERROR;
3673 ret = c4iw_modify_qp(ep->com.qp->rhp,
3674 ep->com.qp,
3675 C4IW_QP_ATTR_NEXT_STATE,
3676 &attrs, 1);
3677 if (ret)
3678 pr_err(MOD
3679 "%s - qp <- error failed!\n",
3680 __func__);
3681 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003682 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303683 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003684 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003685 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303686 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003687 if (fatal)
3688 release_ep_resources(ep);
3689 return ret;
3690}
3691
Vipul Pandya1cab7752012-12-10 09:30:55 +00003692static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3693 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3694{
3695 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003696 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003697
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003698 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3699 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003700 if (!ep)
3701 return;
3702
3703 switch (req->retval) {
3704 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003705 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3706 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3707 send_fw_act_open_req(ep, atid);
3708 return;
3709 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003710 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003711 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3712 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3713 send_fw_act_open_req(ep, atid);
3714 return;
3715 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003716 break;
3717 default:
3718 pr_info("%s unexpected ofld conn wr retval %d\n",
3719 __func__, req->retval);
3720 break;
3721 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003722 pr_err("active ofld_connect_wr failure %d atid %d\n",
3723 req->retval, atid);
3724 mutex_lock(&dev->rdev.stats.lock);
3725 dev->rdev.stats.act_ofld_conn_fails++;
3726 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003727 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003728 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303729 if (ep->com.remote_addr.ss_family == AF_INET6) {
3730 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003731 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303732 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3733 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3734 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003735 remove_handle(dev, &dev->atid_idr, atid);
3736 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3737 dst_release(ep->dst);
3738 cxgb4_l2t_release(ep->l2t);
3739 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003740}
3741
3742static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3743 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3744{
3745 struct sk_buff *rpl_skb;
3746 struct cpl_pass_accept_req *cpl;
3747 int ret;
3748
Paul Bolle710a3112013-02-05 20:51:30 +00003749 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003750 BUG_ON(!rpl_skb);
3751 if (req->retval) {
3752 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003753 mutex_lock(&dev->rdev.stats.lock);
3754 dev->rdev.stats.pas_ofld_conn_fails++;
3755 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003756 kfree_skb(rpl_skb);
3757 } else {
3758 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3759 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003760 (__force u32) htonl(
3761 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003762 ret = pass_accept_req(dev, rpl_skb);
3763 if (!ret)
3764 kfree_skb(rpl_skb);
3765 }
3766 return;
3767}
3768
3769static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003770{
3771 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003772 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3773
3774 switch (rpl->type) {
3775 case FW6_TYPE_CQE:
3776 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3777 break;
3778 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3779 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3780 switch (req->t_state) {
3781 case TCP_SYN_SENT:
3782 active_ofld_conn_reply(dev, skb, req);
3783 break;
3784 case TCP_SYN_RECV:
3785 passive_ofld_conn_reply(dev, skb, req);
3786 break;
3787 default:
3788 pr_err("%s unexpected ofld conn wr state %d\n",
3789 __func__, req->t_state);
3790 break;
3791 }
3792 break;
3793 }
3794 return 0;
3795}
3796
3797static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3798{
Hariprasad S963cab52015-09-23 17:19:27 +05303799 __be32 l2info;
3800 __be16 hdr_len, vlantag, len;
3801 u16 eth_hdr_len;
3802 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003803 u8 intf;
3804 struct cpl_rx_pkt *cpl = cplhdr(skb);
3805 struct cpl_pass_accept_req *req;
3806 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003807 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303808 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003809
Vipul Pandyaf079af72013-03-14 05:08:58 +00003810 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003811 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303812 vlantag = cpl->vlan;
3813 len = cpl->len;
3814 l2info = cpl->l2info;
3815 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003816 intf = cpl->iff;
3817
3818 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3819
3820 /*
3821 * We need to parse the TCP options from SYN packet.
3822 * to generate cpl_pass_accept_req.
3823 */
3824 memset(&tmp_opt, 0, sizeof(tmp_opt));
3825 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003826 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003827
3828 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3829 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303830 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3831 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303832 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303833 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303834 type = dev->rdev.lldi.adapter_type;
3835 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3836 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3837 req->hdr_len =
3838 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3839 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3840 eth_hdr_len = is_t4(type) ?
3841 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3842 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3843 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3844 IP_HDR_LEN_V(ip_hdr_len) |
3845 ETH_HDR_LEN_V(eth_hdr_len));
3846 } else { /* T6 and later */
3847 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3848 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3849 T6_IP_HDR_LEN_V(ip_hdr_len) |
3850 T6_ETH_HDR_LEN_V(eth_hdr_len));
3851 }
3852 req->vlan = vlantag;
3853 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003854 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3855 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003856 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3857 if (tmp_opt.wscale_ok)
3858 req->tcpopt.wsf = tmp_opt.snd_wscale;
3859 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3860 if (tmp_opt.sack_ok)
3861 req->tcpopt.sack = 1;
3862 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3863 return;
3864}
3865
3866static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3867 __be32 laddr, __be16 lport,
3868 __be32 raddr, __be16 rport,
3869 u32 rcv_isn, u32 filter, u16 window,
3870 u32 rss_qid, u8 port_id)
3871{
3872 struct sk_buff *req_skb;
3873 struct fw_ofld_connection_wr *req;
3874 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303875 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003876
3877 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3878 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3879 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003880 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303881 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303882 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003883 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884 req->le.lport = lport;
3885 req->le.pport = rport;
3886 req->le.u.ipv4.lip = laddr;
3887 req->le.u.ipv4.pip = raddr;
3888 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3889 req->tcb.rcv_adv = htons(window);
3890 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303891 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3892 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3893 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003894 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003895
3896 /*
3897 * We store the qid in opt2 which will be used by the firmware
3898 * to send us the wr response.
3899 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003900 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003901
3902 /*
3903 * We initialize the MSS index in TCB to 0xF.
3904 * So that when driver sends cpl_pass_accept_rpl
3905 * TCB picks up the correct value. If this was 0
3906 * TP will ignore any value > 0 for MSS index.
3907 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003908 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303909 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003910
3911 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303912 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3913 if (ret < 0) {
3914 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3915 ret);
3916 kfree_skb(skb);
3917 kfree_skb(req_skb);
3918 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003919}
3920
3921/*
3922 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3923 * messages when a filter is being used instead of server to
3924 * redirect a syn packet. When packets hit filter they are redirected
3925 * to the offload queue and driver tries to establish the connection
3926 * using firmware work request.
3927 */
3928static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3929{
3930 int stid;
3931 unsigned int filter;
3932 struct ethhdr *eh = NULL;
3933 struct vlan_ethhdr *vlan_eh = NULL;
3934 struct iphdr *iph;
3935 struct tcphdr *tcph;
3936 struct rss_header *rss = (void *)skb->data;
3937 struct cpl_rx_pkt *cpl = (void *)skb->data;
3938 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3939 struct l2t_entry *e;
3940 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303941 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003942 u16 window;
3943 struct port_info *pi;
3944 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003945 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003946 int step;
3947 u32 tx_chan;
3948 struct neighbour *neigh;
3949
3950 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003951 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003952 goto reject;
3953
3954 /*
3955 * Drop all packets which did not hit the filter.
3956 * Unlikely to happen.
3957 */
3958 if (!(rss->filter_hit && rss->filter_tid))
3959 goto reject;
3960
3961 /*
3962 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3963 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303964 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003965
Hariprasad Sf86fac72016-05-06 22:18:07 +05303966 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003967 if (!lep) {
3968 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3969 goto reject;
3970 }
3971
Hariprasad S963cab52015-09-23 17:19:27 +05303972 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3973 case CHELSIO_T4:
3974 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3975 break;
3976 case CHELSIO_T5:
3977 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3978 break;
3979 case CHELSIO_T6:
3980 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3981 break;
3982 default:
3983 pr_err("T%d Chip is not supported\n",
3984 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3985 goto reject;
3986 }
3987
Vipul Pandyaf079af72013-03-14 05:08:58 +00003988 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003989 eh = (struct ethhdr *)(req + 1);
3990 iph = (struct iphdr *)(eh + 1);
3991 } else {
3992 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3993 iph = (struct iphdr *)(vlan_eh + 1);
3994 skb->vlan_tci = ntohs(cpl->vlan);
3995 }
3996
3997 if (iph->version != 0x4)
3998 goto reject;
3999
4000 tcph = (struct tcphdr *)(iph + 1);
4001 skb_set_network_header(skb, (void *)iph - (void *)rss);
4002 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
4003 skb_get(skb);
4004
4005 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
4006 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
4007 ntohs(tcph->source), iph->tos);
4008
Vipul Pandya830662f2013-07-04 16:10:47 +05304009 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
4010 iph->tos);
4011 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00004012 pr_err("%s - failed to find dst entry!\n",
4013 __func__);
4014 goto reject;
4015 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00004016 neigh = dst_neigh_lookup_skb(dst, skb);
4017
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00004018 if (!neigh) {
4019 pr_err("%s - failed to allocate neigh!\n",
4020 __func__);
4021 goto free_dst;
4022 }
4023
Vipul Pandya1cab7752012-12-10 09:30:55 +00004024 if (neigh->dev->flags & IFF_LOOPBACK) {
4025 pdev = ip_dev_find(&init_net, iph->daddr);
4026 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
4027 pdev, 0);
4028 pi = (struct port_info *)netdev_priv(pdev);
4029 tx_chan = cxgb4_port_chan(pdev);
4030 dev_put(pdev);
4031 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05304032 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004033 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05304034 pdev, 0);
4035 pi = (struct port_info *)netdev_priv(pdev);
4036 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004037 }
Steve Wiseebf00062014-03-19 17:44:40 +05304038 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004039 if (!e) {
4040 pr_err("%s - failed to allocate l2t entry!\n",
4041 __func__);
4042 goto free_dst;
4043 }
4044
4045 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
4046 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00004047 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00004048
4049 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05304050 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
4051 dev->rdev.lldi.ports[0],
4052 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00004053
4054 /*
4055 * Synthesize the cpl_pass_accept_req. We have everything except the
4056 * TID. Once firmware sends a reply with TID we update the TID field
4057 * in cpl and pass it through the regular cpl_pass_accept_req path.
4058 */
4059 build_cpl_pass_accept_req(skb, stid, iph->tos);
4060 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4061 tcph->source, ntohl(tcph->seq), filter, window,
4062 rss_qid, pi->port_id);
4063 cxgb4_l2t_release(e);
4064free_dst:
4065 dst_release(dst);
4066reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304067 if (lep)
4068 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004069 return 0;
4070}
4071
Steve Wisecfdda9d2010-04-21 15:30:06 -07004072/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004073 * These are the real handlers that are called from a
4074 * work queue.
4075 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304076static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004077 [CPL_ACT_ESTABLISH] = act_establish,
4078 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4079 [CPL_RX_DATA] = rx_data,
4080 [CPL_ABORT_RPL_RSS] = abort_rpl,
4081 [CPL_ABORT_RPL] = abort_rpl,
4082 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4083 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4084 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4085 [CPL_PASS_ESTABLISH] = pass_establish,
4086 [CPL_PEER_CLOSE] = peer_close,
4087 [CPL_ABORT_REQ_RSS] = peer_abort,
4088 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4089 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004090 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004091 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304092 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304093 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4094 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004095};
4096
4097static void process_timeout(struct c4iw_ep *ep)
4098{
4099 struct c4iw_qp_attributes attrs;
4100 int abort = 1;
4101
Steve Wise2f5b48c2010-09-10 11:15:36 -05004102 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4104 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004105 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004106 switch (ep->com.state) {
4107 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004108 connect_reply_upcall(ep, -ETIMEDOUT);
4109 break;
4110 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304111 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304112 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304113 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004114 break;
4115 case CLOSING:
4116 case MORIBUND:
4117 if (ep->com.cm_id && ep->com.qp) {
4118 attrs.next_state = C4IW_QP_STATE_ERROR;
4119 c4iw_modify_qp(ep->com.qp->rhp,
4120 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4121 &attrs, 1);
4122 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304123 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004124 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004125 case ABORTING:
4126 case DEAD:
4127
4128 /*
4129 * These states are expected if the ep timed out at the same
4130 * time as another thread was calling stop_ep_timer().
4131 * So we silently do nothing for these states.
4132 */
4133 abort = 0;
4134 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004135 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004136 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004137 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004138 abort = 0;
4139 }
Steve Wisecc18b932014-04-24 14:31:53 -05004140 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304141 if (abort)
4142 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004143 c4iw_put_ep(&ep->com);
4144}
4145
4146static void process_timedout_eps(void)
4147{
4148 struct c4iw_ep *ep;
4149
4150 spin_lock_irq(&timeout_lock);
4151 while (!list_empty(&timeout_list)) {
4152 struct list_head *tmp;
4153
4154 tmp = timeout_list.next;
4155 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004156 tmp->next = NULL;
4157 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004158 spin_unlock_irq(&timeout_lock);
4159 ep = list_entry(tmp, struct c4iw_ep, entry);
4160 process_timeout(ep);
4161 spin_lock_irq(&timeout_lock);
4162 }
4163 spin_unlock_irq(&timeout_lock);
4164}
4165
4166static void process_work(struct work_struct *work)
4167{
4168 struct sk_buff *skb = NULL;
4169 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004170 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004171 unsigned int opcode;
4172 int ret;
4173
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004174 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004175 while ((skb = skb_dequeue(&rxq))) {
4176 rpl = cplhdr(skb);
4177 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4178 opcode = rpl->ot.opcode;
4179
4180 BUG_ON(!work_handlers[opcode]);
4181 ret = work_handlers[opcode](dev, skb);
4182 if (!ret)
4183 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004184 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004185 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004186}
4187
4188static DECLARE_WORK(skb_work, process_work);
4189
4190static void ep_timeout(unsigned long arg)
4191{
4192 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004193 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004194
4195 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004196 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004197 /*
4198 * Only insert if it is not already on the list.
4199 */
4200 if (!ep->entry.next) {
4201 list_add_tail(&ep->entry, &timeout_list);
4202 kickit = 1;
4203 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004204 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004205 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004206 if (kickit)
4207 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004208}
4209
4210/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004211 * All the CM events are handled on a work queue to have a safe context.
4212 */
4213static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4214{
4215
4216 /*
4217 * Save dev in the skb->cb area.
4218 */
4219 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4220
4221 /*
4222 * Queue the skb and schedule the worker thread.
4223 */
4224 skb_queue_tail(&rxq, skb);
4225 queue_work(workq, &skb_work);
4226 return 0;
4227}
4228
4229static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4230{
4231 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4232
4233 if (rpl->status != CPL_ERR_NONE) {
4234 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4235 "for tid %u\n", rpl->status, GET_TID(rpl));
4236 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004237 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004238 return 0;
4239}
4240
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004241static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4242{
4243 struct cpl_fw6_msg *rpl = cplhdr(skb);
4244 struct c4iw_wr_wait *wr_waitp;
4245 int ret;
4246
4247 PDBG("%s type %u\n", __func__, rpl->type);
4248
4249 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004250 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004251 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004252 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004253 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004254 if (wr_waitp)
4255 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004256 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004257 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004258 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004259 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004260 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004261 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004262 default:
4263 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4264 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004265 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004266 break;
4267 }
4268 return 0;
4269}
4270
Steve Wise8da7e7a2011-06-14 20:59:27 +00004271static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4272{
4273 struct cpl_abort_req_rss *req = cplhdr(skb);
4274 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004275 unsigned int tid = GET_TID(req);
4276
Hariprasad S944661d2016-05-06 22:18:03 +05304277 ep = get_ep_from_tid(dev, tid);
4278 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004279 if (!ep) {
4280 printk(KERN_WARNING MOD
4281 "Abort on non-existent endpoint, tid %d\n", tid);
4282 kfree_skb(skb);
4283 return 0;
4284 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304285 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304286 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4287 __func__, ep->hwtid, req->status,
4288 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304289 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004290 }
4291 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4292 ep->com.state);
4293
Hariprasad S093108c2016-05-06 22:18:09 +05304294 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304295out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004296 sched(dev, skb);
4297 return 0;
4298}
4299
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004300/*
4301 * Most upcalls from the T4 Core go to sched() to
4302 * schedule the processing on a work queue.
4303 */
4304c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4305 [CPL_ACT_ESTABLISH] = sched,
4306 [CPL_ACT_OPEN_RPL] = sched,
4307 [CPL_RX_DATA] = sched,
4308 [CPL_ABORT_RPL_RSS] = sched,
4309 [CPL_ABORT_RPL] = sched,
4310 [CPL_PASS_OPEN_RPL] = sched,
4311 [CPL_CLOSE_LISTSRV_RPL] = sched,
4312 [CPL_PASS_ACCEPT_REQ] = sched,
4313 [CPL_PASS_ESTABLISH] = sched,
4314 [CPL_PEER_CLOSE] = sched,
4315 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004316 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004317 [CPL_RDMA_TERMINATE] = sched,
4318 [CPL_FW4_ACK] = sched,
4319 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004320 [CPL_FW6_MSG] = fw6_msg,
4321 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004322};
4323
Steve Wisecfdda9d2010-04-21 15:30:06 -07004324int __init c4iw_cm_init(void)
4325{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004326 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004327 skb_queue_head_init(&rxq);
4328
4329 workq = create_singlethread_workqueue("iw_cxgb4");
4330 if (!workq)
4331 return -ENOMEM;
4332
Steve Wisecfdda9d2010-04-21 15:30:06 -07004333 return 0;
4334}
4335
Steve Wise46c13762014-06-20 14:26:25 -05004336void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004337{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004338 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004339 flush_workqueue(workq);
4340 destroy_workqueue(workq);
4341}