blob: a08a74839c13d6771e7772454814ce8bb640ef81 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
Steve Wise9eccfe12014-03-26 17:08:09 -05002 * Copyright (c) 2009-2014 Chelsio, Inc. All rights reserved.
Steve Wisecfdda9d2010-04-21 15:30:06 -07003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#include <linux/module.h>
33#include <linux/list.h>
34#include <linux/workqueue.h>
35#include <linux/skbuff.h>
36#include <linux/timer.h>
37#include <linux/notifier.h>
38#include <linux/inetdevice.h>
39#include <linux/ip.h>
40#include <linux/tcp.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000041#include <linux/if_vlan.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070042
43#include <net/neighbour.h>
44#include <net/netevent.h>
45#include <net/route.h>
Vipul Pandya1cab7752012-12-10 09:30:55 +000046#include <net/tcp.h>
Vipul Pandya830662f2013-07-04 16:10:47 +053047#include <net/ip6_route.h>
48#include <net/addrconf.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070049
Steve Wise11b8e222014-05-16 12:42:46 -050050#include <rdma/ib_addr.h>
51
Varun Prakash85e42b02016-09-13 21:23:56 +053052#include <libcxgb_cm.h>
Steve Wisecfdda9d2010-04-21 15:30:06 -070053#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053054#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070055
56static char *states[] = {
57 "idle",
58 "listen",
59 "connecting",
60 "mpa_wait_req",
61 "mpa_req_sent",
62 "mpa_req_rcvd",
63 "mpa_rep_sent",
64 "fpdu_mode",
65 "aborting",
66 "closing",
67 "moribund",
68 "dead",
69 NULL,
70};
71
Vipul Pandya5be78ee2012-12-10 09:30:54 +000072static int nocong;
73module_param(nocong, int, 0644);
74MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
75
76static int enable_ecn;
77module_param(enable_ecn, int, 0644);
78MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
79
Steve Wiseb52fe092011-03-11 22:30:01 +000080static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000081module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000082MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000083
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053084uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070085module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053086MODULE_PARM_DESC(c4iw_max_read_depth,
87 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070088
Steve Wisecfdda9d2010-04-21 15:30:06 -070089static int enable_tcp_timestamps;
90module_param(enable_tcp_timestamps, int, 0644);
91MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
92
93static int enable_tcp_sack;
94module_param(enable_tcp_sack, int, 0644);
95MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
96
97static int enable_tcp_window_scaling = 1;
98module_param(enable_tcp_window_scaling, int, 0644);
99MODULE_PARM_DESC(enable_tcp_window_scaling,
100 "Enable tcp window scaling (default=1)");
101
102int c4iw_debug;
103module_param(c4iw_debug, int, 0644);
104MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
105
Steve Wisedf2d5132014-03-19 17:44:44 +0530106static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700107module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530108MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700109
110static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
111module_param(p2p_type, int, 0644);
112MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
113 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
114
115static int ep_timeout_secs = 60;
116module_param(ep_timeout_secs, int, 0644);
117MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
118 "in seconds (default=60)");
119
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530120static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700121module_param(mpa_rev, int, 0644);
122MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530123 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530124 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700125
126static int markers_enabled;
127module_param(markers_enabled, int, 0644);
128MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
129
130static int crc_enabled = 1;
131module_param(crc_enabled, int, 0644);
132MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
133
134static int rcv_win = 256 * 1024;
135module_param(rcv_win, int, 0644);
136MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
137
Steve Wise98ae68b2010-09-10 11:15:41 -0500138static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700139module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500140MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700143
144static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700145
146static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
147static void ep_timeout(unsigned long arg);
148static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530149static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700150
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700151static LIST_HEAD(timeout_list);
152static spinlock_t timeout_lock;
153
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530154static void deref_cm_id(struct c4iw_ep_common *epc)
155{
156 epc->cm_id->rem_ref(epc->cm_id);
157 epc->cm_id = NULL;
158 set_bit(CM_ID_DEREFED, &epc->history);
159}
160
161static void ref_cm_id(struct c4iw_ep_common *epc)
162{
163 set_bit(CM_ID_REFED, &epc->history);
164 epc->cm_id->add_ref(epc->cm_id);
165}
166
Vipul Pandya325abea2013-01-07 13:11:53 +0000167static void deref_qp(struct c4iw_ep *ep)
168{
169 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
170 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530171 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000172}
173
174static void ref_qp(struct c4iw_ep *ep)
175{
176 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530177 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000178 c4iw_qp_add_ref(&ep->com.qp->ibqp);
179}
180
Steve Wisecfdda9d2010-04-21 15:30:06 -0700181static void start_ep_timer(struct c4iw_ep *ep)
182{
183 PDBG("%s ep %p\n", __func__, ep);
184 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000185 pr_err("%s timer already started! ep %p\n",
186 __func__, ep);
187 return;
188 }
189 clear_bit(TIMEOUT, &ep->com.flags);
190 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700191 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
192 ep->timer.data = (unsigned long)ep;
193 ep->timer.function = ep_timeout;
194 add_timer(&ep->timer);
195}
196
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500197static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700198{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000199 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700200 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500201 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000202 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500203 return 0;
204 }
205 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700206}
207
208static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
209 struct l2t_entry *l2e)
210{
211 int error = 0;
212
213 if (c4iw_fatal_error(rdev)) {
214 kfree_skb(skb);
215 PDBG("%s - device in error state - dropping\n", __func__);
216 return -EIO;
217 }
218 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
219 if (error < 0)
220 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530221 else if (error == NET_XMIT_DROP)
222 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500223 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700224}
225
226int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
227{
228 int error = 0;
229
230 if (c4iw_fatal_error(rdev)) {
231 kfree_skb(skb);
232 PDBG("%s - device in error state - dropping\n", __func__);
233 return -EIO;
234 }
235 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
236 if (error < 0)
237 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500238 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700239}
240
241static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
242{
243 struct cpl_tid_release *req;
244
245 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
246 if (!skb)
247 return;
248 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
249 INIT_TP_WR(req, hwtid);
250 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
251 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
252 c4iw_ofld_send(rdev, skb);
253 return;
254}
255
256static void set_emss(struct c4iw_ep *ep, u16 opt)
257{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800258 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530259 ((AF_INET == ep->com.remote_addr.ss_family) ?
260 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
261 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700262 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800263 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530264 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700265 if (ep->emss < 128)
266 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530267 if (ep->emss & 7)
268 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800269 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
270 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700271 ep->mss, ep->emss);
272}
273
274static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
275{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700276 enum c4iw_ep_state state;
277
Steve Wise2f5b48c2010-09-10 11:15:36 -0500278 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700279 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500280 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700281 return state;
282}
283
284static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
285{
286 epc->state = new;
287}
288
289static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
290{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500291 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700292 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
293 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500294 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700295 return;
296}
297
Hariprasad S4a740832016-06-10 01:05:15 +0530298static int alloc_ep_skb_list(struct sk_buff_head *ep_skb_list, int size)
299{
300 struct sk_buff *skb;
301 unsigned int i;
302 size_t len;
303
304 len = roundup(sizeof(union cpl_wr_size), 16);
305 for (i = 0; i < size; i++) {
306 skb = alloc_skb(len, GFP_KERNEL);
307 if (!skb)
308 goto fail;
309 skb_queue_tail(ep_skb_list, skb);
310 }
311 return 0;
312fail:
313 skb_queue_purge(ep_skb_list);
314 return -ENOMEM;
315}
316
Steve Wisecfdda9d2010-04-21 15:30:06 -0700317static void *alloc_ep(int size, gfp_t gfp)
318{
319 struct c4iw_ep_common *epc;
320
321 epc = kzalloc(size, gfp);
322 if (epc) {
323 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500324 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500325 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700326 }
327 PDBG("%s alloc ep %p\n", __func__, epc);
328 return epc;
329}
330
Hariprasad S944661d2016-05-06 22:18:03 +0530331static void remove_ep_tid(struct c4iw_ep *ep)
332{
333 unsigned long flags;
334
335 spin_lock_irqsave(&ep->com.dev->lock, flags);
336 _remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid, 0);
337 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
338}
339
340static void insert_ep_tid(struct c4iw_ep *ep)
341{
342 unsigned long flags;
343
344 spin_lock_irqsave(&ep->com.dev->lock, flags);
345 _insert_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep, ep->hwtid, 0);
346 spin_unlock_irqrestore(&ep->com.dev->lock, flags);
347}
348
349/*
350 * Atomically lookup the ep ptr given the tid and grab a reference on the ep.
351 */
352static struct c4iw_ep *get_ep_from_tid(struct c4iw_dev *dev, unsigned int tid)
353{
354 struct c4iw_ep *ep;
355 unsigned long flags;
356
357 spin_lock_irqsave(&dev->lock, flags);
358 ep = idr_find(&dev->hwtid_idr, tid);
359 if (ep)
360 c4iw_get_ep(&ep->com);
361 spin_unlock_irqrestore(&dev->lock, flags);
362 return ep;
363}
364
Hariprasad Sf86fac72016-05-06 22:18:07 +0530365/*
366 * Atomically lookup the ep ptr given the stid and grab a reference on the ep.
367 */
368static struct c4iw_listen_ep *get_ep_from_stid(struct c4iw_dev *dev,
369 unsigned int stid)
370{
371 struct c4iw_listen_ep *ep;
372 unsigned long flags;
373
374 spin_lock_irqsave(&dev->lock, flags);
375 ep = idr_find(&dev->stid_idr, stid);
376 if (ep)
377 c4iw_get_ep(&ep->com);
378 spin_unlock_irqrestore(&dev->lock, flags);
379 return ep;
380}
381
Steve Wisecfdda9d2010-04-21 15:30:06 -0700382void _c4iw_free_ep(struct kref *kref)
383{
384 struct c4iw_ep *ep;
385
386 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530387 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000388 if (test_bit(QP_REFERENCED, &ep->com.flags))
389 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700390 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530391 if (ep->com.remote_addr.ss_family == AF_INET6) {
392 struct sockaddr_in6 *sin6 =
393 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600394 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530395
396 cxgb4_clip_release(
397 ep->com.dev->rdev.lldi.ports[0],
398 (const u32 *)&sin6->sin6_addr.s6_addr,
399 1);
400 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700401 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
402 dst_release(ep->dst);
403 cxgb4_l2t_release(ep->l2t);
Hariprasad Sc878b702016-05-06 22:18:04 +0530404 if (ep->mpa_skb)
405 kfree_skb(ep->mpa_skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700406 }
Hariprasad S4a740832016-06-10 01:05:15 +0530407 if (!skb_queue_empty(&ep->com.ep_skb_list))
408 skb_queue_purge(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700409 kfree(ep);
410}
411
412static void release_ep_resources(struct c4iw_ep *ep)
413{
414 set_bit(RELEASE_RESOURCES, &ep->com.flags);
Hariprasad S944661d2016-05-06 22:18:03 +0530415
416 /*
417 * If we have a hwtid, then remove it from the idr table
418 * so lookups will no longer find this endpoint. Otherwise
419 * we have a race where one thread finds the ep ptr just
420 * before the other thread is freeing the ep memory.
421 */
422 if (ep->hwtid != -1)
423 remove_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700424 c4iw_put_ep(&ep->com);
425}
426
Steve Wisecfdda9d2010-04-21 15:30:06 -0700427static int status2errno(int status)
428{
429 switch (status) {
430 case CPL_ERR_NONE:
431 return 0;
432 case CPL_ERR_CONN_RESET:
433 return -ECONNRESET;
434 case CPL_ERR_ARP_MISS:
435 return -EHOSTUNREACH;
436 case CPL_ERR_CONN_TIMEDOUT:
437 return -ETIMEDOUT;
438 case CPL_ERR_TCAM_FULL:
439 return -ENOMEM;
440 case CPL_ERR_CONN_EXIST:
441 return -EADDRINUSE;
442 default:
443 return -EIO;
444 }
445}
446
447/*
448 * Try and reuse skbs already allocated...
449 */
450static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
451{
452 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
453 skb_trim(skb, 0);
454 skb_get(skb);
455 skb_reset_transport_header(skb);
456 } else {
457 skb = alloc_skb(len, gfp);
458 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530459 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700460 return skb;
461}
462
Vipul Pandya830662f2013-07-04 16:10:47 +0530463static struct net_device *get_real_dev(struct net_device *egress_dev)
464{
Steve Wise11b8e222014-05-16 12:42:46 -0500465 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530466}
467
Steve Wisecfdda9d2010-04-21 15:30:06 -0700468static void arp_failure_discard(void *handle, struct sk_buff *skb)
469{
Hariprasad S9dec9002016-05-05 01:27:29 +0530470 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700471 kfree_skb(skb);
472}
473
Hariprasad S64bec742016-05-06 22:18:10 +0530474static void mpa_start_arp_failure(void *handle, struct sk_buff *skb)
475{
476 pr_err("ARP failure during MPA Negotiation - Closing Connection\n");
477}
478
Hariprasad S9dec9002016-05-05 01:27:29 +0530479enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530480 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530481 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530482 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530483};
484
485static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
486{
487 struct c4iw_ep *ep;
488
489 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
490 release_ep_resources(ep);
491 return 0;
492}
493
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530494static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
495{
496 struct c4iw_ep *ep;
497
498 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
499 c4iw_put_ep(&ep->parent_ep->com);
500 release_ep_resources(ep);
501 return 0;
502}
503
Hariprasad S9dec9002016-05-05 01:27:29 +0530504/*
505 * Fake up a special CPL opcode and call sched() so process_work() will call
506 * _put_ep_safe() in a safe context to free the ep resources. This is needed
507 * because ARP error handlers are called in an ATOMIC context, and
508 * _c4iw_free_ep() needs to block.
509 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530510static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
511 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530512{
513 struct cpl_act_establish *rpl = cplhdr(skb);
514
515 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530516 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530517
518 /*
519 * Save ep in the skb->cb area, after where sched() will save the dev
520 * ptr.
521 */
522 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
523 sched(ep->com.dev, skb);
524}
525
526/* Handle an ARP failure for an accept */
527static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
528{
529 struct c4iw_ep *ep = handle;
530
531 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
532 ep->hwtid);
533
534 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530535 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530536}
537
Steve Wisecfdda9d2010-04-21 15:30:06 -0700538/*
539 * Handle an ARP failure for an active open.
540 */
541static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
542{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530543 struct c4iw_ep *ep = handle;
544
Masanari Iidae3d132d2015-10-16 21:14:29 +0900545 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530546 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530547 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530548 if (ep->com.remote_addr.ss_family == AF_INET6) {
549 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600550 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530551 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
552 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
553 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530554 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
555 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530556 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700557}
558
559/*
560 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
561 * and send it along.
562 */
563static void abort_arp_failure(void *handle, struct sk_buff *skb)
564{
Hariprasad S761e19a2016-05-06 22:18:02 +0530565 int ret;
566 struct c4iw_ep *ep = handle;
567 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700568 struct cpl_abort_req *req = cplhdr(skb);
569
570 PDBG("%s rdev %p\n", __func__, rdev);
571 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530572 ret = c4iw_ofld_send(rdev, skb);
573 if (ret) {
574 __state_set(&ep->com, DEAD);
575 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
576 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577}
578
Hariprasad S4a740832016-06-10 01:05:15 +0530579static int send_flowc(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700580{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581 struct fw_flowc_wr *flowc;
Hariprasad S4a740832016-06-10 01:05:15 +0530582 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700583 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530584 u16 vlan = ep->l2t->vlan;
585 int nparams;
586
Hariprasad S4a740832016-06-10 01:05:15 +0530587 if (WARN_ON(!skb))
588 return -ENOMEM;
589
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530590 if (vlan == CPL_L2T_VLAN_NONE)
591 nparams = 8;
592 else
593 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700594
Hariprasad S4a740832016-06-10 01:05:15 +0530595 flowc = (struct fw_flowc_wr *)__skb_put(skb, FLOWC_LEN);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700596
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530597 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530598 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad S4a740832016-06-10 01:05:15 +0530599 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(FLOWC_LEN,
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530600 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700601
602 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530603 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530604 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700605 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
606 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
607 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
608 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
609 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
610 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
611 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
612 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
613 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
614 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
615 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530616 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700617 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
618 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530619 if (nparams == 9) {
620 u16 pri;
621
622 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
623 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
624 flowc->mnemval[8].val = cpu_to_be32(pri);
625 } else {
626 /* Pad WR to 16 byte boundary */
627 flowc->mnemval[8].mnemonic = 0;
628 flowc->mnemval[8].val = 0;
629 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700630 for (i = 0; i < 9; i++) {
631 flowc->mnemval[i].r4[0] = 0;
632 flowc->mnemval[i].r4[1] = 0;
633 flowc->mnemval[i].r4[2] = 0;
634 }
635
636 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530637 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700638}
639
Hariprasad S4a740832016-06-10 01:05:15 +0530640static int send_halfclose(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700641{
642 struct cpl_close_con_req *req;
Hariprasad S4a740832016-06-10 01:05:15 +0530643 struct sk_buff *skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700644 int wrlen = roundup(sizeof *req, 16);
645
646 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530647 if (WARN_ON(!skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700648 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530649
Steve Wisecfdda9d2010-04-21 15:30:06 -0700650 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
651 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
652 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
653 memset(req, 0, wrlen);
654 INIT_TP_WR(req, ep->hwtid);
655 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
656 ep->hwtid));
657 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
658}
659
Hariprasad S4a740832016-06-10 01:05:15 +0530660static int send_abort(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700661{
662 struct cpl_abort_req *req;
663 int wrlen = roundup(sizeof *req, 16);
Hariprasad S4a740832016-06-10 01:05:15 +0530664 struct sk_buff *req_skb = skb_dequeue(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700665
666 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Hariprasad S4a740832016-06-10 01:05:15 +0530667 if (WARN_ON(!req_skb))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668 return -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +0530669
670 set_wr_txq(req_skb, CPL_PRIORITY_DATA, ep->txq_idx);
671 t4_set_arp_err_handler(req_skb, ep, abort_arp_failure);
672 req = (struct cpl_abort_req *)skb_put(req_skb, wrlen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700673 memset(req, 0, wrlen);
674 INIT_TP_WR(req, ep->hwtid);
675 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
676 req->cmd = CPL_ABORT_SEND_RST;
Hariprasad S4a740832016-06-10 01:05:15 +0530677 return c4iw_l2t_send(&ep->com.dev->rdev, req_skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700678}
679
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530680static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530681 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530682{
Hariprasad S04524a42014-09-24 03:53:41 +0530683 unsigned short hdr_size = (ipv6 ?
684 sizeof(struct ipv6hdr) :
685 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530686 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530687 (use_ts ?
688 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530689 unsigned short data_size = mtu - hdr_size;
690
691 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
692}
693
Steve Wisecfdda9d2010-04-21 15:30:06 -0700694static int send_connect(struct c4iw_ep *ep)
695{
Hariprasad S963cab52015-09-23 17:19:27 +0530696 struct cpl_act_open_req *req = NULL;
697 struct cpl_t5_act_open_req *t5req = NULL;
698 struct cpl_t6_act_open_req *t6req = NULL;
699 struct cpl_act_open_req6 *req6 = NULL;
700 struct cpl_t5_act_open_req6 *t5req6 = NULL;
701 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700702 struct sk_buff *skb;
703 u64 opt0;
704 u32 opt2;
705 unsigned int mtu_idx;
706 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530707 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500708 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600709 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500710 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600711 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500712 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600713 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500714 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600715 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530716 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530717 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
718 u32 isn = (prandom_u32() & ~7UL) - 1;
719
720 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
721 case CHELSIO_T4:
722 sizev4 = sizeof(struct cpl_act_open_req);
723 sizev6 = sizeof(struct cpl_act_open_req6);
724 break;
725 case CHELSIO_T5:
726 sizev4 = sizeof(struct cpl_t5_act_open_req);
727 sizev6 = sizeof(struct cpl_t5_act_open_req6);
728 break;
729 case CHELSIO_T6:
730 sizev4 = sizeof(struct cpl_t6_act_open_req);
731 sizev6 = sizeof(struct cpl_t6_act_open_req6);
732 break;
733 default:
734 pr_err("T%d Chip is not supported\n",
735 CHELSIO_CHIP_VERSION(adapter_type));
736 return -EINVAL;
737 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530738
739 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
740 roundup(sizev4, 16) :
741 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700742
743 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
744
745 skb = get_skb(NULL, wrlen, GFP_KERNEL);
746 if (!skb) {
747 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
748 __func__);
749 return -ENOMEM;
750 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000751 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700752
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530753 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530754 enable_tcp_timestamps,
755 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530757
758 /*
759 * Specify the largest window that will fit in opt0. The
760 * remainder will be specified in the rx_data_ack.
761 */
762 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800763 if (win > RCV_BUFSIZ_M)
764 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530765
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800766 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800767 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800768 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800769 WND_SCALE_V(wscale) |
770 MSS_IDX_V(mtu_idx) |
771 L2T_IDX_V(ep->l2t->idx) |
772 TX_CHAN_V(ep->tx_chan) |
773 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530774 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800775 ULP_MODE_V(ULP_MODE_TCPDDP) |
776 RCV_BUFSIZ_V(win);
777 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800778 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800779 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700780 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800781 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700782 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800783 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700784 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800785 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530786 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
787 if (peer2peer)
788 isn += 4;
789
Anish Bhattd7990b02014-11-12 17:15:57 -0800790 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530791 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530792 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500793 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530794
795 if (ep->com.remote_addr.ss_family == AF_INET6)
796 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
797 (const u32 *)&la6->sin6_addr.s6_addr, 1);
798
Hariprasad S5dab6d32014-06-23 19:12:36 +0530799 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700800
Hariprasad S963cab52015-09-23 17:19:27 +0530801 if (ep->com.remote_addr.ss_family == AF_INET) {
802 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
803 case CHELSIO_T4:
804 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530805 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530806 break;
807 case CHELSIO_T5:
808 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
809 wrlen);
810 INIT_TP_WR(t5req, 0);
811 req = (struct cpl_act_open_req *)t5req;
812 break;
813 case CHELSIO_T6:
814 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
815 wrlen);
816 INIT_TP_WR(t6req, 0);
817 req = (struct cpl_act_open_req *)t6req;
818 t5req = (struct cpl_t5_act_open_req *)t6req;
819 break;
820 default:
821 pr_err("T%d Chip is not supported\n",
822 CHELSIO_CHIP_VERSION(adapter_type));
823 ret = -EINVAL;
824 goto clip_release;
825 }
826
827 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
828 ((ep->rss_qid<<14) | ep->atid)));
829 req->local_port = la->sin_port;
830 req->peer_port = ra->sin_port;
831 req->local_ip = la->sin_addr.s_addr;
832 req->peer_ip = ra->sin_addr.s_addr;
833 req->opt0 = cpu_to_be64(opt0);
834
835 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530836 req->params = cpu_to_be32(cxgb4_select_ntuple(
837 ep->com.dev->rdev.lldi.ports[0],
838 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530839 req->opt2 = cpu_to_be32(opt2);
840 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530841 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
842 cxgb4_select_ntuple(
843 ep->com.dev->rdev.lldi.ports[0],
844 ep->l2t)));
845 t5req->rsvd = cpu_to_be32(isn);
846 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
847 t5req->opt2 = cpu_to_be32(opt2);
848 }
849 } else {
850 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
851 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530852 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530853 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530854 break;
855 case CHELSIO_T5:
856 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
857 wrlen);
858 INIT_TP_WR(t5req6, 0);
859 req6 = (struct cpl_act_open_req6 *)t5req6;
860 break;
861 case CHELSIO_T6:
862 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
863 wrlen);
864 INIT_TP_WR(t6req6, 0);
865 req6 = (struct cpl_act_open_req6 *)t6req6;
866 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
867 break;
868 default:
869 pr_err("T%d Chip is not supported\n",
870 CHELSIO_CHIP_VERSION(adapter_type));
871 ret = -EINVAL;
872 goto clip_release;
873 }
874
875 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
876 ((ep->rss_qid<<14)|ep->atid)));
877 req6->local_port = la6->sin6_port;
878 req6->peer_port = ra6->sin6_port;
879 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
880 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
881 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
882 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
883 req6->opt0 = cpu_to_be64(opt0);
884
885 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530886 req6->params = cpu_to_be32(cxgb4_select_ntuple(
887 ep->com.dev->rdev.lldi.ports[0],
888 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530889 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530890 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530891 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
892 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530893 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530894 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530895 t5req6->rsvd = cpu_to_be32(isn);
896 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
897 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530898 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000899 }
900
Vipul Pandya793dad92012-12-10 09:30:56 +0000901 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530902 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530903clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530904 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
905 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
906 (const u32 *)&la6->sin6_addr.s6_addr, 1);
907 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700908}
909
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530910static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
911 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700912{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530913 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700914 struct fw_ofld_tx_data_wr *req;
915 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530916 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700917
918 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
919
920 BUG_ON(skb_cloned(skb));
921
922 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530923 if (mpa_rev_to_use == 2)
924 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700925 wrlen = roundup(mpalen + sizeof *req, 16);
926 skb = get_skb(skb, wrlen, GFP_KERNEL);
927 if (!skb) {
928 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530929 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700930 }
931 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
932
933 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
934 memset(req, 0, wrlen);
935 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530936 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
937 FW_WR_COMPL_F |
938 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700939 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530940 FW_WR_FLOWID_V(ep->hwtid) |
941 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700942 req->plen = cpu_to_be32(mpalen);
943 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530944 FW_OFLD_TX_DATA_WR_FLUSH_F |
945 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700946
947 mpa = (struct mpa_message *)(req + 1);
948 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +0530949
950 mpa->flags = 0;
951 if (crc_enabled)
952 mpa->flags |= MPA_CRC;
953 if (markers_enabled) {
954 mpa->flags |= MPA_MARKERS;
955 ep->mpa_attr.recv_marker_enabled = 1;
956 } else {
957 ep->mpa_attr.recv_marker_enabled = 0;
958 }
959 if (mpa_rev_to_use == 2)
960 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
961
Steve Wisecfdda9d2010-04-21 15:30:06 -0700962 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530963 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530964 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530965 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530966 ep->retry_with_mpa_v1 = 0;
967 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700968
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530969 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700970 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
971 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530972 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
973 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530974 mpa_v2_params.ird = htons((u16)ep->ird);
975 mpa_v2_params.ord = htons((u16)ep->ord);
976
977 if (peer2peer) {
978 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
979 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
980 mpa_v2_params.ord |=
981 htons(MPA_V2_RDMA_WRITE_RTR);
982 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
983 mpa_v2_params.ord |=
984 htons(MPA_V2_RDMA_READ_RTR);
985 }
986 memcpy(mpa->private_data, &mpa_v2_params,
987 sizeof(struct mpa_v2_conn_params));
988
989 if (ep->plen)
990 memcpy(mpa->private_data +
991 sizeof(struct mpa_v2_conn_params),
992 ep->mpa_pkt + sizeof(*mpa), ep->plen);
993 } else
994 if (ep->plen)
995 memcpy(mpa->private_data,
996 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700997
998 /*
999 * Reference the mpa skb. This ensures the data area
1000 * will remain in memory until the hw acks the tx.
1001 * Function fw4_ack() will deref it.
1002 */
1003 skb_get(skb);
1004 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
1005 BUG_ON(ep->mpa_skb);
1006 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301007 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1008 if (ret)
1009 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001010 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05301011 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001012 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +05301013 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301014 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001015}
1016
1017static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
1018{
1019 int mpalen, wrlen;
1020 struct fw_ofld_tx_data_wr *req;
1021 struct mpa_message *mpa;
1022 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301023 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001024
1025 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1026
1027 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301028 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1029 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001030 wrlen = roundup(mpalen + sizeof *req, 16);
1031
1032 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1033 if (!skb) {
1034 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1035 return -ENOMEM;
1036 }
1037 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1038
1039 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1040 memset(req, 0, wrlen);
1041 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301042 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1043 FW_WR_COMPL_F |
1044 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001045 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301046 FW_WR_FLOWID_V(ep->hwtid) |
1047 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001048 req->plen = cpu_to_be32(mpalen);
1049 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301050 FW_OFLD_TX_DATA_WR_FLUSH_F |
1051 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052
1053 mpa = (struct mpa_message *)(req + 1);
1054 memset(mpa, 0, sizeof(*mpa));
1055 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1056 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001057 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001058 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301059
1060 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1061 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001062 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1063 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301064 mpa_v2_params.ird = htons(((u16)ep->ird) |
1065 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1066 0));
1067 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1068 (p2p_type ==
1069 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1070 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1071 FW_RI_INIT_P2PTYPE_READ_REQ ?
1072 MPA_V2_RDMA_READ_RTR : 0) : 0));
1073 memcpy(mpa->private_data, &mpa_v2_params,
1074 sizeof(struct mpa_v2_conn_params));
1075
1076 if (ep->plen)
1077 memcpy(mpa->private_data +
1078 sizeof(struct mpa_v2_conn_params), pdata, plen);
1079 } else
1080 if (plen)
1081 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001082
1083 /*
1084 * Reference the mpa skb again. This ensures the data area
1085 * will remain in memory until the hw acks the tx.
1086 * Function fw4_ack() will deref it.
1087 */
1088 skb_get(skb);
1089 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S64bec742016-05-06 22:18:10 +05301090 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001091 BUG_ON(ep->mpa_skb);
1092 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301093 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1095}
1096
1097static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1098{
1099 int mpalen, wrlen;
1100 struct fw_ofld_tx_data_wr *req;
1101 struct mpa_message *mpa;
1102 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301103 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001104
1105 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1106
1107 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301108 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1109 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001110 wrlen = roundup(mpalen + sizeof *req, 16);
1111
1112 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1113 if (!skb) {
1114 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1115 return -ENOMEM;
1116 }
1117 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1118
1119 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1120 memset(req, 0, wrlen);
1121 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301122 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1123 FW_WR_COMPL_F |
1124 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001125 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301126 FW_WR_FLOWID_V(ep->hwtid) |
1127 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001128 req->plen = cpu_to_be32(mpalen);
1129 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301130 FW_OFLD_TX_DATA_WR_FLUSH_F |
1131 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001132
1133 mpa = (struct mpa_message *)(req + 1);
1134 memset(mpa, 0, sizeof(*mpa));
1135 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
Hariprasad S3d4e7992016-06-10 01:05:11 +05301136 mpa->flags = 0;
1137 if (ep->mpa_attr.crc_enabled)
1138 mpa->flags |= MPA_CRC;
1139 if (ep->mpa_attr.recv_marker_enabled)
1140 mpa->flags |= MPA_MARKERS;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301141 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001142 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301143
1144 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1145 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001146 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1147 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301148 mpa_v2_params.ird = htons((u16)ep->ird);
1149 mpa_v2_params.ord = htons((u16)ep->ord);
1150 if (peer2peer && (ep->mpa_attr.p2p_type !=
1151 FW_RI_INIT_P2PTYPE_DISABLED)) {
1152 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1153
1154 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1155 mpa_v2_params.ord |=
1156 htons(MPA_V2_RDMA_WRITE_RTR);
1157 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1158 mpa_v2_params.ord |=
1159 htons(MPA_V2_RDMA_READ_RTR);
1160 }
1161
1162 memcpy(mpa->private_data, &mpa_v2_params,
1163 sizeof(struct mpa_v2_conn_params));
1164
1165 if (ep->plen)
1166 memcpy(mpa->private_data +
1167 sizeof(struct mpa_v2_conn_params), pdata, plen);
1168 } else
1169 if (plen)
1170 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171
1172 /*
1173 * Reference the mpa skb. This ensures the data area
1174 * will remain in memory until the hw acks the tx.
1175 * Function fw4_ack() will deref it.
1176 */
1177 skb_get(skb);
Hariprasad S64bec742016-05-06 22:18:10 +05301178 t4_set_arp_err_handler(skb, NULL, mpa_start_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301180 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301181 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001182 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1183}
1184
1185static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1186{
1187 struct c4iw_ep *ep;
1188 struct cpl_act_establish *req = cplhdr(skb);
1189 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001190 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001191 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301192 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193
1194 ep = lookup_atid(t, atid);
1195
1196 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1197 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1198
Steve Wisea7db89e2014-03-21 20:40:35 +05301199 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001200 dst_confirm(ep->dst);
1201
1202 /* setup the hwtid for this connection */
1203 ep->hwtid = tid;
1204 cxgb4_insert_tid(t, ep, tid);
Hariprasad S944661d2016-05-06 22:18:03 +05301205 insert_ep_tid(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001206
1207 ep->snd_seq = be32_to_cpu(req->snd_isn);
1208 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1209
1210 set_emss(ep, ntohs(req->tcp_opt));
1211
1212 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001213 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001214 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001215 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001216
1217 /* start MPA negotiation */
Hariprasad S4a740832016-06-10 01:05:15 +05301218 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05301219 if (ret)
1220 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301221 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301222 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301223 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301224 ret = send_mpa_req(ep, skb, mpa_rev);
1225 if (ret)
1226 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301227 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001228 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301229err:
1230 mutex_unlock(&ep->com.mutex);
1231 connect_reply_upcall(ep, -ENOMEM);
1232 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1233 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001234}
1235
Steve Wisebe13b2d2014-03-21 20:40:33 +05301236static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001237{
1238 struct iw_cm_event event;
1239
1240 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1241 memset(&event, 0, sizeof(event));
1242 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301243 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001244 if (ep->com.cm_id) {
1245 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1246 ep, ep->com.cm_id, ep->hwtid);
1247 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301248 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001249 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001250 }
1251}
1252
Steve Wisecfdda9d2010-04-21 15:30:06 -07001253static void peer_close_upcall(struct c4iw_ep *ep)
1254{
1255 struct iw_cm_event event;
1256
1257 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1258 memset(&event, 0, sizeof(event));
1259 event.event = IW_CM_EVENT_DISCONNECT;
1260 if (ep->com.cm_id) {
1261 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1262 ep, ep->com.cm_id, ep->hwtid);
1263 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001264 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001265 }
1266}
1267
1268static void peer_abort_upcall(struct c4iw_ep *ep)
1269{
1270 struct iw_cm_event event;
1271
1272 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1273 memset(&event, 0, sizeof(event));
1274 event.event = IW_CM_EVENT_CLOSE;
1275 event.status = -ECONNRESET;
1276 if (ep->com.cm_id) {
1277 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1278 ep->com.cm_id, ep->hwtid);
1279 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301280 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001281 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001282 }
1283}
1284
1285static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1286{
1287 struct iw_cm_event event;
1288
1289 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1290 memset(&event, 0, sizeof(event));
1291 event.event = IW_CM_EVENT_CONNECT_REPLY;
1292 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301293 memcpy(&event.local_addr, &ep->com.local_addr,
1294 sizeof(ep->com.local_addr));
1295 memcpy(&event.remote_addr, &ep->com.remote_addr,
1296 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001297
1298 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301299 if (!ep->tried_with_mpa_v1) {
1300 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301301 event.ord = ep->ird;
1302 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301303 event.private_data_len = ep->plen -
1304 sizeof(struct mpa_v2_conn_params);
1305 event.private_data = ep->mpa_pkt +
1306 sizeof(struct mpa_message) +
1307 sizeof(struct mpa_v2_conn_params);
1308 } else {
1309 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301310 event.ord = cur_max_read_depth(ep->com.dev);
1311 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301312 event.private_data_len = ep->plen;
1313 event.private_data = ep->mpa_pkt +
1314 sizeof(struct mpa_message);
1315 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001316 }
Roland Dreier85963e42010-07-19 13:13:09 -07001317
1318 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1319 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001320 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001321 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1322
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301323 if (status < 0)
1324 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001325}
1326
Steve Wisebe13b2d2014-03-21 20:40:33 +05301327static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001328{
1329 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301330 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001331
1332 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1333 memset(&event, 0, sizeof(event));
1334 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301335 memcpy(&event.local_addr, &ep->com.local_addr,
1336 sizeof(ep->com.local_addr));
1337 memcpy(&event.remote_addr, &ep->com.remote_addr,
1338 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001339 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301340 if (!ep->tried_with_mpa_v1) {
1341 /* this means MPA_v2 is used */
1342 event.ord = ep->ord;
1343 event.ird = ep->ird;
1344 event.private_data_len = ep->plen -
1345 sizeof(struct mpa_v2_conn_params);
1346 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1347 sizeof(struct mpa_v2_conn_params);
1348 } else {
1349 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301350 event.ord = cur_max_read_depth(ep->com.dev);
1351 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301352 event.private_data_len = ep->plen;
1353 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1354 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301355 c4iw_get_ep(&ep->com);
1356 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1357 &event);
1358 if (ret)
1359 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001360 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001361 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301362 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001363}
1364
1365static void established_upcall(struct c4iw_ep *ep)
1366{
1367 struct iw_cm_event event;
1368
1369 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1370 memset(&event, 0, sizeof(event));
1371 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301372 event.ird = ep->ord;
1373 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001374 if (ep->com.cm_id) {
1375 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1376 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001377 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001378 }
1379}
1380
1381static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1382{
1383 struct cpl_rx_data_ack *req;
1384 struct sk_buff *skb;
1385 int wrlen = roundup(sizeof *req, 16);
1386
1387 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1388 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1389 if (!skb) {
1390 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1391 return 0;
1392 }
1393
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301394 /*
1395 * If we couldn't specify the entire rcv window at connection setup
1396 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1397 * then add the overage in to the credits returned.
1398 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001399 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1400 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301401
Steve Wisecfdda9d2010-04-21 15:30:06 -07001402 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1403 memset(req, 0, wrlen);
1404 INIT_TP_WR(req, ep->hwtid);
1405 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1406 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001407 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301408 RX_DACK_CHANGE_F |
1409 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001410 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001411 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1412 return credits;
1413}
1414
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301415#define RELAXED_IRD_NEGOTIATION 1
1416
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301417/*
1418 * process_mpa_reply - process streaming mode MPA reply
1419 *
1420 * Returns:
1421 *
1422 * 0 upon success indicating a connect request was delivered to the ULP
1423 * or the mpa request is incomplete but valid so far.
1424 *
1425 * 1 if a failure requires the caller to close the connection.
1426 *
1427 * 2 if a failure requires the caller to abort the connection.
1428 */
Steve Wisecc18b932014-04-24 14:31:53 -05001429static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001430{
1431 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301432 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001433 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301434 u16 resp_ird, resp_ord;
1435 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001436 struct c4iw_qp_attributes attrs;
1437 enum c4iw_qp_attr_mask mask;
1438 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001439 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001440
1441 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1442
1443 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001444 * If we get more than the supported amount of private data
1445 * then we must fail this connection.
1446 */
1447 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1448 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301449 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001450 }
1451
1452 /*
1453 * copy the new data into our accumulation buffer.
1454 */
1455 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1456 skb->len);
1457 ep->mpa_pkt_len += skb->len;
1458
1459 /*
1460 * if we don't even have the mpa message, then bail.
1461 */
1462 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001463 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001464 mpa = (struct mpa_message *) ep->mpa_pkt;
1465
1466 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301467 if (mpa->revision > mpa_rev) {
1468 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1469 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001470 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301471 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001472 }
1473 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1474 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301475 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001476 }
1477
1478 plen = ntohs(mpa->private_data_size);
1479
1480 /*
1481 * Fail if there's too much private data.
1482 */
1483 if (plen > MPA_MAX_PRIVATE_DATA) {
1484 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301485 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001486 }
1487
1488 /*
1489 * If plen does not account for pkt size
1490 */
1491 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1492 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301493 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001494 }
1495
1496 ep->plen = (u8) plen;
1497
1498 /*
1499 * If we don't have all the pdata yet, then bail.
1500 * We'll continue process when more data arrives.
1501 */
1502 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001503 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001504
1505 if (mpa->flags & MPA_REJECT) {
1506 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301507 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001508 }
1509
1510 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301511 * Stop mpa timer. If it expired, then
1512 * we ignore the MPA reply. process_timeout()
1513 * will abort the connection.
1514 */
1515 if (stop_ep_timer(ep))
1516 return 0;
1517
1518 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001519 * If we get here we have accumulated the entire mpa
1520 * start reply message including private data. And
1521 * the MPA header is valid.
1522 */
Steve Wisec529fb52014-03-21 20:40:37 +05301523 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001524 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001525 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301526 ep->mpa_attr.version = mpa->revision;
1527 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1528
1529 if (mpa->revision == 2) {
1530 ep->mpa_attr.enhanced_rdma_conn =
1531 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1532 if (ep->mpa_attr.enhanced_rdma_conn) {
1533 mpa_v2_params = (struct mpa_v2_conn_params *)
1534 (ep->mpa_pkt + sizeof(*mpa));
1535 resp_ird = ntohs(mpa_v2_params->ird) &
1536 MPA_V2_IRD_ORD_MASK;
1537 resp_ord = ntohs(mpa_v2_params->ord) &
1538 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301539 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1540 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301541
1542 /*
1543 * This is a double-check. Ideally, below checks are
1544 * not required since ird/ord stuff has been taken
1545 * care of in c4iw_accept_cr
1546 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301547 if (ep->ird < resp_ord) {
1548 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1549 ep->com.dev->rdev.lldi.max_ordird_qp)
1550 ep->ird = resp_ord;
1551 else
1552 insuff_ird = 1;
1553 } else if (ep->ird > resp_ord) {
1554 ep->ird = resp_ord;
1555 }
1556 if (ep->ord > resp_ird) {
1557 if (RELAXED_IRD_NEGOTIATION)
1558 ep->ord = resp_ird;
1559 else
1560 insuff_ird = 1;
1561 }
1562 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301563 err = -ENOMEM;
1564 ep->ird = resp_ord;
1565 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301566 }
1567
1568 if (ntohs(mpa_v2_params->ird) &
1569 MPA_V2_PEER2PEER_MODEL) {
1570 if (ntohs(mpa_v2_params->ord) &
1571 MPA_V2_RDMA_WRITE_RTR)
1572 ep->mpa_attr.p2p_type =
1573 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1574 else if (ntohs(mpa_v2_params->ord) &
1575 MPA_V2_RDMA_READ_RTR)
1576 ep->mpa_attr.p2p_type =
1577 FW_RI_INIT_P2PTYPE_READ_REQ;
1578 }
1579 }
1580 } else if (mpa->revision == 1)
1581 if (peer2peer)
1582 ep->mpa_attr.p2p_type = p2p_type;
1583
Steve Wisecfdda9d2010-04-21 15:30:06 -07001584 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301585 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1586 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1587 ep->mpa_attr.recv_marker_enabled,
1588 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1589 ep->mpa_attr.p2p_type, p2p_type);
1590
1591 /*
1592 * If responder's RTR does not match with that of initiator, assign
1593 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1594 * generated when moving QP to RTS state.
1595 * A TERM message will be sent after QP has moved to RTS state
1596 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001597 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301598 (ep->mpa_attr.p2p_type != p2p_type)) {
1599 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1600 rtr_mismatch = 1;
1601 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001602
1603 attrs.mpa_attr = ep->mpa_attr;
1604 attrs.max_ird = ep->ird;
1605 attrs.max_ord = ep->ord;
1606 attrs.llp_stream_handle = ep;
1607 attrs.next_state = C4IW_QP_STATE_RTS;
1608
1609 mask = C4IW_QP_ATTR_NEXT_STATE |
1610 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1611 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1612
1613 /* bind QP and TID with INIT_WR */
1614 err = c4iw_modify_qp(ep->com.qp->rhp,
1615 ep->com.qp, mask, &attrs, 1);
1616 if (err)
1617 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301618
1619 /*
1620 * If responder's RTR requirement did not match with what initiator
1621 * supports, generate TERM message
1622 */
1623 if (rtr_mismatch) {
1624 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1625 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1626 attrs.ecode = MPA_NOMATCH_RTR;
1627 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001628 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301629 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001630 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301631 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001632 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301633 goto out;
1634 }
1635
1636 /*
1637 * Generate TERM if initiator IRD is not sufficient for responder
1638 * provided ORD. Currently, we do the same behaviour even when
1639 * responder provided IRD is also not sufficient as regards to
1640 * initiator ORD.
1641 */
1642 if (insuff_ird) {
1643 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1644 __func__);
1645 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1646 attrs.ecode = MPA_INSUFF_IRD;
1647 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001648 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301649 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001650 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301651 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001652 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301653 goto out;
1654 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001655 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301656err_stop_timer:
1657 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001658err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301659 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001660out:
1661 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001662 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001663}
1664
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301665/*
1666 * process_mpa_request - process streaming mode MPA request
1667 *
1668 * Returns:
1669 *
1670 * 0 upon success indicating a connect request was delivered to the ULP
1671 * or the mpa request is incomplete but valid so far.
1672 *
1673 * 1 if a failure requires the caller to close the connection.
1674 *
1675 * 2 if a failure requires the caller to abort the connection.
1676 */
1677static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678{
1679 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301680 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001681 u16 plen;
1682
1683 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1684
Steve Wisecfdda9d2010-04-21 15:30:06 -07001685 /*
1686 * If we get more than the supported amount of private data
1687 * then we must fail this connection.
1688 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301689 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1690 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001691
1692 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1693
1694 /*
1695 * Copy the new data into our accumulation buffer.
1696 */
1697 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1698 skb->len);
1699 ep->mpa_pkt_len += skb->len;
1700
1701 /*
1702 * If we don't even have the mpa message, then bail.
1703 * We'll continue process when more data arrives.
1704 */
1705 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301706 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001707
1708 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709 mpa = (struct mpa_message *) ep->mpa_pkt;
1710
1711 /*
1712 * Validate MPA Header.
1713 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301714 if (mpa->revision > mpa_rev) {
1715 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1716 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301717 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001718 }
1719
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301720 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1721 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001722
1723 plen = ntohs(mpa->private_data_size);
1724
1725 /*
1726 * Fail if there's too much private data.
1727 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301728 if (plen > MPA_MAX_PRIVATE_DATA)
1729 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001730
1731 /*
1732 * If plen does not account for pkt size
1733 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301734 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1735 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001736 ep->plen = (u8) plen;
1737
1738 /*
1739 * If we don't have all the pdata yet, then bail.
1740 */
1741 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301742 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001743
1744 /*
1745 * If we get here we have accumulated the entire mpa
1746 * start reply message including private data.
1747 */
1748 ep->mpa_attr.initiator = 0;
1749 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1750 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1751 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301752 ep->mpa_attr.version = mpa->revision;
1753 if (mpa->revision == 1)
1754 ep->tried_with_mpa_v1 = 1;
1755 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1756
1757 if (mpa->revision == 2) {
1758 ep->mpa_attr.enhanced_rdma_conn =
1759 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1760 if (ep->mpa_attr.enhanced_rdma_conn) {
1761 mpa_v2_params = (struct mpa_v2_conn_params *)
1762 (ep->mpa_pkt + sizeof(*mpa));
1763 ep->ird = ntohs(mpa_v2_params->ird) &
1764 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001765 ep->ird = min_t(u32, ep->ird,
1766 cur_max_read_depth(ep->com.dev));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301767 ep->ord = ntohs(mpa_v2_params->ord) &
1768 MPA_V2_IRD_ORD_MASK;
Steve Wise7f446ab2016-08-19 07:29:07 -07001769 ep->ord = min_t(u32, ep->ord,
1770 cur_max_read_depth(ep->com.dev));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301771 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1772 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301773 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1774 if (peer2peer) {
1775 if (ntohs(mpa_v2_params->ord) &
1776 MPA_V2_RDMA_WRITE_RTR)
1777 ep->mpa_attr.p2p_type =
1778 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1779 else if (ntohs(mpa_v2_params->ord) &
1780 MPA_V2_RDMA_READ_RTR)
1781 ep->mpa_attr.p2p_type =
1782 FW_RI_INIT_P2PTYPE_READ_REQ;
1783 }
1784 }
1785 } else if (mpa->revision == 1)
1786 if (peer2peer)
1787 ep->mpa_attr.p2p_type = p2p_type;
1788
Steve Wisecfdda9d2010-04-21 15:30:06 -07001789 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1790 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1791 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1792 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1793 ep->mpa_attr.p2p_type);
1794
Hariprasad Se4b76a22016-05-06 22:17:59 +05301795 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796
Hariprasad Se4b76a22016-05-06 22:17:59 +05301797 /* drive upcall */
1798 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1799 if (ep->parent_ep->com.state != DEAD) {
1800 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301801 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301802 } else {
1803 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301804 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301805 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301806 return 0;
1807
1808err_unlock_parent:
1809 mutex_unlock(&ep->parent_ep->com.mutex);
1810 goto err_out;
1811err_stop_timer:
1812 (void)stop_ep_timer(ep);
1813err_out:
1814 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815}
1816
1817static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1818{
1819 struct c4iw_ep *ep;
1820 struct cpl_rx_data *hdr = cplhdr(skb);
1821 unsigned int dlen = ntohs(hdr->len);
1822 unsigned int tid = GET_TID(hdr);
Vipul Pandya793dad92012-12-10 09:30:56 +00001823 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001824 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001825
Hariprasad S944661d2016-05-06 22:18:03 +05301826 ep = get_ep_from_tid(dev, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301827 if (!ep)
1828 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1830 skb_pull(skb, sizeof(*hdr));
1831 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301832 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001833
Steve Wisecfdda9d2010-04-21 15:30:06 -07001834 /* update RX credits */
1835 update_rx_credits(ep, dlen);
1836
Steve Wisec529fb52014-03-21 20:40:37 +05301837 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001838 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001839 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001840 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001841 break;
1842 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001843 ep->rcv_seq += dlen;
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301844 disconnect = process_mpa_request(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001845 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001846 case FPDU_MODE: {
1847 struct c4iw_qp_attributes attrs;
1848 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001849 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001850 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001851 " qpid %u ep %p state %d tid %u status %d\n",
1852 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301853 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301854 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001855 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001856 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1857 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001858 break;
1859 }
Vipul Pandya15579672013-01-07 13:11:52 +00001860 default:
1861 break;
1862 }
Steve Wisec529fb52014-03-21 20:40:37 +05301863 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001864 if (disconnect)
Hariprasad S4a4dd8d2016-05-06 22:18:08 +05301865 c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05301866 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001867 return 0;
1868}
1869
1870static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1871{
1872 struct c4iw_ep *ep;
1873 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001874 int release = 0;
1875 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001876
Hariprasad S944661d2016-05-06 22:18:03 +05301877 ep = get_ep_from_tid(dev, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301878 if (!ep) {
1879 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1880 return 0;
1881 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001882 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001883 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001884 switch (ep->com.state) {
1885 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001886 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001887 __state_set(&ep->com, DEAD);
1888 release = 1;
1889 break;
1890 default:
1891 printk(KERN_ERR "%s ep %p state %d\n",
1892 __func__, ep, ep->com.state);
1893 break;
1894 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001895 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001896
1897 if (release)
1898 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05301899 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001900 return 0;
1901}
1902
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301903static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001904{
1905 struct sk_buff *skb;
1906 struct fw_ofld_connection_wr *req;
1907 unsigned int mtu_idx;
1908 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301909 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301910 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001911
1912 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1913 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1914 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001915 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301916 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301917 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1918 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001919 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001920 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301921 req->le.lport = sin->sin_port;
1922 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001923 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301924 req->le.pport = sin->sin_port;
1925 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001926 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301927 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1928 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001929 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301930 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001931 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001932 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301933 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301934 enable_tcp_timestamps,
1935 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001936 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301937
1938 /*
1939 * Specify the largest window that will fit in opt0. The
1940 * remainder will be specified in the rx_data_ack.
1941 */
1942 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001943 if (win > RCV_BUFSIZ_M)
1944 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301945
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001946 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1947 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001948 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001949 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001950 WND_SCALE_V(wscale) |
1951 MSS_IDX_V(mtu_idx) |
1952 L2T_IDX_V(ep->l2t->idx) |
1953 TX_CHAN_V(ep->tx_chan) |
1954 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301955 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001956 ULP_MODE_V(ULP_MODE_TCPDDP) |
1957 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001958 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1959 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001960 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001961 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001962 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001963 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001964 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001965 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001966 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001967 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001968 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1969 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1970 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001971 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1972 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301973 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001974}
1975
Steve Wisecfdda9d2010-04-21 15:30:06 -07001976/*
Hariprasad S4c72efe2016-06-10 01:05:14 +05301977 * Some of the error codes above implicitly indicate that there is no TID
1978 * allocated with the result of an ACT_OPEN. We use this predicate to make
1979 * that explicit.
Steve Wisecfdda9d2010-04-21 15:30:06 -07001980 */
1981static inline int act_open_has_tid(int status)
1982{
Hariprasad S4c72efe2016-06-10 01:05:14 +05301983 return (status != CPL_ERR_TCAM_PARITY &&
1984 status != CPL_ERR_TCAM_MISS &&
1985 status != CPL_ERR_TCAM_FULL &&
1986 status != CPL_ERR_CONN_EXIST_SYNRECV &&
1987 status != CPL_ERR_CONN_EXIST);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001988}
1989
Steve Wise7a2cea22014-03-14 21:52:07 +05301990/* Returns whether a CPL status conveys negative advice.
1991 */
1992static int is_neg_adv(unsigned int status)
1993{
1994 return status == CPL_ERR_RTX_NEG_ADVICE ||
1995 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1996 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1997}
1998
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301999static char *neg_adv_str(unsigned int status)
2000{
2001 switch (status) {
2002 case CPL_ERR_RTX_NEG_ADVICE:
2003 return "Retransmit timeout";
2004 case CPL_ERR_PERSIST_NEG_ADVICE:
2005 return "Persist timeout";
2006 case CPL_ERR_KEEPALV_NEG_ADVICE:
2007 return "Keepalive timeout";
2008 default:
2009 return "Unknown";
2010 }
2011}
2012
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302013static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
2014{
2015 ep->snd_win = snd_win;
2016 ep->rcv_win = rcv_win;
2017 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
2018}
2019
Vipul Pandya793dad92012-12-10 09:30:56 +00002020#define ACT_OPEN_RETRY_COUNT 2
2021
Vipul Pandya830662f2013-07-04 16:10:47 +05302022static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
2023 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302024 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05302025{
2026 struct neighbour *n;
2027 int err, step;
2028 struct net_device *pdev;
2029
2030 n = dst_neigh_lookup(dst, peer_ip);
2031 if (!n)
2032 return -ENODEV;
2033
2034 rcu_read_lock();
2035 err = -ENOMEM;
2036 if (n->dev->flags & IFF_LOOPBACK) {
2037 if (iptype == 4)
2038 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
2039 else if (IS_ENABLED(CONFIG_IPV6))
2040 for_each_netdev(&init_net, pdev) {
2041 if (ipv6_chk_addr(&init_net,
2042 (struct in6_addr *)peer_ip,
2043 pdev, 1))
2044 break;
2045 }
2046 else
2047 pdev = NULL;
2048
2049 if (!pdev) {
2050 err = -ENODEV;
2051 goto out;
2052 }
2053 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302054 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302055 if (!ep->l2t)
2056 goto out;
2057 ep->mtu = pdev->mtu;
2058 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302059 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2060 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302061 step = cdev->rdev.lldi.ntxq /
2062 cdev->rdev.lldi.nchan;
2063 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2064 step = cdev->rdev.lldi.nrxq /
2065 cdev->rdev.lldi.nchan;
2066 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2067 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2068 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302069 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302070 dev_put(pdev);
2071 } else {
2072 pdev = get_real_dev(n->dev);
2073 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2074 n, pdev, 0);
2075 if (!ep->l2t)
2076 goto out;
2077 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002078 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302079 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2080 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302081 step = cdev->rdev.lldi.ntxq /
2082 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002083 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2084 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302085 step = cdev->rdev.lldi.nrxq /
2086 cdev->rdev.lldi.nchan;
2087 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002088 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302089 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302090
2091 if (clear_mpa_v1) {
2092 ep->retry_with_mpa_v1 = 0;
2093 ep->tried_with_mpa_v1 = 0;
2094 }
2095 }
2096 err = 0;
2097out:
2098 rcu_read_unlock();
2099
2100 neigh_release(n);
2101
2102 return err;
2103}
2104
Vipul Pandya793dad92012-12-10 09:30:56 +00002105static int c4iw_reconnect(struct c4iw_ep *ep)
2106{
2107 int err = 0;
Hariprasad S4a740832016-06-10 01:05:15 +05302108 int size = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302109 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002110 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302111 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002112 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002114 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302115 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002116 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302117 int iptype;
2118 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002119
2120 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2121 init_timer(&ep->timer);
Hariprasad S093108c2016-05-06 22:18:09 +05302122 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya793dad92012-12-10 09:30:56 +00002123
Hariprasad S4a740832016-06-10 01:05:15 +05302124 /* When MPA revision is different on nodes, the node with MPA_rev=2
2125 * tries to reconnect with MPA_rev 1 for the same EP through
2126 * c4iw_reconnect(), where the same EP is assigned with new tid for
2127 * further connection establishment. As we are using the same EP pointer
2128 * for reconnect, few skbs are used during the previous c4iw_connect(),
2129 * which leaves the EP with inadequate skbs for further
2130 * c4iw_reconnect(), Further causing an assert BUG_ON() due to empty
2131 * skb_list() during peer_abort(). Allocate skbs which is already used.
2132 */
2133 size = (CN_MAX_CON_BUF - skb_queue_len(&ep->com.ep_skb_list));
2134 if (alloc_ep_skb_list(&ep->com.ep_skb_list, size)) {
2135 err = -ENOMEM;
2136 goto fail1;
2137 }
2138
Vipul Pandya793dad92012-12-10 09:30:56 +00002139 /*
2140 * Allocate an active TID to initiate a TCP connection.
2141 */
2142 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2143 if (ep->atid == -1) {
2144 pr_err("%s - cannot alloc atid.\n", __func__);
2145 err = -ENOMEM;
2146 goto fail2;
2147 }
2148 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2149
2150 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002151 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Varun Prakash804c2f32016-09-13 21:23:57 +05302152 ep->dst = cxgb_find_route(&ep->com.dev->rdev.lldi, get_real_dev,
2153 laddr->sin_addr.s_addr,
2154 raddr->sin_addr.s_addr,
2155 laddr->sin_port,
2156 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302157 iptype = 4;
2158 ra = (__u8 *)&raddr->sin_addr;
2159 } else {
Varun Prakash95554762016-09-13 21:23:58 +05302160 ep->dst = cxgb_find_route6(&ep->com.dev->rdev.lldi,
2161 get_real_dev,
2162 laddr6->sin6_addr.s6_addr,
2163 raddr6->sin6_addr.s6_addr,
2164 laddr6->sin6_port,
2165 raddr6->sin6_port, 0,
2166 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302167 iptype = 6;
2168 ra = (__u8 *)&raddr6->sin6_addr;
2169 }
2170 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002171 pr_err("%s - cannot find route.\n", __func__);
2172 err = -EHOSTUNREACH;
2173 goto fail3;
2174 }
Hariprasad S963cab52015-09-23 17:19:27 +05302175 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302176 ep->com.dev->rdev.lldi.adapter_type,
2177 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302178 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002179 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002180 goto fail4;
2181 }
2182
2183 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2184 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2185 ep->l2t->idx);
2186
2187 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302188 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002189
2190 /* send connect request to rnic */
2191 err = send_connect(ep);
2192 if (!err)
2193 goto out;
2194
2195 cxgb4_l2t_release(ep->l2t);
2196fail4:
2197 dst_release(ep->dst);
2198fail3:
2199 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2200 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2201fail2:
2202 /*
2203 * remember to send notification to upper layer.
2204 * We are in here so the upper layer is not aware that this is
2205 * re-connect attempt and so, upper layer is still waiting for
2206 * response of 1st connect request.
2207 */
2208 connect_reply_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05302209fail1:
Vipul Pandya793dad92012-12-10 09:30:56 +00002210 c4iw_put_ep(&ep->com);
2211out:
2212 return err;
2213}
2214
Steve Wisecfdda9d2010-04-21 15:30:06 -07002215static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2216{
2217 struct c4iw_ep *ep;
2218 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002219 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2220 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002221 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002222 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302223 struct sockaddr_in *la;
2224 struct sockaddr_in *ra;
2225 struct sockaddr_in6 *la6;
2226 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302227 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002228
2229 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002230 la = (struct sockaddr_in *)&ep->com.local_addr;
2231 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2232 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2233 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002234
2235 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2236 status, status2errno(status));
2237
Steve Wise7a2cea22014-03-14 21:52:07 +05302238 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302239 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2240 __func__, atid, status, neg_adv_str(status));
2241 ep->stats.connect_neg_adv++;
2242 mutex_lock(&dev->rdev.stats.lock);
2243 dev->rdev.stats.neg_adv++;
2244 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002245 return 0;
2246 }
2247
Vipul Pandya793dad92012-12-10 09:30:56 +00002248 set_bit(ACT_OPEN_RPL, &ep->com.history);
2249
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302250 /*
2251 * Log interesting failures.
2252 */
2253 switch (status) {
2254 case CPL_ERR_CONN_RESET:
2255 case CPL_ERR_CONN_TIMEDOUT:
2256 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002257 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302258 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002259 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302260 mutex_unlock(&dev->rdev.stats.lock);
2261 if (ep->com.local_addr.ss_family == AF_INET &&
2262 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302263 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2264 ntohl(rpl->atid_status))));
2265 if (ret)
2266 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002267 return 0;
2268 }
2269 break;
2270 case CPL_ERR_CONN_EXIST:
2271 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2272 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302273 if (ep->com.remote_addr.ss_family == AF_INET6) {
2274 struct sockaddr_in6 *sin6 =
2275 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002276 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302277 cxgb4_clip_release(
2278 ep->com.dev->rdev.lldi.ports[0],
2279 (const u32 *)
2280 &sin6->sin6_addr.s6_addr, 1);
2281 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002282 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2283 atid);
2284 cxgb4_free_atid(t, atid);
2285 dst_release(ep->dst);
2286 cxgb4_l2t_release(ep->l2t);
2287 c4iw_reconnect(ep);
2288 return 0;
2289 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002290 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302291 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302292 if (ep->com.local_addr.ss_family == AF_INET) {
2293 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2294 atid, status, status2errno(status),
2295 &la->sin_addr.s_addr, ntohs(la->sin_port),
2296 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2297 } else {
2298 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2299 atid, status, status2errno(status),
2300 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2301 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2302 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302303 break;
2304 }
2305
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302306fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002307 connect_reply_upcall(ep, status2errno(status));
2308 state_set(&ep->com, DEAD);
2309
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302310 if (ep->com.remote_addr.ss_family == AF_INET6) {
2311 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002312 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302313 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2314 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2315 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002316 if (status && act_open_has_tid(status))
2317 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2318
Vipul Pandya793dad92012-12-10 09:30:56 +00002319 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002320 cxgb4_free_atid(t, atid);
2321 dst_release(ep->dst);
2322 cxgb4_l2t_release(ep->l2t);
2323 c4iw_put_ep(&ep->com);
2324
2325 return 0;
2326}
2327
2328static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2329{
2330 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002331 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302332 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002333
2334 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002335 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2336 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002337 }
2338 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2339 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002340 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302341 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002342out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 return 0;
2344}
2345
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2347{
2348 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349 unsigned int stid = GET_TID(rpl);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302350 struct c4iw_listen_ep *ep = get_ep_from_stid(dev, stid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351
2352 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002353 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Hariprasad Sf86fac72016-05-06 22:18:07 +05302354 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002355 return 0;
2356}
2357
Hariprasad S9dec9002016-05-05 01:27:29 +05302358static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2359 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002360{
2361 struct cpl_pass_accept_rpl *rpl;
2362 unsigned int mtu_idx;
2363 u64 opt0;
2364 u32 opt2;
2365 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302366 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302367 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302368 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002369
2370 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2371 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302372
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302374 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302375 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302376 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2377 rpl5 = (void *)rpl;
2378 INIT_TP_WR(rpl5, ep->hwtid);
2379 } else {
2380 skb_trim(skb, sizeof(*rpl));
2381 INIT_TP_WR(rpl, ep->hwtid);
2382 }
2383 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2384 ep->hwtid));
2385
2386 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302387 enable_tcp_timestamps && req->tcpopt.tstamp,
2388 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002389 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302390
2391 /*
2392 * Specify the largest window that will fit in opt0. The
2393 * remainder will be specified in the rx_data_ack.
2394 */
2395 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002396 if (win > RCV_BUFSIZ_M)
2397 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002398 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002399 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002400 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002401 WND_SCALE_V(wscale) |
2402 MSS_IDX_V(mtu_idx) |
2403 L2T_IDX_V(ep->l2t->idx) |
2404 TX_CHAN_V(ep->tx_chan) |
2405 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002406 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002407 ULP_MODE_V(ULP_MODE_TCPDDP) |
2408 RCV_BUFSIZ_V(win);
2409 opt2 = RX_CHANNEL_V(0) |
2410 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002411
2412 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002413 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002414 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002415 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002416 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002417 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002418 if (enable_ecn) {
2419 const struct tcphdr *tcph;
2420 u32 hlen = ntohl(req->hdr_len);
2421
Hariprasad S963cab52015-09-23 17:19:27 +05302422 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2423 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2424 IP_HDR_LEN_G(hlen);
2425 else
2426 tcph = (const void *)(req + 1) +
2427 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002428 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002429 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002430 }
Hariprasad S963cab52015-09-23 17:19:27 +05302431 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302432 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002433 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302434 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302435 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302436 rpl5 = (void *)rpl;
2437 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2438 if (peer2peer)
2439 isn += 4;
2440 rpl5->iss = cpu_to_be32(isn);
2441 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002442 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002443
Steve Wisecfdda9d2010-04-21 15:30:06 -07002444 rpl->opt0 = cpu_to_be64(opt0);
2445 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002446 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302447 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448
Hariprasad S9dec9002016-05-05 01:27:29 +05302449 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002450}
2451
Vipul Pandya830662f2013-07-04 16:10:47 +05302452static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002453{
Vipul Pandya830662f2013-07-04 16:10:47 +05302454 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455 BUG_ON(skb_cloned(skb));
2456 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457 release_tid(&dev->rdev, hwtid, skb);
2458 return;
2459}
2460
Steve Wisecfdda9d2010-04-21 15:30:06 -07002461static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2462{
Vipul Pandya793dad92012-12-10 09:30:56 +00002463 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002464 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002465 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002466 struct tid_info *t = dev->rdev.lldi.tids;
2467 unsigned int hwtid = GET_TID(req);
2468 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302469 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002470 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302471 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002472 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002473 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302474 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302475 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302476 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477
Hariprasad Sf86fac72016-05-06 22:18:07 +05302478 parent_ep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002479 if (!parent_ep) {
2480 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2481 goto reject;
2482 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002483
Steve Wisecfdda9d2010-04-21 15:30:06 -07002484 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302485 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 goto reject;
2487 }
2488
Varun Prakash85e42b02016-09-13 21:23:56 +05302489 cxgb_get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type,
2490 &iptype, local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302491
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302493 if (iptype == 4) {
2494 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2495 , __func__, parent_ep, hwtid,
2496 local_ip, peer_ip, ntohs(local_port),
2497 ntohs(peer_port), peer_mss);
Varun Prakash804c2f32016-09-13 21:23:57 +05302498 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
2499 *(__be32 *)local_ip, *(__be32 *)peer_ip,
2500 local_port, peer_port, tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302501 } else {
2502 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2503 , __func__, parent_ep, hwtid,
2504 local_ip, peer_ip, ntohs(local_port),
2505 ntohs(peer_port), peer_mss);
Varun Prakash95554762016-09-13 21:23:58 +05302506 dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
2507 local_ip, peer_ip, local_port, peer_port,
2508 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
2509 ((struct sockaddr_in6 *)
2510 &parent_ep->com.local_addr)->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05302511 }
2512 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002513 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2514 __func__);
2515 goto reject;
2516 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002517
2518 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2519 if (!child_ep) {
2520 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2521 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002522 dst_release(dst);
2523 goto reject;
2524 }
David Miller3786cf12011-12-02 16:52:31 +00002525
Hariprasad S963cab52015-09-23 17:19:27 +05302526 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302527 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002528 if (err) {
2529 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2530 __func__);
2531 dst_release(dst);
2532 kfree(child_ep);
2533 goto reject;
2534 }
2535
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302536 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2537 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2538 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2539 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002540
Hariprasad S4a740832016-06-10 01:05:15 +05302541 skb_queue_head_init(&child_ep->com.ep_skb_list);
2542 if (alloc_ep_skb_list(&child_ep->com.ep_skb_list, CN_MAX_CON_BUF))
2543 goto fail;
2544
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 state_set(&child_ep->com, CONNECTING);
2546 child_ep->com.dev = dev;
2547 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002548
Vipul Pandya830662f2013-07-04 16:10:47 +05302549 if (iptype == 4) {
2550 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002551 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002552
Vipul Pandya830662f2013-07-04 16:10:47 +05302553 sin->sin_family = PF_INET;
2554 sin->sin_port = local_port;
2555 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002556
2557 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2558 sin->sin_family = PF_INET;
2559 sin->sin_port = ((struct sockaddr_in *)
2560 &parent_ep->com.local_addr)->sin_port;
2561 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2562
Steve Wise170003c2016-02-26 09:18:03 -06002563 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302564 sin->sin_family = PF_INET;
2565 sin->sin_port = peer_port;
2566 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2567 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002568 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302569 sin6->sin6_family = PF_INET6;
2570 sin6->sin6_port = local_port;
2571 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002572
2573 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2574 sin6->sin6_family = PF_INET6;
2575 sin6->sin6_port = ((struct sockaddr_in6 *)
2576 &parent_ep->com.local_addr)->sin6_port;
2577 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2578
Steve Wise170003c2016-02-26 09:18:03 -06002579 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302580 sin6->sin6_family = PF_INET6;
2581 sin6->sin6_port = peer_port;
2582 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2583 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002584
Steve Wisecfdda9d2010-04-21 15:30:06 -07002585 c4iw_get_ep(&parent_ep->com);
2586 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302587 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588 child_ep->dst = dst;
2589 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002590
2591 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002592 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002593
2594 init_timer(&child_ep->timer);
2595 cxgb4_insert_tid(t, child_ep, hwtid);
Hariprasad S944661d2016-05-06 22:18:03 +05302596 insert_ep_tid(child_ep);
Hariprasad S9dec9002016-05-05 01:27:29 +05302597 if (accept_cr(child_ep, skb, req)) {
2598 c4iw_put_ep(&parent_ep->com);
2599 release_ep_resources(child_ep);
2600 } else {
2601 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2602 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302603 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002604 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302605 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2606 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2607 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608 goto out;
Hariprasad S4a740832016-06-10 01:05:15 +05302609fail:
2610 c4iw_put_ep(&child_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002611reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302612 reject_cr(dev, hwtid, skb);
Hariprasad Sf86fac72016-05-06 22:18:07 +05302613 if (parent_ep)
2614 c4iw_put_ep(&parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002615out:
2616 return 0;
2617}
2618
2619static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2620{
2621 struct c4iw_ep *ep;
2622 struct cpl_pass_establish *req = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302624 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002625
Hariprasad S944661d2016-05-06 22:18:03 +05302626 ep = get_ep_from_tid(dev, tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002627 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2628 ep->snd_seq = be32_to_cpu(req->snd_isn);
2629 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2630
Vipul Pandya1cab7752012-12-10 09:30:55 +00002631 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2632 ntohs(req->tcp_opt));
2633
Steve Wisecfdda9d2010-04-21 15:30:06 -07002634 set_emss(ep, ntohs(req->tcp_opt));
2635
2636 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302637 mutex_lock(&ep->com.mutex);
2638 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002639 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002640 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05302641 ret = send_flowc(ep);
Hariprasad Sfef44222016-05-05 01:27:33 +05302642 mutex_unlock(&ep->com.mutex);
2643 if (ret)
2644 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Hariprasad S944661d2016-05-06 22:18:03 +05302645 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646
2647 return 0;
2648}
2649
2650static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2651{
2652 struct cpl_peer_close *hdr = cplhdr(skb);
2653 struct c4iw_ep *ep;
2654 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002655 int disconnect = 1;
2656 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002657 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002658 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002659
Hariprasad S944661d2016-05-06 22:18:03 +05302660 ep = get_ep_from_tid(dev, tid);
2661 if (!ep)
2662 return 0;
2663
Steve Wisecfdda9d2010-04-21 15:30:06 -07002664 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2665 dst_confirm(ep->dst);
2666
Vipul Pandya793dad92012-12-10 09:30:56 +00002667 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002668 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002669 switch (ep->com.state) {
2670 case MPA_REQ_WAIT:
2671 __state_set(&ep->com, CLOSING);
2672 break;
2673 case MPA_REQ_SENT:
2674 __state_set(&ep->com, CLOSING);
2675 connect_reply_upcall(ep, -ECONNRESET);
2676 break;
2677 case MPA_REQ_RCVD:
2678
2679 /*
2680 * We're gonna mark this puppy DEAD, but keep
2681 * the reference on it until the ULP accepts or
2682 * rejects the CR. Also wake up anyone waiting
2683 * in rdma connection migration (see c4iw_accept_cr()).
2684 */
2685 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002686 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002687 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002688 break;
2689 case MPA_REP_SENT:
2690 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002692 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002693 break;
2694 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002695 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002696 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002697 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002698 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002699 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002700 if (ret != -ECONNRESET) {
2701 peer_close_upcall(ep);
2702 disconnect = 1;
2703 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002704 break;
2705 case ABORTING:
2706 disconnect = 0;
2707 break;
2708 case CLOSING:
2709 __state_set(&ep->com, MORIBUND);
2710 disconnect = 0;
2711 break;
2712 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002713 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002714 if (ep->com.cm_id && ep->com.qp) {
2715 attrs.next_state = C4IW_QP_STATE_IDLE;
2716 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2717 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2718 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302719 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002720 __state_set(&ep->com, DEAD);
2721 release = 1;
2722 disconnect = 0;
2723 break;
2724 case DEAD:
2725 disconnect = 0;
2726 break;
2727 default:
2728 BUG_ON(1);
2729 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002730 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002731 if (disconnect)
2732 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2733 if (release)
2734 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302735 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002736 return 0;
2737}
2738
Steve Wisecfdda9d2010-04-21 15:30:06 -07002739static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2740{
2741 struct cpl_abort_req_rss *req = cplhdr(skb);
2742 struct c4iw_ep *ep;
2743 struct cpl_abort_rpl *rpl;
2744 struct sk_buff *rpl_skb;
2745 struct c4iw_qp_attributes attrs;
2746 int ret;
2747 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002748 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002749
Hariprasad S944661d2016-05-06 22:18:03 +05302750 ep = get_ep_from_tid(dev, tid);
2751 if (!ep)
2752 return 0;
2753
Steve Wise7a2cea22014-03-14 21:52:07 +05302754 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302755 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2756 __func__, ep->hwtid, req->status,
2757 neg_adv_str(req->status));
2758 ep->stats.abort_neg_adv++;
2759 mutex_lock(&dev->rdev.stats.lock);
2760 dev->rdev.stats.neg_adv++;
2761 mutex_unlock(&dev->rdev.stats.lock);
Hariprasad S944661d2016-05-06 22:18:03 +05302762 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002763 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002764 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2765 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002766 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002767
2768 /*
2769 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302770 * However, this is not needed if com state is just
2771 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002772 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302773 if (ep->com.state != MPA_REQ_SENT)
2774 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002775
2776 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002777 switch (ep->com.state) {
2778 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302779 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002780 break;
2781 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002782 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002783 break;
2784 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002785 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002786 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302787 connect_reply_upcall(ep, -ECONNRESET);
2788 else {
2789 /*
2790 * we just don't send notification upwards because we
2791 * want to retry with mpa_v1 without upper layers even
2792 * knowing it.
2793 *
2794 * do some housekeeping so as to re-initiate the
2795 * connection
2796 */
2797 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2798 mpa_rev);
2799 ep->retry_with_mpa_v1 = 1;
2800 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002801 break;
2802 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002803 break;
2804 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002805 break;
2806 case MORIBUND:
2807 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002808 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002809 /*FALLTHROUGH*/
2810 case FPDU_MODE:
2811 if (ep->com.cm_id && ep->com.qp) {
2812 attrs.next_state = C4IW_QP_STATE_ERROR;
2813 ret = c4iw_modify_qp(ep->com.qp->rhp,
2814 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2815 &attrs, 1);
2816 if (ret)
2817 printk(KERN_ERR MOD
2818 "%s - qp <- error failed!\n",
2819 __func__);
2820 }
2821 peer_abort_upcall(ep);
2822 break;
2823 case ABORTING:
2824 break;
2825 case DEAD:
2826 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002827 mutex_unlock(&ep->com.mutex);
Hariprasad S944661d2016-05-06 22:18:03 +05302828 goto deref_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002829 default:
2830 BUG_ON(1);
2831 break;
2832 }
2833 dst_confirm(ep->dst);
2834 if (ep->com.state != ABORTING) {
2835 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302836 /* we don't release if we want to retry with mpa_v1 */
2837 if (!ep->retry_with_mpa_v1)
2838 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002839 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002840 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002841
Hariprasad S4a740832016-06-10 01:05:15 +05302842 rpl_skb = skb_dequeue(&ep->com.ep_skb_list);
2843 if (WARN_ON(!rpl_skb)) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002844 release = 1;
2845 goto out;
2846 }
2847 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2848 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2849 INIT_TP_WR(rpl, ep->hwtid);
2850 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2851 rpl->cmd = CPL_ABORT_NO_RST;
2852 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2853out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002854 if (release)
2855 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002856 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302857 if (ep->com.remote_addr.ss_family == AF_INET6) {
2858 struct sockaddr_in6 *sin6 =
2859 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002860 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302861 cxgb4_clip_release(
2862 ep->com.dev->rdev.lldi.ports[0],
2863 (const u32 *)&sin6->sin6_addr.s6_addr,
2864 1);
2865 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002866 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302867 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2868 dst_release(ep->dst);
2869 cxgb4_l2t_release(ep->l2t);
2870 c4iw_reconnect(ep);
2871 }
2872
Hariprasad S944661d2016-05-06 22:18:03 +05302873deref_ep:
2874 c4iw_put_ep(&ep->com);
2875 /* Dereferencing ep, referenced in peer_abort_intr() */
2876 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877 return 0;
2878}
2879
2880static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2881{
2882 struct c4iw_ep *ep;
2883 struct c4iw_qp_attributes attrs;
2884 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002886 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002887
Hariprasad S944661d2016-05-06 22:18:03 +05302888 ep = get_ep_from_tid(dev, tid);
2889 if (!ep)
2890 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002891
2892 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2893 BUG_ON(!ep);
2894
2895 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002896 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302897 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002898 switch (ep->com.state) {
2899 case CLOSING:
2900 __state_set(&ep->com, MORIBUND);
2901 break;
2902 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002903 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002904 if ((ep->com.cm_id) && (ep->com.qp)) {
2905 attrs.next_state = C4IW_QP_STATE_IDLE;
2906 c4iw_modify_qp(ep->com.qp->rhp,
2907 ep->com.qp,
2908 C4IW_QP_ATTR_NEXT_STATE,
2909 &attrs, 1);
2910 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302911 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002912 __state_set(&ep->com, DEAD);
2913 release = 1;
2914 break;
2915 case ABORTING:
2916 case DEAD:
2917 break;
2918 default:
2919 BUG_ON(1);
2920 break;
2921 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002922 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002923 if (release)
2924 release_ep_resources(ep);
Hariprasad S944661d2016-05-06 22:18:03 +05302925 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002926 return 0;
2927}
2928
2929static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2930{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002931 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002932 unsigned int tid = GET_TID(rpl);
2933 struct c4iw_ep *ep;
2934 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002935
Hariprasad S944661d2016-05-06 22:18:03 +05302936 ep = get_ep_from_tid(dev, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002937 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938
Steve Wise30c95c22011-05-09 22:06:22 -07002939 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002940 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2941 ep->com.qp->wq.sq.qid);
2942 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2943 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2944 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2945 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002946 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Hariprasad S944661d2016-05-06 22:18:03 +05302947 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002948
Steve Wisecfdda9d2010-04-21 15:30:06 -07002949 return 0;
2950}
2951
2952/*
2953 * Upcall from the adapter indicating data has been transmitted.
2954 * For us its just the single MPA request or reply. We can now free
2955 * the skb holding the mpa message.
2956 */
2957static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2958{
2959 struct c4iw_ep *ep;
2960 struct cpl_fw4_ack *hdr = cplhdr(skb);
2961 u8 credits = hdr->credits;
2962 unsigned int tid = GET_TID(hdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002963
2964
Hariprasad S944661d2016-05-06 22:18:03 +05302965 ep = get_ep_from_tid(dev, tid);
2966 if (!ep)
2967 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002968 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2969 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002970 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2971 __func__, ep, ep->hwtid, state_read(&ep->com));
Hariprasad S944661d2016-05-06 22:18:03 +05302972 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002973 }
2974
2975 dst_confirm(ep->dst);
2976 if (ep->mpa_skb) {
2977 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2978 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2979 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
Steve Wise12eb5132016-07-29 08:38:44 -07002980 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981 kfree_skb(ep->mpa_skb);
2982 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302983 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2984 stop_ep_timer(ep);
2985 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 }
Hariprasad S944661d2016-05-06 22:18:03 +05302987out:
2988 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002989 return 0;
2990}
2991
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2993{
Hariprasad Sbce28412016-06-10 01:05:13 +05302994 int abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002995 struct c4iw_ep *ep = to_ep(cm_id);
Hariprasad Sbce28412016-06-10 01:05:13 +05302996
Steve Wisecfdda9d2010-04-21 15:30:06 -07002997 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2998
Steve Wisea7db89e2014-03-21 20:40:35 +05302999 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303000 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisea7db89e2014-03-21 20:40:35 +05303001 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003002 c4iw_put_ep(&ep->com);
3003 return -ECONNRESET;
3004 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003005 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003006 if (mpa_rev == 0)
Hariprasad Sbce28412016-06-10 01:05:13 +05303007 abort = 1;
3008 else
3009 abort = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05303010 mutex_unlock(&ep->com.mutex);
Hariprasad Sbce28412016-06-10 01:05:13 +05303011
3012 stop_ep_timer(ep);
3013 c4iw_ep_disconnect(ep, abort != 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003014 c4iw_put_ep(&ep->com);
3015 return 0;
3016}
3017
3018int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3019{
3020 int err;
3021 struct c4iw_qp_attributes attrs;
3022 enum c4iw_qp_attr_mask mask;
3023 struct c4iw_ep *ep = to_ep(cm_id);
3024 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
3025 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303026 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003027
3028 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05303029
3030 mutex_lock(&ep->com.mutex);
Hariprasad Se8667a92016-05-06 22:18:06 +05303031 if (ep->com.state != MPA_REQ_RCVD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003032 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303033 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003034 }
3035
Steve Wisecfdda9d2010-04-21 15:30:06 -07003036 BUG_ON(!qp);
3037
Vipul Pandya793dad92012-12-10 09:30:56 +00003038 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303039 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
3040 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003041 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303042 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 }
3044
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303045 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3046 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303047 if (RELAXED_IRD_NEGOTIATION) {
Steve Wise30b03b12016-08-19 07:29:08 -07003048 conn_param->ord = ep->ird;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303049 } else {
3050 ep->ird = conn_param->ird;
3051 ep->ord = conn_param->ord;
3052 send_mpa_reject(ep, conn_param->private_data,
3053 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303054 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303055 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303056 }
3057 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303058 if (conn_param->ird < ep->ord) {
3059 if (RELAXED_IRD_NEGOTIATION &&
3060 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3061 conn_param->ird = ep->ord;
3062 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303063 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303064 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303065 }
3066 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303067 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003068 ep->ird = conn_param->ird;
3069 ep->ord = conn_param->ord;
3070
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303071 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303072 if (peer2peer && ep->ird == 0)
3073 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303074 } else {
3075 if (peer2peer &&
3076 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303077 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303078 ep->ird = 1;
3079 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003080
3081 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3082
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303083 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303084 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303085 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003086 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303087
Steve Wisecfdda9d2010-04-21 15:30:06 -07003088 /* bind QP to EP and move to RTS */
3089 attrs.mpa_attr = ep->mpa_attr;
3090 attrs.max_ird = ep->ird;
3091 attrs.max_ord = ep->ord;
3092 attrs.llp_stream_handle = ep;
3093 attrs.next_state = C4IW_QP_STATE_RTS;
3094
3095 /* bind QP and TID with INIT_WR */
3096 mask = C4IW_QP_ATTR_NEXT_STATE |
3097 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3098 C4IW_QP_ATTR_MPA_ATTR |
3099 C4IW_QP_ATTR_MAX_IRD |
3100 C4IW_QP_ATTR_MAX_ORD;
3101
3102 err = c4iw_modify_qp(ep->com.qp->rhp,
3103 ep->com.qp, mask, &attrs, 1);
3104 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303105 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303106
3107 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003108 err = send_mpa_reply(ep, conn_param->private_data,
3109 conn_param->private_data_len);
3110 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303111 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003112
Steve Wisea7db89e2014-03-21 20:40:35 +05303113 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003114 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303115 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003116 c4iw_put_ep(&ep->com);
3117 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303118err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303119 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303120err_abort:
3121 abort = 1;
3122err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303123 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303124 if (abort)
3125 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003126 c4iw_put_ep(&ep->com);
3127 return err;
3128}
3129
Vipul Pandya830662f2013-07-04 16:10:47 +05303130static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3131{
3132 struct in_device *ind;
3133 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003134 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3135 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303136
3137 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3138 if (!ind)
3139 return -EADDRNOTAVAIL;
3140 for_primary_ifa(ind) {
3141 laddr->sin_addr.s_addr = ifa->ifa_address;
3142 raddr->sin_addr.s_addr = ifa->ifa_address;
3143 found = 1;
3144 break;
3145 }
3146 endfor_ifa(ind);
3147 in_dev_put(ind);
3148 return found ? 0 : -EADDRNOTAVAIL;
3149}
3150
3151static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3152 unsigned char banned_flags)
3153{
3154 struct inet6_dev *idev;
3155 int err = -EADDRNOTAVAIL;
3156
3157 rcu_read_lock();
3158 idev = __in6_dev_get(dev);
3159 if (idev != NULL) {
3160 struct inet6_ifaddr *ifp;
3161
3162 read_lock_bh(&idev->lock);
3163 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3164 if (ifp->scope == IFA_LINK &&
3165 !(ifp->flags & banned_flags)) {
3166 memcpy(addr, &ifp->addr, 16);
3167 err = 0;
3168 break;
3169 }
3170 }
3171 read_unlock_bh(&idev->lock);
3172 }
3173 rcu_read_unlock();
3174 return err;
3175}
3176
3177static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3178{
3179 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003180 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3181 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303182
Nicholas Krause54b9a962015-08-26 23:00:59 -04003183 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303184 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3185 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3186 return 0;
3187 }
3188 return -EADDRNOTAVAIL;
3189}
3190
Steve Wisecfdda9d2010-04-21 15:30:06 -07003191int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3192{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003193 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3194 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003195 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003196 struct sockaddr_in *laddr;
3197 struct sockaddr_in *raddr;
3198 struct sockaddr_in6 *laddr6;
3199 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303200 __u8 *ra;
3201 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003202
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303203 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3204 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003205 err = -EINVAL;
3206 goto out;
3207 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003208 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3209 if (!ep) {
3210 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3211 err = -ENOMEM;
3212 goto out;
3213 }
Hariprasad S4a740832016-06-10 01:05:15 +05303214
3215 skb_queue_head_init(&ep->com.ep_skb_list);
3216 if (alloc_ep_skb_list(&ep->com.ep_skb_list, CN_MAX_CON_BUF)) {
3217 err = -ENOMEM;
3218 goto fail1;
3219 }
3220
Steve Wisecfdda9d2010-04-21 15:30:06 -07003221 init_timer(&ep->timer);
3222 ep->plen = conn_param->private_data_len;
3223 if (ep->plen)
3224 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3225 conn_param->private_data, ep->plen);
3226 ep->ird = conn_param->ird;
3227 ep->ord = conn_param->ord;
3228
3229 if (peer2peer && ep->ord == 0)
3230 ep->ord = 1;
3231
Steve Wisecfdda9d2010-04-21 15:30:06 -07003232 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303233 ref_cm_id(&ep->com);
3234 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003235 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303236 if (!ep->com.qp) {
3237 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3238 err = -EINVAL;
Hariprasad S4a740832016-06-10 01:05:15 +05303239 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303240 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003241 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003242 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3243 ep->com.qp, cm_id);
3244
3245 /*
3246 * Allocate an active TID to initiate a TCP connection.
3247 */
3248 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3249 if (ep->atid == -1) {
3250 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3251 err = -ENOMEM;
Hariprasad S4a740832016-06-10 01:05:15 +05303252 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003253 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003254 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255
Steve Wise170003c2016-02-26 09:18:03 -06003256 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003257 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003258 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003259 sizeof(ep->com.remote_addr));
3260
Steve Wise170003c2016-02-26 09:18:03 -06003261 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3262 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3263 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3264 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003265
Steve Wise170003c2016-02-26 09:18:03 -06003266 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303267 iptype = 4;
3268 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003269
Vipul Pandya830662f2013-07-04 16:10:47 +05303270 /*
3271 * Handle loopback requests to INADDR_ANY.
3272 */
Bart Van Asscheba987e52016-04-12 14:45:24 -07003273 if (raddr->sin_addr.s_addr == htonl(INADDR_ANY)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303274 err = pick_local_ipaddrs(dev, cm_id);
3275 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303276 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303277 }
3278
3279 /* find a route */
3280 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3281 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3282 ra, ntohs(raddr->sin_port));
Varun Prakash804c2f32016-09-13 21:23:57 +05303283 ep->dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3284 laddr->sin_addr.s_addr,
3285 raddr->sin_addr.s_addr,
3286 laddr->sin_port,
3287 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303288 } else {
3289 iptype = 6;
3290 ra = (__u8 *)&raddr6->sin6_addr;
3291
3292 /*
3293 * Handle loopback requests to INADDR_ANY.
3294 */
3295 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3296 err = pick_local_ip6addrs(dev, cm_id);
3297 if (err)
Hariprasad S4a740832016-06-10 01:05:15 +05303298 goto fail2;
Vipul Pandya830662f2013-07-04 16:10:47 +05303299 }
3300
3301 /* find a route */
3302 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3303 __func__, laddr6->sin6_addr.s6_addr,
3304 ntohs(laddr6->sin6_port),
3305 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
Varun Prakash95554762016-09-13 21:23:58 +05303306 ep->dst = cxgb_find_route6(&dev->rdev.lldi, get_real_dev,
3307 laddr6->sin6_addr.s6_addr,
3308 raddr6->sin6_addr.s6_addr,
3309 laddr6->sin6_port,
3310 raddr6->sin6_port, 0,
3311 raddr6->sin6_scope_id);
Vipul Pandya830662f2013-07-04 16:10:47 +05303312 }
3313 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003314 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3315 err = -EHOSTUNREACH;
Hariprasad S4a740832016-06-10 01:05:15 +05303316 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003317 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003318
Hariprasad S963cab52015-09-23 17:19:27 +05303319 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303320 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003321 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003322 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Hariprasad S4a740832016-06-10 01:05:15 +05303323 goto fail4;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003324 }
3325
3326 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3327 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3328 ep->l2t->idx);
3329
3330 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303331 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003332
3333 /* send connect request to rnic */
3334 err = send_connect(ep);
3335 if (!err)
3336 goto out;
3337
3338 cxgb4_l2t_release(ep->l2t);
Hariprasad S4a740832016-06-10 01:05:15 +05303339fail4:
Steve Wise9eccfe12014-03-26 17:08:09 -05003340 dst_release(ep->dst);
Hariprasad S4a740832016-06-10 01:05:15 +05303341fail3:
Vipul Pandya793dad92012-12-10 09:30:56 +00003342 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003343 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S4a740832016-06-10 01:05:15 +05303344fail2:
3345 skb_queue_purge(&ep->com.ep_skb_list);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303346 deref_cm_id(&ep->com);
Hariprasad S4a740832016-06-10 01:05:15 +05303347fail1:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003348 c4iw_put_ep(&ep->com);
3349out:
3350 return err;
3351}
3352
Vipul Pandya830662f2013-07-04 16:10:47 +05303353static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3354{
3355 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003356 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003357 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303358
Hariprasad S28de1f72016-01-13 10:03:14 +05303359 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3360 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3361 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3362 if (err)
3363 return err;
3364 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303365 c4iw_init_wr_wait(&ep->com.wr_wait);
3366 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3367 ep->stid, &sin6->sin6_addr,
3368 sin6->sin6_port,
3369 ep->com.dev->rdev.lldi.rxq_ids[0]);
3370 if (!err)
3371 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3372 &ep->com.wr_wait,
3373 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303374 else if (err > 0)
3375 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303376 if (err) {
3377 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3378 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303379 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3380 err, ep->stid,
3381 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303382 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303383 return err;
3384}
3385
3386static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3387{
3388 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003389 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003390 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303391
3392 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3393 do {
3394 err = cxgb4_create_server_filter(
3395 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3396 sin->sin_addr.s_addr, sin->sin_port, 0,
3397 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3398 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303399 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3400 err = -EIO;
3401 break;
3402 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303403 set_current_state(TASK_UNINTERRUPTIBLE);
3404 schedule_timeout(usecs_to_jiffies(100));
3405 }
3406 } while (err == -EBUSY);
3407 } else {
3408 c4iw_init_wr_wait(&ep->com.wr_wait);
3409 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3410 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3411 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3412 if (!err)
3413 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3414 &ep->com.wr_wait,
3415 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303416 else if (err > 0)
3417 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303418 }
3419 if (err)
3420 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3421 , err, ep->stid,
3422 &sin->sin_addr, ntohs(sin->sin_port));
3423 return err;
3424}
3425
Steve Wisecfdda9d2010-04-21 15:30:06 -07003426int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3427{
3428 int err = 0;
3429 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3430 struct c4iw_listen_ep *ep;
3431
Steve Wisecfdda9d2010-04-21 15:30:06 -07003432 might_sleep();
3433
3434 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3435 if (!ep) {
3436 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3437 err = -ENOMEM;
3438 goto fail1;
3439 }
Hariprasad S4a740832016-06-10 01:05:15 +05303440 skb_queue_head_init(&ep->com.ep_skb_list);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003441 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003442 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303443 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003444 ep->com.dev = dev;
3445 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003446 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303447 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003448
3449 /*
3450 * Allocate a server TID.
3451 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303452 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3453 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303454 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003455 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003456 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303457 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003458 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003459
Steve Wisecfdda9d2010-04-21 15:30:06 -07003460 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003461 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003462 err = -ENOMEM;
3463 goto fail2;
3464 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003465 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003466
Steve Wise170003c2016-02-26 09:18:03 -06003467 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3468 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003469
Steve Wisecfdda9d2010-04-21 15:30:06 -07003470 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303471 if (ep->com.local_addr.ss_family == AF_INET)
3472 err = create_server4(dev, ep);
3473 else
3474 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003475 if (!err) {
3476 cm_id->provider_data = ep;
3477 goto out;
3478 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003479
Vipul Pandya830662f2013-07-04 16:10:47 +05303480 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3481 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003482fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303483 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003484 c4iw_put_ep(&ep->com);
3485fail1:
3486out:
3487 return err;
3488}
3489
3490int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3491{
3492 int err;
3493 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3494
3495 PDBG("%s ep %p\n", __func__, ep);
3496
3497 might_sleep();
3498 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303499 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3500 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003501 err = cxgb4_remove_server_filter(
3502 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3503 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3504 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303505 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003506 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303507 err = cxgb4_remove_server(
3508 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3509 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003510 if (err)
3511 goto done;
3512 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3513 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003514 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303515 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3516 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003517 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003518 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303519 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3520 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003521done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303522 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003523 c4iw_put_ep(&ep->com);
3524 return err;
3525}
3526
3527int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3528{
3529 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003530 int close = 0;
3531 int fatal = 0;
3532 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003533
Steve Wise2f5b48c2010-09-10 11:15:36 -05003534 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535
3536 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3537 states[ep->com.state], abrupt);
3538
Hariprasad S6e410d82016-05-05 01:27:31 +05303539 /*
3540 * Ref the ep here in case we have fatal errors causing the
3541 * ep to be released and freed.
3542 */
3543 c4iw_get_ep(&ep->com);
3544
Steve Wisecfdda9d2010-04-21 15:30:06 -07003545 rdev = &ep->com.dev->rdev;
3546 if (c4iw_fatal_error(rdev)) {
3547 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303548 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003549 ep->com.state = DEAD;
3550 }
3551 switch (ep->com.state) {
3552 case MPA_REQ_WAIT:
3553 case MPA_REQ_SENT:
3554 case MPA_REQ_RCVD:
3555 case MPA_REP_SENT:
3556 case FPDU_MODE:
Hariprasad S4a740832016-06-10 01:05:15 +05303557 case CONNECTING:
Steve Wisecfdda9d2010-04-21 15:30:06 -07003558 close = 1;
3559 if (abrupt)
3560 ep->com.state = ABORTING;
3561 else {
3562 ep->com.state = CLOSING;
Steve Wise12eb5132016-07-29 08:38:44 -07003563
3564 /*
3565 * if we close before we see the fw4_ack() then we fix
3566 * up the timer state since we're reusing it.
3567 */
3568 if (ep->mpa_skb &&
3569 test_bit(STOP_MPA_TIMER, &ep->com.flags)) {
3570 clear_bit(STOP_MPA_TIMER, &ep->com.flags);
3571 stop_ep_timer(ep);
3572 }
Steve Wiseca5a2202010-07-23 19:12:37 +00003573 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003574 }
3575 set_bit(CLOSE_SENT, &ep->com.flags);
3576 break;
3577 case CLOSING:
3578 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3579 close = 1;
3580 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003581 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003582 ep->com.state = ABORTING;
3583 } else
3584 ep->com.state = MORIBUND;
3585 }
3586 break;
3587 case MORIBUND:
3588 case ABORTING:
3589 case DEAD:
3590 PDBG("%s ignoring disconnect ep %p state %u\n",
3591 __func__, ep, ep->com.state);
3592 break;
3593 default:
3594 BUG();
3595 break;
3596 }
3597
Steve Wisecfdda9d2010-04-21 15:30:06 -07003598 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003599 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003600 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303601 close_complete_upcall(ep, -ECONNRESET);
Hariprasad S4a740832016-06-10 01:05:15 +05303602 ret = send_abort(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003603 } else {
3604 set_bit(EP_DISC_CLOSE, &ep->com.history);
Hariprasad S4a740832016-06-10 01:05:15 +05303605 ret = send_halfclose(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00003606 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303607 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303608 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303609 if (!abrupt) {
3610 stop_ep_timer(ep);
3611 close_complete_upcall(ep, -EIO);
3612 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303613 if (ep->com.qp) {
3614 struct c4iw_qp_attributes attrs;
3615
3616 attrs.next_state = C4IW_QP_STATE_ERROR;
3617 ret = c4iw_modify_qp(ep->com.qp->rhp,
3618 ep->com.qp,
3619 C4IW_QP_ATTR_NEXT_STATE,
3620 &attrs, 1);
3621 if (ret)
3622 pr_err(MOD
3623 "%s - qp <- error failed!\n",
3624 __func__);
3625 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003626 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303627 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003628 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003629 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303630 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003631 if (fatal)
3632 release_ep_resources(ep);
3633 return ret;
3634}
3635
Vipul Pandya1cab7752012-12-10 09:30:55 +00003636static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3637 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3638{
3639 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003640 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003641
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003642 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3643 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003644 if (!ep)
3645 return;
3646
3647 switch (req->retval) {
3648 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003649 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3650 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3651 send_fw_act_open_req(ep, atid);
3652 return;
3653 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003654 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003655 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3656 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3657 send_fw_act_open_req(ep, atid);
3658 return;
3659 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003660 break;
3661 default:
3662 pr_info("%s unexpected ofld conn wr retval %d\n",
3663 __func__, req->retval);
3664 break;
3665 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003666 pr_err("active ofld_connect_wr failure %d atid %d\n",
3667 req->retval, atid);
3668 mutex_lock(&dev->rdev.stats.lock);
3669 dev->rdev.stats.act_ofld_conn_fails++;
3670 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003672 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303673 if (ep->com.remote_addr.ss_family == AF_INET6) {
3674 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003675 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303676 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3677 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3678 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003679 remove_handle(dev, &dev->atid_idr, atid);
3680 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3681 dst_release(ep->dst);
3682 cxgb4_l2t_release(ep->l2t);
3683 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003684}
3685
3686static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3687 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3688{
3689 struct sk_buff *rpl_skb;
3690 struct cpl_pass_accept_req *cpl;
3691 int ret;
3692
Paul Bolle710a3112013-02-05 20:51:30 +00003693 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003694 BUG_ON(!rpl_skb);
3695 if (req->retval) {
3696 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003697 mutex_lock(&dev->rdev.stats.lock);
3698 dev->rdev.stats.pas_ofld_conn_fails++;
3699 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003700 kfree_skb(rpl_skb);
3701 } else {
3702 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3703 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003704 (__force u32) htonl(
3705 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003706 ret = pass_accept_req(dev, rpl_skb);
3707 if (!ret)
3708 kfree_skb(rpl_skb);
3709 }
3710 return;
3711}
3712
3713static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003714{
3715 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003716 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3717
3718 switch (rpl->type) {
3719 case FW6_TYPE_CQE:
3720 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3721 break;
3722 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3723 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3724 switch (req->t_state) {
3725 case TCP_SYN_SENT:
3726 active_ofld_conn_reply(dev, skb, req);
3727 break;
3728 case TCP_SYN_RECV:
3729 passive_ofld_conn_reply(dev, skb, req);
3730 break;
3731 default:
3732 pr_err("%s unexpected ofld conn wr state %d\n",
3733 __func__, req->t_state);
3734 break;
3735 }
3736 break;
3737 }
3738 return 0;
3739}
3740
3741static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3742{
Hariprasad S963cab52015-09-23 17:19:27 +05303743 __be32 l2info;
3744 __be16 hdr_len, vlantag, len;
3745 u16 eth_hdr_len;
3746 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003747 u8 intf;
3748 struct cpl_rx_pkt *cpl = cplhdr(skb);
3749 struct cpl_pass_accept_req *req;
3750 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003751 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303752 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003753
Vipul Pandyaf079af72013-03-14 05:08:58 +00003754 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003755 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303756 vlantag = cpl->vlan;
3757 len = cpl->len;
3758 l2info = cpl->l2info;
3759 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003760 intf = cpl->iff;
3761
3762 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3763
3764 /*
3765 * We need to parse the TCP options from SYN packet.
3766 * to generate cpl_pass_accept_req.
3767 */
3768 memset(&tmp_opt, 0, sizeof(tmp_opt));
3769 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003770 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003771
3772 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3773 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303774 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3775 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303776 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303777 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303778 type = dev->rdev.lldi.adapter_type;
3779 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3780 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3781 req->hdr_len =
3782 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3783 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3784 eth_hdr_len = is_t4(type) ?
3785 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3786 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3787 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3788 IP_HDR_LEN_V(ip_hdr_len) |
3789 ETH_HDR_LEN_V(eth_hdr_len));
3790 } else { /* T6 and later */
3791 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3792 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3793 T6_IP_HDR_LEN_V(ip_hdr_len) |
3794 T6_ETH_HDR_LEN_V(eth_hdr_len));
3795 }
3796 req->vlan = vlantag;
3797 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003798 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3799 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003800 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3801 if (tmp_opt.wscale_ok)
3802 req->tcpopt.wsf = tmp_opt.snd_wscale;
3803 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3804 if (tmp_opt.sack_ok)
3805 req->tcpopt.sack = 1;
3806 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3807 return;
3808}
3809
3810static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3811 __be32 laddr, __be16 lport,
3812 __be32 raddr, __be16 rport,
3813 u32 rcv_isn, u32 filter, u16 window,
3814 u32 rss_qid, u8 port_id)
3815{
3816 struct sk_buff *req_skb;
3817 struct fw_ofld_connection_wr *req;
3818 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303819 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003820
3821 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3822 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3823 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003824 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303825 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303826 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003827 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003828 req->le.lport = lport;
3829 req->le.pport = rport;
3830 req->le.u.ipv4.lip = laddr;
3831 req->le.u.ipv4.pip = raddr;
3832 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3833 req->tcb.rcv_adv = htons(window);
3834 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303835 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3836 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3837 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003838 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003839
3840 /*
3841 * We store the qid in opt2 which will be used by the firmware
3842 * to send us the wr response.
3843 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003844 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003845
3846 /*
3847 * We initialize the MSS index in TCB to 0xF.
3848 * So that when driver sends cpl_pass_accept_rpl
3849 * TCB picks up the correct value. If this was 0
3850 * TP will ignore any value > 0 for MSS index.
3851 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003852 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303853 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003854
3855 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303856 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3857 if (ret < 0) {
3858 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3859 ret);
3860 kfree_skb(skb);
3861 kfree_skb(req_skb);
3862 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863}
3864
3865/*
3866 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3867 * messages when a filter is being used instead of server to
3868 * redirect a syn packet. When packets hit filter they are redirected
3869 * to the offload queue and driver tries to establish the connection
3870 * using firmware work request.
3871 */
3872static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3873{
3874 int stid;
3875 unsigned int filter;
3876 struct ethhdr *eh = NULL;
3877 struct vlan_ethhdr *vlan_eh = NULL;
3878 struct iphdr *iph;
3879 struct tcphdr *tcph;
3880 struct rss_header *rss = (void *)skb->data;
3881 struct cpl_rx_pkt *cpl = (void *)skb->data;
3882 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3883 struct l2t_entry *e;
3884 struct dst_entry *dst;
Hariprasad Sf86fac72016-05-06 22:18:07 +05303885 struct c4iw_ep *lep = NULL;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003886 u16 window;
3887 struct port_info *pi;
3888 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003889 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003890 int step;
3891 u32 tx_chan;
3892 struct neighbour *neigh;
3893
3894 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003895 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003896 goto reject;
3897
3898 /*
3899 * Drop all packets which did not hit the filter.
3900 * Unlikely to happen.
3901 */
3902 if (!(rss->filter_hit && rss->filter_tid))
3903 goto reject;
3904
3905 /*
3906 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3907 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303908 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003909
Hariprasad Sf86fac72016-05-06 22:18:07 +05303910 lep = (struct c4iw_ep *)get_ep_from_stid(dev, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003911 if (!lep) {
3912 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3913 goto reject;
3914 }
3915
Hariprasad S963cab52015-09-23 17:19:27 +05303916 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3917 case CHELSIO_T4:
3918 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3919 break;
3920 case CHELSIO_T5:
3921 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3922 break;
3923 case CHELSIO_T6:
3924 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3925 break;
3926 default:
3927 pr_err("T%d Chip is not supported\n",
3928 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3929 goto reject;
3930 }
3931
Vipul Pandyaf079af72013-03-14 05:08:58 +00003932 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003933 eh = (struct ethhdr *)(req + 1);
3934 iph = (struct iphdr *)(eh + 1);
3935 } else {
3936 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3937 iph = (struct iphdr *)(vlan_eh + 1);
3938 skb->vlan_tci = ntohs(cpl->vlan);
3939 }
3940
3941 if (iph->version != 0x4)
3942 goto reject;
3943
3944 tcph = (struct tcphdr *)(iph + 1);
3945 skb_set_network_header(skb, (void *)iph - (void *)rss);
3946 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3947 skb_get(skb);
3948
3949 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3950 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3951 ntohs(tcph->source), iph->tos);
3952
Varun Prakash804c2f32016-09-13 21:23:57 +05303953 dst = cxgb_find_route(&dev->rdev.lldi, get_real_dev,
3954 iph->daddr, iph->saddr, tcph->dest,
3955 tcph->source, iph->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303956 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003957 pr_err("%s - failed to find dst entry!\n",
3958 __func__);
3959 goto reject;
3960 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003961 neigh = dst_neigh_lookup_skb(dst, skb);
3962
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003963 if (!neigh) {
3964 pr_err("%s - failed to allocate neigh!\n",
3965 __func__);
3966 goto free_dst;
3967 }
3968
Vipul Pandya1cab7752012-12-10 09:30:55 +00003969 if (neigh->dev->flags & IFF_LOOPBACK) {
3970 pdev = ip_dev_find(&init_net, iph->daddr);
3971 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3972 pdev, 0);
3973 pi = (struct port_info *)netdev_priv(pdev);
3974 tx_chan = cxgb4_port_chan(pdev);
3975 dev_put(pdev);
3976 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303977 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003978 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303979 pdev, 0);
3980 pi = (struct port_info *)netdev_priv(pdev);
3981 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003982 }
Steve Wiseebf00062014-03-19 17:44:40 +05303983 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003984 if (!e) {
3985 pr_err("%s - failed to allocate l2t entry!\n",
3986 __func__);
3987 goto free_dst;
3988 }
3989
3990 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3991 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003992 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003993
3994 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303995 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3996 dev->rdev.lldi.ports[0],
3997 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003998
3999 /*
4000 * Synthesize the cpl_pass_accept_req. We have everything except the
4001 * TID. Once firmware sends a reply with TID we update the TID field
4002 * in cpl and pass it through the regular cpl_pass_accept_req path.
4003 */
4004 build_cpl_pass_accept_req(skb, stid, iph->tos);
4005 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
4006 tcph->source, ntohl(tcph->seq), filter, window,
4007 rss_qid, pi->port_id);
4008 cxgb4_l2t_release(e);
4009free_dst:
4010 dst_release(dst);
4011reject:
Hariprasad Sf86fac72016-05-06 22:18:07 +05304012 if (lep)
4013 c4iw_put_ep(&lep->com);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004014 return 0;
4015}
4016
Steve Wisecfdda9d2010-04-21 15:30:06 -07004017/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004018 * These are the real handlers that are called from a
4019 * work queue.
4020 */
Hariprasad S9dec9002016-05-05 01:27:29 +05304021static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004022 [CPL_ACT_ESTABLISH] = act_establish,
4023 [CPL_ACT_OPEN_RPL] = act_open_rpl,
4024 [CPL_RX_DATA] = rx_data,
4025 [CPL_ABORT_RPL_RSS] = abort_rpl,
4026 [CPL_ABORT_RPL] = abort_rpl,
4027 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
4028 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
4029 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
4030 [CPL_PASS_ESTABLISH] = pass_establish,
4031 [CPL_PEER_CLOSE] = peer_close,
4032 [CPL_ABORT_REQ_RSS] = peer_abort,
4033 [CPL_CLOSE_CON_RPL] = close_con_rpl,
4034 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05004035 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004036 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05304037 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05304038 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
4039 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004040};
4041
4042static void process_timeout(struct c4iw_ep *ep)
4043{
4044 struct c4iw_qp_attributes attrs;
4045 int abort = 1;
4046
Steve Wise2f5b48c2010-09-10 11:15:36 -05004047 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004048 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
4049 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00004050 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004051 switch (ep->com.state) {
4052 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004053 connect_reply_upcall(ep, -ETIMEDOUT);
4054 break;
4055 case MPA_REQ_WAIT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304056 case MPA_REQ_RCVD:
Hariprasad Se4b76a22016-05-06 22:17:59 +05304057 case MPA_REP_SENT:
Hariprasad Sceb110a2016-05-06 22:18:05 +05304058 case FPDU_MODE:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004059 break;
4060 case CLOSING:
4061 case MORIBUND:
4062 if (ep->com.cm_id && ep->com.qp) {
4063 attrs.next_state = C4IW_QP_STATE_ERROR;
4064 c4iw_modify_qp(ep->com.qp->rhp,
4065 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
4066 &attrs, 1);
4067 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05304068 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004069 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004070 case ABORTING:
4071 case DEAD:
4072
4073 /*
4074 * These states are expected if the ep timed out at the same
4075 * time as another thread was calling stop_ep_timer().
4076 * So we silently do nothing for these states.
4077 */
4078 abort = 0;
4079 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004080 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004081 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004082 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004083 abort = 0;
4084 }
Steve Wisecc18b932014-04-24 14:31:53 -05004085 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304086 if (abort)
4087 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004088 c4iw_put_ep(&ep->com);
4089}
4090
4091static void process_timedout_eps(void)
4092{
4093 struct c4iw_ep *ep;
4094
4095 spin_lock_irq(&timeout_lock);
4096 while (!list_empty(&timeout_list)) {
4097 struct list_head *tmp;
4098
4099 tmp = timeout_list.next;
4100 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004101 tmp->next = NULL;
4102 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004103 spin_unlock_irq(&timeout_lock);
4104 ep = list_entry(tmp, struct c4iw_ep, entry);
4105 process_timeout(ep);
4106 spin_lock_irq(&timeout_lock);
4107 }
4108 spin_unlock_irq(&timeout_lock);
4109}
4110
4111static void process_work(struct work_struct *work)
4112{
4113 struct sk_buff *skb = NULL;
4114 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004115 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004116 unsigned int opcode;
4117 int ret;
4118
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004119 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004120 while ((skb = skb_dequeue(&rxq))) {
4121 rpl = cplhdr(skb);
4122 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4123 opcode = rpl->ot.opcode;
4124
4125 BUG_ON(!work_handlers[opcode]);
4126 ret = work_handlers[opcode](dev, skb);
4127 if (!ret)
4128 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004129 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004130 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004131}
4132
4133static DECLARE_WORK(skb_work, process_work);
4134
4135static void ep_timeout(unsigned long arg)
4136{
4137 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004138 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004139
4140 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004141 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004142 /*
4143 * Only insert if it is not already on the list.
4144 */
4145 if (!ep->entry.next) {
4146 list_add_tail(&ep->entry, &timeout_list);
4147 kickit = 1;
4148 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004149 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004150 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004151 if (kickit)
4152 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004153}
4154
4155/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004156 * All the CM events are handled on a work queue to have a safe context.
4157 */
4158static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4159{
4160
4161 /*
4162 * Save dev in the skb->cb area.
4163 */
4164 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4165
4166 /*
4167 * Queue the skb and schedule the worker thread.
4168 */
4169 skb_queue_tail(&rxq, skb);
4170 queue_work(workq, &skb_work);
4171 return 0;
4172}
4173
4174static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4175{
4176 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4177
4178 if (rpl->status != CPL_ERR_NONE) {
4179 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4180 "for tid %u\n", rpl->status, GET_TID(rpl));
4181 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004182 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004183 return 0;
4184}
4185
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004186static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4187{
4188 struct cpl_fw6_msg *rpl = cplhdr(skb);
4189 struct c4iw_wr_wait *wr_waitp;
4190 int ret;
4191
4192 PDBG("%s type %u\n", __func__, rpl->type);
4193
4194 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004195 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004196 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004197 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004198 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004199 if (wr_waitp)
4200 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004201 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004202 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004203 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004204 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004205 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004206 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004207 default:
4208 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4209 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004210 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004211 break;
4212 }
4213 return 0;
4214}
4215
Steve Wise8da7e7a2011-06-14 20:59:27 +00004216static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4217{
4218 struct cpl_abort_req_rss *req = cplhdr(skb);
4219 struct c4iw_ep *ep;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004220 unsigned int tid = GET_TID(req);
4221
Hariprasad S944661d2016-05-06 22:18:03 +05304222 ep = get_ep_from_tid(dev, tid);
4223 /* This EP will be dereferenced in peer_abort() */
Steve Wise14b92222012-04-30 15:31:29 -05004224 if (!ep) {
4225 printk(KERN_WARNING MOD
4226 "Abort on non-existent endpoint, tid %d\n", tid);
4227 kfree_skb(skb);
4228 return 0;
4229 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304230 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304231 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4232 __func__, ep->hwtid, req->status,
4233 neg_adv_str(req->status));
Hariprasad S944661d2016-05-06 22:18:03 +05304234 goto out;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004235 }
4236 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4237 ep->com.state);
4238
Hariprasad S093108c2016-05-06 22:18:09 +05304239 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Hariprasad S944661d2016-05-06 22:18:03 +05304240out:
Steve Wise8da7e7a2011-06-14 20:59:27 +00004241 sched(dev, skb);
4242 return 0;
4243}
4244
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004245/*
4246 * Most upcalls from the T4 Core go to sched() to
4247 * schedule the processing on a work queue.
4248 */
4249c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4250 [CPL_ACT_ESTABLISH] = sched,
4251 [CPL_ACT_OPEN_RPL] = sched,
4252 [CPL_RX_DATA] = sched,
4253 [CPL_ABORT_RPL_RSS] = sched,
4254 [CPL_ABORT_RPL] = sched,
4255 [CPL_PASS_OPEN_RPL] = sched,
4256 [CPL_CLOSE_LISTSRV_RPL] = sched,
4257 [CPL_PASS_ACCEPT_REQ] = sched,
4258 [CPL_PASS_ESTABLISH] = sched,
4259 [CPL_PEER_CLOSE] = sched,
4260 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004261 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004262 [CPL_RDMA_TERMINATE] = sched,
4263 [CPL_FW4_ACK] = sched,
4264 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004265 [CPL_FW6_MSG] = fw6_msg,
4266 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004267};
4268
Steve Wisecfdda9d2010-04-21 15:30:06 -07004269int __init c4iw_cm_init(void)
4270{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004271 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004272 skb_queue_head_init(&rxq);
4273
4274 workq = create_singlethread_workqueue("iw_cxgb4");
4275 if (!workq)
4276 return -ENOMEM;
4277
Steve Wisecfdda9d2010-04-21 15:30:06 -07004278 return 0;
4279}
4280
Steve Wise46c13762014-06-20 14:26:25 -05004281void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004282{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004283 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004284 flush_workqueue(workq);
4285 destroy_workqueue(workq);
4286}