blob: 6129dbd0dc9e2dd283df61f0a8f3bcd820d06486 [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
Steve Wisecfdda9d2010-04-21 15:30:06 -070052#include "iw_cxgb4.h"
Hariprasad S84cc6ac62015-08-25 14:08:23 +053053#include "clip_tbl.h"
Steve Wisecfdda9d2010-04-21 15:30:06 -070054
55static char *states[] = {
56 "idle",
57 "listen",
58 "connecting",
59 "mpa_wait_req",
60 "mpa_req_sent",
61 "mpa_req_rcvd",
62 "mpa_rep_sent",
63 "fpdu_mode",
64 "aborting",
65 "closing",
66 "moribund",
67 "dead",
68 NULL,
69};
70
Vipul Pandya5be78ee2012-12-10 09:30:54 +000071static int nocong;
72module_param(nocong, int, 0644);
73MODULE_PARM_DESC(nocong, "Turn of congestion control (default=0)");
74
75static int enable_ecn;
76module_param(enable_ecn, int, 0644);
77MODULE_PARM_DESC(enable_ecn, "Enable ECN (default=0/disabled)");
78
Steve Wiseb52fe092011-03-11 22:30:01 +000079static int dack_mode = 1;
Steve Wiseba6d3922010-06-23 15:46:49 +000080module_param(dack_mode, int, 0644);
Steve Wiseb52fe092011-03-11 22:30:01 +000081MODULE_PARM_DESC(dack_mode, "Delayed ack mode (default=1)");
Steve Wiseba6d3922010-06-23 15:46:49 +000082
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053083uint c4iw_max_read_depth = 32;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070084module_param(c4iw_max_read_depth, int, 0644);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +053085MODULE_PARM_DESC(c4iw_max_read_depth,
86 "Per-connection max ORD/IRD (default=32)");
Roland Dreierbe4c9ba2010-05-05 14:45:40 -070087
Steve Wisecfdda9d2010-04-21 15:30:06 -070088static int enable_tcp_timestamps;
89module_param(enable_tcp_timestamps, int, 0644);
90MODULE_PARM_DESC(enable_tcp_timestamps, "Enable tcp timestamps (default=0)");
91
92static int enable_tcp_sack;
93module_param(enable_tcp_sack, int, 0644);
94MODULE_PARM_DESC(enable_tcp_sack, "Enable tcp SACK (default=0)");
95
96static int enable_tcp_window_scaling = 1;
97module_param(enable_tcp_window_scaling, int, 0644);
98MODULE_PARM_DESC(enable_tcp_window_scaling,
99 "Enable tcp window scaling (default=1)");
100
101int c4iw_debug;
102module_param(c4iw_debug, int, 0644);
103MODULE_PARM_DESC(c4iw_debug, "Enable debug logging (default=0)");
104
Steve Wisedf2d5132014-03-19 17:44:44 +0530105static int peer2peer = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700106module_param(peer2peer, int, 0644);
Steve Wisedf2d5132014-03-19 17:44:44 +0530107MODULE_PARM_DESC(peer2peer, "Support peer2peer ULPs (default=1)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700108
109static int p2p_type = FW_RI_INIT_P2PTYPE_READ_REQ;
110module_param(p2p_type, int, 0644);
111MODULE_PARM_DESC(p2p_type, "RDMAP opcode to use for the RTR message: "
112 "1=RDMA_READ 0=RDMA_WRITE (default 1)");
113
114static int ep_timeout_secs = 60;
115module_param(ep_timeout_secs, int, 0644);
116MODULE_PARM_DESC(ep_timeout_secs, "CM Endpoint operation timeout "
117 "in seconds (default=60)");
118
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530119static int mpa_rev = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700120module_param(mpa_rev, int, 0644);
121MODULE_PARM_DESC(mpa_rev, "MPA Revision, 0 supports amso1100, "
Hariprasad Sccd2c302016-05-06 22:17:55 +0530122 "1 is RFC5044 spec compliant, 2 is IETF MPA Peer Connect Draft"
Hariprasad Sb8ac3112015-07-27 14:08:52 +0530123 " compliant (default=2)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700124
125static int markers_enabled;
126module_param(markers_enabled, int, 0644);
127MODULE_PARM_DESC(markers_enabled, "Enable MPA MARKERS (default(0)=disabled)");
128
129static int crc_enabled = 1;
130module_param(crc_enabled, int, 0644);
131MODULE_PARM_DESC(crc_enabled, "Enable MPA CRC (default(1)=enabled)");
132
133static int rcv_win = 256 * 1024;
134module_param(rcv_win, int, 0644);
135MODULE_PARM_DESC(rcv_win, "TCP receive window in bytes (default=256KB)");
136
Steve Wise98ae68b2010-09-10 11:15:41 -0500137static int snd_win = 128 * 1024;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700138module_param(snd_win, int, 0644);
Steve Wise98ae68b2010-09-10 11:15:41 -0500139MODULE_PARM_DESC(snd_win, "TCP send window in bytes (default=128KB)");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700140
Steve Wisecfdda9d2010-04-21 15:30:06 -0700141static struct workqueue_struct *workq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700142
143static struct sk_buff_head rxq;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700144
145static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp);
146static void ep_timeout(unsigned long arg);
147static void connect_reply_upcall(struct c4iw_ep *ep, int status);
Hariprasad S9dec9002016-05-05 01:27:29 +0530148static int sched(struct c4iw_dev *dev, struct sk_buff *skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700149
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700150static LIST_HEAD(timeout_list);
151static spinlock_t timeout_lock;
152
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530153static void deref_cm_id(struct c4iw_ep_common *epc)
154{
155 epc->cm_id->rem_ref(epc->cm_id);
156 epc->cm_id = NULL;
157 set_bit(CM_ID_DEREFED, &epc->history);
158}
159
160static void ref_cm_id(struct c4iw_ep_common *epc)
161{
162 set_bit(CM_ID_REFED, &epc->history);
163 epc->cm_id->add_ref(epc->cm_id);
164}
165
Vipul Pandya325abea2013-01-07 13:11:53 +0000166static void deref_qp(struct c4iw_ep *ep)
167{
168 c4iw_qp_rem_ref(&ep->com.qp->ibqp);
169 clear_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530170 set_bit(QP_DEREFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000171}
172
173static void ref_qp(struct c4iw_ep *ep)
174{
175 set_bit(QP_REFERENCED, &ep->com.flags);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +0530176 set_bit(QP_REFED, &ep->com.history);
Vipul Pandya325abea2013-01-07 13:11:53 +0000177 c4iw_qp_add_ref(&ep->com.qp->ibqp);
178}
179
Steve Wisecfdda9d2010-04-21 15:30:06 -0700180static void start_ep_timer(struct c4iw_ep *ep)
181{
182 PDBG("%s ep %p\n", __func__, ep);
183 if (timer_pending(&ep->timer)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000184 pr_err("%s timer already started! ep %p\n",
185 __func__, ep);
186 return;
187 }
188 clear_bit(TIMEOUT, &ep->com.flags);
189 c4iw_get_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700190 ep->timer.expires = jiffies + ep_timeout_secs * HZ;
191 ep->timer.data = (unsigned long)ep;
192 ep->timer.function = ep_timeout;
193 add_timer(&ep->timer);
194}
195
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500196static int stop_ep_timer(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700197{
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000198 PDBG("%s ep %p stopping\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700199 del_timer_sync(&ep->timer);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500200 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Vipul Pandya1ec779c2013-01-07 13:11:56 +0000201 c4iw_put_ep(&ep->com);
Steve Wiseb33bd0c2014-04-09 09:38:25 -0500202 return 0;
203 }
204 return 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700205}
206
207static int c4iw_l2t_send(struct c4iw_rdev *rdev, struct sk_buff *skb,
208 struct l2t_entry *l2e)
209{
210 int error = 0;
211
212 if (c4iw_fatal_error(rdev)) {
213 kfree_skb(skb);
214 PDBG("%s - device in error state - dropping\n", __func__);
215 return -EIO;
216 }
217 error = cxgb4_l2t_send(rdev->lldi.ports[0], skb, l2e);
218 if (error < 0)
219 kfree_skb(skb);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530220 else if (error == NET_XMIT_DROP)
221 return -ENOMEM;
Steve Wise74594862010-09-10 11:14:58 -0500222 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700223}
224
225int c4iw_ofld_send(struct c4iw_rdev *rdev, struct sk_buff *skb)
226{
227 int error = 0;
228
229 if (c4iw_fatal_error(rdev)) {
230 kfree_skb(skb);
231 PDBG("%s - device in error state - dropping\n", __func__);
232 return -EIO;
233 }
234 error = cxgb4_ofld_send(rdev->lldi.ports[0], skb);
235 if (error < 0)
236 kfree_skb(skb);
Steve Wise74594862010-09-10 11:14:58 -0500237 return error < 0 ? error : 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700238}
239
240static void release_tid(struct c4iw_rdev *rdev, u32 hwtid, struct sk_buff *skb)
241{
242 struct cpl_tid_release *req;
243
244 skb = get_skb(skb, sizeof *req, GFP_KERNEL);
245 if (!skb)
246 return;
247 req = (struct cpl_tid_release *) skb_put(skb, sizeof(*req));
248 INIT_TP_WR(req, hwtid);
249 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_TID_RELEASE, hwtid));
250 set_wr_txq(skb, CPL_PRIORITY_SETUP, 0);
251 c4iw_ofld_send(rdev, skb);
252 return;
253}
254
255static void set_emss(struct c4iw_ep *ep, u16 opt)
256{
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800257 ep->emss = ep->com.dev->rdev.lldi.mtus[TCPOPT_MSS_G(opt)] -
Hariprasad S04524a42014-09-24 03:53:41 +0530258 ((AF_INET == ep->com.remote_addr.ss_family) ?
259 sizeof(struct iphdr) : sizeof(struct ipv6hdr)) -
260 sizeof(struct tcphdr);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700261 ep->mss = ep->emss;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800262 if (TCPOPT_TSTAMP_G(opt))
Hariprasad S04524a42014-09-24 03:53:41 +0530263 ep->emss -= round_up(TCPOLEN_TIMESTAMP, 4);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700264 if (ep->emss < 128)
265 ep->emss = 128;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530266 if (ep->emss & 7)
267 PDBG("Warning: misaligned mtu idx %u mss %u emss=%u\n",
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800268 TCPOPT_MSS_G(opt), ep->mss, ep->emss);
269 PDBG("%s mss_idx %u mss %u emss=%u\n", __func__, TCPOPT_MSS_G(opt),
Steve Wisecfdda9d2010-04-21 15:30:06 -0700270 ep->mss, ep->emss);
271}
272
273static enum c4iw_ep_state state_read(struct c4iw_ep_common *epc)
274{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 enum c4iw_ep_state state;
276
Steve Wise2f5b48c2010-09-10 11:15:36 -0500277 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700278 state = epc->state;
Steve Wise2f5b48c2010-09-10 11:15:36 -0500279 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700280 return state;
281}
282
283static void __state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
284{
285 epc->state = new;
286}
287
288static void state_set(struct c4iw_ep_common *epc, enum c4iw_ep_state new)
289{
Steve Wise2f5b48c2010-09-10 11:15:36 -0500290 mutex_lock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700291 PDBG("%s - %s -> %s\n", __func__, states[epc->state], states[new]);
292 __state_set(epc, new);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500293 mutex_unlock(&epc->mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700294 return;
295}
296
297static void *alloc_ep(int size, gfp_t gfp)
298{
299 struct c4iw_ep_common *epc;
300
301 epc = kzalloc(size, gfp);
302 if (epc) {
303 kref_init(&epc->kref);
Steve Wise2f5b48c2010-09-10 11:15:36 -0500304 mutex_init(&epc->mutex);
Steve Wiseaadc4df2010-09-10 11:15:25 -0500305 c4iw_init_wr_wait(&epc->wr_wait);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700306 }
307 PDBG("%s alloc ep %p\n", __func__, epc);
308 return epc;
309}
310
311void _c4iw_free_ep(struct kref *kref)
312{
313 struct c4iw_ep *ep;
314
315 ep = container_of(kref, struct c4iw_ep, com.kref);
Hariprasad S9dec9002016-05-05 01:27:29 +0530316 PDBG("%s ep %p state %s\n", __func__, ep, states[ep->com.state]);
Vipul Pandya325abea2013-01-07 13:11:53 +0000317 if (test_bit(QP_REFERENCED, &ep->com.flags))
318 deref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700319 if (test_bit(RELEASE_RESOURCES, &ep->com.flags)) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530320 if (ep->com.remote_addr.ss_family == AF_INET6) {
321 struct sockaddr_in6 *sin6 =
322 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600323 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530324
325 cxgb4_clip_release(
326 ep->com.dev->rdev.lldi.ports[0],
327 (const u32 *)&sin6->sin6_addr.s6_addr,
328 1);
329 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +0000330 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700331 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
332 dst_release(ep->dst);
333 cxgb4_l2t_release(ep->l2t);
334 }
335 kfree(ep);
336}
337
338static void release_ep_resources(struct c4iw_ep *ep)
339{
340 set_bit(RELEASE_RESOURCES, &ep->com.flags);
341 c4iw_put_ep(&ep->com);
342}
343
Steve Wisecfdda9d2010-04-21 15:30:06 -0700344static int status2errno(int status)
345{
346 switch (status) {
347 case CPL_ERR_NONE:
348 return 0;
349 case CPL_ERR_CONN_RESET:
350 return -ECONNRESET;
351 case CPL_ERR_ARP_MISS:
352 return -EHOSTUNREACH;
353 case CPL_ERR_CONN_TIMEDOUT:
354 return -ETIMEDOUT;
355 case CPL_ERR_TCAM_FULL:
356 return -ENOMEM;
357 case CPL_ERR_CONN_EXIST:
358 return -EADDRINUSE;
359 default:
360 return -EIO;
361 }
362}
363
364/*
365 * Try and reuse skbs already allocated...
366 */
367static struct sk_buff *get_skb(struct sk_buff *skb, int len, gfp_t gfp)
368{
369 if (skb && !skb_is_nonlinear(skb) && !skb_cloned(skb)) {
370 skb_trim(skb, 0);
371 skb_get(skb);
372 skb_reset_transport_header(skb);
373 } else {
374 skb = alloc_skb(len, gfp);
375 }
Steve Wiseb38a0ad2013-08-06 21:04:37 +0530376 t4_set_arp_err_handler(skb, NULL, NULL);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700377 return skb;
378}
379
Vipul Pandya830662f2013-07-04 16:10:47 +0530380static struct net_device *get_real_dev(struct net_device *egress_dev)
381{
Steve Wise11b8e222014-05-16 12:42:46 -0500382 return rdma_vlan_dev_real_dev(egress_dev) ? : egress_dev;
Vipul Pandya830662f2013-07-04 16:10:47 +0530383}
384
385static int our_interface(struct c4iw_dev *dev, struct net_device *egress_dev)
386{
387 int i;
388
389 egress_dev = get_real_dev(egress_dev);
390 for (i = 0; i < dev->rdev.lldi.nports; i++)
391 if (dev->rdev.lldi.ports[i] == egress_dev)
392 return 1;
393 return 0;
394}
395
396static struct dst_entry *find_route6(struct c4iw_dev *dev, __u8 *local_ip,
397 __u8 *peer_ip, __be16 local_port,
398 __be16 peer_port, u8 tos,
399 __u32 sin6_scope_id)
400{
401 struct dst_entry *dst = NULL;
402
403 if (IS_ENABLED(CONFIG_IPV6)) {
404 struct flowi6 fl6;
405
406 memset(&fl6, 0, sizeof(fl6));
407 memcpy(&fl6.daddr, peer_ip, 16);
408 memcpy(&fl6.saddr, local_ip, 16);
409 if (ipv6_addr_type(&fl6.daddr) & IPV6_ADDR_LINKLOCAL)
410 fl6.flowi6_oif = sin6_scope_id;
411 dst = ip6_route_output(&init_net, NULL, &fl6);
412 if (!dst)
413 goto out;
414 if (!our_interface(dev, ip6_dst_idev(dst)->dev) &&
415 !(ip6_dst_idev(dst)->dev->flags & IFF_LOOPBACK)) {
416 dst_release(dst);
417 dst = NULL;
418 }
419 }
420
421out:
422 return dst;
423}
424
425static struct dst_entry *find_route(struct c4iw_dev *dev, __be32 local_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -0700426 __be32 peer_ip, __be16 local_port,
427 __be16 peer_port, u8 tos)
428{
429 struct rtable *rt;
David S. Miller31e4543d2011-05-03 20:25:42 -0700430 struct flowi4 fl4;
Vipul Pandya830662f2013-07-04 16:10:47 +0530431 struct neighbour *n;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700432
David S. Miller31e4543d2011-05-03 20:25:42 -0700433 rt = ip_route_output_ports(&init_net, &fl4, NULL, peer_ip, local_ip,
David S. Miller78fbfd82011-03-12 00:00:52 -0500434 peer_port, local_port, IPPROTO_TCP,
435 tos, 0);
David S. Millerb23dd4f2011-03-02 14:31:35 -0800436 if (IS_ERR(rt))
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437 return NULL;
Vipul Pandya830662f2013-07-04 16:10:47 +0530438 n = dst_neigh_lookup(&rt->dst, &peer_ip);
439 if (!n)
440 return NULL;
Steve Wisef8e81902014-03-19 17:44:39 +0530441 if (!our_interface(dev, n->dev) &&
442 !(n->dev->flags & IFF_LOOPBACK)) {
Hariprasad Sd4802012014-09-24 03:53:42 +0530443 neigh_release(n);
Vipul Pandya830662f2013-07-04 16:10:47 +0530444 dst_release(&rt->dst);
445 return NULL;
446 }
447 neigh_release(n);
448 return &rt->dst;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700449}
450
451static void arp_failure_discard(void *handle, struct sk_buff *skb)
452{
Hariprasad S9dec9002016-05-05 01:27:29 +0530453 pr_err(MOD "ARP failure\n");
Steve Wisecfdda9d2010-04-21 15:30:06 -0700454 kfree_skb(skb);
455}
456
Hariprasad S9dec9002016-05-05 01:27:29 +0530457enum {
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530458 NUM_FAKE_CPLS = 2,
Hariprasad S9dec9002016-05-05 01:27:29 +0530459 FAKE_CPL_PUT_EP_SAFE = NUM_CPL_CMDS + 0,
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530460 FAKE_CPL_PASS_PUT_EP_SAFE = NUM_CPL_CMDS + 1,
Hariprasad S9dec9002016-05-05 01:27:29 +0530461};
462
463static int _put_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
464{
465 struct c4iw_ep *ep;
466
467 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
468 release_ep_resources(ep);
469 return 0;
470}
471
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530472static int _put_pass_ep_safe(struct c4iw_dev *dev, struct sk_buff *skb)
473{
474 struct c4iw_ep *ep;
475
476 ep = *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *)));
477 c4iw_put_ep(&ep->parent_ep->com);
478 release_ep_resources(ep);
479 return 0;
480}
481
Hariprasad S9dec9002016-05-05 01:27:29 +0530482/*
483 * Fake up a special CPL opcode and call sched() so process_work() will call
484 * _put_ep_safe() in a safe context to free the ep resources. This is needed
485 * because ARP error handlers are called in an ATOMIC context, and
486 * _c4iw_free_ep() needs to block.
487 */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530488static void queue_arp_failure_cpl(struct c4iw_ep *ep, struct sk_buff *skb,
489 int cpl)
Hariprasad S9dec9002016-05-05 01:27:29 +0530490{
491 struct cpl_act_establish *rpl = cplhdr(skb);
492
493 /* Set our special ARP_FAILURE opcode */
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530494 rpl->ot.opcode = cpl;
Hariprasad S9dec9002016-05-05 01:27:29 +0530495
496 /*
497 * Save ep in the skb->cb area, after where sched() will save the dev
498 * ptr.
499 */
500 *((struct c4iw_ep **)(skb->cb + 2 * sizeof(void *))) = ep;
501 sched(ep->com.dev, skb);
502}
503
504/* Handle an ARP failure for an accept */
505static void pass_accept_rpl_arp_failure(void *handle, struct sk_buff *skb)
506{
507 struct c4iw_ep *ep = handle;
508
509 pr_err(MOD "ARP failure during accept - tid %u -dropping connection\n",
510 ep->hwtid);
511
512 __state_set(&ep->com, DEAD);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530513 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PASS_PUT_EP_SAFE);
Hariprasad S9dec9002016-05-05 01:27:29 +0530514}
515
Steve Wisecfdda9d2010-04-21 15:30:06 -0700516/*
517 * Handle an ARP failure for an active open.
518 */
519static void act_open_req_arp_failure(void *handle, struct sk_buff *skb)
520{
Hariprasad S5dab6d32014-06-23 19:12:36 +0530521 struct c4iw_ep *ep = handle;
522
Masanari Iidae3d132d2015-10-16 21:14:29 +0900523 printk(KERN_ERR MOD "ARP failure during connect\n");
Hariprasad S5dab6d32014-06-23 19:12:36 +0530524 connect_reply_upcall(ep, -EHOSTUNREACH);
Hariprasad S9dec9002016-05-05 01:27:29 +0530525 __state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530526 if (ep->com.remote_addr.ss_family == AF_INET6) {
527 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -0600528 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530529 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
530 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
531 }
Hariprasad S5dab6d32014-06-23 19:12:36 +0530532 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
533 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Hariprasad S8d1f1a62016-05-06 22:17:57 +0530534 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700535}
536
537/*
538 * Handle an ARP failure for a CPL_ABORT_REQ. Change it into a no RST variant
539 * and send it along.
540 */
541static void abort_arp_failure(void *handle, struct sk_buff *skb)
542{
Hariprasad S761e19a2016-05-06 22:18:02 +0530543 int ret;
544 struct c4iw_ep *ep = handle;
545 struct c4iw_rdev *rdev = &ep->com.dev->rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700546 struct cpl_abort_req *req = cplhdr(skb);
547
548 PDBG("%s rdev %p\n", __func__, rdev);
549 req->cmd = CPL_ABORT_NO_RST;
Hariprasad S761e19a2016-05-06 22:18:02 +0530550 ret = c4iw_ofld_send(rdev, skb);
551 if (ret) {
552 __state_set(&ep->com, DEAD);
553 queue_arp_failure_cpl(ep, skb, FAKE_CPL_PUT_EP_SAFE);
554 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700555}
556
Hariprasad Sfef44222016-05-05 01:27:33 +0530557static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700558{
559 unsigned int flowclen = 80;
560 struct fw_flowc_wr *flowc;
561 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530562 u16 vlan = ep->l2t->vlan;
563 int nparams;
564
565 if (vlan == CPL_L2T_VLAN_NONE)
566 nparams = 8;
567 else
568 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700569
570 skb = get_skb(skb, flowclen, GFP_KERNEL);
571 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
572
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530573 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530574 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530575 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
576 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700577
578 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530579 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530580 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700581 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
582 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
583 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
584 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
585 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
586 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
587 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
588 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
589 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
590 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
591 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530592 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700593 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
594 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530595 if (nparams == 9) {
596 u16 pri;
597
598 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
599 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
600 flowc->mnemval[8].val = cpu_to_be32(pri);
601 } else {
602 /* Pad WR to 16 byte boundary */
603 flowc->mnemval[8].mnemonic = 0;
604 flowc->mnemval[8].val = 0;
605 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700606 for (i = 0; i < 9; i++) {
607 flowc->mnemval[i].r4[0] = 0;
608 flowc->mnemval[i].r4[1] = 0;
609 flowc->mnemval[i].r4[2] = 0;
610 }
611
612 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530613 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700614}
615
616static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
617{
618 struct cpl_close_con_req *req;
619 struct sk_buff *skb;
620 int wrlen = roundup(sizeof *req, 16);
621
622 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
623 skb = get_skb(NULL, wrlen, gfp);
624 if (!skb) {
625 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
626 return -ENOMEM;
627 }
628 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
629 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
630 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
631 memset(req, 0, wrlen);
632 INIT_TP_WR(req, ep->hwtid);
633 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
634 ep->hwtid));
635 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
636}
637
638static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
639{
640 struct cpl_abort_req *req;
641 int wrlen = roundup(sizeof *req, 16);
642
643 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
644 skb = get_skb(skb, wrlen, gfp);
645 if (!skb) {
646 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
647 __func__);
648 return -ENOMEM;
649 }
650 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad S761e19a2016-05-06 22:18:02 +0530651 t4_set_arp_err_handler(skb, ep, abort_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700652 req = (struct cpl_abort_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_ABORT_REQ, ep->hwtid));
656 req->cmd = CPL_ABORT_SEND_RST;
657 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
658}
659
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530660static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530661 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530662{
Hariprasad S04524a42014-09-24 03:53:41 +0530663 unsigned short hdr_size = (ipv6 ?
664 sizeof(struct ipv6hdr) :
665 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530666 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530667 (use_ts ?
668 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530669 unsigned short data_size = mtu - hdr_size;
670
671 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
672}
673
Steve Wisecfdda9d2010-04-21 15:30:06 -0700674static int send_connect(struct c4iw_ep *ep)
675{
Hariprasad S963cab52015-09-23 17:19:27 +0530676 struct cpl_act_open_req *req = NULL;
677 struct cpl_t5_act_open_req *t5req = NULL;
678 struct cpl_t6_act_open_req *t6req = NULL;
679 struct cpl_act_open_req6 *req6 = NULL;
680 struct cpl_t5_act_open_req6 *t5req6 = NULL;
681 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700682 struct sk_buff *skb;
683 u64 opt0;
684 u32 opt2;
685 unsigned int mtu_idx;
686 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530687 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500688 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600689 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500690 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600691 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500692 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600693 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500694 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600695 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530696 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530697 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
698 u32 isn = (prandom_u32() & ~7UL) - 1;
699
700 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
701 case CHELSIO_T4:
702 sizev4 = sizeof(struct cpl_act_open_req);
703 sizev6 = sizeof(struct cpl_act_open_req6);
704 break;
705 case CHELSIO_T5:
706 sizev4 = sizeof(struct cpl_t5_act_open_req);
707 sizev6 = sizeof(struct cpl_t5_act_open_req6);
708 break;
709 case CHELSIO_T6:
710 sizev4 = sizeof(struct cpl_t6_act_open_req);
711 sizev6 = sizeof(struct cpl_t6_act_open_req6);
712 break;
713 default:
714 pr_err("T%d Chip is not supported\n",
715 CHELSIO_CHIP_VERSION(adapter_type));
716 return -EINVAL;
717 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530718
719 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
720 roundup(sizev4, 16) :
721 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700722
723 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
724
725 skb = get_skb(NULL, wrlen, GFP_KERNEL);
726 if (!skb) {
727 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
728 __func__);
729 return -ENOMEM;
730 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000731 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700732
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530733 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530734 enable_tcp_timestamps,
735 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700736 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530737
738 /*
739 * Specify the largest window that will fit in opt0. The
740 * remainder will be specified in the rx_data_ack.
741 */
742 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800743 if (win > RCV_BUFSIZ_M)
744 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530745
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800746 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800747 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800748 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800749 WND_SCALE_V(wscale) |
750 MSS_IDX_V(mtu_idx) |
751 L2T_IDX_V(ep->l2t->idx) |
752 TX_CHAN_V(ep->tx_chan) |
753 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530754 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800755 ULP_MODE_V(ULP_MODE_TCPDDP) |
756 RCV_BUFSIZ_V(win);
757 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800758 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800759 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700760 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800761 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700762 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800763 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700764 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800765 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530766 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
767 if (peer2peer)
768 isn += 4;
769
Anish Bhattd7990b02014-11-12 17:15:57 -0800770 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530771 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530772 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500773 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530774
775 if (ep->com.remote_addr.ss_family == AF_INET6)
776 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
777 (const u32 *)&la6->sin6_addr.s6_addr, 1);
778
Hariprasad S5dab6d32014-06-23 19:12:36 +0530779 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700780
Hariprasad S963cab52015-09-23 17:19:27 +0530781 if (ep->com.remote_addr.ss_family == AF_INET) {
782 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
783 case CHELSIO_T4:
784 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530785 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530786 break;
787 case CHELSIO_T5:
788 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
789 wrlen);
790 INIT_TP_WR(t5req, 0);
791 req = (struct cpl_act_open_req *)t5req;
792 break;
793 case CHELSIO_T6:
794 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
795 wrlen);
796 INIT_TP_WR(t6req, 0);
797 req = (struct cpl_act_open_req *)t6req;
798 t5req = (struct cpl_t5_act_open_req *)t6req;
799 break;
800 default:
801 pr_err("T%d Chip is not supported\n",
802 CHELSIO_CHIP_VERSION(adapter_type));
803 ret = -EINVAL;
804 goto clip_release;
805 }
806
807 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
808 ((ep->rss_qid<<14) | ep->atid)));
809 req->local_port = la->sin_port;
810 req->peer_port = ra->sin_port;
811 req->local_ip = la->sin_addr.s_addr;
812 req->peer_ip = ra->sin_addr.s_addr;
813 req->opt0 = cpu_to_be64(opt0);
814
815 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530816 req->params = cpu_to_be32(cxgb4_select_ntuple(
817 ep->com.dev->rdev.lldi.ports[0],
818 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530819 req->opt2 = cpu_to_be32(opt2);
820 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530821 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
822 cxgb4_select_ntuple(
823 ep->com.dev->rdev.lldi.ports[0],
824 ep->l2t)));
825 t5req->rsvd = cpu_to_be32(isn);
826 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
827 t5req->opt2 = cpu_to_be32(opt2);
828 }
829 } else {
830 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
831 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530832 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530833 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530834 break;
835 case CHELSIO_T5:
836 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
837 wrlen);
838 INIT_TP_WR(t5req6, 0);
839 req6 = (struct cpl_act_open_req6 *)t5req6;
840 break;
841 case CHELSIO_T6:
842 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
843 wrlen);
844 INIT_TP_WR(t6req6, 0);
845 req6 = (struct cpl_act_open_req6 *)t6req6;
846 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
847 break;
848 default:
849 pr_err("T%d Chip is not supported\n",
850 CHELSIO_CHIP_VERSION(adapter_type));
851 ret = -EINVAL;
852 goto clip_release;
853 }
854
855 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
856 ((ep->rss_qid<<14)|ep->atid)));
857 req6->local_port = la6->sin6_port;
858 req6->peer_port = ra6->sin6_port;
859 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
860 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
861 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
862 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
863 req6->opt0 = cpu_to_be64(opt0);
864
865 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530866 req6->params = cpu_to_be32(cxgb4_select_ntuple(
867 ep->com.dev->rdev.lldi.ports[0],
868 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530869 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530870 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530871 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
872 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530873 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530874 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530875 t5req6->rsvd = cpu_to_be32(isn);
876 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
877 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530878 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000879 }
880
Vipul Pandya793dad92012-12-10 09:30:56 +0000881 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530882 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530883clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530884 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
885 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
886 (const u32 *)&la6->sin6_addr.s6_addr, 1);
887 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888}
889
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530890static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
891 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700892{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530893 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700894 struct fw_ofld_tx_data_wr *req;
895 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530896 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700897
898 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
899
900 BUG_ON(skb_cloned(skb));
901
902 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530903 if (mpa_rev_to_use == 2)
904 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700905 wrlen = roundup(mpalen + sizeof *req, 16);
906 skb = get_skb(skb, wrlen, GFP_KERNEL);
907 if (!skb) {
908 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530909 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700910 }
911 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
912
913 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
914 memset(req, 0, wrlen);
915 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530916 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
917 FW_WR_COMPL_F |
918 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700919 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530920 FW_WR_FLOWID_V(ep->hwtid) |
921 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700922 req->plen = cpu_to_be32(mpalen);
923 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530924 FW_OFLD_TX_DATA_WR_FLUSH_F |
925 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926
927 mpa = (struct mpa_message *)(req + 1);
928 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
929 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530930 (markers_enabled ? MPA_MARKERS : 0) |
931 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530933 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530934 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530935 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530936 ep->retry_with_mpa_v1 = 0;
937 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700938
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530939 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700940 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
941 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530942 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
943 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530944 mpa_v2_params.ird = htons((u16)ep->ird);
945 mpa_v2_params.ord = htons((u16)ep->ord);
946
947 if (peer2peer) {
948 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
949 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
950 mpa_v2_params.ord |=
951 htons(MPA_V2_RDMA_WRITE_RTR);
952 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
953 mpa_v2_params.ord |=
954 htons(MPA_V2_RDMA_READ_RTR);
955 }
956 memcpy(mpa->private_data, &mpa_v2_params,
957 sizeof(struct mpa_v2_conn_params));
958
959 if (ep->plen)
960 memcpy(mpa->private_data +
961 sizeof(struct mpa_v2_conn_params),
962 ep->mpa_pkt + sizeof(*mpa), ep->plen);
963 } else
964 if (ep->plen)
965 memcpy(mpa->private_data,
966 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700967
968 /*
969 * Reference the mpa skb. This ensures the data area
970 * will remain in memory until the hw acks the tx.
971 * Function fw4_ack() will deref it.
972 */
973 skb_get(skb);
974 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
975 BUG_ON(ep->mpa_skb);
976 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530977 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
978 if (ret)
979 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700980 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530981 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700982 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530983 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530984 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700985}
986
987static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
988{
989 int mpalen, wrlen;
990 struct fw_ofld_tx_data_wr *req;
991 struct mpa_message *mpa;
992 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530993 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994
995 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
996
997 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530998 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
999 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001000 wrlen = roundup(mpalen + sizeof *req, 16);
1001
1002 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1003 if (!skb) {
1004 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1005 return -ENOMEM;
1006 }
1007 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1008
1009 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1010 memset(req, 0, wrlen);
1011 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301012 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1013 FW_WR_COMPL_F |
1014 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001015 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301016 FW_WR_FLOWID_V(ep->hwtid) |
1017 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001018 req->plen = cpu_to_be32(mpalen);
1019 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301020 FW_OFLD_TX_DATA_WR_FLUSH_F |
1021 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001022
1023 mpa = (struct mpa_message *)(req + 1);
1024 memset(mpa, 0, sizeof(*mpa));
1025 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1026 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001027 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001028 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301029
1030 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1031 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001032 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1033 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301034 mpa_v2_params.ird = htons(((u16)ep->ird) |
1035 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1036 0));
1037 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1038 (p2p_type ==
1039 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1040 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1041 FW_RI_INIT_P2PTYPE_READ_REQ ?
1042 MPA_V2_RDMA_READ_RTR : 0) : 0));
1043 memcpy(mpa->private_data, &mpa_v2_params,
1044 sizeof(struct mpa_v2_conn_params));
1045
1046 if (ep->plen)
1047 memcpy(mpa->private_data +
1048 sizeof(struct mpa_v2_conn_params), pdata, plen);
1049 } else
1050 if (plen)
1051 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001052
1053 /*
1054 * Reference the mpa skb again. This ensures the data area
1055 * will remain in memory until the hw acks the tx.
1056 * Function fw4_ack() will deref it.
1057 */
1058 skb_get(skb);
1059 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001060 BUG_ON(ep->mpa_skb);
1061 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301062 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001063 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1064}
1065
1066static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1067{
1068 int mpalen, wrlen;
1069 struct fw_ofld_tx_data_wr *req;
1070 struct mpa_message *mpa;
1071 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301072 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001073
1074 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1075
1076 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301077 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1078 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001079 wrlen = roundup(mpalen + sizeof *req, 16);
1080
1081 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1082 if (!skb) {
1083 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1084 return -ENOMEM;
1085 }
1086 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1087
1088 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1089 memset(req, 0, wrlen);
1090 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301091 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1092 FW_WR_COMPL_F |
1093 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001094 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301095 FW_WR_FLOWID_V(ep->hwtid) |
1096 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001097 req->plen = cpu_to_be32(mpalen);
1098 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301099 FW_OFLD_TX_DATA_WR_FLUSH_F |
1100 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001101
1102 mpa = (struct mpa_message *)(req + 1);
1103 memset(mpa, 0, sizeof(*mpa));
1104 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1105 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1106 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301107 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001108 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301109
1110 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1111 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001112 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1113 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301114 mpa_v2_params.ird = htons((u16)ep->ird);
1115 mpa_v2_params.ord = htons((u16)ep->ord);
1116 if (peer2peer && (ep->mpa_attr.p2p_type !=
1117 FW_RI_INIT_P2PTYPE_DISABLED)) {
1118 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1119
1120 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1121 mpa_v2_params.ord |=
1122 htons(MPA_V2_RDMA_WRITE_RTR);
1123 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1124 mpa_v2_params.ord |=
1125 htons(MPA_V2_RDMA_READ_RTR);
1126 }
1127
1128 memcpy(mpa->private_data, &mpa_v2_params,
1129 sizeof(struct mpa_v2_conn_params));
1130
1131 if (ep->plen)
1132 memcpy(mpa->private_data +
1133 sizeof(struct mpa_v2_conn_params), pdata, plen);
1134 } else
1135 if (plen)
1136 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001137
1138 /*
1139 * Reference the mpa skb. This ensures the data area
1140 * will remain in memory until the hw acks the tx.
1141 * Function fw4_ack() will deref it.
1142 */
1143 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001144 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301145 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301146 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001147 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1148}
1149
1150static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1151{
1152 struct c4iw_ep *ep;
1153 struct cpl_act_establish *req = cplhdr(skb);
1154 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001155 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001156 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301157 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001158
1159 ep = lookup_atid(t, atid);
1160
1161 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1162 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1163
Steve Wisea7db89e2014-03-21 20:40:35 +05301164 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165 dst_confirm(ep->dst);
1166
1167 /* setup the hwtid for this connection */
1168 ep->hwtid = tid;
1169 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001170 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001171
1172 ep->snd_seq = be32_to_cpu(req->snd_isn);
1173 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1174
1175 set_emss(ep, ntohs(req->tcp_opt));
1176
1177 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001178 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001179 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001180 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001181
1182 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301183 ret = send_flowc(ep, NULL);
1184 if (ret)
1185 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301186 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301187 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301188 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301189 ret = send_mpa_req(ep, skb, mpa_rev);
1190 if (ret)
1191 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301192 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301194err:
1195 mutex_unlock(&ep->com.mutex);
1196 connect_reply_upcall(ep, -ENOMEM);
1197 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1198 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001199}
1200
Steve Wisebe13b2d2014-03-21 20:40:33 +05301201static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001202{
1203 struct iw_cm_event event;
1204
1205 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1206 memset(&event, 0, sizeof(event));
1207 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301208 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001209 if (ep->com.cm_id) {
1210 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1211 ep, ep->com.cm_id, ep->hwtid);
1212 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301213 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001214 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001215 }
1216}
1217
Steve Wisecfdda9d2010-04-21 15:30:06 -07001218static void peer_close_upcall(struct c4iw_ep *ep)
1219{
1220 struct iw_cm_event event;
1221
1222 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1223 memset(&event, 0, sizeof(event));
1224 event.event = IW_CM_EVENT_DISCONNECT;
1225 if (ep->com.cm_id) {
1226 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1227 ep, ep->com.cm_id, ep->hwtid);
1228 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001229 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001230 }
1231}
1232
1233static void peer_abort_upcall(struct c4iw_ep *ep)
1234{
1235 struct iw_cm_event event;
1236
1237 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1238 memset(&event, 0, sizeof(event));
1239 event.event = IW_CM_EVENT_CLOSE;
1240 event.status = -ECONNRESET;
1241 if (ep->com.cm_id) {
1242 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1243 ep->com.cm_id, ep->hwtid);
1244 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301245 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001246 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001247 }
1248}
1249
1250static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1251{
1252 struct iw_cm_event event;
1253
1254 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1255 memset(&event, 0, sizeof(event));
1256 event.event = IW_CM_EVENT_CONNECT_REPLY;
1257 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301258 memcpy(&event.local_addr, &ep->com.local_addr,
1259 sizeof(ep->com.local_addr));
1260 memcpy(&event.remote_addr, &ep->com.remote_addr,
1261 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001262
1263 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301264 if (!ep->tried_with_mpa_v1) {
1265 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301266 event.ord = ep->ird;
1267 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301268 event.private_data_len = ep->plen -
1269 sizeof(struct mpa_v2_conn_params);
1270 event.private_data = ep->mpa_pkt +
1271 sizeof(struct mpa_message) +
1272 sizeof(struct mpa_v2_conn_params);
1273 } else {
1274 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301275 event.ord = cur_max_read_depth(ep->com.dev);
1276 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301277 event.private_data_len = ep->plen;
1278 event.private_data = ep->mpa_pkt +
1279 sizeof(struct mpa_message);
1280 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001281 }
Roland Dreier85963e42010-07-19 13:13:09 -07001282
1283 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1284 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001285 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001286 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1287
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301288 if (status < 0)
1289 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001290}
1291
Steve Wisebe13b2d2014-03-21 20:40:33 +05301292static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001293{
1294 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301295 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001296
1297 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1298 memset(&event, 0, sizeof(event));
1299 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301300 memcpy(&event.local_addr, &ep->com.local_addr,
1301 sizeof(ep->com.local_addr));
1302 memcpy(&event.remote_addr, &ep->com.remote_addr,
1303 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001304 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301305 if (!ep->tried_with_mpa_v1) {
1306 /* this means MPA_v2 is used */
1307 event.ord = ep->ord;
1308 event.ird = ep->ird;
1309 event.private_data_len = ep->plen -
1310 sizeof(struct mpa_v2_conn_params);
1311 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1312 sizeof(struct mpa_v2_conn_params);
1313 } else {
1314 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301315 event.ord = cur_max_read_depth(ep->com.dev);
1316 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301317 event.private_data_len = ep->plen;
1318 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1319 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301320 c4iw_get_ep(&ep->com);
1321 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1322 &event);
1323 if (ret)
1324 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001325 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001326 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301327 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001328}
1329
1330static void established_upcall(struct c4iw_ep *ep)
1331{
1332 struct iw_cm_event event;
1333
1334 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1335 memset(&event, 0, sizeof(event));
1336 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301337 event.ird = ep->ord;
1338 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001339 if (ep->com.cm_id) {
1340 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1341 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001342 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001343 }
1344}
1345
1346static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1347{
1348 struct cpl_rx_data_ack *req;
1349 struct sk_buff *skb;
1350 int wrlen = roundup(sizeof *req, 16);
1351
1352 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1353 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1354 if (!skb) {
1355 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1356 return 0;
1357 }
1358
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301359 /*
1360 * If we couldn't specify the entire rcv window at connection setup
1361 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1362 * then add the overage in to the credits returned.
1363 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001364 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1365 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301366
Steve Wisecfdda9d2010-04-21 15:30:06 -07001367 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1368 memset(req, 0, wrlen);
1369 INIT_TP_WR(req, ep->hwtid);
1370 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1371 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001372 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301373 RX_DACK_CHANGE_F |
1374 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001375 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001376 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1377 return credits;
1378}
1379
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301380#define RELAXED_IRD_NEGOTIATION 1
1381
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301382/*
1383 * process_mpa_reply - process streaming mode MPA reply
1384 *
1385 * Returns:
1386 *
1387 * 0 upon success indicating a connect request was delivered to the ULP
1388 * or the mpa request is incomplete but valid so far.
1389 *
1390 * 1 if a failure requires the caller to close the connection.
1391 *
1392 * 2 if a failure requires the caller to abort the connection.
1393 */
Steve Wisecc18b932014-04-24 14:31:53 -05001394static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001395{
1396 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301397 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001398 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301399 u16 resp_ird, resp_ord;
1400 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001401 struct c4iw_qp_attributes attrs;
1402 enum c4iw_qp_attr_mask mask;
1403 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001404 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001405
1406 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1407
1408 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 * If we get more than the supported amount of private data
1410 * then we must fail this connection.
1411 */
1412 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1413 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301414 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001415 }
1416
1417 /*
1418 * copy the new data into our accumulation buffer.
1419 */
1420 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1421 skb->len);
1422 ep->mpa_pkt_len += skb->len;
1423
1424 /*
1425 * if we don't even have the mpa message, then bail.
1426 */
1427 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001428 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429 mpa = (struct mpa_message *) ep->mpa_pkt;
1430
1431 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301432 if (mpa->revision > mpa_rev) {
1433 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1434 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001435 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301436 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001437 }
1438 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1439 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301440 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001441 }
1442
1443 plen = ntohs(mpa->private_data_size);
1444
1445 /*
1446 * Fail if there's too much private data.
1447 */
1448 if (plen > MPA_MAX_PRIVATE_DATA) {
1449 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301450 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001451 }
1452
1453 /*
1454 * If plen does not account for pkt size
1455 */
1456 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1457 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301458 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001459 }
1460
1461 ep->plen = (u8) plen;
1462
1463 /*
1464 * If we don't have all the pdata yet, then bail.
1465 * We'll continue process when more data arrives.
1466 */
1467 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001468 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001469
1470 if (mpa->flags & MPA_REJECT) {
1471 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301472 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001473 }
1474
1475 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301476 * Stop mpa timer. If it expired, then
1477 * we ignore the MPA reply. process_timeout()
1478 * will abort the connection.
1479 */
1480 if (stop_ep_timer(ep))
1481 return 0;
1482
1483 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001484 * If we get here we have accumulated the entire mpa
1485 * start reply message including private data. And
1486 * the MPA header is valid.
1487 */
Steve Wisec529fb52014-03-21 20:40:37 +05301488 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001489 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1490 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1491 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301492 ep->mpa_attr.version = mpa->revision;
1493 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1494
1495 if (mpa->revision == 2) {
1496 ep->mpa_attr.enhanced_rdma_conn =
1497 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1498 if (ep->mpa_attr.enhanced_rdma_conn) {
1499 mpa_v2_params = (struct mpa_v2_conn_params *)
1500 (ep->mpa_pkt + sizeof(*mpa));
1501 resp_ird = ntohs(mpa_v2_params->ird) &
1502 MPA_V2_IRD_ORD_MASK;
1503 resp_ord = ntohs(mpa_v2_params->ord) &
1504 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301505 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1506 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301507
1508 /*
1509 * This is a double-check. Ideally, below checks are
1510 * not required since ird/ord stuff has been taken
1511 * care of in c4iw_accept_cr
1512 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301513 if (ep->ird < resp_ord) {
1514 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1515 ep->com.dev->rdev.lldi.max_ordird_qp)
1516 ep->ird = resp_ord;
1517 else
1518 insuff_ird = 1;
1519 } else if (ep->ird > resp_ord) {
1520 ep->ird = resp_ord;
1521 }
1522 if (ep->ord > resp_ird) {
1523 if (RELAXED_IRD_NEGOTIATION)
1524 ep->ord = resp_ird;
1525 else
1526 insuff_ird = 1;
1527 }
1528 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301529 err = -ENOMEM;
1530 ep->ird = resp_ord;
1531 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301532 }
1533
1534 if (ntohs(mpa_v2_params->ird) &
1535 MPA_V2_PEER2PEER_MODEL) {
1536 if (ntohs(mpa_v2_params->ord) &
1537 MPA_V2_RDMA_WRITE_RTR)
1538 ep->mpa_attr.p2p_type =
1539 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1540 else if (ntohs(mpa_v2_params->ord) &
1541 MPA_V2_RDMA_READ_RTR)
1542 ep->mpa_attr.p2p_type =
1543 FW_RI_INIT_P2PTYPE_READ_REQ;
1544 }
1545 }
1546 } else if (mpa->revision == 1)
1547 if (peer2peer)
1548 ep->mpa_attr.p2p_type = p2p_type;
1549
Steve Wisecfdda9d2010-04-21 15:30:06 -07001550 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301551 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1552 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1553 ep->mpa_attr.recv_marker_enabled,
1554 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1555 ep->mpa_attr.p2p_type, p2p_type);
1556
1557 /*
1558 * If responder's RTR does not match with that of initiator, assign
1559 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1560 * generated when moving QP to RTS state.
1561 * A TERM message will be sent after QP has moved to RTS state
1562 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001563 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301564 (ep->mpa_attr.p2p_type != p2p_type)) {
1565 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1566 rtr_mismatch = 1;
1567 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001568
1569 attrs.mpa_attr = ep->mpa_attr;
1570 attrs.max_ird = ep->ird;
1571 attrs.max_ord = ep->ord;
1572 attrs.llp_stream_handle = ep;
1573 attrs.next_state = C4IW_QP_STATE_RTS;
1574
1575 mask = C4IW_QP_ATTR_NEXT_STATE |
1576 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1577 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1578
1579 /* bind QP and TID with INIT_WR */
1580 err = c4iw_modify_qp(ep->com.qp->rhp,
1581 ep->com.qp, mask, &attrs, 1);
1582 if (err)
1583 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301584
1585 /*
1586 * If responder's RTR requirement did not match with what initiator
1587 * supports, generate TERM message
1588 */
1589 if (rtr_mismatch) {
1590 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1591 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1592 attrs.ecode = MPA_NOMATCH_RTR;
1593 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001594 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301595 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001596 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301597 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001598 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301599 goto out;
1600 }
1601
1602 /*
1603 * Generate TERM if initiator IRD is not sufficient for responder
1604 * provided ORD. Currently, we do the same behaviour even when
1605 * responder provided IRD is also not sufficient as regards to
1606 * initiator ORD.
1607 */
1608 if (insuff_ird) {
1609 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1610 __func__);
1611 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1612 attrs.ecode = MPA_INSUFF_IRD;
1613 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001614 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301615 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001616 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301617 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001618 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301619 goto out;
1620 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001621 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301622err_stop_timer:
1623 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001624err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301625 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001626out:
1627 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001628 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001629}
1630
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301631/*
1632 * process_mpa_request - process streaming mode MPA request
1633 *
1634 * Returns:
1635 *
1636 * 0 upon success indicating a connect request was delivered to the ULP
1637 * or the mpa request is incomplete but valid so far.
1638 *
1639 * 1 if a failure requires the caller to close the connection.
1640 *
1641 * 2 if a failure requires the caller to abort the connection.
1642 */
1643static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001644{
1645 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301646 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001647 u16 plen;
1648
1649 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1650
Steve Wisecfdda9d2010-04-21 15:30:06 -07001651 /*
1652 * If we get more than the supported amount of private data
1653 * then we must fail this connection.
1654 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301655 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1656 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001657
1658 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1659
1660 /*
1661 * Copy the new data into our accumulation buffer.
1662 */
1663 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1664 skb->len);
1665 ep->mpa_pkt_len += skb->len;
1666
1667 /*
1668 * If we don't even have the mpa message, then bail.
1669 * We'll continue process when more data arrives.
1670 */
1671 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301672 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001673
1674 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001675 mpa = (struct mpa_message *) ep->mpa_pkt;
1676
1677 /*
1678 * Validate MPA Header.
1679 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301680 if (mpa->revision > mpa_rev) {
1681 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1682 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301683 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001684 }
1685
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301686 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1687 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001688
1689 plen = ntohs(mpa->private_data_size);
1690
1691 /*
1692 * Fail if there's too much private data.
1693 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301694 if (plen > MPA_MAX_PRIVATE_DATA)
1695 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696
1697 /*
1698 * If plen does not account for pkt size
1699 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301700 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1701 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001702 ep->plen = (u8) plen;
1703
1704 /*
1705 * If we don't have all the pdata yet, then bail.
1706 */
1707 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301708 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001709
1710 /*
1711 * If we get here we have accumulated the entire mpa
1712 * start reply message including private data.
1713 */
1714 ep->mpa_attr.initiator = 0;
1715 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1716 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1717 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301718 ep->mpa_attr.version = mpa->revision;
1719 if (mpa->revision == 1)
1720 ep->tried_with_mpa_v1 = 1;
1721 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1722
1723 if (mpa->revision == 2) {
1724 ep->mpa_attr.enhanced_rdma_conn =
1725 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1726 if (ep->mpa_attr.enhanced_rdma_conn) {
1727 mpa_v2_params = (struct mpa_v2_conn_params *)
1728 (ep->mpa_pkt + sizeof(*mpa));
1729 ep->ird = ntohs(mpa_v2_params->ird) &
1730 MPA_V2_IRD_ORD_MASK;
1731 ep->ord = ntohs(mpa_v2_params->ord) &
1732 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301733 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1734 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301735 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1736 if (peer2peer) {
1737 if (ntohs(mpa_v2_params->ord) &
1738 MPA_V2_RDMA_WRITE_RTR)
1739 ep->mpa_attr.p2p_type =
1740 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1741 else if (ntohs(mpa_v2_params->ord) &
1742 MPA_V2_RDMA_READ_RTR)
1743 ep->mpa_attr.p2p_type =
1744 FW_RI_INIT_P2PTYPE_READ_REQ;
1745 }
1746 }
1747 } else if (mpa->revision == 1)
1748 if (peer2peer)
1749 ep->mpa_attr.p2p_type = p2p_type;
1750
Steve Wisecfdda9d2010-04-21 15:30:06 -07001751 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1752 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1753 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1754 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1755 ep->mpa_attr.p2p_type);
1756
Hariprasad Se4b76a22016-05-06 22:17:59 +05301757 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001758
Hariprasad Se4b76a22016-05-06 22:17:59 +05301759 /* drive upcall */
1760 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1761 if (ep->parent_ep->com.state != DEAD) {
1762 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301763 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301764 } else {
1765 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301766 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301767 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301768 return 0;
1769
1770err_unlock_parent:
1771 mutex_unlock(&ep->parent_ep->com.mutex);
1772 goto err_out;
1773err_stop_timer:
1774 (void)stop_ep_timer(ep);
1775err_out:
1776 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001777}
1778
1779static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1780{
1781 struct c4iw_ep *ep;
1782 struct cpl_rx_data *hdr = cplhdr(skb);
1783 unsigned int dlen = ntohs(hdr->len);
1784 unsigned int tid = GET_TID(hdr);
1785 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001786 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001787 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001788
1789 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301790 if (!ep)
1791 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001792 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1793 skb_pull(skb, sizeof(*hdr));
1794 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301795 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001796
Steve Wisecfdda9d2010-04-21 15:30:06 -07001797 /* update RX credits */
1798 update_rx_credits(ep, dlen);
1799
Steve Wisec529fb52014-03-21 20:40:37 +05301800 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001802 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001803 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001804 break;
1805 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001806 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001807 process_mpa_request(ep, skb);
1808 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001809 case FPDU_MODE: {
1810 struct c4iw_qp_attributes attrs;
1811 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001812 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001813 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001814 " qpid %u ep %p state %d tid %u status %d\n",
1815 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301816 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301817 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001818 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001819 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1820 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001821 break;
1822 }
Vipul Pandya15579672013-01-07 13:11:52 +00001823 default:
1824 break;
1825 }
Steve Wisec529fb52014-03-21 20:40:37 +05301826 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001827 if (disconnect)
1828 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001829 return 0;
1830}
1831
1832static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1833{
1834 struct c4iw_ep *ep;
1835 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001836 int release = 0;
1837 unsigned int tid = GET_TID(rpl);
1838 struct tid_info *t = dev->rdev.lldi.tids;
1839
1840 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301841 if (!ep) {
1842 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1843 return 0;
1844 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001845 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001846 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001847 switch (ep->com.state) {
1848 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001849 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001850 __state_set(&ep->com, DEAD);
1851 release = 1;
1852 break;
1853 default:
1854 printk(KERN_ERR "%s ep %p state %d\n",
1855 __func__, ep, ep->com.state);
1856 break;
1857 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001858 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001859
1860 if (release)
1861 release_ep_resources(ep);
1862 return 0;
1863}
1864
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301865static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001866{
1867 struct sk_buff *skb;
1868 struct fw_ofld_connection_wr *req;
1869 unsigned int mtu_idx;
1870 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301871 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301872 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001873
1874 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1875 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1876 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001877 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301878 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301879 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1880 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001881 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001882 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301883 req->le.lport = sin->sin_port;
1884 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001885 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301886 req->le.pport = sin->sin_port;
1887 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001888 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301889 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1890 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001891 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301892 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001893 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001894 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301895 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301896 enable_tcp_timestamps,
1897 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001898 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301899
1900 /*
1901 * Specify the largest window that will fit in opt0. The
1902 * remainder will be specified in the rx_data_ack.
1903 */
1904 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001905 if (win > RCV_BUFSIZ_M)
1906 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301907
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001908 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1909 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001910 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001911 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001912 WND_SCALE_V(wscale) |
1913 MSS_IDX_V(mtu_idx) |
1914 L2T_IDX_V(ep->l2t->idx) |
1915 TX_CHAN_V(ep->tx_chan) |
1916 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301917 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001918 ULP_MODE_V(ULP_MODE_TCPDDP) |
1919 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001920 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1921 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001922 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001923 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001924 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001925 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001926 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001927 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001928 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001929 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001930 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1931 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1932 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001933 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1934 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301935 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001936}
1937
Steve Wisecfdda9d2010-04-21 15:30:06 -07001938/*
1939 * Return whether a failed active open has allocated a TID
1940 */
1941static inline int act_open_has_tid(int status)
1942{
1943 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1944 status != CPL_ERR_ARP_MISS;
1945}
1946
Steve Wise7a2cea22014-03-14 21:52:07 +05301947/* Returns whether a CPL status conveys negative advice.
1948 */
1949static int is_neg_adv(unsigned int status)
1950{
1951 return status == CPL_ERR_RTX_NEG_ADVICE ||
1952 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1953 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1954}
1955
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301956static char *neg_adv_str(unsigned int status)
1957{
1958 switch (status) {
1959 case CPL_ERR_RTX_NEG_ADVICE:
1960 return "Retransmit timeout";
1961 case CPL_ERR_PERSIST_NEG_ADVICE:
1962 return "Persist timeout";
1963 case CPL_ERR_KEEPALV_NEG_ADVICE:
1964 return "Keepalive timeout";
1965 default:
1966 return "Unknown";
1967 }
1968}
1969
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301970static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1971{
1972 ep->snd_win = snd_win;
1973 ep->rcv_win = rcv_win;
1974 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1975}
1976
Vipul Pandya793dad92012-12-10 09:30:56 +00001977#define ACT_OPEN_RETRY_COUNT 2
1978
Vipul Pandya830662f2013-07-04 16:10:47 +05301979static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1980 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301981 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301982{
1983 struct neighbour *n;
1984 int err, step;
1985 struct net_device *pdev;
1986
1987 n = dst_neigh_lookup(dst, peer_ip);
1988 if (!n)
1989 return -ENODEV;
1990
1991 rcu_read_lock();
1992 err = -ENOMEM;
1993 if (n->dev->flags & IFF_LOOPBACK) {
1994 if (iptype == 4)
1995 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1996 else if (IS_ENABLED(CONFIG_IPV6))
1997 for_each_netdev(&init_net, pdev) {
1998 if (ipv6_chk_addr(&init_net,
1999 (struct in6_addr *)peer_ip,
2000 pdev, 1))
2001 break;
2002 }
2003 else
2004 pdev = NULL;
2005
2006 if (!pdev) {
2007 err = -ENODEV;
2008 goto out;
2009 }
2010 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302011 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302012 if (!ep->l2t)
2013 goto out;
2014 ep->mtu = pdev->mtu;
2015 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302016 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2017 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302018 step = cdev->rdev.lldi.ntxq /
2019 cdev->rdev.lldi.nchan;
2020 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2021 step = cdev->rdev.lldi.nrxq /
2022 cdev->rdev.lldi.nchan;
2023 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2024 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2025 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302026 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302027 dev_put(pdev);
2028 } else {
2029 pdev = get_real_dev(n->dev);
2030 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2031 n, pdev, 0);
2032 if (!ep->l2t)
2033 goto out;
2034 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002035 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302036 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2037 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302038 step = cdev->rdev.lldi.ntxq /
2039 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002040 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2041 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302042 step = cdev->rdev.lldi.nrxq /
2043 cdev->rdev.lldi.nchan;
2044 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002045 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302046 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302047
2048 if (clear_mpa_v1) {
2049 ep->retry_with_mpa_v1 = 0;
2050 ep->tried_with_mpa_v1 = 0;
2051 }
2052 }
2053 err = 0;
2054out:
2055 rcu_read_unlock();
2056
2057 neigh_release(n);
2058
2059 return err;
2060}
2061
Vipul Pandya793dad92012-12-10 09:30:56 +00002062static int c4iw_reconnect(struct c4iw_ep *ep)
2063{
2064 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302065 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002066 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302067 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002068 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302069 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002070 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302071 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002072 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302073 int iptype;
2074 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002075
2076 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2077 init_timer(&ep->timer);
2078
2079 /*
2080 * Allocate an active TID to initiate a TCP connection.
2081 */
2082 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2083 if (ep->atid == -1) {
2084 pr_err("%s - cannot alloc atid.\n", __func__);
2085 err = -ENOMEM;
2086 goto fail2;
2087 }
2088 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2089
2090 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002091 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302092 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2093 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302094 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302095 iptype = 4;
2096 ra = (__u8 *)&raddr->sin_addr;
2097 } else {
2098 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2099 raddr6->sin6_addr.s6_addr,
2100 laddr6->sin6_port, raddr6->sin6_port, 0,
2101 raddr6->sin6_scope_id);
2102 iptype = 6;
2103 ra = (__u8 *)&raddr6->sin6_addr;
2104 }
2105 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002106 pr_err("%s - cannot find route.\n", __func__);
2107 err = -EHOSTUNREACH;
2108 goto fail3;
2109 }
Hariprasad S963cab52015-09-23 17:19:27 +05302110 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302111 ep->com.dev->rdev.lldi.adapter_type,
2112 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302113 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002114 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002115 goto fail4;
2116 }
2117
2118 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2119 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2120 ep->l2t->idx);
2121
2122 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302123 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002124
2125 /* send connect request to rnic */
2126 err = send_connect(ep);
2127 if (!err)
2128 goto out;
2129
2130 cxgb4_l2t_release(ep->l2t);
2131fail4:
2132 dst_release(ep->dst);
2133fail3:
2134 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2135 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2136fail2:
2137 /*
2138 * remember to send notification to upper layer.
2139 * We are in here so the upper layer is not aware that this is
2140 * re-connect attempt and so, upper layer is still waiting for
2141 * response of 1st connect request.
2142 */
2143 connect_reply_upcall(ep, -ECONNRESET);
2144 c4iw_put_ep(&ep->com);
2145out:
2146 return err;
2147}
2148
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2150{
2151 struct c4iw_ep *ep;
2152 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002153 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2154 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002155 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002156 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302157 struct sockaddr_in *la;
2158 struct sockaddr_in *ra;
2159 struct sockaddr_in6 *la6;
2160 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302161 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002162
2163 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002164 la = (struct sockaddr_in *)&ep->com.local_addr;
2165 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2166 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2167 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002168
2169 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2170 status, status2errno(status));
2171
Steve Wise7a2cea22014-03-14 21:52:07 +05302172 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302173 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2174 __func__, atid, status, neg_adv_str(status));
2175 ep->stats.connect_neg_adv++;
2176 mutex_lock(&dev->rdev.stats.lock);
2177 dev->rdev.stats.neg_adv++;
2178 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002179 return 0;
2180 }
2181
Vipul Pandya793dad92012-12-10 09:30:56 +00002182 set_bit(ACT_OPEN_RPL, &ep->com.history);
2183
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302184 /*
2185 * Log interesting failures.
2186 */
2187 switch (status) {
2188 case CPL_ERR_CONN_RESET:
2189 case CPL_ERR_CONN_TIMEDOUT:
2190 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002191 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302192 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002193 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302194 mutex_unlock(&dev->rdev.stats.lock);
2195 if (ep->com.local_addr.ss_family == AF_INET &&
2196 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302197 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2198 ntohl(rpl->atid_status))));
2199 if (ret)
2200 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002201 return 0;
2202 }
2203 break;
2204 case CPL_ERR_CONN_EXIST:
2205 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2206 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302207 if (ep->com.remote_addr.ss_family == AF_INET6) {
2208 struct sockaddr_in6 *sin6 =
2209 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002210 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302211 cxgb4_clip_release(
2212 ep->com.dev->rdev.lldi.ports[0],
2213 (const u32 *)
2214 &sin6->sin6_addr.s6_addr, 1);
2215 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002216 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2217 atid);
2218 cxgb4_free_atid(t, atid);
2219 dst_release(ep->dst);
2220 cxgb4_l2t_release(ep->l2t);
2221 c4iw_reconnect(ep);
2222 return 0;
2223 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002224 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302225 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302226 if (ep->com.local_addr.ss_family == AF_INET) {
2227 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2228 atid, status, status2errno(status),
2229 &la->sin_addr.s_addr, ntohs(la->sin_port),
2230 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2231 } else {
2232 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2233 atid, status, status2errno(status),
2234 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2235 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2236 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302237 break;
2238 }
2239
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302240fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002241 connect_reply_upcall(ep, status2errno(status));
2242 state_set(&ep->com, DEAD);
2243
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302244 if (ep->com.remote_addr.ss_family == AF_INET6) {
2245 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002246 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302247 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2248 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2249 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002250 if (status && act_open_has_tid(status))
2251 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2252
Vipul Pandya793dad92012-12-10 09:30:56 +00002253 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002254 cxgb4_free_atid(t, atid);
2255 dst_release(ep->dst);
2256 cxgb4_l2t_release(ep->l2t);
2257 c4iw_put_ep(&ep->com);
2258
2259 return 0;
2260}
2261
2262static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2263{
2264 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2265 struct tid_info *t = dev->rdev.lldi.tids;
2266 unsigned int stid = GET_TID(rpl);
2267 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2268
2269 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002270 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2271 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 }
2273 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2274 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002275 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002276
Vipul Pandya1cab7752012-12-10 09:30:55 +00002277out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002278 return 0;
2279}
2280
Steve Wisecfdda9d2010-04-21 15:30:06 -07002281static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2282{
2283 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2284 struct tid_info *t = dev->rdev.lldi.tids;
2285 unsigned int stid = GET_TID(rpl);
2286 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2287
2288 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002289 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002290 return 0;
2291}
2292
Hariprasad S9dec9002016-05-05 01:27:29 +05302293static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2294 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002295{
2296 struct cpl_pass_accept_rpl *rpl;
2297 unsigned int mtu_idx;
2298 u64 opt0;
2299 u32 opt2;
2300 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302301 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302302 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302303 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002304
2305 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2306 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302307
Steve Wisecfdda9d2010-04-21 15:30:06 -07002308 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302309 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302310 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302311 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2312 rpl5 = (void *)rpl;
2313 INIT_TP_WR(rpl5, ep->hwtid);
2314 } else {
2315 skb_trim(skb, sizeof(*rpl));
2316 INIT_TP_WR(rpl, ep->hwtid);
2317 }
2318 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2319 ep->hwtid));
2320
2321 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302322 enable_tcp_timestamps && req->tcpopt.tstamp,
2323 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002324 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302325
2326 /*
2327 * Specify the largest window that will fit in opt0. The
2328 * remainder will be specified in the rx_data_ack.
2329 */
2330 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002331 if (win > RCV_BUFSIZ_M)
2332 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002333 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002334 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002335 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002336 WND_SCALE_V(wscale) |
2337 MSS_IDX_V(mtu_idx) |
2338 L2T_IDX_V(ep->l2t->idx) |
2339 TX_CHAN_V(ep->tx_chan) |
2340 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002341 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002342 ULP_MODE_V(ULP_MODE_TCPDDP) |
2343 RCV_BUFSIZ_V(win);
2344 opt2 = RX_CHANNEL_V(0) |
2345 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002346
2347 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002348 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002349 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002350 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002351 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002352 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002353 if (enable_ecn) {
2354 const struct tcphdr *tcph;
2355 u32 hlen = ntohl(req->hdr_len);
2356
Hariprasad S963cab52015-09-23 17:19:27 +05302357 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2358 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2359 IP_HDR_LEN_G(hlen);
2360 else
2361 tcph = (const void *)(req + 1) +
2362 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002363 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002364 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002365 }
Hariprasad S963cab52015-09-23 17:19:27 +05302366 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302367 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002368 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302369 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302370 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302371 rpl5 = (void *)rpl;
2372 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2373 if (peer2peer)
2374 isn += 4;
2375 rpl5->iss = cpu_to_be32(isn);
2376 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002377 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002378
Steve Wisecfdda9d2010-04-21 15:30:06 -07002379 rpl->opt0 = cpu_to_be64(opt0);
2380 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002381 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302382 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002383
Hariprasad S9dec9002016-05-05 01:27:29 +05302384 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002385}
2386
Vipul Pandya830662f2013-07-04 16:10:47 +05302387static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002388{
Vipul Pandya830662f2013-07-04 16:10:47 +05302389 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002390 BUG_ON(skb_cloned(skb));
2391 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392 release_tid(&dev->rdev, hwtid, skb);
2393 return;
2394}
2395
Hariprasad S963cab52015-09-23 17:19:27 +05302396static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2397 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002398 __be16 *local_port, __be16 *peer_port)
2399{
Hariprasad S963cab52015-09-23 17:19:27 +05302400 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2401 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2402 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2403 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2404 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2405 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002406 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302407 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002408 struct tcphdr *tcp = (struct tcphdr *)
2409 ((u8 *)(req + 1) + eth_len + ip_len);
2410
Vipul Pandya830662f2013-07-04 16:10:47 +05302411 if (ip->version == 4) {
2412 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2413 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2414 ntohs(tcp->dest));
2415 *iptype = 4;
2416 memcpy(peer_ip, &ip->saddr, 4);
2417 memcpy(local_ip, &ip->daddr, 4);
2418 } else {
2419 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2420 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2421 ntohs(tcp->dest));
2422 *iptype = 6;
2423 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2424 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2425 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002426 *peer_port = tcp->source;
2427 *local_port = tcp->dest;
2428
2429 return;
2430}
2431
2432static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2433{
Vipul Pandya793dad92012-12-10 09:30:56 +00002434 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002436 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002437 struct tid_info *t = dev->rdev.lldi.tids;
2438 unsigned int hwtid = GET_TID(req);
2439 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302440 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002441 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302442 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002443 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002444 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302445 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302446 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302447 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002448
2449 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002450 if (!parent_ep) {
2451 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2452 goto reject;
2453 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002454
Steve Wisecfdda9d2010-04-21 15:30:06 -07002455 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302456 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457 goto reject;
2458 }
2459
Hariprasad S963cab52015-09-23 17:19:27 +05302460 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2461 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302462
Steve Wisecfdda9d2010-04-21 15:30:06 -07002463 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302464 if (iptype == 4) {
2465 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2466 , __func__, parent_ep, hwtid,
2467 local_ip, peer_ip, ntohs(local_port),
2468 ntohs(peer_port), peer_mss);
2469 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2470 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302471 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302472 } else {
2473 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2474 , __func__, parent_ep, hwtid,
2475 local_ip, peer_ip, ntohs(local_port),
2476 ntohs(peer_port), peer_mss);
2477 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002478 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302479 ((struct sockaddr_in6 *)
2480 &parent_ep->com.local_addr)->sin6_scope_id);
2481 }
2482 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002483 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2484 __func__);
2485 goto reject;
2486 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002487
2488 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2489 if (!child_ep) {
2490 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2491 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002492 dst_release(dst);
2493 goto reject;
2494 }
David Miller3786cf12011-12-02 16:52:31 +00002495
Hariprasad S963cab52015-09-23 17:19:27 +05302496 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302497 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002498 if (err) {
2499 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2500 __func__);
2501 dst_release(dst);
2502 kfree(child_ep);
2503 goto reject;
2504 }
2505
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302506 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2507 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2508 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2509 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002510
Steve Wisecfdda9d2010-04-21 15:30:06 -07002511 state_set(&child_ep->com, CONNECTING);
2512 child_ep->com.dev = dev;
2513 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002514
Vipul Pandya830662f2013-07-04 16:10:47 +05302515 if (iptype == 4) {
2516 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002517 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002518
Vipul Pandya830662f2013-07-04 16:10:47 +05302519 sin->sin_family = PF_INET;
2520 sin->sin_port = local_port;
2521 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002522
2523 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2524 sin->sin_family = PF_INET;
2525 sin->sin_port = ((struct sockaddr_in *)
2526 &parent_ep->com.local_addr)->sin_port;
2527 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2528
Steve Wise170003c2016-02-26 09:18:03 -06002529 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302530 sin->sin_family = PF_INET;
2531 sin->sin_port = peer_port;
2532 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2533 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002534 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302535 sin6->sin6_family = PF_INET6;
2536 sin6->sin6_port = local_port;
2537 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002538
2539 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2540 sin6->sin6_family = PF_INET6;
2541 sin6->sin6_port = ((struct sockaddr_in6 *)
2542 &parent_ep->com.local_addr)->sin6_port;
2543 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2544
Steve Wise170003c2016-02-26 09:18:03 -06002545 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302546 sin6->sin6_family = PF_INET6;
2547 sin6->sin6_port = peer_port;
2548 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2549 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002550
Steve Wisecfdda9d2010-04-21 15:30:06 -07002551 c4iw_get_ep(&parent_ep->com);
2552 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302553 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002554 child_ep->dst = dst;
2555 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002556
2557 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002558 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002559
2560 init_timer(&child_ep->timer);
2561 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002562 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302563 if (accept_cr(child_ep, skb, req)) {
2564 c4iw_put_ep(&parent_ep->com);
2565 release_ep_resources(child_ep);
2566 } else {
2567 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2568 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302569 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002570 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302571 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2572 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2573 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002574 goto out;
2575reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302576 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002577out:
2578 return 0;
2579}
2580
2581static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2582{
2583 struct c4iw_ep *ep;
2584 struct cpl_pass_establish *req = cplhdr(skb);
2585 struct tid_info *t = dev->rdev.lldi.tids;
2586 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302587 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002588
2589 ep = lookup_tid(t, tid);
2590 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2591 ep->snd_seq = be32_to_cpu(req->snd_isn);
2592 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2593
Vipul Pandya1cab7752012-12-10 09:30:55 +00002594 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2595 ntohs(req->tcp_opt));
2596
Steve Wisecfdda9d2010-04-21 15:30:06 -07002597 set_emss(ep, ntohs(req->tcp_opt));
2598
2599 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302600 mutex_lock(&ep->com.mutex);
2601 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002603 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302604 ret = send_flowc(ep, skb);
2605 mutex_unlock(&ep->com.mutex);
2606 if (ret)
2607 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002608
2609 return 0;
2610}
2611
2612static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2613{
2614 struct cpl_peer_close *hdr = cplhdr(skb);
2615 struct c4iw_ep *ep;
2616 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002617 int disconnect = 1;
2618 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002619 struct tid_info *t = dev->rdev.lldi.tids;
2620 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002621 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002622
2623 ep = lookup_tid(t, tid);
2624 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2625 dst_confirm(ep->dst);
2626
Vipul Pandya793dad92012-12-10 09:30:56 +00002627 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002628 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002629 switch (ep->com.state) {
2630 case MPA_REQ_WAIT:
2631 __state_set(&ep->com, CLOSING);
2632 break;
2633 case MPA_REQ_SENT:
2634 __state_set(&ep->com, CLOSING);
2635 connect_reply_upcall(ep, -ECONNRESET);
2636 break;
2637 case MPA_REQ_RCVD:
2638
2639 /*
2640 * We're gonna mark this puppy DEAD, but keep
2641 * the reference on it until the ULP accepts or
2642 * rejects the CR. Also wake up anyone waiting
2643 * in rdma connection migration (see c4iw_accept_cr()).
2644 */
2645 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002646 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002647 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002648 break;
2649 case MPA_REP_SENT:
2650 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002651 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002652 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002653 break;
2654 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002655 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002656 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002657 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002658 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002659 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002660 if (ret != -ECONNRESET) {
2661 peer_close_upcall(ep);
2662 disconnect = 1;
2663 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002664 break;
2665 case ABORTING:
2666 disconnect = 0;
2667 break;
2668 case CLOSING:
2669 __state_set(&ep->com, MORIBUND);
2670 disconnect = 0;
2671 break;
2672 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002673 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002674 if (ep->com.cm_id && ep->com.qp) {
2675 attrs.next_state = C4IW_QP_STATE_IDLE;
2676 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2677 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2678 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302679 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002680 __state_set(&ep->com, DEAD);
2681 release = 1;
2682 disconnect = 0;
2683 break;
2684 case DEAD:
2685 disconnect = 0;
2686 break;
2687 default:
2688 BUG_ON(1);
2689 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002690 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002691 if (disconnect)
2692 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2693 if (release)
2694 release_ep_resources(ep);
2695 return 0;
2696}
2697
Steve Wisecfdda9d2010-04-21 15:30:06 -07002698static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2699{
2700 struct cpl_abort_req_rss *req = cplhdr(skb);
2701 struct c4iw_ep *ep;
2702 struct cpl_abort_rpl *rpl;
2703 struct sk_buff *rpl_skb;
2704 struct c4iw_qp_attributes attrs;
2705 int ret;
2706 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002707 struct tid_info *t = dev->rdev.lldi.tids;
2708 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002709
2710 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302711 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302712 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2713 __func__, ep->hwtid, req->status,
2714 neg_adv_str(req->status));
2715 ep->stats.abort_neg_adv++;
2716 mutex_lock(&dev->rdev.stats.lock);
2717 dev->rdev.stats.neg_adv++;
2718 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002719 return 0;
2720 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002721 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2722 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002723 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002724
2725 /*
2726 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302727 * However, this is not needed if com state is just
2728 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002729 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302730 if (ep->com.state != MPA_REQ_SENT)
2731 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002732
2733 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734 switch (ep->com.state) {
2735 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302736 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002737 break;
2738 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002739 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002740 break;
2741 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002742 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002743 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302744 connect_reply_upcall(ep, -ECONNRESET);
2745 else {
2746 /*
2747 * we just don't send notification upwards because we
2748 * want to retry with mpa_v1 without upper layers even
2749 * knowing it.
2750 *
2751 * do some housekeeping so as to re-initiate the
2752 * connection
2753 */
2754 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2755 mpa_rev);
2756 ep->retry_with_mpa_v1 = 1;
2757 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002758 break;
2759 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760 break;
2761 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002762 break;
2763 case MORIBUND:
2764 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002765 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002766 /*FALLTHROUGH*/
2767 case FPDU_MODE:
2768 if (ep->com.cm_id && ep->com.qp) {
2769 attrs.next_state = C4IW_QP_STATE_ERROR;
2770 ret = c4iw_modify_qp(ep->com.qp->rhp,
2771 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2772 &attrs, 1);
2773 if (ret)
2774 printk(KERN_ERR MOD
2775 "%s - qp <- error failed!\n",
2776 __func__);
2777 }
2778 peer_abort_upcall(ep);
2779 break;
2780 case ABORTING:
2781 break;
2782 case DEAD:
2783 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002784 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002785 return 0;
2786 default:
2787 BUG_ON(1);
2788 break;
2789 }
2790 dst_confirm(ep->dst);
2791 if (ep->com.state != ABORTING) {
2792 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302793 /* we don't release if we want to retry with mpa_v1 */
2794 if (!ep->retry_with_mpa_v1)
2795 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002796 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002797 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002798
2799 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2800 if (!rpl_skb) {
2801 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2802 __func__);
2803 release = 1;
2804 goto out;
2805 }
2806 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2807 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2808 INIT_TP_WR(rpl, ep->hwtid);
2809 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2810 rpl->cmd = CPL_ABORT_NO_RST;
2811 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2812out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002813 if (release)
2814 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002815 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302816 if (ep->com.remote_addr.ss_family == AF_INET6) {
2817 struct sockaddr_in6 *sin6 =
2818 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002819 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302820 cxgb4_clip_release(
2821 ep->com.dev->rdev.lldi.ports[0],
2822 (const u32 *)&sin6->sin6_addr.s6_addr,
2823 1);
2824 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002825 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302826 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2827 dst_release(ep->dst);
2828 cxgb4_l2t_release(ep->l2t);
2829 c4iw_reconnect(ep);
2830 }
2831
Steve Wisecfdda9d2010-04-21 15:30:06 -07002832 return 0;
2833}
2834
2835static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2836{
2837 struct c4iw_ep *ep;
2838 struct c4iw_qp_attributes attrs;
2839 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002840 int release = 0;
2841 struct tid_info *t = dev->rdev.lldi.tids;
2842 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002843
2844 ep = lookup_tid(t, tid);
2845
2846 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2847 BUG_ON(!ep);
2848
2849 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002850 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302851 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002852 switch (ep->com.state) {
2853 case CLOSING:
2854 __state_set(&ep->com, MORIBUND);
2855 break;
2856 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002857 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002858 if ((ep->com.cm_id) && (ep->com.qp)) {
2859 attrs.next_state = C4IW_QP_STATE_IDLE;
2860 c4iw_modify_qp(ep->com.qp->rhp,
2861 ep->com.qp,
2862 C4IW_QP_ATTR_NEXT_STATE,
2863 &attrs, 1);
2864 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302865 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002866 __state_set(&ep->com, DEAD);
2867 release = 1;
2868 break;
2869 case ABORTING:
2870 case DEAD:
2871 break;
2872 default:
2873 BUG_ON(1);
2874 break;
2875 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002876 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002877 if (release)
2878 release_ep_resources(ep);
2879 return 0;
2880}
2881
2882static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2883{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002884 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002885 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002886 unsigned int tid = GET_TID(rpl);
2887 struct c4iw_ep *ep;
2888 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002889
2890 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002891 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002892
Steve Wise30c95c22011-05-09 22:06:22 -07002893 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002894 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2895 ep->com.qp->wq.sq.qid);
2896 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2897 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2898 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2899 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002900 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002901
Steve Wisecfdda9d2010-04-21 15:30:06 -07002902 return 0;
2903}
2904
2905/*
2906 * Upcall from the adapter indicating data has been transmitted.
2907 * For us its just the single MPA request or reply. We can now free
2908 * the skb holding the mpa message.
2909 */
2910static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2911{
2912 struct c4iw_ep *ep;
2913 struct cpl_fw4_ack *hdr = cplhdr(skb);
2914 u8 credits = hdr->credits;
2915 unsigned int tid = GET_TID(hdr);
2916 struct tid_info *t = dev->rdev.lldi.tids;
2917
2918
2919 ep = lookup_tid(t, tid);
2920 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2921 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002922 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2923 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002924 return 0;
2925 }
2926
2927 dst_confirm(ep->dst);
2928 if (ep->mpa_skb) {
2929 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2930 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2931 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2932 kfree_skb(ep->mpa_skb);
2933 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302934 mutex_lock(&ep->com.mutex);
2935 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2936 stop_ep_timer(ep);
2937 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002938 }
2939 return 0;
2940}
2941
Steve Wisecfdda9d2010-04-21 15:30:06 -07002942int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2943{
Steve Wisea7db89e2014-03-21 20:40:35 +05302944 int err = 0;
2945 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 struct c4iw_ep *ep = to_ep(cm_id);
2947 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2948
Steve Wisea7db89e2014-03-21 20:40:35 +05302949 mutex_lock(&ep->com.mutex);
2950 if (ep->com.state == DEAD) {
2951 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002952 c4iw_put_ep(&ep->com);
2953 return -ECONNRESET;
2954 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002955 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302956 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002957 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302958 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002959 else {
2960 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302961 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302963 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302964 if (disconnect) {
2965 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302966 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302967 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002968 c4iw_put_ep(&ep->com);
2969 return 0;
2970}
2971
2972int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2973{
2974 int err;
2975 struct c4iw_qp_attributes attrs;
2976 enum c4iw_qp_attr_mask mask;
2977 struct c4iw_ep *ep = to_ep(cm_id);
2978 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2979 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302980 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002981
2982 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302983
2984 mutex_lock(&ep->com.mutex);
2985 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002986 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302987 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002988 }
2989
Steve Wisea7db89e2014-03-21 20:40:35 +05302990 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002991 BUG_ON(!qp);
2992
Vipul Pandya793dad92012-12-10 09:30:56 +00002993 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302994 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2995 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002996 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302997 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002998 }
2999
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303000 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
3001 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303002 if (RELAXED_IRD_NEGOTIATION) {
3003 ep->ord = ep->ird;
3004 } else {
3005 ep->ird = conn_param->ird;
3006 ep->ord = conn_param->ord;
3007 send_mpa_reject(ep, conn_param->private_data,
3008 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303009 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303010 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303011 }
3012 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303013 if (conn_param->ird < ep->ord) {
3014 if (RELAXED_IRD_NEGOTIATION &&
3015 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3016 conn_param->ird = ep->ord;
3017 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303018 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303019 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303020 }
3021 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303022 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003023 ep->ird = conn_param->ird;
3024 ep->ord = conn_param->ord;
3025
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303026 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303027 if (peer2peer && ep->ird == 0)
3028 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303029 } else {
3030 if (peer2peer &&
3031 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303032 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303033 ep->ird = 1;
3034 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003035
3036 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3037
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303038 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303039 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303040 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003041 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303042
Steve Wisecfdda9d2010-04-21 15:30:06 -07003043 /* bind QP to EP and move to RTS */
3044 attrs.mpa_attr = ep->mpa_attr;
3045 attrs.max_ird = ep->ird;
3046 attrs.max_ord = ep->ord;
3047 attrs.llp_stream_handle = ep;
3048 attrs.next_state = C4IW_QP_STATE_RTS;
3049
3050 /* bind QP and TID with INIT_WR */
3051 mask = C4IW_QP_ATTR_NEXT_STATE |
3052 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3053 C4IW_QP_ATTR_MPA_ATTR |
3054 C4IW_QP_ATTR_MAX_IRD |
3055 C4IW_QP_ATTR_MAX_ORD;
3056
3057 err = c4iw_modify_qp(ep->com.qp->rhp,
3058 ep->com.qp, mask, &attrs, 1);
3059 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303060 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303061
3062 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063 err = send_mpa_reply(ep, conn_param->private_data,
3064 conn_param->private_data_len);
3065 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303066 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003067
Steve Wisea7db89e2014-03-21 20:40:35 +05303068 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003069 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303070 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003071 c4iw_put_ep(&ep->com);
3072 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303073err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303074 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303075err_abort:
3076 abort = 1;
3077err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303078 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303079 if (abort)
3080 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003081 c4iw_put_ep(&ep->com);
3082 return err;
3083}
3084
Vipul Pandya830662f2013-07-04 16:10:47 +05303085static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3086{
3087 struct in_device *ind;
3088 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003089 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3090 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303091
3092 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3093 if (!ind)
3094 return -EADDRNOTAVAIL;
3095 for_primary_ifa(ind) {
3096 laddr->sin_addr.s_addr = ifa->ifa_address;
3097 raddr->sin_addr.s_addr = ifa->ifa_address;
3098 found = 1;
3099 break;
3100 }
3101 endfor_ifa(ind);
3102 in_dev_put(ind);
3103 return found ? 0 : -EADDRNOTAVAIL;
3104}
3105
3106static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3107 unsigned char banned_flags)
3108{
3109 struct inet6_dev *idev;
3110 int err = -EADDRNOTAVAIL;
3111
3112 rcu_read_lock();
3113 idev = __in6_dev_get(dev);
3114 if (idev != NULL) {
3115 struct inet6_ifaddr *ifp;
3116
3117 read_lock_bh(&idev->lock);
3118 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3119 if (ifp->scope == IFA_LINK &&
3120 !(ifp->flags & banned_flags)) {
3121 memcpy(addr, &ifp->addr, 16);
3122 err = 0;
3123 break;
3124 }
3125 }
3126 read_unlock_bh(&idev->lock);
3127 }
3128 rcu_read_unlock();
3129 return err;
3130}
3131
3132static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3133{
3134 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003135 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3136 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303137
Nicholas Krause54b9a962015-08-26 23:00:59 -04003138 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303139 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3140 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3141 return 0;
3142 }
3143 return -EADDRNOTAVAIL;
3144}
3145
Steve Wisecfdda9d2010-04-21 15:30:06 -07003146int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3147{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003148 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3149 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003150 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003151 struct sockaddr_in *laddr;
3152 struct sockaddr_in *raddr;
3153 struct sockaddr_in6 *laddr6;
3154 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303155 __u8 *ra;
3156 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003157
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303158 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3159 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003160 err = -EINVAL;
3161 goto out;
3162 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003163 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3164 if (!ep) {
3165 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3166 err = -ENOMEM;
3167 goto out;
3168 }
3169 init_timer(&ep->timer);
3170 ep->plen = conn_param->private_data_len;
3171 if (ep->plen)
3172 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3173 conn_param->private_data, ep->plen);
3174 ep->ird = conn_param->ird;
3175 ep->ord = conn_param->ord;
3176
3177 if (peer2peer && ep->ord == 0)
3178 ep->ord = 1;
3179
Steve Wisecfdda9d2010-04-21 15:30:06 -07003180 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303181 ref_cm_id(&ep->com);
3182 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003183 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303184 if (!ep->com.qp) {
3185 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3186 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003187 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303188 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003189 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003190 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3191 ep->com.qp, cm_id);
3192
3193 /*
3194 * Allocate an active TID to initiate a TCP connection.
3195 */
3196 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3197 if (ep->atid == -1) {
3198 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3199 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003200 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003201 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003202 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003203
Steve Wise170003c2016-02-26 09:18:03 -06003204 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003205 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003206 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003207 sizeof(ep->com.remote_addr));
3208
Steve Wise170003c2016-02-26 09:18:03 -06003209 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3210 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3211 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3212 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003213
Steve Wise170003c2016-02-26 09:18:03 -06003214 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303215 iptype = 4;
3216 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003217
Vipul Pandya830662f2013-07-04 16:10:47 +05303218 /*
3219 * Handle loopback requests to INADDR_ANY.
3220 */
3221 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3222 err = pick_local_ipaddrs(dev, cm_id);
3223 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003224 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303225 }
3226
3227 /* find a route */
3228 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3229 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3230 ra, ntohs(raddr->sin_port));
3231 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3232 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303233 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303234 } else {
3235 iptype = 6;
3236 ra = (__u8 *)&raddr6->sin6_addr;
3237
3238 /*
3239 * Handle loopback requests to INADDR_ANY.
3240 */
3241 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3242 err = pick_local_ip6addrs(dev, cm_id);
3243 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003244 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303245 }
3246
3247 /* find a route */
3248 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3249 __func__, laddr6->sin6_addr.s6_addr,
3250 ntohs(laddr6->sin6_port),
3251 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3252 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3253 raddr6->sin6_addr.s6_addr,
3254 laddr6->sin6_port, raddr6->sin6_port, 0,
3255 raddr6->sin6_scope_id);
3256 }
3257 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003258 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3259 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003260 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003261 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003262
Hariprasad S963cab52015-09-23 17:19:27 +05303263 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303264 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003265 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003266 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003267 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003268 }
3269
3270 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3271 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3272 ep->l2t->idx);
3273
3274 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303275 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003276
3277 /* send connect request to rnic */
3278 err = send_connect(ep);
3279 if (!err)
3280 goto out;
3281
3282 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003283fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003284 dst_release(ep->dst);
3285fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003286 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003287 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003288fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303289 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003290 c4iw_put_ep(&ep->com);
3291out:
3292 return err;
3293}
3294
Vipul Pandya830662f2013-07-04 16:10:47 +05303295static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3296{
3297 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003298 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003299 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303300
Hariprasad S28de1f72016-01-13 10:03:14 +05303301 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3302 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3303 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3304 if (err)
3305 return err;
3306 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303307 c4iw_init_wr_wait(&ep->com.wr_wait);
3308 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3309 ep->stid, &sin6->sin6_addr,
3310 sin6->sin6_port,
3311 ep->com.dev->rdev.lldi.rxq_ids[0]);
3312 if (!err)
3313 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3314 &ep->com.wr_wait,
3315 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303316 else if (err > 0)
3317 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303318 if (err) {
3319 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3320 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303321 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3322 err, ep->stid,
3323 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303324 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303325 return err;
3326}
3327
3328static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3329{
3330 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003331 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003332 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303333
3334 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3335 do {
3336 err = cxgb4_create_server_filter(
3337 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3338 sin->sin_addr.s_addr, sin->sin_port, 0,
3339 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3340 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303341 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3342 err = -EIO;
3343 break;
3344 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303345 set_current_state(TASK_UNINTERRUPTIBLE);
3346 schedule_timeout(usecs_to_jiffies(100));
3347 }
3348 } while (err == -EBUSY);
3349 } else {
3350 c4iw_init_wr_wait(&ep->com.wr_wait);
3351 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3352 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3353 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3354 if (!err)
3355 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3356 &ep->com.wr_wait,
3357 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303358 else if (err > 0)
3359 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303360 }
3361 if (err)
3362 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3363 , err, ep->stid,
3364 &sin->sin_addr, ntohs(sin->sin_port));
3365 return err;
3366}
3367
Steve Wisecfdda9d2010-04-21 15:30:06 -07003368int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3369{
3370 int err = 0;
3371 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3372 struct c4iw_listen_ep *ep;
3373
Steve Wisecfdda9d2010-04-21 15:30:06 -07003374 might_sleep();
3375
3376 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3377 if (!ep) {
3378 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3379 err = -ENOMEM;
3380 goto fail1;
3381 }
3382 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003383 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303384 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003385 ep->com.dev = dev;
3386 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003387 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303388 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003389
3390 /*
3391 * Allocate a server TID.
3392 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303393 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3394 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303395 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003396 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003397 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303398 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003399 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003400
Steve Wisecfdda9d2010-04-21 15:30:06 -07003401 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003402 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003403 err = -ENOMEM;
3404 goto fail2;
3405 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003406 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003407
Steve Wise170003c2016-02-26 09:18:03 -06003408 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3409 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003410
Steve Wisecfdda9d2010-04-21 15:30:06 -07003411 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303412 if (ep->com.local_addr.ss_family == AF_INET)
3413 err = create_server4(dev, ep);
3414 else
3415 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003416 if (!err) {
3417 cm_id->provider_data = ep;
3418 goto out;
3419 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003420
Vipul Pandya830662f2013-07-04 16:10:47 +05303421 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3422 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003423fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303424 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003425 c4iw_put_ep(&ep->com);
3426fail1:
3427out:
3428 return err;
3429}
3430
3431int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3432{
3433 int err;
3434 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3435
3436 PDBG("%s ep %p\n", __func__, ep);
3437
3438 might_sleep();
3439 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303440 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3441 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003442 err = cxgb4_remove_server_filter(
3443 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3444 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3445 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303446 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003447 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303448 err = cxgb4_remove_server(
3449 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3450 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003451 if (err)
3452 goto done;
3453 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3454 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003455 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303456 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3457 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003458 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003459 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303460 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3461 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003462done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303463 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003464 c4iw_put_ep(&ep->com);
3465 return err;
3466}
3467
3468int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3469{
3470 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003471 int close = 0;
3472 int fatal = 0;
3473 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003474
Steve Wise2f5b48c2010-09-10 11:15:36 -05003475 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003476
3477 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3478 states[ep->com.state], abrupt);
3479
Hariprasad S6e410d82016-05-05 01:27:31 +05303480 /*
3481 * Ref the ep here in case we have fatal errors causing the
3482 * ep to be released and freed.
3483 */
3484 c4iw_get_ep(&ep->com);
3485
Steve Wisecfdda9d2010-04-21 15:30:06 -07003486 rdev = &ep->com.dev->rdev;
3487 if (c4iw_fatal_error(rdev)) {
3488 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303489 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003490 ep->com.state = DEAD;
3491 }
3492 switch (ep->com.state) {
3493 case MPA_REQ_WAIT:
3494 case MPA_REQ_SENT:
3495 case MPA_REQ_RCVD:
3496 case MPA_REP_SENT:
3497 case FPDU_MODE:
3498 close = 1;
3499 if (abrupt)
3500 ep->com.state = ABORTING;
3501 else {
3502 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003503 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003504 }
3505 set_bit(CLOSE_SENT, &ep->com.flags);
3506 break;
3507 case CLOSING:
3508 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3509 close = 1;
3510 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003511 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003512 ep->com.state = ABORTING;
3513 } else
3514 ep->com.state = MORIBUND;
3515 }
3516 break;
3517 case MORIBUND:
3518 case ABORTING:
3519 case DEAD:
3520 PDBG("%s ignoring disconnect ep %p state %u\n",
3521 __func__, ep, ep->com.state);
3522 break;
3523 default:
3524 BUG();
3525 break;
3526 }
3527
Steve Wisecfdda9d2010-04-21 15:30:06 -07003528 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003529 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003530 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303531 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003532 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003533 } else {
3534 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003535 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003536 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303537 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303538 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303539 if (!abrupt) {
3540 stop_ep_timer(ep);
3541 close_complete_upcall(ep, -EIO);
3542 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303543 if (ep->com.qp) {
3544 struct c4iw_qp_attributes attrs;
3545
3546 attrs.next_state = C4IW_QP_STATE_ERROR;
3547 ret = c4iw_modify_qp(ep->com.qp->rhp,
3548 ep->com.qp,
3549 C4IW_QP_ATTR_NEXT_STATE,
3550 &attrs, 1);
3551 if (ret)
3552 pr_err(MOD
3553 "%s - qp <- error failed!\n",
3554 __func__);
3555 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003556 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303557 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003558 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003559 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303560 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003561 if (fatal)
3562 release_ep_resources(ep);
3563 return ret;
3564}
3565
Vipul Pandya1cab7752012-12-10 09:30:55 +00003566static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3567 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3568{
3569 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003570 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003571
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003572 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3573 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003574 if (!ep)
3575 return;
3576
3577 switch (req->retval) {
3578 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003579 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3580 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3581 send_fw_act_open_req(ep, atid);
3582 return;
3583 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003584 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003585 set_bit(ACT_RETRY_INUSE, &ep->com.history);
3586 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3587 send_fw_act_open_req(ep, atid);
3588 return;
3589 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003590 break;
3591 default:
3592 pr_info("%s unexpected ofld conn wr retval %d\n",
3593 __func__, req->retval);
3594 break;
3595 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003596 pr_err("active ofld_connect_wr failure %d atid %d\n",
3597 req->retval, atid);
3598 mutex_lock(&dev->rdev.stats.lock);
3599 dev->rdev.stats.act_ofld_conn_fails++;
3600 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003601 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003602 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303603 if (ep->com.remote_addr.ss_family == AF_INET6) {
3604 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003605 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303606 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3607 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3608 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003609 remove_handle(dev, &dev->atid_idr, atid);
3610 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3611 dst_release(ep->dst);
3612 cxgb4_l2t_release(ep->l2t);
3613 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003614}
3615
3616static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3617 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3618{
3619 struct sk_buff *rpl_skb;
3620 struct cpl_pass_accept_req *cpl;
3621 int ret;
3622
Paul Bolle710a3112013-02-05 20:51:30 +00003623 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003624 BUG_ON(!rpl_skb);
3625 if (req->retval) {
3626 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003627 mutex_lock(&dev->rdev.stats.lock);
3628 dev->rdev.stats.pas_ofld_conn_fails++;
3629 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630 kfree_skb(rpl_skb);
3631 } else {
3632 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3633 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003634 (__force u32) htonl(
3635 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003636 ret = pass_accept_req(dev, rpl_skb);
3637 if (!ret)
3638 kfree_skb(rpl_skb);
3639 }
3640 return;
3641}
3642
3643static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003644{
3645 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003646 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3647
3648 switch (rpl->type) {
3649 case FW6_TYPE_CQE:
3650 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3651 break;
3652 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3653 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3654 switch (req->t_state) {
3655 case TCP_SYN_SENT:
3656 active_ofld_conn_reply(dev, skb, req);
3657 break;
3658 case TCP_SYN_RECV:
3659 passive_ofld_conn_reply(dev, skb, req);
3660 break;
3661 default:
3662 pr_err("%s unexpected ofld conn wr state %d\n",
3663 __func__, req->t_state);
3664 break;
3665 }
3666 break;
3667 }
3668 return 0;
3669}
3670
3671static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3672{
Hariprasad S963cab52015-09-23 17:19:27 +05303673 __be32 l2info;
3674 __be16 hdr_len, vlantag, len;
3675 u16 eth_hdr_len;
3676 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677 u8 intf;
3678 struct cpl_rx_pkt *cpl = cplhdr(skb);
3679 struct cpl_pass_accept_req *req;
3680 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003681 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303682 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003683
Vipul Pandyaf079af72013-03-14 05:08:58 +00003684 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003685 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303686 vlantag = cpl->vlan;
3687 len = cpl->len;
3688 l2info = cpl->l2info;
3689 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003690 intf = cpl->iff;
3691
3692 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3693
3694 /*
3695 * We need to parse the TCP options from SYN packet.
3696 * to generate cpl_pass_accept_req.
3697 */
3698 memset(&tmp_opt, 0, sizeof(tmp_opt));
3699 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003700 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003701
3702 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3703 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303704 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3705 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303706 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303707 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303708 type = dev->rdev.lldi.adapter_type;
3709 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3710 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3711 req->hdr_len =
3712 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3713 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3714 eth_hdr_len = is_t4(type) ?
3715 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3716 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3717 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3718 IP_HDR_LEN_V(ip_hdr_len) |
3719 ETH_HDR_LEN_V(eth_hdr_len));
3720 } else { /* T6 and later */
3721 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3722 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3723 T6_IP_HDR_LEN_V(ip_hdr_len) |
3724 T6_ETH_HDR_LEN_V(eth_hdr_len));
3725 }
3726 req->vlan = vlantag;
3727 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003728 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3729 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003730 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3731 if (tmp_opt.wscale_ok)
3732 req->tcpopt.wsf = tmp_opt.snd_wscale;
3733 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3734 if (tmp_opt.sack_ok)
3735 req->tcpopt.sack = 1;
3736 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3737 return;
3738}
3739
3740static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3741 __be32 laddr, __be16 lport,
3742 __be32 raddr, __be16 rport,
3743 u32 rcv_isn, u32 filter, u16 window,
3744 u32 rss_qid, u8 port_id)
3745{
3746 struct sk_buff *req_skb;
3747 struct fw_ofld_connection_wr *req;
3748 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303749 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003750
3751 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3752 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3753 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003754 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303755 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303756 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003757 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003758 req->le.lport = lport;
3759 req->le.pport = rport;
3760 req->le.u.ipv4.lip = laddr;
3761 req->le.u.ipv4.pip = raddr;
3762 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3763 req->tcb.rcv_adv = htons(window);
3764 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303765 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3766 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3767 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003768 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769
3770 /*
3771 * We store the qid in opt2 which will be used by the firmware
3772 * to send us the wr response.
3773 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003774 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003775
3776 /*
3777 * We initialize the MSS index in TCB to 0xF.
3778 * So that when driver sends cpl_pass_accept_rpl
3779 * TCB picks up the correct value. If this was 0
3780 * TP will ignore any value > 0 for MSS index.
3781 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003782 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303783 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003784
3785 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303786 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3787 if (ret < 0) {
3788 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3789 ret);
3790 kfree_skb(skb);
3791 kfree_skb(req_skb);
3792 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003793}
3794
3795/*
3796 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3797 * messages when a filter is being used instead of server to
3798 * redirect a syn packet. When packets hit filter they are redirected
3799 * to the offload queue and driver tries to establish the connection
3800 * using firmware work request.
3801 */
3802static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3803{
3804 int stid;
3805 unsigned int filter;
3806 struct ethhdr *eh = NULL;
3807 struct vlan_ethhdr *vlan_eh = NULL;
3808 struct iphdr *iph;
3809 struct tcphdr *tcph;
3810 struct rss_header *rss = (void *)skb->data;
3811 struct cpl_rx_pkt *cpl = (void *)skb->data;
3812 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3813 struct l2t_entry *e;
3814 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003815 struct c4iw_ep *lep;
3816 u16 window;
3817 struct port_info *pi;
3818 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003819 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003820 int step;
3821 u32 tx_chan;
3822 struct neighbour *neigh;
3823
3824 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003825 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003826 goto reject;
3827
3828 /*
3829 * Drop all packets which did not hit the filter.
3830 * Unlikely to happen.
3831 */
3832 if (!(rss->filter_hit && rss->filter_tid))
3833 goto reject;
3834
3835 /*
3836 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3837 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303838 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003839
3840 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3841 if (!lep) {
3842 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3843 goto reject;
3844 }
3845
Hariprasad S963cab52015-09-23 17:19:27 +05303846 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3847 case CHELSIO_T4:
3848 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3849 break;
3850 case CHELSIO_T5:
3851 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3852 break;
3853 case CHELSIO_T6:
3854 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3855 break;
3856 default:
3857 pr_err("T%d Chip is not supported\n",
3858 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3859 goto reject;
3860 }
3861
Vipul Pandyaf079af72013-03-14 05:08:58 +00003862 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003863 eh = (struct ethhdr *)(req + 1);
3864 iph = (struct iphdr *)(eh + 1);
3865 } else {
3866 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3867 iph = (struct iphdr *)(vlan_eh + 1);
3868 skb->vlan_tci = ntohs(cpl->vlan);
3869 }
3870
3871 if (iph->version != 0x4)
3872 goto reject;
3873
3874 tcph = (struct tcphdr *)(iph + 1);
3875 skb_set_network_header(skb, (void *)iph - (void *)rss);
3876 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3877 skb_get(skb);
3878
3879 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3880 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3881 ntohs(tcph->source), iph->tos);
3882
Vipul Pandya830662f2013-07-04 16:10:47 +05303883 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3884 iph->tos);
3885 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003886 pr_err("%s - failed to find dst entry!\n",
3887 __func__);
3888 goto reject;
3889 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003890 neigh = dst_neigh_lookup_skb(dst, skb);
3891
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003892 if (!neigh) {
3893 pr_err("%s - failed to allocate neigh!\n",
3894 __func__);
3895 goto free_dst;
3896 }
3897
Vipul Pandya1cab7752012-12-10 09:30:55 +00003898 if (neigh->dev->flags & IFF_LOOPBACK) {
3899 pdev = ip_dev_find(&init_net, iph->daddr);
3900 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3901 pdev, 0);
3902 pi = (struct port_info *)netdev_priv(pdev);
3903 tx_chan = cxgb4_port_chan(pdev);
3904 dev_put(pdev);
3905 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303906 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003907 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303908 pdev, 0);
3909 pi = (struct port_info *)netdev_priv(pdev);
3910 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003911 }
Steve Wiseebf00062014-03-19 17:44:40 +05303912 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003913 if (!e) {
3914 pr_err("%s - failed to allocate l2t entry!\n",
3915 __func__);
3916 goto free_dst;
3917 }
3918
3919 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3920 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003921 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003922
3923 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303924 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3925 dev->rdev.lldi.ports[0],
3926 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003927
3928 /*
3929 * Synthesize the cpl_pass_accept_req. We have everything except the
3930 * TID. Once firmware sends a reply with TID we update the TID field
3931 * in cpl and pass it through the regular cpl_pass_accept_req path.
3932 */
3933 build_cpl_pass_accept_req(skb, stid, iph->tos);
3934 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3935 tcph->source, ntohl(tcph->seq), filter, window,
3936 rss_qid, pi->port_id);
3937 cxgb4_l2t_release(e);
3938free_dst:
3939 dst_release(dst);
3940reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003941 return 0;
3942}
3943
Steve Wisecfdda9d2010-04-21 15:30:06 -07003944/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003945 * These are the real handlers that are called from a
3946 * work queue.
3947 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303948static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003949 [CPL_ACT_ESTABLISH] = act_establish,
3950 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3951 [CPL_RX_DATA] = rx_data,
3952 [CPL_ABORT_RPL_RSS] = abort_rpl,
3953 [CPL_ABORT_RPL] = abort_rpl,
3954 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3955 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3956 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3957 [CPL_PASS_ESTABLISH] = pass_establish,
3958 [CPL_PEER_CLOSE] = peer_close,
3959 [CPL_ABORT_REQ_RSS] = peer_abort,
3960 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3961 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003962 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003963 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303964 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05303965 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
3966 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003967};
3968
3969static void process_timeout(struct c4iw_ep *ep)
3970{
3971 struct c4iw_qp_attributes attrs;
3972 int abort = 1;
3973
Steve Wise2f5b48c2010-09-10 11:15:36 -05003974 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003975 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3976 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003977 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 switch (ep->com.state) {
3979 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003980 connect_reply_upcall(ep, -ETIMEDOUT);
3981 break;
3982 case MPA_REQ_WAIT:
Hariprasad Se4b76a22016-05-06 22:17:59 +05303983 case MPA_REP_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003984 break;
3985 case CLOSING:
3986 case MORIBUND:
3987 if (ep->com.cm_id && ep->com.qp) {
3988 attrs.next_state = C4IW_QP_STATE_ERROR;
3989 c4iw_modify_qp(ep->com.qp->rhp,
3990 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3991 &attrs, 1);
3992 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05303993 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003994 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003995 case ABORTING:
3996 case DEAD:
3997
3998 /*
3999 * These states are expected if the ep timed out at the same
4000 * time as another thread was calling stop_ep_timer().
4001 * So we silently do nothing for these states.
4002 */
4003 abort = 0;
4004 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004005 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004006 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004007 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004008 abort = 0;
4009 }
Steve Wisecc18b932014-04-24 14:31:53 -05004010 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304011 if (abort)
4012 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004013 c4iw_put_ep(&ep->com);
4014}
4015
4016static void process_timedout_eps(void)
4017{
4018 struct c4iw_ep *ep;
4019
4020 spin_lock_irq(&timeout_lock);
4021 while (!list_empty(&timeout_list)) {
4022 struct list_head *tmp;
4023
4024 tmp = timeout_list.next;
4025 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004026 tmp->next = NULL;
4027 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004028 spin_unlock_irq(&timeout_lock);
4029 ep = list_entry(tmp, struct c4iw_ep, entry);
4030 process_timeout(ep);
4031 spin_lock_irq(&timeout_lock);
4032 }
4033 spin_unlock_irq(&timeout_lock);
4034}
4035
4036static void process_work(struct work_struct *work)
4037{
4038 struct sk_buff *skb = NULL;
4039 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004040 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004041 unsigned int opcode;
4042 int ret;
4043
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004044 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004045 while ((skb = skb_dequeue(&rxq))) {
4046 rpl = cplhdr(skb);
4047 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4048 opcode = rpl->ot.opcode;
4049
4050 BUG_ON(!work_handlers[opcode]);
4051 ret = work_handlers[opcode](dev, skb);
4052 if (!ret)
4053 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004054 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004055 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004056}
4057
4058static DECLARE_WORK(skb_work, process_work);
4059
4060static void ep_timeout(unsigned long arg)
4061{
4062 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004063 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004064
4065 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004066 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004067 /*
4068 * Only insert if it is not already on the list.
4069 */
4070 if (!ep->entry.next) {
4071 list_add_tail(&ep->entry, &timeout_list);
4072 kickit = 1;
4073 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004074 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004075 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004076 if (kickit)
4077 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004078}
4079
4080/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004081 * All the CM events are handled on a work queue to have a safe context.
4082 */
4083static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4084{
4085
4086 /*
4087 * Save dev in the skb->cb area.
4088 */
4089 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4090
4091 /*
4092 * Queue the skb and schedule the worker thread.
4093 */
4094 skb_queue_tail(&rxq, skb);
4095 queue_work(workq, &skb_work);
4096 return 0;
4097}
4098
4099static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4100{
4101 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4102
4103 if (rpl->status != CPL_ERR_NONE) {
4104 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4105 "for tid %u\n", rpl->status, GET_TID(rpl));
4106 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004107 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004108 return 0;
4109}
4110
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004111static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4112{
4113 struct cpl_fw6_msg *rpl = cplhdr(skb);
4114 struct c4iw_wr_wait *wr_waitp;
4115 int ret;
4116
4117 PDBG("%s type %u\n", __func__, rpl->type);
4118
4119 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004120 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004121 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004122 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004123 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004124 if (wr_waitp)
4125 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004126 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004127 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004128 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004129 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004130 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004131 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004132 default:
4133 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4134 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004135 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004136 break;
4137 }
4138 return 0;
4139}
4140
Steve Wise8da7e7a2011-06-14 20:59:27 +00004141static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4142{
4143 struct cpl_abort_req_rss *req = cplhdr(skb);
4144 struct c4iw_ep *ep;
4145 struct tid_info *t = dev->rdev.lldi.tids;
4146 unsigned int tid = GET_TID(req);
4147
4148 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004149 if (!ep) {
4150 printk(KERN_WARNING MOD
4151 "Abort on non-existent endpoint, tid %d\n", tid);
4152 kfree_skb(skb);
4153 return 0;
4154 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304155 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304156 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4157 __func__, ep->hwtid, req->status,
4158 neg_adv_str(req->status));
4159 ep->stats.abort_neg_adv++;
4160 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004161 kfree_skb(skb);
4162 return 0;
4163 }
4164 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4165 ep->com.state);
4166
4167 /*
4168 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004169 * However, if we are on MPAv2 and want to retry with MPAv1
4170 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004171 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004172 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4173 if (ep->com.state != MPA_REQ_SENT)
4174 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4175 } else
4176 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004177 sched(dev, skb);
4178 return 0;
4179}
4180
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004181/*
4182 * Most upcalls from the T4 Core go to sched() to
4183 * schedule the processing on a work queue.
4184 */
4185c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4186 [CPL_ACT_ESTABLISH] = sched,
4187 [CPL_ACT_OPEN_RPL] = sched,
4188 [CPL_RX_DATA] = sched,
4189 [CPL_ABORT_RPL_RSS] = sched,
4190 [CPL_ABORT_RPL] = sched,
4191 [CPL_PASS_OPEN_RPL] = sched,
4192 [CPL_CLOSE_LISTSRV_RPL] = sched,
4193 [CPL_PASS_ACCEPT_REQ] = sched,
4194 [CPL_PASS_ESTABLISH] = sched,
4195 [CPL_PEER_CLOSE] = sched,
4196 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004197 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004198 [CPL_RDMA_TERMINATE] = sched,
4199 [CPL_FW4_ACK] = sched,
4200 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004201 [CPL_FW6_MSG] = fw6_msg,
4202 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004203};
4204
Steve Wisecfdda9d2010-04-21 15:30:06 -07004205int __init c4iw_cm_init(void)
4206{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004207 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004208 skb_queue_head_init(&rxq);
4209
4210 workq = create_singlethread_workqueue("iw_cxgb4");
4211 if (!workq)
4212 return -ENOMEM;
4213
Steve Wisecfdda9d2010-04-21 15:30:06 -07004214 return 0;
4215}
4216
Steve Wise46c13762014-06-20 14:26:25 -05004217void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004218{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004219 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004220 flush_workqueue(workq);
4221 destroy_workqueue(workq);
4222}