blob: 6c22bc95a11227ddee89cd1fd01adc3e4490e4e0 [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{
543 struct c4iw_rdev *rdev = handle;
544 struct cpl_abort_req *req = cplhdr(skb);
545
546 PDBG("%s rdev %p\n", __func__, rdev);
547 req->cmd = CPL_ABORT_NO_RST;
548 c4iw_ofld_send(rdev, skb);
549}
550
Hariprasad Sfef44222016-05-05 01:27:33 +0530551static int send_flowc(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700552{
553 unsigned int flowclen = 80;
554 struct fw_flowc_wr *flowc;
555 int i;
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530556 u16 vlan = ep->l2t->vlan;
557 int nparams;
558
559 if (vlan == CPL_L2T_VLAN_NONE)
560 nparams = 8;
561 else
562 nparams = 9;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700563
564 skb = get_skb(skb, flowclen, GFP_KERNEL);
565 flowc = (struct fw_flowc_wr *)__skb_put(skb, flowclen);
566
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530567 flowc->op_to_nparams = cpu_to_be32(FW_WR_OP_V(FW_FLOWC_WR) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530568 FW_FLOWC_WR_NPARAMS_V(nparams));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530569 flowc->flowid_len16 = cpu_to_be32(FW_WR_LEN16_V(DIV_ROUND_UP(flowclen,
570 16)) | FW_WR_FLOWID_V(ep->hwtid));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700571
572 flowc->mnemval[0].mnemonic = FW_FLOWC_MNEM_PFNVFN;
Hariprasad Shenai51678652014-11-21 12:52:02 +0530573 flowc->mnemval[0].val = cpu_to_be32(FW_PFVF_CMD_PFN_V
Hariprasad Shenai35b1de52014-06-27 19:23:47 +0530574 (ep->com.dev->rdev.lldi.pf));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700575 flowc->mnemval[1].mnemonic = FW_FLOWC_MNEM_CH;
576 flowc->mnemval[1].val = cpu_to_be32(ep->tx_chan);
577 flowc->mnemval[2].mnemonic = FW_FLOWC_MNEM_PORT;
578 flowc->mnemval[2].val = cpu_to_be32(ep->tx_chan);
579 flowc->mnemval[3].mnemonic = FW_FLOWC_MNEM_IQID;
580 flowc->mnemval[3].val = cpu_to_be32(ep->rss_qid);
581 flowc->mnemval[4].mnemonic = FW_FLOWC_MNEM_SNDNXT;
582 flowc->mnemval[4].val = cpu_to_be32(ep->snd_seq);
583 flowc->mnemval[5].mnemonic = FW_FLOWC_MNEM_RCVNXT;
584 flowc->mnemval[5].val = cpu_to_be32(ep->rcv_seq);
585 flowc->mnemval[6].mnemonic = FW_FLOWC_MNEM_SNDBUF;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530586 flowc->mnemval[6].val = cpu_to_be32(ep->snd_win);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700587 flowc->mnemval[7].mnemonic = FW_FLOWC_MNEM_MSS;
588 flowc->mnemval[7].val = cpu_to_be32(ep->emss);
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530589 if (nparams == 9) {
590 u16 pri;
591
592 pri = (vlan & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
593 flowc->mnemval[8].mnemonic = FW_FLOWC_MNEM_SCHEDCLASS;
594 flowc->mnemval[8].val = cpu_to_be32(pri);
595 } else {
596 /* Pad WR to 16 byte boundary */
597 flowc->mnemval[8].mnemonic = 0;
598 flowc->mnemval[8].val = 0;
599 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700600 for (i = 0; i < 9; i++) {
601 flowc->mnemval[i].r4[0] = 0;
602 flowc->mnemval[i].r4[1] = 0;
603 flowc->mnemval[i].r4[2] = 0;
604 }
605
606 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Hariprasad Sfef44222016-05-05 01:27:33 +0530607 return c4iw_ofld_send(&ep->com.dev->rdev, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700608}
609
610static int send_halfclose(struct c4iw_ep *ep, gfp_t gfp)
611{
612 struct cpl_close_con_req *req;
613 struct sk_buff *skb;
614 int wrlen = roundup(sizeof *req, 16);
615
616 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
617 skb = get_skb(NULL, wrlen, gfp);
618 if (!skb) {
619 printk(KERN_ERR MOD "%s - failed to alloc skb\n", __func__);
620 return -ENOMEM;
621 }
622 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
623 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
624 req = (struct cpl_close_con_req *) skb_put(skb, wrlen);
625 memset(req, 0, wrlen);
626 INIT_TP_WR(req, ep->hwtid);
627 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_CLOSE_CON_REQ,
628 ep->hwtid));
629 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
630}
631
632static int send_abort(struct c4iw_ep *ep, struct sk_buff *skb, gfp_t gfp)
633{
634 struct cpl_abort_req *req;
635 int wrlen = roundup(sizeof *req, 16);
636
637 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
638 skb = get_skb(skb, wrlen, gfp);
639 if (!skb) {
640 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
641 __func__);
642 return -ENOMEM;
643 }
644 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
645 t4_set_arp_err_handler(skb, &ep->com.dev->rdev, abort_arp_failure);
646 req = (struct cpl_abort_req *) skb_put(skb, wrlen);
647 memset(req, 0, wrlen);
648 INIT_TP_WR(req, ep->hwtid);
649 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_REQ, ep->hwtid));
650 req->cmd = CPL_ABORT_SEND_RST;
651 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
652}
653
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530654static void best_mtu(const unsigned short *mtus, unsigned short mtu,
Hariprasad S04524a42014-09-24 03:53:41 +0530655 unsigned int *idx, int use_ts, int ipv6)
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530656{
Hariprasad S04524a42014-09-24 03:53:41 +0530657 unsigned short hdr_size = (ipv6 ?
658 sizeof(struct ipv6hdr) :
659 sizeof(struct iphdr)) +
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530660 sizeof(struct tcphdr) +
Hariprasad S04524a42014-09-24 03:53:41 +0530661 (use_ts ?
662 round_up(TCPOLEN_TIMESTAMP, 4) : 0);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530663 unsigned short data_size = mtu - hdr_size;
664
665 cxgb4_best_aligned_mtu(mtus, hdr_size, data_size, 8, idx);
666}
667
Steve Wisecfdda9d2010-04-21 15:30:06 -0700668static int send_connect(struct c4iw_ep *ep)
669{
Hariprasad S963cab52015-09-23 17:19:27 +0530670 struct cpl_act_open_req *req = NULL;
671 struct cpl_t5_act_open_req *t5req = NULL;
672 struct cpl_t6_act_open_req *t6req = NULL;
673 struct cpl_act_open_req6 *req6 = NULL;
674 struct cpl_t5_act_open_req6 *t5req6 = NULL;
675 struct cpl_t6_act_open_req6 *t6req6 = NULL;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700676 struct sk_buff *skb;
677 u64 opt0;
678 u32 opt2;
679 unsigned int mtu_idx;
680 int wscale;
Hariprasad S963cab52015-09-23 17:19:27 +0530681 int win, sizev4, sizev6, wrlen;
Steve Wise9eccfe12014-03-26 17:08:09 -0500682 struct sockaddr_in *la = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600683 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500684 struct sockaddr_in *ra = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -0600685 &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500686 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600687 &ep->com.local_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -0500688 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -0600689 &ep->com.remote_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530690 int ret;
Hariprasad S963cab52015-09-23 17:19:27 +0530691 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
692 u32 isn = (prandom_u32() & ~7UL) - 1;
693
694 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
695 case CHELSIO_T4:
696 sizev4 = sizeof(struct cpl_act_open_req);
697 sizev6 = sizeof(struct cpl_act_open_req6);
698 break;
699 case CHELSIO_T5:
700 sizev4 = sizeof(struct cpl_t5_act_open_req);
701 sizev6 = sizeof(struct cpl_t5_act_open_req6);
702 break;
703 case CHELSIO_T6:
704 sizev4 = sizeof(struct cpl_t6_act_open_req);
705 sizev6 = sizeof(struct cpl_t6_act_open_req6);
706 break;
707 default:
708 pr_err("T%d Chip is not supported\n",
709 CHELSIO_CHIP_VERSION(adapter_type));
710 return -EINVAL;
711 }
Vipul Pandya830662f2013-07-04 16:10:47 +0530712
713 wrlen = (ep->com.remote_addr.ss_family == AF_INET) ?
714 roundup(sizev4, 16) :
715 roundup(sizev6, 16);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700716
717 PDBG("%s ep %p atid %u\n", __func__, ep, ep->atid);
718
719 skb = get_skb(NULL, wrlen, GFP_KERNEL);
720 if (!skb) {
721 printk(KERN_ERR MOD "%s - failed to alloc skb.\n",
722 __func__);
723 return -ENOMEM;
724 }
Steve Wised4f1a5c2010-07-23 19:12:32 +0000725 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700726
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +0530727 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +0530728 enable_tcp_timestamps,
729 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700730 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530731
732 /*
733 * Specify the largest window that will fit in opt0. The
734 * remainder will be specified in the rx_data_ack.
735 */
736 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -0800737 if (win > RCV_BUFSIZ_M)
738 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +0530739
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800740 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800741 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800742 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -0800743 WND_SCALE_V(wscale) |
744 MSS_IDX_V(mtu_idx) |
745 L2T_IDX_V(ep->l2t->idx) |
746 TX_CHAN_V(ep->tx_chan) |
747 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +0530748 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800749 ULP_MODE_V(ULP_MODE_TCPDDP) |
750 RCV_BUFSIZ_V(win);
751 opt2 = RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800752 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -0800753 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700754 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800755 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700756 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -0800757 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700758 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -0800759 opt2 |= WND_SCALE_EN_F;
Hariprasad S963cab52015-09-23 17:19:27 +0530760 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
761 if (peer2peer)
762 isn += 4;
763
Anish Bhattd7990b02014-11-12 17:15:57 -0800764 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +0530765 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +0530766 opt2 |= T5_ISS_F;
Steve Wise92e50112014-04-24 14:31:59 -0500767 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530768
769 if (ep->com.remote_addr.ss_family == AF_INET6)
770 cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
771 (const u32 *)&la6->sin6_addr.s6_addr, 1);
772
Hariprasad S5dab6d32014-06-23 19:12:36 +0530773 t4_set_arp_err_handler(skb, ep, act_open_req_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700774
Hariprasad S963cab52015-09-23 17:19:27 +0530775 if (ep->com.remote_addr.ss_family == AF_INET) {
776 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
777 case CHELSIO_T4:
778 req = (struct cpl_act_open_req *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530779 INIT_TP_WR(req, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530780 break;
781 case CHELSIO_T5:
782 t5req = (struct cpl_t5_act_open_req *)skb_put(skb,
783 wrlen);
784 INIT_TP_WR(t5req, 0);
785 req = (struct cpl_act_open_req *)t5req;
786 break;
787 case CHELSIO_T6:
788 t6req = (struct cpl_t6_act_open_req *)skb_put(skb,
789 wrlen);
790 INIT_TP_WR(t6req, 0);
791 req = (struct cpl_act_open_req *)t6req;
792 t5req = (struct cpl_t5_act_open_req *)t6req;
793 break;
794 default:
795 pr_err("T%d Chip is not supported\n",
796 CHELSIO_CHIP_VERSION(adapter_type));
797 ret = -EINVAL;
798 goto clip_release;
799 }
800
801 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ,
802 ((ep->rss_qid<<14) | ep->atid)));
803 req->local_port = la->sin_port;
804 req->peer_port = ra->sin_port;
805 req->local_ip = la->sin_addr.s_addr;
806 req->peer_ip = ra->sin_addr.s_addr;
807 req->opt0 = cpu_to_be64(opt0);
808
809 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530810 req->params = cpu_to_be32(cxgb4_select_ntuple(
811 ep->com.dev->rdev.lldi.ports[0],
812 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530813 req->opt2 = cpu_to_be32(opt2);
814 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530815 t5req->params = cpu_to_be64(FILTER_TUPLE_V(
816 cxgb4_select_ntuple(
817 ep->com.dev->rdev.lldi.ports[0],
818 ep->l2t)));
819 t5req->rsvd = cpu_to_be32(isn);
820 PDBG("%s snd_isn %u\n", __func__, t5req->rsvd);
821 t5req->opt2 = cpu_to_be32(opt2);
822 }
823 } else {
824 switch (CHELSIO_CHIP_VERSION(adapter_type)) {
825 case CHELSIO_T4:
Vipul Pandya830662f2013-07-04 16:10:47 +0530826 req6 = (struct cpl_act_open_req6 *)skb_put(skb, wrlen);
Vipul Pandya830662f2013-07-04 16:10:47 +0530827 INIT_TP_WR(req6, 0);
Hariprasad S963cab52015-09-23 17:19:27 +0530828 break;
829 case CHELSIO_T5:
830 t5req6 = (struct cpl_t5_act_open_req6 *)skb_put(skb,
831 wrlen);
832 INIT_TP_WR(t5req6, 0);
833 req6 = (struct cpl_act_open_req6 *)t5req6;
834 break;
835 case CHELSIO_T6:
836 t6req6 = (struct cpl_t6_act_open_req6 *)skb_put(skb,
837 wrlen);
838 INIT_TP_WR(t6req6, 0);
839 req6 = (struct cpl_act_open_req6 *)t6req6;
840 t5req6 = (struct cpl_t5_act_open_req6 *)t6req6;
841 break;
842 default:
843 pr_err("T%d Chip is not supported\n",
844 CHELSIO_CHIP_VERSION(adapter_type));
845 ret = -EINVAL;
846 goto clip_release;
847 }
848
849 OPCODE_TID(req6) = cpu_to_be32(MK_OPCODE_TID(CPL_ACT_OPEN_REQ6,
850 ((ep->rss_qid<<14)|ep->atid)));
851 req6->local_port = la6->sin6_port;
852 req6->peer_port = ra6->sin6_port;
853 req6->local_ip_hi = *((__be64 *)(la6->sin6_addr.s6_addr));
854 req6->local_ip_lo = *((__be64 *)(la6->sin6_addr.s6_addr + 8));
855 req6->peer_ip_hi = *((__be64 *)(ra6->sin6_addr.s6_addr));
856 req6->peer_ip_lo = *((__be64 *)(ra6->sin6_addr.s6_addr + 8));
857 req6->opt0 = cpu_to_be64(opt0);
858
859 if (is_t4(ep->com.dev->rdev.lldi.adapter_type)) {
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530860 req6->params = cpu_to_be32(cxgb4_select_ntuple(
861 ep->com.dev->rdev.lldi.ports[0],
862 ep->l2t));
Vipul Pandya830662f2013-07-04 16:10:47 +0530863 req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530864 } else {
Hariprasad S963cab52015-09-23 17:19:27 +0530865 t5req6->params = cpu_to_be64(FILTER_TUPLE_V(
866 cxgb4_select_ntuple(
Kumar Sanghvi41b4f862013-12-18 16:38:26 +0530867 ep->com.dev->rdev.lldi.ports[0],
Hariprasad Sda22b8962014-09-24 03:53:43 +0530868 ep->l2t)));
Hariprasad S963cab52015-09-23 17:19:27 +0530869 t5req6->rsvd = cpu_to_be32(isn);
870 PDBG("%s snd_isn %u\n", __func__, t5req6->rsvd);
871 t5req6->opt2 = cpu_to_be32(opt2);
Vipul Pandya830662f2013-07-04 16:10:47 +0530872 }
Vipul Pandyaf079af72013-03-14 05:08:58 +0000873 }
874
Vipul Pandya793dad92012-12-10 09:30:56 +0000875 set_bit(ACT_OPEN_REQ, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530876 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Hariprasad S963cab52015-09-23 17:19:27 +0530877clip_release:
Hariprasad S84cc6ac62015-08-25 14:08:23 +0530878 if (ret && ep->com.remote_addr.ss_family == AF_INET6)
879 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
880 (const u32 *)&la6->sin6_addr.s6_addr, 1);
881 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700882}
883
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530884static int send_mpa_req(struct c4iw_ep *ep, struct sk_buff *skb,
885 u8 mpa_rev_to_use)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700886{
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530887 int mpalen, wrlen, ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700888 struct fw_ofld_tx_data_wr *req;
889 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530890 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700891
892 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
893
894 BUG_ON(skb_cloned(skb));
895
896 mpalen = sizeof(*mpa) + ep->plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530897 if (mpa_rev_to_use == 2)
898 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700899 wrlen = roundup(mpalen + sizeof *req, 16);
900 skb = get_skb(skb, wrlen, GFP_KERNEL);
901 if (!skb) {
902 connect_reply_upcall(ep, -ENOMEM);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530903 return -ENOMEM;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700904 }
905 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
906
907 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
908 memset(req, 0, wrlen);
909 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530910 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
911 FW_WR_COMPL_F |
912 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700913 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530914 FW_WR_FLOWID_V(ep->hwtid) |
915 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -0700916 req->plen = cpu_to_be32(mpalen);
917 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +0530918 FW_OFLD_TX_DATA_WR_FLUSH_F |
919 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700920
921 mpa = (struct mpa_message *)(req + 1);
922 memcpy(mpa->key, MPA_KEY_REQ, sizeof(mpa->key));
923 mpa->flags = (crc_enabled ? MPA_CRC : 0) |
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530924 (markers_enabled ? MPA_MARKERS : 0) |
925 (mpa_rev_to_use == 2 ? MPA_ENHANCED_RDMA_CONN : 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700926 mpa->private_data_size = htons(ep->plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530927 mpa->revision = mpa_rev_to_use;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530928 if (mpa_rev_to_use == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530929 ep->tried_with_mpa_v1 = 1;
Kumar Sanghvi01b225e2011-11-28 22:09:15 +0530930 ep->retry_with_mpa_v1 = 0;
931 }
Steve Wisecfdda9d2010-04-21 15:30:06 -0700932
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530933 if (mpa_rev_to_use == 2) {
Roland Dreierf747c342012-07-05 14:16:54 -0700934 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
935 sizeof (struct mpa_v2_conn_params));
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +0530936 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
937 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530938 mpa_v2_params.ird = htons((u16)ep->ird);
939 mpa_v2_params.ord = htons((u16)ep->ord);
940
941 if (peer2peer) {
942 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
943 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
944 mpa_v2_params.ord |=
945 htons(MPA_V2_RDMA_WRITE_RTR);
946 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
947 mpa_v2_params.ord |=
948 htons(MPA_V2_RDMA_READ_RTR);
949 }
950 memcpy(mpa->private_data, &mpa_v2_params,
951 sizeof(struct mpa_v2_conn_params));
952
953 if (ep->plen)
954 memcpy(mpa->private_data +
955 sizeof(struct mpa_v2_conn_params),
956 ep->mpa_pkt + sizeof(*mpa), ep->plen);
957 } else
958 if (ep->plen)
959 memcpy(mpa->private_data,
960 ep->mpa_pkt + sizeof(*mpa), ep->plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700961
962 /*
963 * Reference the mpa skb. This ensures the data area
964 * will remain in memory until the hw acks the tx.
965 * Function fw4_ack() will deref it.
966 */
967 skb_get(skb);
968 t4_set_arp_err_handler(skb, NULL, arp_failure_discard);
969 BUG_ON(ep->mpa_skb);
970 ep->mpa_skb = skb;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530971 ret = c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
972 if (ret)
973 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700974 start_ep_timer(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +0530975 __state_set(&ep->com, MPA_REQ_SENT);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700976 ep->mpa_attr.initiator = 1;
Steve Wise9c88aa02014-03-21 20:40:34 +0530977 ep->snd_seq += mpalen;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +0530978 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700979}
980
981static int send_mpa_reject(struct c4iw_ep *ep, const void *pdata, u8 plen)
982{
983 int mpalen, wrlen;
984 struct fw_ofld_tx_data_wr *req;
985 struct mpa_message *mpa;
986 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530987 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700988
989 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
990
991 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +0530992 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
993 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700994 wrlen = roundup(mpalen + sizeof *req, 16);
995
996 skb = get_skb(NULL, wrlen, GFP_KERNEL);
997 if (!skb) {
998 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
999 return -ENOMEM;
1000 }
1001 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1002
1003 req = (struct fw_ofld_tx_data_wr *)skb_put(skb, wrlen);
1004 memset(req, 0, wrlen);
1005 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301006 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1007 FW_WR_COMPL_F |
1008 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001009 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301010 FW_WR_FLOWID_V(ep->hwtid) |
1011 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001012 req->plen = cpu_to_be32(mpalen);
1013 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301014 FW_OFLD_TX_DATA_WR_FLUSH_F |
1015 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001016
1017 mpa = (struct mpa_message *)(req + 1);
1018 memset(mpa, 0, sizeof(*mpa));
1019 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1020 mpa->flags = MPA_REJECT;
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00001021 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001022 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301023
1024 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1025 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001026 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1027 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301028 mpa_v2_params.ird = htons(((u16)ep->ird) |
1029 (peer2peer ? MPA_V2_PEER2PEER_MODEL :
1030 0));
1031 mpa_v2_params.ord = htons(((u16)ep->ord) | (peer2peer ?
1032 (p2p_type ==
1033 FW_RI_INIT_P2PTYPE_RDMA_WRITE ?
1034 MPA_V2_RDMA_WRITE_RTR : p2p_type ==
1035 FW_RI_INIT_P2PTYPE_READ_REQ ?
1036 MPA_V2_RDMA_READ_RTR : 0) : 0));
1037 memcpy(mpa->private_data, &mpa_v2_params,
1038 sizeof(struct mpa_v2_conn_params));
1039
1040 if (ep->plen)
1041 memcpy(mpa->private_data +
1042 sizeof(struct mpa_v2_conn_params), pdata, plen);
1043 } else
1044 if (plen)
1045 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001046
1047 /*
1048 * Reference the mpa skb again. This ensures the data area
1049 * will remain in memory until the hw acks the tx.
1050 * Function fw4_ack() will deref it.
1051 */
1052 skb_get(skb);
1053 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001054 BUG_ON(ep->mpa_skb);
1055 ep->mpa_skb = skb;
Steve Wise9c88aa02014-03-21 20:40:34 +05301056 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001057 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1058}
1059
1060static int send_mpa_reply(struct c4iw_ep *ep, const void *pdata, u8 plen)
1061{
1062 int mpalen, wrlen;
1063 struct fw_ofld_tx_data_wr *req;
1064 struct mpa_message *mpa;
1065 struct sk_buff *skb;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301066 struct mpa_v2_conn_params mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001067
1068 PDBG("%s ep %p tid %u pd_len %d\n", __func__, ep, ep->hwtid, ep->plen);
1069
1070 mpalen = sizeof(*mpa) + plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301071 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn)
1072 mpalen += sizeof(struct mpa_v2_conn_params);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001073 wrlen = roundup(mpalen + sizeof *req, 16);
1074
1075 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1076 if (!skb) {
1077 printk(KERN_ERR MOD "%s - cannot alloc skb!\n", __func__);
1078 return -ENOMEM;
1079 }
1080 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
1081
1082 req = (struct fw_ofld_tx_data_wr *) skb_put(skb, wrlen);
1083 memset(req, 0, wrlen);
1084 req->op_to_immdlen = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301085 FW_WR_OP_V(FW_OFLD_TX_DATA_WR) |
1086 FW_WR_COMPL_F |
1087 FW_WR_IMMDLEN_V(mpalen));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001088 req->flowid_len16 = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301089 FW_WR_FLOWID_V(ep->hwtid) |
1090 FW_WR_LEN16_V(wrlen >> 4));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001091 req->plen = cpu_to_be32(mpalen);
1092 req->tunnel_to_proxy = cpu_to_be32(
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301093 FW_OFLD_TX_DATA_WR_FLUSH_F |
1094 FW_OFLD_TX_DATA_WR_SHOVE_F);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001095
1096 mpa = (struct mpa_message *)(req + 1);
1097 memset(mpa, 0, sizeof(*mpa));
1098 memcpy(mpa->key, MPA_KEY_REP, sizeof(mpa->key));
1099 mpa->flags = (ep->mpa_attr.crc_enabled ? MPA_CRC : 0) |
1100 (markers_enabled ? MPA_MARKERS : 0);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301101 mpa->revision = ep->mpa_attr.version;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001102 mpa->private_data_size = htons(plen);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301103
1104 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
1105 mpa->flags |= MPA_ENHANCED_RDMA_CONN;
Roland Dreierf747c342012-07-05 14:16:54 -07001106 mpa->private_data_size = htons(ntohs(mpa->private_data_size) +
1107 sizeof (struct mpa_v2_conn_params));
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301108 mpa_v2_params.ird = htons((u16)ep->ird);
1109 mpa_v2_params.ord = htons((u16)ep->ord);
1110 if (peer2peer && (ep->mpa_attr.p2p_type !=
1111 FW_RI_INIT_P2PTYPE_DISABLED)) {
1112 mpa_v2_params.ird |= htons(MPA_V2_PEER2PEER_MODEL);
1113
1114 if (p2p_type == FW_RI_INIT_P2PTYPE_RDMA_WRITE)
1115 mpa_v2_params.ord |=
1116 htons(MPA_V2_RDMA_WRITE_RTR);
1117 else if (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ)
1118 mpa_v2_params.ord |=
1119 htons(MPA_V2_RDMA_READ_RTR);
1120 }
1121
1122 memcpy(mpa->private_data, &mpa_v2_params,
1123 sizeof(struct mpa_v2_conn_params));
1124
1125 if (ep->plen)
1126 memcpy(mpa->private_data +
1127 sizeof(struct mpa_v2_conn_params), pdata, plen);
1128 } else
1129 if (plen)
1130 memcpy(mpa->private_data, pdata, plen);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001131
1132 /*
1133 * Reference the mpa skb. This ensures the data area
1134 * will remain in memory until the hw acks the tx.
1135 * Function fw4_ack() will deref it.
1136 */
1137 skb_get(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001138 ep->mpa_skb = skb;
Steve Wisea7db89e2014-03-21 20:40:35 +05301139 __state_set(&ep->com, MPA_REP_SENT);
Steve Wise9c88aa02014-03-21 20:40:34 +05301140 ep->snd_seq += mpalen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001141 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
1142}
1143
1144static int act_establish(struct c4iw_dev *dev, struct sk_buff *skb)
1145{
1146 struct c4iw_ep *ep;
1147 struct cpl_act_establish *req = cplhdr(skb);
1148 unsigned int tid = GET_TID(req);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001149 unsigned int atid = TID_TID_G(ntohl(req->tos_atid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001150 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Sfef44222016-05-05 01:27:33 +05301151 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001152
1153 ep = lookup_atid(t, atid);
1154
1155 PDBG("%s ep %p tid %u snd_isn %u rcv_isn %u\n", __func__, ep, tid,
1156 be32_to_cpu(req->snd_isn), be32_to_cpu(req->rcv_isn));
1157
Steve Wisea7db89e2014-03-21 20:40:35 +05301158 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001159 dst_confirm(ep->dst);
1160
1161 /* setup the hwtid for this connection */
1162 ep->hwtid = tid;
1163 cxgb4_insert_tid(t, ep, tid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001164 insert_handle(dev, &dev->hwtid_idr, ep, ep->hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001165
1166 ep->snd_seq = be32_to_cpu(req->snd_isn);
1167 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
1168
1169 set_emss(ep, ntohs(req->tcp_opt));
1170
1171 /* dealloc the atid */
Vipul Pandya793dad92012-12-10 09:30:56 +00001172 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001173 cxgb4_free_atid(t, atid);
Vipul Pandya793dad92012-12-10 09:30:56 +00001174 set_bit(ACT_ESTAB, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001175
1176 /* start MPA negotiation */
Hariprasad Sfef44222016-05-05 01:27:33 +05301177 ret = send_flowc(ep, NULL);
1178 if (ret)
1179 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301180 if (ep->retry_with_mpa_v1)
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301181 ret = send_mpa_req(ep, skb, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301182 else
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301183 ret = send_mpa_req(ep, skb, mpa_rev);
1184 if (ret)
1185 goto err;
Steve Wisea7db89e2014-03-21 20:40:35 +05301186 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001187 return 0;
Hariprasad Sfef44222016-05-05 01:27:33 +05301188err:
1189 mutex_unlock(&ep->com.mutex);
1190 connect_reply_upcall(ep, -ENOMEM);
1191 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
1192 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001193}
1194
Steve Wisebe13b2d2014-03-21 20:40:33 +05301195static void close_complete_upcall(struct c4iw_ep *ep, int status)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001196{
1197 struct iw_cm_event event;
1198
1199 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1200 memset(&event, 0, sizeof(event));
1201 event.event = IW_CM_EVENT_CLOSE;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301202 event.status = status;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001203 if (ep->com.cm_id) {
1204 PDBG("close complete delivered ep %p cm_id %p tid %u\n",
1205 ep, ep->com.cm_id, ep->hwtid);
1206 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301207 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001208 set_bit(CLOSE_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001209 }
1210}
1211
Steve Wisecfdda9d2010-04-21 15:30:06 -07001212static void peer_close_upcall(struct c4iw_ep *ep)
1213{
1214 struct iw_cm_event event;
1215
1216 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1217 memset(&event, 0, sizeof(event));
1218 event.event = IW_CM_EVENT_DISCONNECT;
1219 if (ep->com.cm_id) {
1220 PDBG("peer close delivered ep %p cm_id %p tid %u\n",
1221 ep, ep->com.cm_id, ep->hwtid);
1222 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001223 set_bit(DISCONN_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001224 }
1225}
1226
1227static void peer_abort_upcall(struct c4iw_ep *ep)
1228{
1229 struct iw_cm_event event;
1230
1231 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1232 memset(&event, 0, sizeof(event));
1233 event.event = IW_CM_EVENT_CLOSE;
1234 event.status = -ECONNRESET;
1235 if (ep->com.cm_id) {
1236 PDBG("abort delivered ep %p cm_id %p tid %u\n", ep,
1237 ep->com.cm_id, ep->hwtid);
1238 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301239 deref_cm_id(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001240 set_bit(ABORT_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001241 }
1242}
1243
1244static void connect_reply_upcall(struct c4iw_ep *ep, int status)
1245{
1246 struct iw_cm_event event;
1247
1248 PDBG("%s ep %p tid %u status %d\n", __func__, ep, ep->hwtid, status);
1249 memset(&event, 0, sizeof(event));
1250 event.event = IW_CM_EVENT_CONNECT_REPLY;
1251 event.status = status;
Steve Wise24d44a32013-07-04 16:10:44 +05301252 memcpy(&event.local_addr, &ep->com.local_addr,
1253 sizeof(ep->com.local_addr));
1254 memcpy(&event.remote_addr, &ep->com.remote_addr,
1255 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001256
1257 if ((status == 0) || (status == -ECONNREFUSED)) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301258 if (!ep->tried_with_mpa_v1) {
1259 /* this means MPA_v2 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301260 event.ord = ep->ird;
1261 event.ird = ep->ord;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301262 event.private_data_len = ep->plen -
1263 sizeof(struct mpa_v2_conn_params);
1264 event.private_data = ep->mpa_pkt +
1265 sizeof(struct mpa_message) +
1266 sizeof(struct mpa_v2_conn_params);
1267 } else {
1268 /* this means MPA_v1 is used */
Hariprasad S158c7762015-09-08 09:56:58 +05301269 event.ord = cur_max_read_depth(ep->com.dev);
1270 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301271 event.private_data_len = ep->plen;
1272 event.private_data = ep->mpa_pkt +
1273 sizeof(struct mpa_message);
1274 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001275 }
Roland Dreier85963e42010-07-19 13:13:09 -07001276
1277 PDBG("%s ep %p tid %u status %d\n", __func__, ep,
1278 ep->hwtid, status);
Vipul Pandya793dad92012-12-10 09:30:56 +00001279 set_bit(CONN_RPL_UPCALL, &ep->com.history);
Roland Dreier85963e42010-07-19 13:13:09 -07001280 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
1281
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05301282 if (status < 0)
1283 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001284}
1285
Steve Wisebe13b2d2014-03-21 20:40:33 +05301286static int connect_request_upcall(struct c4iw_ep *ep)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001287{
1288 struct iw_cm_event event;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301289 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001290
1291 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1292 memset(&event, 0, sizeof(event));
1293 event.event = IW_CM_EVENT_CONNECT_REQUEST;
Steve Wise24d44a32013-07-04 16:10:44 +05301294 memcpy(&event.local_addr, &ep->com.local_addr,
1295 sizeof(ep->com.local_addr));
1296 memcpy(&event.remote_addr, &ep->com.remote_addr,
1297 sizeof(ep->com.remote_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07001298 event.provider_data = ep;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301299 if (!ep->tried_with_mpa_v1) {
1300 /* this means MPA_v2 is used */
1301 event.ord = ep->ord;
1302 event.ird = ep->ird;
1303 event.private_data_len = ep->plen -
1304 sizeof(struct mpa_v2_conn_params);
1305 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message) +
1306 sizeof(struct mpa_v2_conn_params);
1307 } else {
1308 /* this means MPA_v1 is used. Send max supported */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301309 event.ord = cur_max_read_depth(ep->com.dev);
1310 event.ird = cur_max_read_depth(ep->com.dev);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301311 event.private_data_len = ep->plen;
1312 event.private_data = ep->mpa_pkt + sizeof(struct mpa_message);
1313 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05301314 c4iw_get_ep(&ep->com);
1315 ret = ep->parent_ep->com.cm_id->event_handler(ep->parent_ep->com.cm_id,
1316 &event);
1317 if (ret)
1318 c4iw_put_ep(&ep->com);
Vipul Pandya793dad92012-12-10 09:30:56 +00001319 set_bit(CONNREQ_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001320 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisebe13b2d2014-03-21 20:40:33 +05301321 return ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001322}
1323
1324static void established_upcall(struct c4iw_ep *ep)
1325{
1326 struct iw_cm_event event;
1327
1328 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1329 memset(&event, 0, sizeof(event));
1330 event.event = IW_CM_EVENT_ESTABLISHED;
Hariprasad S3dd9a5d2015-09-08 09:57:00 +05301331 event.ird = ep->ord;
1332 event.ord = ep->ird;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001333 if (ep->com.cm_id) {
1334 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1335 ep->com.cm_id->event_handler(ep->com.cm_id, &event);
Vipul Pandya793dad92012-12-10 09:30:56 +00001336 set_bit(ESTAB_UPCALL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001337 }
1338}
1339
1340static int update_rx_credits(struct c4iw_ep *ep, u32 credits)
1341{
1342 struct cpl_rx_data_ack *req;
1343 struct sk_buff *skb;
1344 int wrlen = roundup(sizeof *req, 16);
1345
1346 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
1347 skb = get_skb(NULL, wrlen, GFP_KERNEL);
1348 if (!skb) {
1349 printk(KERN_ERR MOD "update_rx_credits - cannot alloc skb!\n");
1350 return 0;
1351 }
1352
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301353 /*
1354 * If we couldn't specify the entire rcv window at connection setup
1355 * due to the limit in the number of bits in the RCV_BUFSIZ field,
1356 * then add the overage in to the credits returned.
1357 */
Anish Bhattd7990b02014-11-12 17:15:57 -08001358 if (ep->rcv_win > RCV_BUFSIZ_M * 1024)
1359 credits += ep->rcv_win - RCV_BUFSIZ_M * 1024;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301360
Steve Wisecfdda9d2010-04-21 15:30:06 -07001361 req = (struct cpl_rx_data_ack *) skb_put(skb, wrlen);
1362 memset(req, 0, wrlen);
1363 INIT_TP_WR(req, ep->hwtid);
1364 OPCODE_TID(req) = cpu_to_be32(MK_OPCODE_TID(CPL_RX_DATA_ACK,
1365 ep->hwtid));
Anish Bhattd7990b02014-11-12 17:15:57 -08001366 req->credit_dack = cpu_to_be32(credits | RX_FORCE_ACK_F |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05301367 RX_DACK_CHANGE_F |
1368 RX_DACK_MODE_V(dack_mode));
Steve Wised4f1a5c2010-07-23 19:12:32 +00001369 set_wr_txq(skb, CPL_PRIORITY_ACK, ep->ctrlq_idx);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001370 c4iw_ofld_send(&ep->com.dev->rdev, skb);
1371 return credits;
1372}
1373
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301374#define RELAXED_IRD_NEGOTIATION 1
1375
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301376/*
1377 * process_mpa_reply - process streaming mode MPA reply
1378 *
1379 * Returns:
1380 *
1381 * 0 upon success indicating a connect request was delivered to the ULP
1382 * or the mpa request is incomplete but valid so far.
1383 *
1384 * 1 if a failure requires the caller to close the connection.
1385 *
1386 * 2 if a failure requires the caller to abort the connection.
1387 */
Steve Wisecc18b932014-04-24 14:31:53 -05001388static int process_mpa_reply(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001389{
1390 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301391 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001392 u16 plen;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301393 u16 resp_ird, resp_ord;
1394 u8 rtr_mismatch = 0, insuff_ird = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001395 struct c4iw_qp_attributes attrs;
1396 enum c4iw_qp_attr_mask mask;
1397 int err;
Steve Wisecc18b932014-04-24 14:31:53 -05001398 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001399
1400 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1401
1402 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001403 * If we get more than the supported amount of private data
1404 * then we must fail this connection.
1405 */
1406 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt)) {
1407 err = -EINVAL;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301408 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001409 }
1410
1411 /*
1412 * copy the new data into our accumulation buffer.
1413 */
1414 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1415 skb->len);
1416 ep->mpa_pkt_len += skb->len;
1417
1418 /*
1419 * if we don't even have the mpa message, then bail.
1420 */
1421 if (ep->mpa_pkt_len < sizeof(*mpa))
Steve Wisecc18b932014-04-24 14:31:53 -05001422 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001423 mpa = (struct mpa_message *) ep->mpa_pkt;
1424
1425 /* Validate MPA header. */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301426 if (mpa->revision > mpa_rev) {
1427 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1428 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001429 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301430 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001431 }
1432 if (memcmp(mpa->key, MPA_KEY_REP, sizeof(mpa->key))) {
1433 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301434 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001435 }
1436
1437 plen = ntohs(mpa->private_data_size);
1438
1439 /*
1440 * Fail if there's too much private data.
1441 */
1442 if (plen > MPA_MAX_PRIVATE_DATA) {
1443 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301444 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001445 }
1446
1447 /*
1448 * If plen does not account for pkt size
1449 */
1450 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen)) {
1451 err = -EPROTO;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301452 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001453 }
1454
1455 ep->plen = (u8) plen;
1456
1457 /*
1458 * If we don't have all the pdata yet, then bail.
1459 * We'll continue process when more data arrives.
1460 */
1461 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Steve Wisecc18b932014-04-24 14:31:53 -05001462 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001463
1464 if (mpa->flags & MPA_REJECT) {
1465 err = -ECONNREFUSED;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301466 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001467 }
1468
1469 /*
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301470 * Stop mpa timer. If it expired, then
1471 * we ignore the MPA reply. process_timeout()
1472 * will abort the connection.
1473 */
1474 if (stop_ep_timer(ep))
1475 return 0;
1476
1477 /*
Steve Wisecfdda9d2010-04-21 15:30:06 -07001478 * If we get here we have accumulated the entire mpa
1479 * start reply message including private data. And
1480 * the MPA header is valid.
1481 */
Steve Wisec529fb52014-03-21 20:40:37 +05301482 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001483 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1484 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1485 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301486 ep->mpa_attr.version = mpa->revision;
1487 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1488
1489 if (mpa->revision == 2) {
1490 ep->mpa_attr.enhanced_rdma_conn =
1491 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1492 if (ep->mpa_attr.enhanced_rdma_conn) {
1493 mpa_v2_params = (struct mpa_v2_conn_params *)
1494 (ep->mpa_pkt + sizeof(*mpa));
1495 resp_ird = ntohs(mpa_v2_params->ird) &
1496 MPA_V2_IRD_ORD_MASK;
1497 resp_ord = ntohs(mpa_v2_params->ord) &
1498 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301499 PDBG("%s responder ird %u ord %u ep ird %u ord %u\n",
1500 __func__, resp_ird, resp_ord, ep->ird, ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301501
1502 /*
1503 * This is a double-check. Ideally, below checks are
1504 * not required since ird/ord stuff has been taken
1505 * care of in c4iw_accept_cr
1506 */
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301507 if (ep->ird < resp_ord) {
1508 if (RELAXED_IRD_NEGOTIATION && resp_ord <=
1509 ep->com.dev->rdev.lldi.max_ordird_qp)
1510 ep->ird = resp_ord;
1511 else
1512 insuff_ird = 1;
1513 } else if (ep->ird > resp_ord) {
1514 ep->ird = resp_ord;
1515 }
1516 if (ep->ord > resp_ird) {
1517 if (RELAXED_IRD_NEGOTIATION)
1518 ep->ord = resp_ird;
1519 else
1520 insuff_ird = 1;
1521 }
1522 if (insuff_ird) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301523 err = -ENOMEM;
1524 ep->ird = resp_ord;
1525 ep->ord = resp_ird;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301526 }
1527
1528 if (ntohs(mpa_v2_params->ird) &
1529 MPA_V2_PEER2PEER_MODEL) {
1530 if (ntohs(mpa_v2_params->ord) &
1531 MPA_V2_RDMA_WRITE_RTR)
1532 ep->mpa_attr.p2p_type =
1533 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1534 else if (ntohs(mpa_v2_params->ord) &
1535 MPA_V2_RDMA_READ_RTR)
1536 ep->mpa_attr.p2p_type =
1537 FW_RI_INIT_P2PTYPE_READ_REQ;
1538 }
1539 }
1540 } else if (mpa->revision == 1)
1541 if (peer2peer)
1542 ep->mpa_attr.p2p_type = p2p_type;
1543
Steve Wisecfdda9d2010-04-21 15:30:06 -07001544 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301545 "xmit_marker_enabled=%d, version=%d p2p_type=%d local-p2p_type = "
1546 "%d\n", __func__, ep->mpa_attr.crc_enabled,
1547 ep->mpa_attr.recv_marker_enabled,
1548 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1549 ep->mpa_attr.p2p_type, p2p_type);
1550
1551 /*
1552 * If responder's RTR does not match with that of initiator, assign
1553 * FW_RI_INIT_P2PTYPE_DISABLED in mpa attributes so that RTR is not
1554 * generated when moving QP to RTS state.
1555 * A TERM message will be sent after QP has moved to RTS state
1556 */
Kumar Sanghvi91018f82012-02-25 17:45:02 -08001557 if ((ep->mpa_attr.version == 2) && peer2peer &&
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301558 (ep->mpa_attr.p2p_type != p2p_type)) {
1559 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1560 rtr_mismatch = 1;
1561 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001562
1563 attrs.mpa_attr = ep->mpa_attr;
1564 attrs.max_ird = ep->ird;
1565 attrs.max_ord = ep->ord;
1566 attrs.llp_stream_handle = ep;
1567 attrs.next_state = C4IW_QP_STATE_RTS;
1568
1569 mask = C4IW_QP_ATTR_NEXT_STATE |
1570 C4IW_QP_ATTR_LLP_STREAM_HANDLE | C4IW_QP_ATTR_MPA_ATTR |
1571 C4IW_QP_ATTR_MAX_IRD | C4IW_QP_ATTR_MAX_ORD;
1572
1573 /* bind QP and TID with INIT_WR */
1574 err = c4iw_modify_qp(ep->com.qp->rhp,
1575 ep->com.qp, mask, &attrs, 1);
1576 if (err)
1577 goto err;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301578
1579 /*
1580 * If responder's RTR requirement did not match with what initiator
1581 * supports, generate TERM message
1582 */
1583 if (rtr_mismatch) {
1584 printk(KERN_ERR "%s: RTR mismatch, sending TERM\n", __func__);
1585 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1586 attrs.ecode = MPA_NOMATCH_RTR;
1587 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001588 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301589 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001590 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301591 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001592 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301593 goto out;
1594 }
1595
1596 /*
1597 * Generate TERM if initiator IRD is not sufficient for responder
1598 * provided ORD. Currently, we do the same behaviour even when
1599 * responder provided IRD is also not sufficient as regards to
1600 * initiator ORD.
1601 */
1602 if (insuff_ird) {
1603 printk(KERN_ERR "%s: Insufficient IRD, sending TERM\n",
1604 __func__);
1605 attrs.layer_etype = LAYER_MPA | DDP_LLP;
1606 attrs.ecode = MPA_INSUFF_IRD;
1607 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Steve Wisecc18b932014-04-24 14:31:53 -05001608 attrs.send_term = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301609 err = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001610 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301611 err = -ENOMEM;
Steve Wisecc18b932014-04-24 14:31:53 -05001612 disconnect = 1;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301613 goto out;
1614 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07001615 goto out;
Hariprasad Sda1cecd2016-05-06 22:17:58 +05301616err_stop_timer:
1617 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001618err:
Hariprasad Sf8e1e1d2016-05-05 01:27:32 +05301619 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001620out:
1621 connect_reply_upcall(ep, err);
Steve Wisecc18b932014-04-24 14:31:53 -05001622 return disconnect;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001623}
1624
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301625/*
1626 * process_mpa_request - process streaming mode MPA request
1627 *
1628 * Returns:
1629 *
1630 * 0 upon success indicating a connect request was delivered to the ULP
1631 * or the mpa request is incomplete but valid so far.
1632 *
1633 * 1 if a failure requires the caller to close the connection.
1634 *
1635 * 2 if a failure requires the caller to abort the connection.
1636 */
1637static int process_mpa_request(struct c4iw_ep *ep, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07001638{
1639 struct mpa_message *mpa;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301640 struct mpa_v2_conn_params *mpa_v2_params;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001641 u16 plen;
1642
1643 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
1644
Steve Wisecfdda9d2010-04-21 15:30:06 -07001645 /*
1646 * If we get more than the supported amount of private data
1647 * then we must fail this connection.
1648 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301649 if (ep->mpa_pkt_len + skb->len > sizeof(ep->mpa_pkt))
1650 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001651
1652 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
1653
1654 /*
1655 * Copy the new data into our accumulation buffer.
1656 */
1657 skb_copy_from_linear_data(skb, &(ep->mpa_pkt[ep->mpa_pkt_len]),
1658 skb->len);
1659 ep->mpa_pkt_len += skb->len;
1660
1661 /*
1662 * If we don't even have the mpa message, then bail.
1663 * We'll continue process when more data arrives.
1664 */
1665 if (ep->mpa_pkt_len < sizeof(*mpa))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301666 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001667
1668 PDBG("%s enter (%s line %u)\n", __func__, __FILE__, __LINE__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001669 mpa = (struct mpa_message *) ep->mpa_pkt;
1670
1671 /*
1672 * Validate MPA Header.
1673 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301674 if (mpa->revision > mpa_rev) {
1675 printk(KERN_ERR MOD "%s MPA version mismatch. Local = %d,"
1676 " Received = %d\n", __func__, mpa_rev, mpa->revision);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301677 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001678 }
1679
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301680 if (memcmp(mpa->key, MPA_KEY_REQ, sizeof(mpa->key)))
1681 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001682
1683 plen = ntohs(mpa->private_data_size);
1684
1685 /*
1686 * Fail if there's too much private data.
1687 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301688 if (plen > MPA_MAX_PRIVATE_DATA)
1689 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001690
1691 /*
1692 * If plen does not account for pkt size
1693 */
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301694 if (ep->mpa_pkt_len > (sizeof(*mpa) + plen))
1695 goto err_stop_timer;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001696 ep->plen = (u8) plen;
1697
1698 /*
1699 * If we don't have all the pdata yet, then bail.
1700 */
1701 if (ep->mpa_pkt_len < (sizeof(*mpa) + plen))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301702 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001703
1704 /*
1705 * If we get here we have accumulated the entire mpa
1706 * start reply message including private data.
1707 */
1708 ep->mpa_attr.initiator = 0;
1709 ep->mpa_attr.crc_enabled = (mpa->flags & MPA_CRC) | crc_enabled ? 1 : 0;
1710 ep->mpa_attr.recv_marker_enabled = markers_enabled;
1711 ep->mpa_attr.xmit_marker_enabled = mpa->flags & MPA_MARKERS ? 1 : 0;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301712 ep->mpa_attr.version = mpa->revision;
1713 if (mpa->revision == 1)
1714 ep->tried_with_mpa_v1 = 1;
1715 ep->mpa_attr.p2p_type = FW_RI_INIT_P2PTYPE_DISABLED;
1716
1717 if (mpa->revision == 2) {
1718 ep->mpa_attr.enhanced_rdma_conn =
1719 mpa->flags & MPA_ENHANCED_RDMA_CONN ? 1 : 0;
1720 if (ep->mpa_attr.enhanced_rdma_conn) {
1721 mpa_v2_params = (struct mpa_v2_conn_params *)
1722 (ep->mpa_pkt + sizeof(*mpa));
1723 ep->ird = ntohs(mpa_v2_params->ird) &
1724 MPA_V2_IRD_ORD_MASK;
1725 ep->ord = ntohs(mpa_v2_params->ord) &
1726 MPA_V2_IRD_ORD_MASK;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05301727 PDBG("%s initiator ird %u ord %u\n", __func__, ep->ird,
1728 ep->ord);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05301729 if (ntohs(mpa_v2_params->ird) & MPA_V2_PEER2PEER_MODEL)
1730 if (peer2peer) {
1731 if (ntohs(mpa_v2_params->ord) &
1732 MPA_V2_RDMA_WRITE_RTR)
1733 ep->mpa_attr.p2p_type =
1734 FW_RI_INIT_P2PTYPE_RDMA_WRITE;
1735 else if (ntohs(mpa_v2_params->ord) &
1736 MPA_V2_RDMA_READ_RTR)
1737 ep->mpa_attr.p2p_type =
1738 FW_RI_INIT_P2PTYPE_READ_REQ;
1739 }
1740 }
1741 } else if (mpa->revision == 1)
1742 if (peer2peer)
1743 ep->mpa_attr.p2p_type = p2p_type;
1744
Steve Wisecfdda9d2010-04-21 15:30:06 -07001745 PDBG("%s - crc_enabled=%d, recv_marker_enabled=%d, "
1746 "xmit_marker_enabled=%d, version=%d p2p_type=%d\n", __func__,
1747 ep->mpa_attr.crc_enabled, ep->mpa_attr.recv_marker_enabled,
1748 ep->mpa_attr.xmit_marker_enabled, ep->mpa_attr.version,
1749 ep->mpa_attr.p2p_type);
1750
Hariprasad Se4b76a22016-05-06 22:17:59 +05301751 __state_set(&ep->com, MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001752
Hariprasad Se4b76a22016-05-06 22:17:59 +05301753 /* drive upcall */
1754 mutex_lock_nested(&ep->parent_ep->com.mutex, SINGLE_DEPTH_NESTING);
1755 if (ep->parent_ep->com.state != DEAD) {
1756 if (connect_request_upcall(ep))
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301757 goto err_unlock_parent;
Hariprasad Se4b76a22016-05-06 22:17:59 +05301758 } else {
1759 goto err_unlock_parent;
Steve Wisebe13b2d2014-03-21 20:40:33 +05301760 }
Hariprasad Se4b76a22016-05-06 22:17:59 +05301761 mutex_unlock(&ep->parent_ep->com.mutex);
Hariprasad Sfd6aabe2016-05-05 01:27:35 +05301762 return 0;
1763
1764err_unlock_parent:
1765 mutex_unlock(&ep->parent_ep->com.mutex);
1766 goto err_out;
1767err_stop_timer:
1768 (void)stop_ep_timer(ep);
1769err_out:
1770 return 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001771}
1772
1773static int rx_data(struct c4iw_dev *dev, struct sk_buff *skb)
1774{
1775 struct c4iw_ep *ep;
1776 struct cpl_rx_data *hdr = cplhdr(skb);
1777 unsigned int dlen = ntohs(hdr->len);
1778 unsigned int tid = GET_TID(hdr);
1779 struct tid_info *t = dev->rdev.lldi.tids;
Vipul Pandya793dad92012-12-10 09:30:56 +00001780 __u8 status = hdr->status;
Steve Wisecc18b932014-04-24 14:31:53 -05001781 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001782
1783 ep = lookup_tid(t, tid);
Steve Wise977116c2014-03-21 20:40:36 +05301784 if (!ep)
1785 return 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001786 PDBG("%s ep %p tid %u dlen %u\n", __func__, ep, ep->hwtid, dlen);
1787 skb_pull(skb, sizeof(*hdr));
1788 skb_trim(skb, dlen);
Steve Wisec529fb52014-03-21 20:40:37 +05301789 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001790
Steve Wisecfdda9d2010-04-21 15:30:06 -07001791 /* update RX credits */
1792 update_rx_credits(ep, dlen);
1793
Steve Wisec529fb52014-03-21 20:40:37 +05301794 switch (ep->com.state) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07001795 case MPA_REQ_SENT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001796 ep->rcv_seq += dlen;
Steve Wisecc18b932014-04-24 14:31:53 -05001797 disconnect = process_mpa_reply(ep, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001798 break;
1799 case MPA_REQ_WAIT:
Vipul Pandya55abf8d2013-01-07 13:11:50 +00001800 ep->rcv_seq += dlen;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001801 process_mpa_request(ep, skb);
1802 break;
Vipul Pandya15579672013-01-07 13:11:52 +00001803 case FPDU_MODE: {
1804 struct c4iw_qp_attributes attrs;
1805 BUG_ON(!ep->com.qp);
Vipul Pandyae8e5b922013-01-07 13:11:55 +00001806 if (status)
Vipul Pandya15579672013-01-07 13:11:52 +00001807 pr_err("%s Unexpected streaming data." \
Vipul Pandya04236df2013-01-07 13:11:54 +00001808 " qpid %u ep %p state %d tid %u status %d\n",
1809 __func__, ep->com.qp->wq.sq.qid, ep,
Steve Wisec529fb52014-03-21 20:40:37 +05301810 ep->com.state, ep->hwtid, status);
Steve Wise97d7ec02013-08-06 21:04:34 +05301811 attrs.next_state = C4IW_QP_STATE_TERMINATE;
Vipul Pandya15579672013-01-07 13:11:52 +00001812 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wisecc18b932014-04-24 14:31:53 -05001813 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
1814 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07001815 break;
1816 }
Vipul Pandya15579672013-01-07 13:11:52 +00001817 default:
1818 break;
1819 }
Steve Wisec529fb52014-03-21 20:40:37 +05301820 mutex_unlock(&ep->com.mutex);
Steve Wisecc18b932014-04-24 14:31:53 -05001821 if (disconnect)
1822 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001823 return 0;
1824}
1825
1826static int abort_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
1827{
1828 struct c4iw_ep *ep;
1829 struct cpl_abort_rpl_rss *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001830 int release = 0;
1831 unsigned int tid = GET_TID(rpl);
1832 struct tid_info *t = dev->rdev.lldi.tids;
1833
1834 ep = lookup_tid(t, tid);
Vipul Pandya49840372012-05-18 15:29:29 +05301835 if (!ep) {
1836 printk(KERN_WARNING MOD "Abort rpl to freed endpoint\n");
1837 return 0;
1838 }
Wei Yongjun92dd6c32012-09-07 06:51:23 +00001839 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wise2f5b48c2010-09-10 11:15:36 -05001840 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001841 switch (ep->com.state) {
1842 case ABORTING:
Vipul Pandya91e9c0712013-01-07 13:11:51 +00001843 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001844 __state_set(&ep->com, DEAD);
1845 release = 1;
1846 break;
1847 default:
1848 printk(KERN_ERR "%s ep %p state %d\n",
1849 __func__, ep, ep->com.state);
1850 break;
1851 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05001852 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07001853
1854 if (release)
1855 release_ep_resources(ep);
1856 return 0;
1857}
1858
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301859static int send_fw_act_open_req(struct c4iw_ep *ep, unsigned int atid)
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001860{
1861 struct sk_buff *skb;
1862 struct fw_ofld_connection_wr *req;
1863 unsigned int mtu_idx;
1864 int wscale;
Vipul Pandya830662f2013-07-04 16:10:47 +05301865 struct sockaddr_in *sin;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301866 int win;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001867
1868 skb = get_skb(NULL, sizeof(*req), GFP_KERNEL);
1869 req = (struct fw_ofld_connection_wr *)__skb_put(skb, sizeof(*req));
1870 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001871 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR));
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05301872 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05301873 req->le.filter = cpu_to_be32(cxgb4_select_ntuple(
1874 ep->com.dev->rdev.lldi.ports[0],
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001875 ep->l2t));
Steve Wise170003c2016-02-26 09:18:03 -06001876 sin = (struct sockaddr_in *)&ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301877 req->le.lport = sin->sin_port;
1878 req->le.u.ipv4.lip = sin->sin_addr.s_addr;
Steve Wise170003c2016-02-26 09:18:03 -06001879 sin = (struct sockaddr_in *)&ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05301880 req->le.pport = sin->sin_port;
1881 req->le.u.ipv4.pip = sin->sin_addr.s_addr;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001882 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301883 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_SENT) |
1884 FW_OFLD_CONNECTION_WR_ASTID_V(atid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001885 req->tcb.cplrxdataack_cplpassacceptrpl =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05301886 htons(FW_OFLD_CONNECTION_WR_CPLRXDATAACK_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00001887 req->tcb.tx_max = (__force __be32) jiffies;
Vipul Pandya793dad92012-12-10 09:30:56 +00001888 req->tcb.rcv_adv = htons(1);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05301889 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05301890 enable_tcp_timestamps,
1891 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001892 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301893
1894 /*
1895 * Specify the largest window that will fit in opt0. The
1896 * remainder will be specified in the rx_data_ack.
1897 */
1898 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08001899 if (win > RCV_BUFSIZ_M)
1900 win = RCV_BUFSIZ_M;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301901
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001902 req->tcb.opt0 = (__force __be64) (TCAM_BYPASS_F |
1903 (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001904 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001905 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08001906 WND_SCALE_V(wscale) |
1907 MSS_IDX_V(mtu_idx) |
1908 L2T_IDX_V(ep->l2t->idx) |
1909 TX_CHAN_V(ep->tx_chan) |
1910 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301911 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001912 ULP_MODE_V(ULP_MODE_TCPDDP) |
1913 RCV_BUFSIZ_V(win));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001914 req->tcb.opt2 = (__force __be32) (PACE_V(1) |
1915 TX_QUEUE_V(ep->com.dev->rdev.lldi.tx_modq[ep->tx_chan]) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001916 RX_CHANNEL_V(0) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001917 CCTRL_ECN_V(enable_ecn) |
Anish Bhattd7990b02014-11-12 17:15:57 -08001918 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid));
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001919 if (enable_tcp_timestamps)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001920 req->tcb.opt2 |= (__force __be32)TSTAMPS_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001921 if (enable_tcp_sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08001922 req->tcb.opt2 |= (__force __be32)SACK_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001923 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08001924 req->tcb.opt2 |= (__force __be32)WND_SCALE_EN_F;
1925 req->tcb.opt0 = cpu_to_be64((__force u64)req->tcb.opt0);
1926 req->tcb.opt2 = cpu_to_be32((__force u32)req->tcb.opt2);
Vipul Pandya793dad92012-12-10 09:30:56 +00001927 set_wr_txq(skb, CPL_PRIORITY_CONTROL, ep->ctrlq_idx);
1928 set_bit(ACT_OFLD_CONN, &ep->com.history);
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05301929 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00001930}
1931
Steve Wisecfdda9d2010-04-21 15:30:06 -07001932/*
1933 * Return whether a failed active open has allocated a TID
1934 */
1935static inline int act_open_has_tid(int status)
1936{
1937 return status != CPL_ERR_TCAM_FULL && status != CPL_ERR_CONN_EXIST &&
1938 status != CPL_ERR_ARP_MISS;
1939}
1940
Steve Wise7a2cea22014-03-14 21:52:07 +05301941/* Returns whether a CPL status conveys negative advice.
1942 */
1943static int is_neg_adv(unsigned int status)
1944{
1945 return status == CPL_ERR_RTX_NEG_ADVICE ||
1946 status == CPL_ERR_PERSIST_NEG_ADVICE ||
1947 status == CPL_ERR_KEEPALV_NEG_ADVICE;
1948}
1949
Hariprasad Shenaidd92b122014-07-21 20:55:13 +05301950static char *neg_adv_str(unsigned int status)
1951{
1952 switch (status) {
1953 case CPL_ERR_RTX_NEG_ADVICE:
1954 return "Retransmit timeout";
1955 case CPL_ERR_PERSIST_NEG_ADVICE:
1956 return "Persist timeout";
1957 case CPL_ERR_KEEPALV_NEG_ADVICE:
1958 return "Keepalive timeout";
1959 default:
1960 return "Unknown";
1961 }
1962}
1963
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05301964static void set_tcp_window(struct c4iw_ep *ep, struct port_info *pi)
1965{
1966 ep->snd_win = snd_win;
1967 ep->rcv_win = rcv_win;
1968 PDBG("%s snd_win %d rcv_win %d\n", __func__, ep->snd_win, ep->rcv_win);
1969}
1970
Vipul Pandya793dad92012-12-10 09:30:56 +00001971#define ACT_OPEN_RETRY_COUNT 2
1972
Vipul Pandya830662f2013-07-04 16:10:47 +05301973static int import_ep(struct c4iw_ep *ep, int iptype, __u8 *peer_ip,
1974 struct dst_entry *dst, struct c4iw_dev *cdev,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05301975 bool clear_mpa_v1, enum chip_type adapter_type, u8 tos)
Vipul Pandya830662f2013-07-04 16:10:47 +05301976{
1977 struct neighbour *n;
1978 int err, step;
1979 struct net_device *pdev;
1980
1981 n = dst_neigh_lookup(dst, peer_ip);
1982 if (!n)
1983 return -ENODEV;
1984
1985 rcu_read_lock();
1986 err = -ENOMEM;
1987 if (n->dev->flags & IFF_LOOPBACK) {
1988 if (iptype == 4)
1989 pdev = ip_dev_find(&init_net, *(__be32 *)peer_ip);
1990 else if (IS_ENABLED(CONFIG_IPV6))
1991 for_each_netdev(&init_net, pdev) {
1992 if (ipv6_chk_addr(&init_net,
1993 (struct in6_addr *)peer_ip,
1994 pdev, 1))
1995 break;
1996 }
1997 else
1998 pdev = NULL;
1999
2000 if (!pdev) {
2001 err = -ENODEV;
2002 goto out;
2003 }
2004 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302005 n, pdev, rt_tos2priority(tos));
Vipul Pandya830662f2013-07-04 16:10:47 +05302006 if (!ep->l2t)
2007 goto out;
2008 ep->mtu = pdev->mtu;
2009 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302010 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2011 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302012 step = cdev->rdev.lldi.ntxq /
2013 cdev->rdev.lldi.nchan;
2014 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2015 step = cdev->rdev.lldi.nrxq /
2016 cdev->rdev.lldi.nchan;
2017 ep->ctrlq_idx = cxgb4_port_idx(pdev);
2018 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
2019 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302020 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302021 dev_put(pdev);
2022 } else {
2023 pdev = get_real_dev(n->dev);
2024 ep->l2t = cxgb4_l2t_get(cdev->rdev.lldi.l2t,
2025 n, pdev, 0);
2026 if (!ep->l2t)
2027 goto out;
2028 ep->mtu = dst_mtu(dst);
Steve Wise11b8e222014-05-16 12:42:46 -05002029 ep->tx_chan = cxgb4_port_chan(pdev);
Hariprasad S963cab52015-09-23 17:19:27 +05302030 ep->smac_idx = cxgb4_tp_smt_idx(adapter_type,
2031 cxgb4_port_viid(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302032 step = cdev->rdev.lldi.ntxq /
2033 cdev->rdev.lldi.nchan;
Steve Wise11b8e222014-05-16 12:42:46 -05002034 ep->txq_idx = cxgb4_port_idx(pdev) * step;
2035 ep->ctrlq_idx = cxgb4_port_idx(pdev);
Vipul Pandya830662f2013-07-04 16:10:47 +05302036 step = cdev->rdev.lldi.nrxq /
2037 cdev->rdev.lldi.nchan;
2038 ep->rss_qid = cdev->rdev.lldi.rxq_ids[
Steve Wise11b8e222014-05-16 12:42:46 -05002039 cxgb4_port_idx(pdev) * step];
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302040 set_tcp_window(ep, (struct port_info *)netdev_priv(pdev));
Vipul Pandya830662f2013-07-04 16:10:47 +05302041
2042 if (clear_mpa_v1) {
2043 ep->retry_with_mpa_v1 = 0;
2044 ep->tried_with_mpa_v1 = 0;
2045 }
2046 }
2047 err = 0;
2048out:
2049 rcu_read_unlock();
2050
2051 neigh_release(n);
2052
2053 return err;
2054}
2055
Vipul Pandya793dad92012-12-10 09:30:56 +00002056static int c4iw_reconnect(struct c4iw_ep *ep)
2057{
2058 int err = 0;
Steve Wise24d44a32013-07-04 16:10:44 +05302059 struct sockaddr_in *laddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002060 &ep->com.cm_id->m_local_addr;
Steve Wise24d44a32013-07-04 16:10:44 +05302061 struct sockaddr_in *raddr = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002062 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302063 struct sockaddr_in6 *laddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002064 &ep->com.cm_id->m_local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302065 struct sockaddr_in6 *raddr6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002066 &ep->com.cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302067 int iptype;
2068 __u8 *ra;
Vipul Pandya793dad92012-12-10 09:30:56 +00002069
2070 PDBG("%s qp %p cm_id %p\n", __func__, ep->com.qp, ep->com.cm_id);
2071 init_timer(&ep->timer);
2072
2073 /*
2074 * Allocate an active TID to initiate a TCP connection.
2075 */
2076 ep->atid = cxgb4_alloc_atid(ep->com.dev->rdev.lldi.tids, ep);
2077 if (ep->atid == -1) {
2078 pr_err("%s - cannot alloc atid.\n", __func__);
2079 err = -ENOMEM;
2080 goto fail2;
2081 }
2082 insert_handle(ep->com.dev, &ep->com.dev->atid_idr, ep, ep->atid);
2083
2084 /* find a route */
Steve Wise170003c2016-02-26 09:18:03 -06002085 if (ep->com.cm_id->m_local_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05302086 ep->dst = find_route(ep->com.dev, laddr->sin_addr.s_addr,
2087 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302088 raddr->sin_port, ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302089 iptype = 4;
2090 ra = (__u8 *)&raddr->sin_addr;
2091 } else {
2092 ep->dst = find_route6(ep->com.dev, laddr6->sin6_addr.s6_addr,
2093 raddr6->sin6_addr.s6_addr,
2094 laddr6->sin6_port, raddr6->sin6_port, 0,
2095 raddr6->sin6_scope_id);
2096 iptype = 6;
2097 ra = (__u8 *)&raddr6->sin6_addr;
2098 }
2099 if (!ep->dst) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002100 pr_err("%s - cannot find route.\n", __func__);
2101 err = -EHOSTUNREACH;
2102 goto fail3;
2103 }
Hariprasad S963cab52015-09-23 17:19:27 +05302104 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302105 ep->com.dev->rdev.lldi.adapter_type,
2106 ep->com.cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302107 if (err) {
Vipul Pandya793dad92012-12-10 09:30:56 +00002108 pr_err("%s - cannot alloc l2e.\n", __func__);
Vipul Pandya793dad92012-12-10 09:30:56 +00002109 goto fail4;
2110 }
2111
2112 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
2113 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
2114 ep->l2t->idx);
2115
2116 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302117 ep->tos = ep->com.cm_id->tos;
Vipul Pandya793dad92012-12-10 09:30:56 +00002118
2119 /* send connect request to rnic */
2120 err = send_connect(ep);
2121 if (!err)
2122 goto out;
2123
2124 cxgb4_l2t_release(ep->l2t);
2125fail4:
2126 dst_release(ep->dst);
2127fail3:
2128 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
2129 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
2130fail2:
2131 /*
2132 * remember to send notification to upper layer.
2133 * We are in here so the upper layer is not aware that this is
2134 * re-connect attempt and so, upper layer is still waiting for
2135 * response of 1st connect request.
2136 */
2137 connect_reply_upcall(ep, -ECONNRESET);
2138 c4iw_put_ep(&ep->com);
2139out:
2140 return err;
2141}
2142
Steve Wisecfdda9d2010-04-21 15:30:06 -07002143static int act_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2144{
2145 struct c4iw_ep *ep;
2146 struct cpl_act_open_rpl *rpl = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002147 unsigned int atid = TID_TID_G(AOPEN_ATID_G(
2148 ntohl(rpl->atid_status)));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002149 struct tid_info *t = dev->rdev.lldi.tids;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002150 int status = AOPEN_STATUS_G(ntohl(rpl->atid_status));
Vipul Pandya830662f2013-07-04 16:10:47 +05302151 struct sockaddr_in *la;
2152 struct sockaddr_in *ra;
2153 struct sockaddr_in6 *la6;
2154 struct sockaddr_in6 *ra6;
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302155 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002156
2157 ep = lookup_atid(t, atid);
Steve Wise170003c2016-02-26 09:18:03 -06002158 la = (struct sockaddr_in *)&ep->com.local_addr;
2159 ra = (struct sockaddr_in *)&ep->com.remote_addr;
2160 la6 = (struct sockaddr_in6 *)&ep->com.local_addr;
2161 ra6 = (struct sockaddr_in6 *)&ep->com.remote_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002162
2163 PDBG("%s ep %p atid %u status %u errno %d\n", __func__, ep, atid,
2164 status, status2errno(status));
2165
Steve Wise7a2cea22014-03-14 21:52:07 +05302166 if (is_neg_adv(status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302167 PDBG("%s Connection problems for atid %u status %u (%s)\n",
2168 __func__, atid, status, neg_adv_str(status));
2169 ep->stats.connect_neg_adv++;
2170 mutex_lock(&dev->rdev.stats.lock);
2171 dev->rdev.stats.neg_adv++;
2172 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002173 return 0;
2174 }
2175
Vipul Pandya793dad92012-12-10 09:30:56 +00002176 set_bit(ACT_OPEN_RPL, &ep->com.history);
2177
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302178 /*
2179 * Log interesting failures.
2180 */
2181 switch (status) {
2182 case CPL_ERR_CONN_RESET:
2183 case CPL_ERR_CONN_TIMEDOUT:
2184 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002185 case CPL_ERR_TCAM_FULL:
Vipul Pandya830662f2013-07-04 16:10:47 +05302186 mutex_lock(&dev->rdev.stats.lock);
Vipul Pandya3b174d92013-03-14 05:09:03 +00002187 dev->rdev.stats.tcam_full++;
Vipul Pandya830662f2013-07-04 16:10:47 +05302188 mutex_unlock(&dev->rdev.stats.lock);
2189 if (ep->com.local_addr.ss_family == AF_INET &&
2190 dev->rdev.lldi.enable_fw_ofld_conn) {
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302191 ret = send_fw_act_open_req(ep, TID_TID_G(AOPEN_ATID_G(
2192 ntohl(rpl->atid_status))));
2193 if (ret)
2194 goto fail;
Vipul Pandya793dad92012-12-10 09:30:56 +00002195 return 0;
2196 }
2197 break;
2198 case CPL_ERR_CONN_EXIST:
2199 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
2200 set_bit(ACT_RETRY_INUSE, &ep->com.history);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302201 if (ep->com.remote_addr.ss_family == AF_INET6) {
2202 struct sockaddr_in6 *sin6 =
2203 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002204 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302205 cxgb4_clip_release(
2206 ep->com.dev->rdev.lldi.ports[0],
2207 (const u32 *)
2208 &sin6->sin6_addr.s6_addr, 1);
2209 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002210 remove_handle(ep->com.dev, &ep->com.dev->atid_idr,
2211 atid);
2212 cxgb4_free_atid(t, atid);
2213 dst_release(ep->dst);
2214 cxgb4_l2t_release(ep->l2t);
2215 c4iw_reconnect(ep);
2216 return 0;
2217 }
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002218 break;
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302219 default:
Vipul Pandya830662f2013-07-04 16:10:47 +05302220 if (ep->com.local_addr.ss_family == AF_INET) {
2221 pr_info("Active open failure - atid %u status %u errno %d %pI4:%u->%pI4:%u\n",
2222 atid, status, status2errno(status),
2223 &la->sin_addr.s_addr, ntohs(la->sin_port),
2224 &ra->sin_addr.s_addr, ntohs(ra->sin_port));
2225 } else {
2226 pr_info("Active open failure - atid %u status %u errno %d %pI6:%u->%pI6:%u\n",
2227 atid, status, status2errno(status),
2228 la6->sin6_addr.s6_addr, ntohs(la6->sin6_port),
2229 ra6->sin6_addr.s6_addr, ntohs(ra6->sin6_port));
2230 }
Vipul Pandyad716a2a2012-05-18 15:29:31 +05302231 break;
2232 }
2233
Hariprasad Scaa6c9f2016-05-06 22:18:00 +05302234fail:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002235 connect_reply_upcall(ep, status2errno(status));
2236 state_set(&ep->com, DEAD);
2237
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302238 if (ep->com.remote_addr.ss_family == AF_INET6) {
2239 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06002240 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302241 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
2242 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2243 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002244 if (status && act_open_has_tid(status))
2245 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, GET_TID(rpl));
2246
Vipul Pandya793dad92012-12-10 09:30:56 +00002247 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002248 cxgb4_free_atid(t, atid);
2249 dst_release(ep->dst);
2250 cxgb4_l2t_release(ep->l2t);
2251 c4iw_put_ep(&ep->com);
2252
2253 return 0;
2254}
2255
2256static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2257{
2258 struct cpl_pass_open_rpl *rpl = cplhdr(skb);
2259 struct tid_info *t = dev->rdev.lldi.tids;
2260 unsigned int stid = GET_TID(rpl);
2261 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2262
2263 if (!ep) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00002264 PDBG("%s stid %d lookup failure!\n", __func__, stid);
2265 goto out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002266 }
2267 PDBG("%s ep %p status %d error %d\n", __func__, ep,
2268 rpl->status, status2errno(rpl->status));
Steve Wised9594d92011-05-09 22:06:22 -07002269 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002270
Vipul Pandya1cab7752012-12-10 09:30:55 +00002271out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002272 return 0;
2273}
2274
Steve Wisecfdda9d2010-04-21 15:30:06 -07002275static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2276{
2277 struct cpl_close_listsvr_rpl *rpl = cplhdr(skb);
2278 struct tid_info *t = dev->rdev.lldi.tids;
2279 unsigned int stid = GET_TID(rpl);
2280 struct c4iw_listen_ep *ep = lookup_stid(t, stid);
2281
2282 PDBG("%s ep %p\n", __func__, ep);
Steve Wised9594d92011-05-09 22:06:22 -07002283 c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002284 return 0;
2285}
2286
Hariprasad S9dec9002016-05-05 01:27:29 +05302287static int accept_cr(struct c4iw_ep *ep, struct sk_buff *skb,
2288 struct cpl_pass_accept_req *req)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002289{
2290 struct cpl_pass_accept_rpl *rpl;
2291 unsigned int mtu_idx;
2292 u64 opt0;
2293 u32 opt2;
2294 int wscale;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302295 struct cpl_t5_pass_accept_rpl *rpl5 = NULL;
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302296 int win;
Hariprasad S963cab52015-09-23 17:19:27 +05302297 enum chip_type adapter_type = ep->com.dev->rdev.lldi.adapter_type;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002298
2299 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2300 BUG_ON(skb_cloned(skb));
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302301
Steve Wisecfdda9d2010-04-21 15:30:06 -07002302 skb_get(skb);
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302303 rpl = cplhdr(skb);
Hariprasad S963cab52015-09-23 17:19:27 +05302304 if (!is_t4(adapter_type)) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302305 skb_trim(skb, roundup(sizeof(*rpl5), 16));
2306 rpl5 = (void *)rpl;
2307 INIT_TP_WR(rpl5, ep->hwtid);
2308 } else {
2309 skb_trim(skb, sizeof(*rpl));
2310 INIT_TP_WR(rpl, ep->hwtid);
2311 }
2312 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_PASS_ACCEPT_RPL,
2313 ep->hwtid));
2314
2315 best_mtu(ep->com.dev->rdev.lldi.mtus, ep->mtu, &mtu_idx,
Hariprasad S04524a42014-09-24 03:53:41 +05302316 enable_tcp_timestamps && req->tcpopt.tstamp,
2317 (AF_INET == ep->com.remote_addr.ss_family) ? 0 : 1);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002318 wscale = compute_wscale(rcv_win);
Hariprasad Shenaib408ff22014-06-06 21:40:44 +05302319
2320 /*
2321 * Specify the largest window that will fit in opt0. The
2322 * remainder will be specified in the rx_data_ack.
2323 */
2324 win = ep->rcv_win >> 10;
Anish Bhattd7990b02014-11-12 17:15:57 -08002325 if (win > RCV_BUFSIZ_M)
2326 win = RCV_BUFSIZ_M;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002327 opt0 = (nocong ? NO_CONG_F : 0) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002328 KEEP_ALIVE_F |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002329 DELACK_F |
Anish Bhattd7990b02014-11-12 17:15:57 -08002330 WND_SCALE_V(wscale) |
2331 MSS_IDX_V(mtu_idx) |
2332 L2T_IDX_V(ep->l2t->idx) |
2333 TX_CHAN_V(ep->tx_chan) |
2334 SMAC_SEL_V(ep->smac_idx) |
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002335 DSCP_V(ep->tos >> 2) |
Anish Bhattd7990b02014-11-12 17:15:57 -08002336 ULP_MODE_V(ULP_MODE_TCPDDP) |
2337 RCV_BUFSIZ_V(win);
2338 opt2 = RX_CHANNEL_V(0) |
2339 RSS_QUEUE_VALID_F | RSS_QUEUE_V(ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002340
2341 if (enable_tcp_timestamps && req->tcpopt.tstamp)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002342 opt2 |= TSTAMPS_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002343 if (enable_tcp_sack && req->tcpopt.sack)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002344 opt2 |= SACK_EN_F;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002345 if (wscale && enable_tcp_window_scaling)
Anish Bhattd7990b02014-11-12 17:15:57 -08002346 opt2 |= WND_SCALE_EN_F;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002347 if (enable_ecn) {
2348 const struct tcphdr *tcph;
2349 u32 hlen = ntohl(req->hdr_len);
2350
Hariprasad S963cab52015-09-23 17:19:27 +05302351 if (CHELSIO_CHIP_VERSION(adapter_type) <= CHELSIO_T5)
2352 tcph = (const void *)(req + 1) + ETH_HDR_LEN_G(hlen) +
2353 IP_HDR_LEN_G(hlen);
2354 else
2355 tcph = (const void *)(req + 1) +
2356 T6_ETH_HDR_LEN_G(hlen) + T6_IP_HDR_LEN_G(hlen);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002357 if (tcph->ece && tcph->cwr)
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002358 opt2 |= CCTRL_ECN_V(1);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00002359 }
Hariprasad S963cab52015-09-23 17:19:27 +05302360 if (CHELSIO_CHIP_VERSION(adapter_type) > CHELSIO_T4) {
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302361 u32 isn = (prandom_u32() & ~7UL) - 1;
Anish Bhattd7990b02014-11-12 17:15:57 -08002362 opt2 |= T5_OPT_2_VALID_F;
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05302363 opt2 |= CONG_CNTRL_V(CONG_ALG_TAHOE);
Hariprasad S0b741042015-04-22 01:44:58 +05302364 opt2 |= T5_ISS_F;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302365 rpl5 = (void *)rpl;
2366 memset(&rpl5->iss, 0, roundup(sizeof(*rpl5)-sizeof(*rpl), 16));
2367 if (peer2peer)
2368 isn += 4;
2369 rpl5->iss = cpu_to_be32(isn);
2370 PDBG("%s iss %u\n", __func__, be32_to_cpu(rpl5->iss));
Steve Wise92e50112014-04-24 14:31:59 -05002371 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002372
Steve Wisecfdda9d2010-04-21 15:30:06 -07002373 rpl->opt0 = cpu_to_be64(opt0);
2374 rpl->opt2 = cpu_to_be32(opt2);
Steve Wised4f1a5c2010-07-23 19:12:32 +00002375 set_wr_txq(skb, CPL_PRIORITY_SETUP, ep->ctrlq_idx);
Hariprasad S9dec9002016-05-05 01:27:29 +05302376 t4_set_arp_err_handler(skb, ep, pass_accept_rpl_arp_failure);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002377
Hariprasad S9dec9002016-05-05 01:27:29 +05302378 return c4iw_l2t_send(&ep->com.dev->rdev, skb, ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002379}
2380
Vipul Pandya830662f2013-07-04 16:10:47 +05302381static void reject_cr(struct c4iw_dev *dev, u32 hwtid, struct sk_buff *skb)
Steve Wisecfdda9d2010-04-21 15:30:06 -07002382{
Vipul Pandya830662f2013-07-04 16:10:47 +05302383 PDBG("%s c4iw_dev %p tid %u\n", __func__, dev, hwtid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002384 BUG_ON(skb_cloned(skb));
2385 skb_trim(skb, sizeof(struct cpl_tid_release));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002386 release_tid(&dev->rdev, hwtid, skb);
2387 return;
2388}
2389
Hariprasad S963cab52015-09-23 17:19:27 +05302390static void get_4tuple(struct cpl_pass_accept_req *req, enum chip_type type,
2391 int *iptype, __u8 *local_ip, __u8 *peer_ip,
Steve Wisecfdda9d2010-04-21 15:30:06 -07002392 __be16 *local_port, __be16 *peer_port)
2393{
Hariprasad S963cab52015-09-23 17:19:27 +05302394 int eth_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2395 ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2396 T6_ETH_HDR_LEN_G(be32_to_cpu(req->hdr_len));
2397 int ip_len = (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) ?
2398 IP_HDR_LEN_G(be32_to_cpu(req->hdr_len)) :
2399 T6_IP_HDR_LEN_G(be32_to_cpu(req->hdr_len));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002400 struct iphdr *ip = (struct iphdr *)((u8 *)(req + 1) + eth_len);
Vipul Pandya830662f2013-07-04 16:10:47 +05302401 struct ipv6hdr *ip6 = (struct ipv6hdr *)((u8 *)(req + 1) + eth_len);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002402 struct tcphdr *tcp = (struct tcphdr *)
2403 ((u8 *)(req + 1) + eth_len + ip_len);
2404
Vipul Pandya830662f2013-07-04 16:10:47 +05302405 if (ip->version == 4) {
2406 PDBG("%s saddr 0x%x daddr 0x%x sport %u dport %u\n", __func__,
2407 ntohl(ip->saddr), ntohl(ip->daddr), ntohs(tcp->source),
2408 ntohs(tcp->dest));
2409 *iptype = 4;
2410 memcpy(peer_ip, &ip->saddr, 4);
2411 memcpy(local_ip, &ip->daddr, 4);
2412 } else {
2413 PDBG("%s saddr %pI6 daddr %pI6 sport %u dport %u\n", __func__,
2414 ip6->saddr.s6_addr, ip6->daddr.s6_addr, ntohs(tcp->source),
2415 ntohs(tcp->dest));
2416 *iptype = 6;
2417 memcpy(peer_ip, ip6->saddr.s6_addr, 16);
2418 memcpy(local_ip, ip6->daddr.s6_addr, 16);
2419 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002420 *peer_port = tcp->source;
2421 *local_port = tcp->dest;
2422
2423 return;
2424}
2425
2426static int pass_accept_req(struct c4iw_dev *dev, struct sk_buff *skb)
2427{
Vipul Pandya793dad92012-12-10 09:30:56 +00002428 struct c4iw_ep *child_ep = NULL, *parent_ep;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002429 struct cpl_pass_accept_req *req = cplhdr(skb);
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002430 unsigned int stid = PASS_OPEN_TID_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002431 struct tid_info *t = dev->rdev.lldi.tids;
2432 unsigned int hwtid = GET_TID(req);
2433 struct dst_entry *dst;
Vipul Pandya830662f2013-07-04 16:10:47 +05302434 __u8 local_ip[16], peer_ip[16];
Steve Wisecfdda9d2010-04-21 15:30:06 -07002435 __be16 local_port, peer_port;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302436 struct sockaddr_in6 *sin6;
David Miller3786cf12011-12-02 16:52:31 +00002437 int err;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002438 u16 peer_mss = ntohs(req->tcpopt.mss);
Vipul Pandya830662f2013-07-04 16:10:47 +05302439 int iptype;
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302440 unsigned short hdrs;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302441 u8 tos = PASS_OPEN_TOS_G(ntohl(req->tos_stid));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002442
2443 parent_ep = lookup_stid(t, stid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00002444 if (!parent_ep) {
2445 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
2446 goto reject;
2447 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00002448
Steve Wisecfdda9d2010-04-21 15:30:06 -07002449 if (state_read(&parent_ep->com) != LISTEN) {
Hariprasad S6812fae2016-02-05 11:43:29 +05302450 PDBG("%s - listening ep not in LISTEN\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002451 goto reject;
2452 }
2453
Hariprasad S963cab52015-09-23 17:19:27 +05302454 get_4tuple(req, parent_ep->com.dev->rdev.lldi.adapter_type, &iptype,
2455 local_ip, peer_ip, &local_port, &peer_port);
Vipul Pandya830662f2013-07-04 16:10:47 +05302456
Steve Wisecfdda9d2010-04-21 15:30:06 -07002457 /* Find output route */
Vipul Pandya830662f2013-07-04 16:10:47 +05302458 if (iptype == 4) {
2459 PDBG("%s parent ep %p hwtid %u laddr %pI4 raddr %pI4 lport %d rport %d peer_mss %d\n"
2460 , __func__, parent_ep, hwtid,
2461 local_ip, peer_ip, ntohs(local_port),
2462 ntohs(peer_port), peer_mss);
2463 dst = find_route(dev, *(__be32 *)local_ip, *(__be32 *)peer_ip,
2464 local_port, peer_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302465 tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05302466 } else {
2467 PDBG("%s parent ep %p hwtid %u laddr %pI6 raddr %pI6 lport %d rport %d peer_mss %d\n"
2468 , __func__, parent_ep, hwtid,
2469 local_ip, peer_ip, ntohs(local_port),
2470 ntohs(peer_port), peer_mss);
2471 dst = find_route6(dev, local_ip, peer_ip, local_port, peer_port,
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08002472 PASS_OPEN_TOS_G(ntohl(req->tos_stid)),
Vipul Pandya830662f2013-07-04 16:10:47 +05302473 ((struct sockaddr_in6 *)
2474 &parent_ep->com.local_addr)->sin6_scope_id);
2475 }
2476 if (!dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002477 printk(KERN_ERR MOD "%s - failed to find dst entry!\n",
2478 __func__);
2479 goto reject;
2480 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002481
2482 child_ep = alloc_ep(sizeof(*child_ep), GFP_KERNEL);
2483 if (!child_ep) {
2484 printk(KERN_ERR MOD "%s - failed to allocate ep entry!\n",
2485 __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002486 dst_release(dst);
2487 goto reject;
2488 }
David Miller3786cf12011-12-02 16:52:31 +00002489
Hariprasad S963cab52015-09-23 17:19:27 +05302490 err = import_ep(child_ep, iptype, peer_ip, dst, dev, false,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302491 parent_ep->com.dev->rdev.lldi.adapter_type, tos);
David Miller3786cf12011-12-02 16:52:31 +00002492 if (err) {
2493 printk(KERN_ERR MOD "%s - failed to allocate l2t entry!\n",
2494 __func__);
2495 dst_release(dst);
2496 kfree(child_ep);
2497 goto reject;
2498 }
2499
Hariprasad Shenai92e7ae72014-06-06 21:40:43 +05302500 hdrs = sizeof(struct iphdr) + sizeof(struct tcphdr) +
2501 ((enable_tcp_timestamps && req->tcpopt.tstamp) ? 12 : 0);
2502 if (peer_mss && child_ep->mtu > (peer_mss + hdrs))
2503 child_ep->mtu = peer_mss + hdrs;
Vipul Pandya1cab7752012-12-10 09:30:55 +00002504
Steve Wisecfdda9d2010-04-21 15:30:06 -07002505 state_set(&child_ep->com, CONNECTING);
2506 child_ep->com.dev = dev;
2507 child_ep->com.cm_id = NULL;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002508
Vipul Pandya830662f2013-07-04 16:10:47 +05302509 if (iptype == 4) {
2510 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06002511 &child_ep->com.local_addr;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002512
Vipul Pandya830662f2013-07-04 16:10:47 +05302513 sin->sin_family = PF_INET;
2514 sin->sin_port = local_port;
2515 sin->sin_addr.s_addr = *(__be32 *)local_ip;
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002516
2517 sin = (struct sockaddr_in *)&child_ep->com.local_addr;
2518 sin->sin_family = PF_INET;
2519 sin->sin_port = ((struct sockaddr_in *)
2520 &parent_ep->com.local_addr)->sin_port;
2521 sin->sin_addr.s_addr = *(__be32 *)local_ip;
2522
Steve Wise170003c2016-02-26 09:18:03 -06002523 sin = (struct sockaddr_in *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302524 sin->sin_family = PF_INET;
2525 sin->sin_port = peer_port;
2526 sin->sin_addr.s_addr = *(__be32 *)peer_ip;
2527 } else {
Steve Wise170003c2016-02-26 09:18:03 -06002528 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302529 sin6->sin6_family = PF_INET6;
2530 sin6->sin6_port = local_port;
2531 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002532
2533 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
2534 sin6->sin6_family = PF_INET6;
2535 sin6->sin6_port = ((struct sockaddr_in6 *)
2536 &parent_ep->com.local_addr)->sin6_port;
2537 memcpy(sin6->sin6_addr.s6_addr, local_ip, 16);
2538
Steve Wise170003c2016-02-26 09:18:03 -06002539 sin6 = (struct sockaddr_in6 *)&child_ep->com.remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05302540 sin6->sin6_family = PF_INET6;
2541 sin6->sin6_port = peer_port;
2542 memcpy(sin6->sin6_addr.s6_addr, peer_ip, 16);
2543 }
Steve Wise5b6b8fe2015-04-21 16:28:41 -04002544
Steve Wisecfdda9d2010-04-21 15:30:06 -07002545 c4iw_get_ep(&parent_ep->com);
2546 child_ep->parent_ep = parent_ep;
Hariprasad Sac8e4c62016-02-05 11:43:30 +05302547 child_ep->tos = tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002548 child_ep->dst = dst;
2549 child_ep->hwtid = hwtid;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002550
2551 PDBG("%s tx_chan %u smac_idx %u rss_qid %u\n", __func__,
David Miller3786cf12011-12-02 16:52:31 +00002552 child_ep->tx_chan, child_ep->smac_idx, child_ep->rss_qid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002553
2554 init_timer(&child_ep->timer);
2555 cxgb4_insert_tid(t, child_ep, hwtid);
Vipul Pandyab3de6cf2013-01-07 13:11:59 +00002556 insert_handle(dev, &dev->hwtid_idr, child_ep, child_ep->hwtid);
Hariprasad S9dec9002016-05-05 01:27:29 +05302557 if (accept_cr(child_ep, skb, req)) {
2558 c4iw_put_ep(&parent_ep->com);
2559 release_ep_resources(child_ep);
2560 } else {
2561 set_bit(PASS_ACCEPT_REQ, &child_ep->com.history);
2562 }
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302563 if (iptype == 6) {
Steve Wise170003c2016-02-26 09:18:03 -06002564 sin6 = (struct sockaddr_in6 *)&child_ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302565 cxgb4_clip_get(child_ep->com.dev->rdev.lldi.ports[0],
2566 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
2567 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002568 goto out;
2569reject:
Vipul Pandya830662f2013-07-04 16:10:47 +05302570 reject_cr(dev, hwtid, skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002571out:
2572 return 0;
2573}
2574
2575static int pass_establish(struct c4iw_dev *dev, struct sk_buff *skb)
2576{
2577 struct c4iw_ep *ep;
2578 struct cpl_pass_establish *req = cplhdr(skb);
2579 struct tid_info *t = dev->rdev.lldi.tids;
2580 unsigned int tid = GET_TID(req);
Hariprasad Sfef44222016-05-05 01:27:33 +05302581 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002582
2583 ep = lookup_tid(t, tid);
2584 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2585 ep->snd_seq = be32_to_cpu(req->snd_isn);
2586 ep->rcv_seq = be32_to_cpu(req->rcv_isn);
2587
Vipul Pandya1cab7752012-12-10 09:30:55 +00002588 PDBG("%s ep %p hwtid %u tcp_opt 0x%02x\n", __func__, ep, tid,
2589 ntohs(req->tcp_opt));
2590
Steve Wisecfdda9d2010-04-21 15:30:06 -07002591 set_emss(ep, ntohs(req->tcp_opt));
2592
2593 dst_confirm(ep->dst);
Hariprasad Sfef44222016-05-05 01:27:33 +05302594 mutex_lock(&ep->com.mutex);
2595 ep->com.state = MPA_REQ_WAIT;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002596 start_ep_timer(ep);
Vipul Pandya793dad92012-12-10 09:30:56 +00002597 set_bit(PASS_ESTAB, &ep->com.history);
Hariprasad Sfef44222016-05-05 01:27:33 +05302598 ret = send_flowc(ep, skb);
2599 mutex_unlock(&ep->com.mutex);
2600 if (ret)
2601 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002602
2603 return 0;
2604}
2605
2606static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb)
2607{
2608 struct cpl_peer_close *hdr = cplhdr(skb);
2609 struct c4iw_ep *ep;
2610 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002611 int disconnect = 1;
2612 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002613 struct tid_info *t = dev->rdev.lldi.tids;
2614 unsigned int tid = GET_TID(hdr);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002615 int ret;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002616
2617 ep = lookup_tid(t, tid);
2618 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2619 dst_confirm(ep->dst);
2620
Vipul Pandya793dad92012-12-10 09:30:56 +00002621 set_bit(PEER_CLOSE, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002622 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002623 switch (ep->com.state) {
2624 case MPA_REQ_WAIT:
2625 __state_set(&ep->com, CLOSING);
2626 break;
2627 case MPA_REQ_SENT:
2628 __state_set(&ep->com, CLOSING);
2629 connect_reply_upcall(ep, -ECONNRESET);
2630 break;
2631 case MPA_REQ_RCVD:
2632
2633 /*
2634 * We're gonna mark this puppy DEAD, but keep
2635 * the reference on it until the ULP accepts or
2636 * rejects the CR. Also wake up anyone waiting
2637 * in rdma connection migration (see c4iw_accept_cr()).
2638 */
2639 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002640 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002641 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002642 break;
2643 case MPA_REP_SENT:
2644 __state_set(&ep->com, CLOSING);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002645 PDBG("waking up ep %p tid %u\n", ep, ep->hwtid);
Steve Wised9594d92011-05-09 22:06:22 -07002646 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002647 break;
2648 case FPDU_MODE:
Steve Wiseca5a2202010-07-23 19:12:37 +00002649 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002650 __state_set(&ep->com, CLOSING);
Steve Wise30c95c22011-05-09 22:06:22 -07002651 attrs.next_state = C4IW_QP_STATE_CLOSING;
Steve Wise8da7e7a2011-06-14 20:59:27 +00002652 ret = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
Steve Wise30c95c22011-05-09 22:06:22 -07002653 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
Steve Wise8da7e7a2011-06-14 20:59:27 +00002654 if (ret != -ECONNRESET) {
2655 peer_close_upcall(ep);
2656 disconnect = 1;
2657 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002658 break;
2659 case ABORTING:
2660 disconnect = 0;
2661 break;
2662 case CLOSING:
2663 __state_set(&ep->com, MORIBUND);
2664 disconnect = 0;
2665 break;
2666 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002667 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002668 if (ep->com.cm_id && ep->com.qp) {
2669 attrs.next_state = C4IW_QP_STATE_IDLE;
2670 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2671 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2672 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302673 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002674 __state_set(&ep->com, DEAD);
2675 release = 1;
2676 disconnect = 0;
2677 break;
2678 case DEAD:
2679 disconnect = 0;
2680 break;
2681 default:
2682 BUG_ON(1);
2683 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002684 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002685 if (disconnect)
2686 c4iw_ep_disconnect(ep, 0, GFP_KERNEL);
2687 if (release)
2688 release_ep_resources(ep);
2689 return 0;
2690}
2691
Steve Wisecfdda9d2010-04-21 15:30:06 -07002692static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb)
2693{
2694 struct cpl_abort_req_rss *req = cplhdr(skb);
2695 struct c4iw_ep *ep;
2696 struct cpl_abort_rpl *rpl;
2697 struct sk_buff *rpl_skb;
2698 struct c4iw_qp_attributes attrs;
2699 int ret;
2700 int release = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002701 struct tid_info *t = dev->rdev.lldi.tids;
2702 unsigned int tid = GET_TID(req);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002703
2704 ep = lookup_tid(t, tid);
Steve Wise7a2cea22014-03-14 21:52:07 +05302705 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05302706 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
2707 __func__, ep->hwtid, req->status,
2708 neg_adv_str(req->status));
2709 ep->stats.abort_neg_adv++;
2710 mutex_lock(&dev->rdev.stats.lock);
2711 dev->rdev.stats.neg_adv++;
2712 mutex_unlock(&dev->rdev.stats.lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002713 return 0;
2714 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002715 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
2716 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00002717 set_bit(PEER_ABORT, &ep->com.history);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002718
2719 /*
2720 * Wake up any threads in rdma_init() or rdma_fini().
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302721 * However, this is not needed if com state is just
2722 * MPA_REQ_SENT
Steve Wise2f5b48c2010-09-10 11:15:36 -05002723 */
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302724 if (ep->com.state != MPA_REQ_SENT)
2725 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002726
2727 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002728 switch (ep->com.state) {
2729 case CONNECTING:
Hariprasad S9dec9002016-05-05 01:27:29 +05302730 c4iw_put_ep(&ep->parent_ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002731 break;
2732 case MPA_REQ_WAIT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002733 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002734 break;
2735 case MPA_REQ_SENT:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002736 (void)stop_ep_timer(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002737 if (mpa_rev == 1 || (mpa_rev == 2 && ep->tried_with_mpa_v1))
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302738 connect_reply_upcall(ep, -ECONNRESET);
2739 else {
2740 /*
2741 * we just don't send notification upwards because we
2742 * want to retry with mpa_v1 without upper layers even
2743 * knowing it.
2744 *
2745 * do some housekeeping so as to re-initiate the
2746 * connection
2747 */
2748 PDBG("%s: mpa_rev=%d. Retrying with mpav1\n", __func__,
2749 mpa_rev);
2750 ep->retry_with_mpa_v1 = 1;
2751 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002752 break;
2753 case MPA_REP_SENT:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002754 break;
2755 case MPA_REQ_RCVD:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002756 break;
2757 case MORIBUND:
2758 case CLOSING:
Steve Wiseca5a2202010-07-23 19:12:37 +00002759 stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002760 /*FALLTHROUGH*/
2761 case FPDU_MODE:
2762 if (ep->com.cm_id && ep->com.qp) {
2763 attrs.next_state = C4IW_QP_STATE_ERROR;
2764 ret = c4iw_modify_qp(ep->com.qp->rhp,
2765 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
2766 &attrs, 1);
2767 if (ret)
2768 printk(KERN_ERR MOD
2769 "%s - qp <- error failed!\n",
2770 __func__);
2771 }
2772 peer_abort_upcall(ep);
2773 break;
2774 case ABORTING:
2775 break;
2776 case DEAD:
2777 PDBG("%s PEER_ABORT IN DEAD STATE!!!!\n", __func__);
Steve Wise2f5b48c2010-09-10 11:15:36 -05002778 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002779 return 0;
2780 default:
2781 BUG_ON(1);
2782 break;
2783 }
2784 dst_confirm(ep->dst);
2785 if (ep->com.state != ABORTING) {
2786 __state_set(&ep->com, DEAD);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302787 /* we don't release if we want to retry with mpa_v1 */
2788 if (!ep->retry_with_mpa_v1)
2789 release = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002790 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002791 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002792
2793 rpl_skb = get_skb(skb, sizeof(*rpl), GFP_KERNEL);
2794 if (!rpl_skb) {
2795 printk(KERN_ERR MOD "%s - cannot allocate skb!\n",
2796 __func__);
2797 release = 1;
2798 goto out;
2799 }
2800 set_wr_txq(skb, CPL_PRIORITY_DATA, ep->txq_idx);
2801 rpl = (struct cpl_abort_rpl *) skb_put(rpl_skb, sizeof(*rpl));
2802 INIT_TP_WR(rpl, ep->hwtid);
2803 OPCODE_TID(rpl) = cpu_to_be32(MK_OPCODE_TID(CPL_ABORT_RPL, ep->hwtid));
2804 rpl->cmd = CPL_ABORT_NO_RST;
2805 c4iw_ofld_send(&ep->com.dev->rdev, rpl_skb);
2806out:
Steve Wisecfdda9d2010-04-21 15:30:06 -07002807 if (release)
2808 release_ep_resources(ep);
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002809 else if (ep->retry_with_mpa_v1) {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302810 if (ep->com.remote_addr.ss_family == AF_INET6) {
2811 struct sockaddr_in6 *sin6 =
2812 (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06002813 &ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05302814 cxgb4_clip_release(
2815 ep->com.dev->rdev.lldi.ports[0],
2816 (const u32 *)&sin6->sin6_addr.s6_addr,
2817 1);
2818 }
Vipul Pandyafe7e0a42013-01-07 13:11:57 +00002819 remove_handle(ep->com.dev, &ep->com.dev->hwtid_idr, ep->hwtid);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302820 cxgb4_remove_tid(ep->com.dev->rdev.lldi.tids, 0, ep->hwtid);
2821 dst_release(ep->dst);
2822 cxgb4_l2t_release(ep->l2t);
2823 c4iw_reconnect(ep);
2824 }
2825
Steve Wisecfdda9d2010-04-21 15:30:06 -07002826 return 0;
2827}
2828
2829static int close_con_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
2830{
2831 struct c4iw_ep *ep;
2832 struct c4iw_qp_attributes attrs;
2833 struct cpl_close_con_rpl *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002834 int release = 0;
2835 struct tid_info *t = dev->rdev.lldi.tids;
2836 unsigned int tid = GET_TID(rpl);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002837
2838 ep = lookup_tid(t, tid);
2839
2840 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2841 BUG_ON(!ep);
2842
2843 /* The cm_id may be null if we failed to connect */
Steve Wise2f5b48c2010-09-10 11:15:36 -05002844 mutex_lock(&ep->com.mutex);
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05302845 set_bit(CLOSE_CON_RPL, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002846 switch (ep->com.state) {
2847 case CLOSING:
2848 __state_set(&ep->com, MORIBUND);
2849 break;
2850 case MORIBUND:
Steve Wiseb33bd0c2014-04-09 09:38:25 -05002851 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002852 if ((ep->com.cm_id) && (ep->com.qp)) {
2853 attrs.next_state = C4IW_QP_STATE_IDLE;
2854 c4iw_modify_qp(ep->com.qp->rhp,
2855 ep->com.qp,
2856 C4IW_QP_ATTR_NEXT_STATE,
2857 &attrs, 1);
2858 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05302859 close_complete_upcall(ep, 0);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002860 __state_set(&ep->com, DEAD);
2861 release = 1;
2862 break;
2863 case ABORTING:
2864 case DEAD:
2865 break;
2866 default:
2867 BUG_ON(1);
2868 break;
2869 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05002870 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002871 if (release)
2872 release_ep_resources(ep);
2873 return 0;
2874}
2875
2876static int terminate(struct c4iw_dev *dev, struct sk_buff *skb)
2877{
Steve Wise0e42c1f2010-09-10 11:15:09 -05002878 struct cpl_rdma_terminate *rpl = cplhdr(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002879 struct tid_info *t = dev->rdev.lldi.tids;
Steve Wise0e42c1f2010-09-10 11:15:09 -05002880 unsigned int tid = GET_TID(rpl);
2881 struct c4iw_ep *ep;
2882 struct c4iw_qp_attributes attrs;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002883
2884 ep = lookup_tid(t, tid);
Steve Wise0e42c1f2010-09-10 11:15:09 -05002885 BUG_ON(!ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002886
Steve Wise30c95c22011-05-09 22:06:22 -07002887 if (ep && ep->com.qp) {
Steve Wise0e42c1f2010-09-10 11:15:09 -05002888 printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid,
2889 ep->com.qp->wq.sq.qid);
2890 attrs.next_state = C4IW_QP_STATE_TERMINATE;
2891 c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp,
2892 C4IW_QP_ATTR_NEXT_STATE, &attrs, 1);
2893 } else
Steve Wise30c95c22011-05-09 22:06:22 -07002894 printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002895
Steve Wisecfdda9d2010-04-21 15:30:06 -07002896 return 0;
2897}
2898
2899/*
2900 * Upcall from the adapter indicating data has been transmitted.
2901 * For us its just the single MPA request or reply. We can now free
2902 * the skb holding the mpa message.
2903 */
2904static int fw4_ack(struct c4iw_dev *dev, struct sk_buff *skb)
2905{
2906 struct c4iw_ep *ep;
2907 struct cpl_fw4_ack *hdr = cplhdr(skb);
2908 u8 credits = hdr->credits;
2909 unsigned int tid = GET_TID(hdr);
2910 struct tid_info *t = dev->rdev.lldi.tids;
2911
2912
2913 ep = lookup_tid(t, tid);
2914 PDBG("%s ep %p tid %u credits %u\n", __func__, ep, ep->hwtid, credits);
2915 if (credits == 0) {
Joe Perchesaa1ad262010-10-25 19:44:22 -07002916 PDBG("%s 0 credit ack ep %p tid %u state %u\n",
2917 __func__, ep, ep->hwtid, state_read(&ep->com));
Steve Wisecfdda9d2010-04-21 15:30:06 -07002918 return 0;
2919 }
2920
2921 dst_confirm(ep->dst);
2922 if (ep->mpa_skb) {
2923 PDBG("%s last streaming msg ack ep %p tid %u state %u "
2924 "initiator %u freeing skb\n", __func__, ep, ep->hwtid,
2925 state_read(&ep->com), ep->mpa_attr.initiator ? 1 : 0);
2926 kfree_skb(ep->mpa_skb);
2927 ep->mpa_skb = NULL;
Hariprasad Se4b76a22016-05-06 22:17:59 +05302928 mutex_lock(&ep->com.mutex);
2929 if (test_bit(STOP_MPA_TIMER, &ep->com.flags))
2930 stop_ep_timer(ep);
2931 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002932 }
2933 return 0;
2934}
2935
Steve Wisecfdda9d2010-04-21 15:30:06 -07002936int c4iw_reject_cr(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
2937{
Steve Wisea7db89e2014-03-21 20:40:35 +05302938 int err = 0;
2939 int disconnect = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002940 struct c4iw_ep *ep = to_ep(cm_id);
2941 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
2942
Steve Wisea7db89e2014-03-21 20:40:35 +05302943 mutex_lock(&ep->com.mutex);
2944 if (ep->com.state == DEAD) {
2945 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002946 c4iw_put_ep(&ep->com);
2947 return -ECONNRESET;
2948 }
Vipul Pandya793dad92012-12-10 09:30:56 +00002949 set_bit(ULP_REJECT, &ep->com.history);
Steve Wisea7db89e2014-03-21 20:40:35 +05302950 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002951 if (mpa_rev == 0)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302952 disconnect = 2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002953 else {
2954 err = send_mpa_reject(ep, pdata, pdata_len);
Steve Wisea7db89e2014-03-21 20:40:35 +05302955 disconnect = 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002956 }
Steve Wisea7db89e2014-03-21 20:40:35 +05302957 mutex_unlock(&ep->com.mutex);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302958 if (disconnect) {
2959 stop_ep_timer(ep);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302960 err = c4iw_ep_disconnect(ep, disconnect == 2, GFP_KERNEL);
Hariprasad Se4b76a22016-05-06 22:17:59 +05302961 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07002962 c4iw_put_ep(&ep->com);
2963 return 0;
2964}
2965
2966int c4iw_accept_cr(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
2967{
2968 int err;
2969 struct c4iw_qp_attributes attrs;
2970 enum c4iw_qp_attr_mask mask;
2971 struct c4iw_ep *ep = to_ep(cm_id);
2972 struct c4iw_dev *h = to_c4iw_dev(cm_id->device);
2973 struct c4iw_qp *qp = get_qhp(h, conn_param->qpn);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302974 int abort = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002975
2976 PDBG("%s ep %p tid %u\n", __func__, ep, ep->hwtid);
Steve Wisea7db89e2014-03-21 20:40:35 +05302977
2978 mutex_lock(&ep->com.mutex);
2979 if (ep->com.state == DEAD) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002980 err = -ECONNRESET;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302981 goto err_out;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002982 }
2983
Steve Wisea7db89e2014-03-21 20:40:35 +05302984 BUG_ON(ep->com.state != MPA_REQ_RCVD);
Steve Wisecfdda9d2010-04-21 15:30:06 -07002985 BUG_ON(!qp);
2986
Vipul Pandya793dad92012-12-10 09:30:56 +00002987 set_bit(ULP_ACCEPT, &ep->com.history);
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302988 if ((conn_param->ord > cur_max_read_depth(ep->com.dev)) ||
2989 (conn_param->ird > cur_max_read_depth(ep->com.dev))) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07002990 err = -EINVAL;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05302991 goto err_abort;
Steve Wisecfdda9d2010-04-21 15:30:06 -07002992 }
2993
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05302994 if (ep->mpa_attr.version == 2 && ep->mpa_attr.enhanced_rdma_conn) {
2995 if (conn_param->ord > ep->ird) {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05302996 if (RELAXED_IRD_NEGOTIATION) {
2997 ep->ord = ep->ird;
2998 } else {
2999 ep->ird = conn_param->ird;
3000 ep->ord = conn_param->ord;
3001 send_mpa_reject(ep, conn_param->private_data,
3002 conn_param->private_data_len);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303003 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303004 goto err_abort;
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303005 }
3006 }
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303007 if (conn_param->ird < ep->ord) {
3008 if (RELAXED_IRD_NEGOTIATION &&
3009 ep->ord <= h->rdev.lldi.max_ordird_qp) {
3010 conn_param->ird = ep->ord;
3011 } else {
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303012 err = -ENOMEM;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303013 goto err_abort;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303014 }
3015 }
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303016 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003017 ep->ird = conn_param->ird;
3018 ep->ord = conn_param->ord;
3019
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303020 if (ep->mpa_attr.version == 1) {
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303021 if (peer2peer && ep->ird == 0)
3022 ep->ird = 1;
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303023 } else {
3024 if (peer2peer &&
3025 (ep->mpa_attr.p2p_type != FW_RI_INIT_P2PTYPE_DISABLED) &&
Hariprasad Sf57b7802015-09-08 09:56:59 +05303026 (p2p_type == FW_RI_INIT_P2PTYPE_READ_REQ) && ep->ird == 0)
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303027 ep->ird = 1;
3028 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003029
3030 PDBG("%s %d ird %d ord %d\n", __func__, __LINE__, ep->ird, ep->ord);
3031
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303032 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303033 ref_cm_id(&ep->com);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303034 ep->com.qp = qp;
Vipul Pandya325abea2013-01-07 13:11:53 +00003035 ref_qp(ep);
Kumar Sanghvid2fe99e2011-09-25 20:17:44 +05303036
Steve Wisecfdda9d2010-04-21 15:30:06 -07003037 /* bind QP to EP and move to RTS */
3038 attrs.mpa_attr = ep->mpa_attr;
3039 attrs.max_ird = ep->ird;
3040 attrs.max_ord = ep->ord;
3041 attrs.llp_stream_handle = ep;
3042 attrs.next_state = C4IW_QP_STATE_RTS;
3043
3044 /* bind QP and TID with INIT_WR */
3045 mask = C4IW_QP_ATTR_NEXT_STATE |
3046 C4IW_QP_ATTR_LLP_STREAM_HANDLE |
3047 C4IW_QP_ATTR_MPA_ATTR |
3048 C4IW_QP_ATTR_MAX_IRD |
3049 C4IW_QP_ATTR_MAX_ORD;
3050
3051 err = c4iw_modify_qp(ep->com.qp->rhp,
3052 ep->com.qp, mask, &attrs, 1);
3053 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303054 goto err_deref_cm_id;
Hariprasad Se4b76a22016-05-06 22:17:59 +05303055
3056 set_bit(STOP_MPA_TIMER, &ep->com.flags);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003057 err = send_mpa_reply(ep, conn_param->private_data,
3058 conn_param->private_data_len);
3059 if (err)
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303060 goto err_deref_cm_id;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003061
Steve Wisea7db89e2014-03-21 20:40:35 +05303062 __state_set(&ep->com, FPDU_MODE);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003063 established_upcall(ep);
Steve Wisea7db89e2014-03-21 20:40:35 +05303064 mutex_unlock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003065 c4iw_put_ep(&ep->com);
3066 return 0;
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303067err_deref_cm_id:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303068 deref_cm_id(&ep->com);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303069err_abort:
3070 abort = 1;
3071err_out:
Steve Wisea7db89e2014-03-21 20:40:35 +05303072 mutex_unlock(&ep->com.mutex);
Hariprasad Seaf4c6d2016-05-05 01:27:34 +05303073 if (abort)
3074 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003075 c4iw_put_ep(&ep->com);
3076 return err;
3077}
3078
Vipul Pandya830662f2013-07-04 16:10:47 +05303079static int pick_local_ipaddrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3080{
3081 struct in_device *ind;
3082 int found = 0;
Steve Wise170003c2016-02-26 09:18:03 -06003083 struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_id->m_local_addr;
3084 struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303085
3086 ind = in_dev_get(dev->rdev.lldi.ports[0]);
3087 if (!ind)
3088 return -EADDRNOTAVAIL;
3089 for_primary_ifa(ind) {
3090 laddr->sin_addr.s_addr = ifa->ifa_address;
3091 raddr->sin_addr.s_addr = ifa->ifa_address;
3092 found = 1;
3093 break;
3094 }
3095 endfor_ifa(ind);
3096 in_dev_put(ind);
3097 return found ? 0 : -EADDRNOTAVAIL;
3098}
3099
3100static int get_lladdr(struct net_device *dev, struct in6_addr *addr,
3101 unsigned char banned_flags)
3102{
3103 struct inet6_dev *idev;
3104 int err = -EADDRNOTAVAIL;
3105
3106 rcu_read_lock();
3107 idev = __in6_dev_get(dev);
3108 if (idev != NULL) {
3109 struct inet6_ifaddr *ifp;
3110
3111 read_lock_bh(&idev->lock);
3112 list_for_each_entry(ifp, &idev->addr_list, if_list) {
3113 if (ifp->scope == IFA_LINK &&
3114 !(ifp->flags & banned_flags)) {
3115 memcpy(addr, &ifp->addr, 16);
3116 err = 0;
3117 break;
3118 }
3119 }
3120 read_unlock_bh(&idev->lock);
3121 }
3122 rcu_read_unlock();
3123 return err;
3124}
3125
3126static int pick_local_ip6addrs(struct c4iw_dev *dev, struct iw_cm_id *cm_id)
3127{
3128 struct in6_addr uninitialized_var(addr);
Steve Wise170003c2016-02-26 09:18:03 -06003129 struct sockaddr_in6 *la6 = (struct sockaddr_in6 *)&cm_id->m_local_addr;
3130 struct sockaddr_in6 *ra6 = (struct sockaddr_in6 *)&cm_id->m_remote_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303131
Nicholas Krause54b9a962015-08-26 23:00:59 -04003132 if (!get_lladdr(dev->rdev.lldi.ports[0], &addr, IFA_F_TENTATIVE)) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303133 memcpy(la6->sin6_addr.s6_addr, &addr, 16);
3134 memcpy(ra6->sin6_addr.s6_addr, &addr, 16);
3135 return 0;
3136 }
3137 return -EADDRNOTAVAIL;
3138}
3139
Steve Wisecfdda9d2010-04-21 15:30:06 -07003140int c4iw_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
3141{
Steve Wisecfdda9d2010-04-21 15:30:06 -07003142 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3143 struct c4iw_ep *ep;
David Miller3786cf12011-12-02 16:52:31 +00003144 int err = 0;
Steve Wise9eccfe12014-03-26 17:08:09 -05003145 struct sockaddr_in *laddr;
3146 struct sockaddr_in *raddr;
3147 struct sockaddr_in6 *laddr6;
3148 struct sockaddr_in6 *raddr6;
Vipul Pandya830662f2013-07-04 16:10:47 +05303149 __u8 *ra;
3150 int iptype;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003151
Hariprasad Shenai4c2c5762014-07-14 21:34:52 +05303152 if ((conn_param->ord > cur_max_read_depth(dev)) ||
3153 (conn_param->ird > cur_max_read_depth(dev))) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003154 err = -EINVAL;
3155 goto out;
3156 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003157 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3158 if (!ep) {
3159 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3160 err = -ENOMEM;
3161 goto out;
3162 }
3163 init_timer(&ep->timer);
3164 ep->plen = conn_param->private_data_len;
3165 if (ep->plen)
3166 memcpy(ep->mpa_pkt + sizeof(struct mpa_message),
3167 conn_param->private_data, ep->plen);
3168 ep->ird = conn_param->ird;
3169 ep->ord = conn_param->ord;
3170
3171 if (peer2peer && ep->ord == 0)
3172 ep->ord = 1;
3173
Steve Wisecfdda9d2010-04-21 15:30:06 -07003174 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303175 ref_cm_id(&ep->com);
3176 ep->com.dev = dev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003177 ep->com.qp = get_qhp(dev, conn_param->qpn);
Vipul Pandya830662f2013-07-04 16:10:47 +05303178 if (!ep->com.qp) {
3179 PDBG("%s qpn 0x%x not found!\n", __func__, conn_param->qpn);
3180 err = -EINVAL;
Steve Wise9eccfe12014-03-26 17:08:09 -05003181 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303182 }
Vipul Pandya325abea2013-01-07 13:11:53 +00003183 ref_qp(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003184 PDBG("%s qpn 0x%x qp %p cm_id %p\n", __func__, conn_param->qpn,
3185 ep->com.qp, cm_id);
3186
3187 /*
3188 * Allocate an active TID to initiate a TCP connection.
3189 */
3190 ep->atid = cxgb4_alloc_atid(dev->rdev.lldi.tids, ep);
3191 if (ep->atid == -1) {
3192 printk(KERN_ERR MOD "%s - cannot alloc atid.\n", __func__);
3193 err = -ENOMEM;
Steve Wise9eccfe12014-03-26 17:08:09 -05003194 goto fail1;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003195 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003196 insert_handle(dev, &dev->atid_idr, ep, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003197
Steve Wise170003c2016-02-26 09:18:03 -06003198 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003199 sizeof(ep->com.local_addr));
Steve Wise170003c2016-02-26 09:18:03 -06003200 memcpy(&ep->com.remote_addr, &cm_id->m_remote_addr,
Steve Wise9eccfe12014-03-26 17:08:09 -05003201 sizeof(ep->com.remote_addr));
3202
Steve Wise170003c2016-02-26 09:18:03 -06003203 laddr = (struct sockaddr_in *)&ep->com.local_addr;
3204 raddr = (struct sockaddr_in *)&ep->com.remote_addr;
3205 laddr6 = (struct sockaddr_in6 *)&ep->com.local_addr;
3206 raddr6 = (struct sockaddr_in6 *) &ep->com.remote_addr;
Steve Wise9eccfe12014-03-26 17:08:09 -05003207
Steve Wise170003c2016-02-26 09:18:03 -06003208 if (cm_id->m_remote_addr.ss_family == AF_INET) {
Vipul Pandya830662f2013-07-04 16:10:47 +05303209 iptype = 4;
3210 ra = (__u8 *)&raddr->sin_addr;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003211
Vipul Pandya830662f2013-07-04 16:10:47 +05303212 /*
3213 * Handle loopback requests to INADDR_ANY.
3214 */
3215 if ((__force int)raddr->sin_addr.s_addr == INADDR_ANY) {
3216 err = pick_local_ipaddrs(dev, cm_id);
3217 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003218 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303219 }
3220
3221 /* find a route */
3222 PDBG("%s saddr %pI4 sport 0x%x raddr %pI4 rport 0x%x\n",
3223 __func__, &laddr->sin_addr, ntohs(laddr->sin_port),
3224 ra, ntohs(raddr->sin_port));
3225 ep->dst = find_route(dev, laddr->sin_addr.s_addr,
3226 raddr->sin_addr.s_addr, laddr->sin_port,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303227 raddr->sin_port, cm_id->tos);
Vipul Pandya830662f2013-07-04 16:10:47 +05303228 } else {
3229 iptype = 6;
3230 ra = (__u8 *)&raddr6->sin6_addr;
3231
3232 /*
3233 * Handle loopback requests to INADDR_ANY.
3234 */
3235 if (ipv6_addr_type(&raddr6->sin6_addr) == IPV6_ADDR_ANY) {
3236 err = pick_local_ip6addrs(dev, cm_id);
3237 if (err)
Steve Wise9eccfe12014-03-26 17:08:09 -05003238 goto fail1;
Vipul Pandya830662f2013-07-04 16:10:47 +05303239 }
3240
3241 /* find a route */
3242 PDBG("%s saddr %pI6 sport 0x%x raddr %pI6 rport 0x%x\n",
3243 __func__, laddr6->sin6_addr.s6_addr,
3244 ntohs(laddr6->sin6_port),
3245 raddr6->sin6_addr.s6_addr, ntohs(raddr6->sin6_port));
3246 ep->dst = find_route6(dev, laddr6->sin6_addr.s6_addr,
3247 raddr6->sin6_addr.s6_addr,
3248 laddr6->sin6_port, raddr6->sin6_port, 0,
3249 raddr6->sin6_scope_id);
3250 }
3251 if (!ep->dst) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003252 printk(KERN_ERR MOD "%s - cannot find route.\n", __func__);
3253 err = -EHOSTUNREACH;
Steve Wise9eccfe12014-03-26 17:08:09 -05003254 goto fail2;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003255 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003256
Hariprasad S963cab52015-09-23 17:19:27 +05303257 err = import_ep(ep, iptype, ra, ep->dst, ep->com.dev, true,
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303258 ep->com.dev->rdev.lldi.adapter_type, cm_id->tos);
David Miller3786cf12011-12-02 16:52:31 +00003259 if (err) {
Steve Wisecfdda9d2010-04-21 15:30:06 -07003260 printk(KERN_ERR MOD "%s - cannot alloc l2e.\n", __func__);
Steve Wise9eccfe12014-03-26 17:08:09 -05003261 goto fail3;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003262 }
3263
3264 PDBG("%s txq_idx %u tx_chan %u smac_idx %u rss_qid %u l2t_idx %u\n",
3265 __func__, ep->txq_idx, ep->tx_chan, ep->smac_idx, ep->rss_qid,
3266 ep->l2t->idx);
3267
3268 state_set(&ep->com, CONNECTING);
Hariprasad Sac8e4c62016-02-05 11:43:30 +05303269 ep->tos = cm_id->tos;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003270
3271 /* send connect request to rnic */
3272 err = send_connect(ep);
3273 if (!err)
3274 goto out;
3275
3276 cxgb4_l2t_release(ep->l2t);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003277fail3:
Steve Wise9eccfe12014-03-26 17:08:09 -05003278 dst_release(ep->dst);
3279fail2:
Vipul Pandya793dad92012-12-10 09:30:56 +00003280 remove_handle(ep->com.dev, &ep->com.dev->atid_idr, ep->atid);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003281 cxgb4_free_atid(ep->com.dev->rdev.lldi.tids, ep->atid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003282fail1:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303283 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003284 c4iw_put_ep(&ep->com);
3285out:
3286 return err;
3287}
3288
Vipul Pandya830662f2013-07-04 16:10:47 +05303289static int create_server6(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3290{
3291 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003292 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)
Steve Wise170003c2016-02-26 09:18:03 -06003293 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303294
Hariprasad S28de1f72016-01-13 10:03:14 +05303295 if (ipv6_addr_type(&sin6->sin6_addr) != IPV6_ADDR_ANY) {
3296 err = cxgb4_clip_get(ep->com.dev->rdev.lldi.ports[0],
3297 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3298 if (err)
3299 return err;
3300 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303301 c4iw_init_wr_wait(&ep->com.wr_wait);
3302 err = cxgb4_create_server6(ep->com.dev->rdev.lldi.ports[0],
3303 ep->stid, &sin6->sin6_addr,
3304 sin6->sin6_port,
3305 ep->com.dev->rdev.lldi.rxq_ids[0]);
3306 if (!err)
3307 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3308 &ep->com.wr_wait,
3309 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303310 else if (err > 0)
3311 err = net_xmit_errno(err);
Hariprasad S28de1f72016-01-13 10:03:14 +05303312 if (err) {
3313 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3314 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya830662f2013-07-04 16:10:47 +05303315 pr_err("cxgb4_create_server6/filter failed err %d stid %d laddr %pI6 lport %d\n",
3316 err, ep->stid,
3317 sin6->sin6_addr.s6_addr, ntohs(sin6->sin6_port));
Hariprasad S28de1f72016-01-13 10:03:14 +05303318 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303319 return err;
3320}
3321
3322static int create_server4(struct c4iw_dev *dev, struct c4iw_listen_ep *ep)
3323{
3324 int err;
Steve Wise9eccfe12014-03-26 17:08:09 -05003325 struct sockaddr_in *sin = (struct sockaddr_in *)
Steve Wise170003c2016-02-26 09:18:03 -06003326 &ep->com.local_addr;
Vipul Pandya830662f2013-07-04 16:10:47 +05303327
3328 if (dev->rdev.lldi.enable_fw_ofld_conn) {
3329 do {
3330 err = cxgb4_create_server_filter(
3331 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3332 sin->sin_addr.s_addr, sin->sin_port, 0,
3333 ep->com.dev->rdev.lldi.rxq_ids[0], 0, 0);
3334 if (err == -EBUSY) {
Hariprasad S99718e52015-09-08 09:56:57 +05303335 if (c4iw_fatal_error(&ep->com.dev->rdev)) {
3336 err = -EIO;
3337 break;
3338 }
Vipul Pandya830662f2013-07-04 16:10:47 +05303339 set_current_state(TASK_UNINTERRUPTIBLE);
3340 schedule_timeout(usecs_to_jiffies(100));
3341 }
3342 } while (err == -EBUSY);
3343 } else {
3344 c4iw_init_wr_wait(&ep->com.wr_wait);
3345 err = cxgb4_create_server(ep->com.dev->rdev.lldi.ports[0],
3346 ep->stid, sin->sin_addr.s_addr, sin->sin_port,
3347 0, ep->com.dev->rdev.lldi.rxq_ids[0]);
3348 if (!err)
3349 err = c4iw_wait_for_reply(&ep->com.dev->rdev,
3350 &ep->com.wr_wait,
3351 0, 0, __func__);
Hariprasad Se6b11162014-12-08 15:02:47 +05303352 else if (err > 0)
3353 err = net_xmit_errno(err);
Vipul Pandya830662f2013-07-04 16:10:47 +05303354 }
3355 if (err)
3356 pr_err("cxgb4_create_server/filter failed err %d stid %d laddr %pI4 lport %d\n"
3357 , err, ep->stid,
3358 &sin->sin_addr, ntohs(sin->sin_port));
3359 return err;
3360}
3361
Steve Wisecfdda9d2010-04-21 15:30:06 -07003362int c4iw_create_listen(struct iw_cm_id *cm_id, int backlog)
3363{
3364 int err = 0;
3365 struct c4iw_dev *dev = to_c4iw_dev(cm_id->device);
3366 struct c4iw_listen_ep *ep;
3367
Steve Wisecfdda9d2010-04-21 15:30:06 -07003368 might_sleep();
3369
3370 ep = alloc_ep(sizeof(*ep), GFP_KERNEL);
3371 if (!ep) {
3372 printk(KERN_ERR MOD "%s - cannot alloc ep.\n", __func__);
3373 err = -ENOMEM;
3374 goto fail1;
3375 }
3376 PDBG("%s ep %p\n", __func__, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003377 ep->com.cm_id = cm_id;
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303378 ref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003379 ep->com.dev = dev;
3380 ep->backlog = backlog;
Steve Wise170003c2016-02-26 09:18:03 -06003381 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
Steve Wise24d44a32013-07-04 16:10:44 +05303382 sizeof(ep->com.local_addr));
Steve Wisecfdda9d2010-04-21 15:30:06 -07003383
3384 /*
3385 * Allocate a server TID.
3386 */
Kumar Sanghvi8c044692013-12-18 16:38:25 +05303387 if (dev->rdev.lldi.enable_fw_ofld_conn &&
3388 ep->com.local_addr.ss_family == AF_INET)
Vipul Pandya830662f2013-07-04 16:10:47 +05303389 ep->stid = cxgb4_alloc_sftid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003390 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003391 else
Vipul Pandya830662f2013-07-04 16:10:47 +05303392 ep->stid = cxgb4_alloc_stid(dev->rdev.lldi.tids,
Steve Wise170003c2016-02-26 09:18:03 -06003393 cm_id->m_local_addr.ss_family, ep);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003394
Steve Wisecfdda9d2010-04-21 15:30:06 -07003395 if (ep->stid == -1) {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003396 printk(KERN_ERR MOD "%s - cannot alloc stid.\n", __func__);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003397 err = -ENOMEM;
3398 goto fail2;
3399 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003400 insert_handle(dev, &dev->stid_idr, ep, ep->stid);
Steve Wise9eccfe12014-03-26 17:08:09 -05003401
Steve Wise170003c2016-02-26 09:18:03 -06003402 memcpy(&ep->com.local_addr, &cm_id->m_local_addr,
3403 sizeof(ep->com.local_addr));
Steve Wise9eccfe12014-03-26 17:08:09 -05003404
Steve Wisecfdda9d2010-04-21 15:30:06 -07003405 state_set(&ep->com, LISTEN);
Vipul Pandya830662f2013-07-04 16:10:47 +05303406 if (ep->com.local_addr.ss_family == AF_INET)
3407 err = create_server4(dev, ep);
3408 else
3409 err = create_server6(dev, ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003410 if (!err) {
3411 cm_id->provider_data = ep;
3412 goto out;
3413 }
Steve Wise9eccfe12014-03-26 17:08:09 -05003414
Vipul Pandya830662f2013-07-04 16:10:47 +05303415 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3416 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003417fail2:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303418 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003419 c4iw_put_ep(&ep->com);
3420fail1:
3421out:
3422 return err;
3423}
3424
3425int c4iw_destroy_listen(struct iw_cm_id *cm_id)
3426{
3427 int err;
3428 struct c4iw_listen_ep *ep = to_listen_ep(cm_id);
3429
3430 PDBG("%s ep %p\n", __func__, ep);
3431
3432 might_sleep();
3433 state_set(&ep->com, DEAD);
Vipul Pandya830662f2013-07-04 16:10:47 +05303434 if (ep->com.dev->rdev.lldi.enable_fw_ofld_conn &&
3435 ep->com.local_addr.ss_family == AF_INET) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003436 err = cxgb4_remove_server_filter(
3437 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3438 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
3439 } else {
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303440 struct sockaddr_in6 *sin6;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003441 c4iw_init_wr_wait(&ep->com.wr_wait);
Vipul Pandya830662f2013-07-04 16:10:47 +05303442 err = cxgb4_remove_server(
3443 ep->com.dev->rdev.lldi.ports[0], ep->stid,
3444 ep->com.dev->rdev.lldi.rxq_ids[0], 0);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003445 if (err)
3446 goto done;
3447 err = c4iw_wait_for_reply(&ep->com.dev->rdev, &ep->com.wr_wait,
3448 0, 0, __func__);
Steve Wise170003c2016-02-26 09:18:03 -06003449 sin6 = (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303450 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3451 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003452 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003453 remove_handle(ep->com.dev, &ep->com.dev->stid_idr, ep->stid);
Vipul Pandya830662f2013-07-04 16:10:47 +05303454 cxgb4_free_stid(ep->com.dev->rdev.lldi.tids, ep->stid,
3455 ep->com.local_addr.ss_family);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003456done:
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303457 deref_cm_id(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003458 c4iw_put_ep(&ep->com);
3459 return err;
3460}
3461
3462int c4iw_ep_disconnect(struct c4iw_ep *ep, int abrupt, gfp_t gfp)
3463{
3464 int ret = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003465 int close = 0;
3466 int fatal = 0;
3467 struct c4iw_rdev *rdev;
Steve Wisecfdda9d2010-04-21 15:30:06 -07003468
Steve Wise2f5b48c2010-09-10 11:15:36 -05003469 mutex_lock(&ep->com.mutex);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003470
3471 PDBG("%s ep %p state %s, abrupt %d\n", __func__, ep,
3472 states[ep->com.state], abrupt);
3473
Hariprasad S6e410d82016-05-05 01:27:31 +05303474 /*
3475 * Ref the ep here in case we have fatal errors causing the
3476 * ep to be released and freed.
3477 */
3478 c4iw_get_ep(&ep->com);
3479
Steve Wisecfdda9d2010-04-21 15:30:06 -07003480 rdev = &ep->com.dev->rdev;
3481 if (c4iw_fatal_error(rdev)) {
3482 fatal = 1;
Steve Wisebe13b2d2014-03-21 20:40:33 +05303483 close_complete_upcall(ep, -EIO);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003484 ep->com.state = DEAD;
3485 }
3486 switch (ep->com.state) {
3487 case MPA_REQ_WAIT:
3488 case MPA_REQ_SENT:
3489 case MPA_REQ_RCVD:
3490 case MPA_REP_SENT:
3491 case FPDU_MODE:
3492 close = 1;
3493 if (abrupt)
3494 ep->com.state = ABORTING;
3495 else {
3496 ep->com.state = CLOSING;
Steve Wiseca5a2202010-07-23 19:12:37 +00003497 start_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003498 }
3499 set_bit(CLOSE_SENT, &ep->com.flags);
3500 break;
3501 case CLOSING:
3502 if (!test_and_set_bit(CLOSE_SENT, &ep->com.flags)) {
3503 close = 1;
3504 if (abrupt) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003505 (void)stop_ep_timer(ep);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003506 ep->com.state = ABORTING;
3507 } else
3508 ep->com.state = MORIBUND;
3509 }
3510 break;
3511 case MORIBUND:
3512 case ABORTING:
3513 case DEAD:
3514 PDBG("%s ignoring disconnect ep %p state %u\n",
3515 __func__, ep, ep->com.state);
3516 break;
3517 default:
3518 BUG();
3519 break;
3520 }
3521
Steve Wisecfdda9d2010-04-21 15:30:06 -07003522 if (close) {
Steve Wise8da7e7a2011-06-14 20:59:27 +00003523 if (abrupt) {
Vipul Pandya793dad92012-12-10 09:30:56 +00003524 set_bit(EP_DISC_ABORT, &ep->com.history);
Steve Wisebe13b2d2014-03-21 20:40:33 +05303525 close_complete_upcall(ep, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00003526 ret = send_abort(ep, NULL, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003527 } else {
3528 set_bit(EP_DISC_CLOSE, &ep->com.history);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003529 ret = send_halfclose(ep, gfp);
Vipul Pandya793dad92012-12-10 09:30:56 +00003530 }
Hariprasad S88bc230d2016-05-05 01:27:30 +05303531 if (ret) {
Hariprasad S9ca6f7c2016-05-06 22:17:54 +05303532 set_bit(EP_DISC_FAIL, &ep->com.history);
Hariprasad S88bc230d2016-05-05 01:27:30 +05303533 if (!abrupt) {
3534 stop_ep_timer(ep);
3535 close_complete_upcall(ep, -EIO);
3536 }
Hariprasad Sc00dcba2016-05-05 01:27:36 +05303537 if (ep->com.qp) {
3538 struct c4iw_qp_attributes attrs;
3539
3540 attrs.next_state = C4IW_QP_STATE_ERROR;
3541 ret = c4iw_modify_qp(ep->com.qp->rhp,
3542 ep->com.qp,
3543 C4IW_QP_ATTR_NEXT_STATE,
3544 &attrs, 1);
3545 if (ret)
3546 pr_err(MOD
3547 "%s - qp <- error failed!\n",
3548 __func__);
3549 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003550 fatal = 1;
Hariprasad S88bc230d2016-05-05 01:27:30 +05303551 }
Steve Wisecfdda9d2010-04-21 15:30:06 -07003552 }
Steve Wise8da7e7a2011-06-14 20:59:27 +00003553 mutex_unlock(&ep->com.mutex);
Hariprasad S6e410d82016-05-05 01:27:31 +05303554 c4iw_put_ep(&ep->com);
Steve Wisecfdda9d2010-04-21 15:30:06 -07003555 if (fatal)
3556 release_ep_resources(ep);
3557 return ret;
3558}
3559
Vipul Pandya1cab7752012-12-10 09:30:55 +00003560static void active_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3561 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3562{
3563 struct c4iw_ep *ep;
Vipul Pandya793dad92012-12-10 09:30:56 +00003564 int atid = be32_to_cpu(req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003565
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003566 ep = (struct c4iw_ep *)lookup_atid(dev->rdev.lldi.tids,
3567 (__force u32) req->tid);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003568 if (!ep)
3569 return;
3570
3571 switch (req->retval) {
3572 case FW_ENOMEM:
Vipul Pandya793dad92012-12-10 09:30:56 +00003573 set_bit(ACT_RETRY_NOMEM, &ep->com.history);
3574 if (ep->retry_count++ < ACT_OPEN_RETRY_COUNT) {
3575 send_fw_act_open_req(ep, atid);
3576 return;
3577 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003578 case FW_EADDRINUSE:
Vipul Pandya793dad92012-12-10 09:30:56 +00003579 set_bit(ACT_RETRY_INUSE, &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 break;
3585 default:
3586 pr_info("%s unexpected ofld conn wr retval %d\n",
3587 __func__, req->retval);
3588 break;
3589 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003590 pr_err("active ofld_connect_wr failure %d atid %d\n",
3591 req->retval, atid);
3592 mutex_lock(&dev->rdev.stats.lock);
3593 dev->rdev.stats.act_ofld_conn_fails++;
3594 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003595 connect_reply_upcall(ep, status2errno(req->retval));
Vipul Pandya793dad92012-12-10 09:30:56 +00003596 state_set(&ep->com, DEAD);
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303597 if (ep->com.remote_addr.ss_family == AF_INET6) {
3598 struct sockaddr_in6 *sin6 =
Steve Wise170003c2016-02-26 09:18:03 -06003599 (struct sockaddr_in6 *)&ep->com.local_addr;
Hariprasad S84cc6ac62015-08-25 14:08:23 +05303600 cxgb4_clip_release(ep->com.dev->rdev.lldi.ports[0],
3601 (const u32 *)&sin6->sin6_addr.s6_addr, 1);
3602 }
Vipul Pandya793dad92012-12-10 09:30:56 +00003603 remove_handle(dev, &dev->atid_idr, atid);
3604 cxgb4_free_atid(dev->rdev.lldi.tids, atid);
3605 dst_release(ep->dst);
3606 cxgb4_l2t_release(ep->l2t);
3607 c4iw_put_ep(&ep->com);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003608}
3609
3610static void passive_ofld_conn_reply(struct c4iw_dev *dev, struct sk_buff *skb,
3611 struct cpl_fw6_msg_ofld_connection_wr_rpl *req)
3612{
3613 struct sk_buff *rpl_skb;
3614 struct cpl_pass_accept_req *cpl;
3615 int ret;
3616
Paul Bolle710a3112013-02-05 20:51:30 +00003617 rpl_skb = (struct sk_buff *)(unsigned long)req->cookie;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003618 BUG_ON(!rpl_skb);
3619 if (req->retval) {
3620 PDBG("%s passive open failure %d\n", __func__, req->retval);
Vipul Pandya793dad92012-12-10 09:30:56 +00003621 mutex_lock(&dev->rdev.stats.lock);
3622 dev->rdev.stats.pas_ofld_conn_fails++;
3623 mutex_unlock(&dev->rdev.stats.lock);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003624 kfree_skb(rpl_skb);
3625 } else {
3626 cpl = (struct cpl_pass_accept_req *)cplhdr(rpl_skb);
3627 OPCODE_TID(cpl) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ,
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003628 (__force u32) htonl(
3629 (__force u32) req->tid)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003630 ret = pass_accept_req(dev, rpl_skb);
3631 if (!ret)
3632 kfree_skb(rpl_skb);
3633 }
3634 return;
3635}
3636
3637static int deferred_fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
Steve Wise2f5b48c2010-09-10 11:15:36 -05003638{
3639 struct cpl_fw6_msg *rpl = cplhdr(skb);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003640 struct cpl_fw6_msg_ofld_connection_wr_rpl *req;
3641
3642 switch (rpl->type) {
3643 case FW6_TYPE_CQE:
3644 c4iw_ev_dispatch(dev, (struct t4_cqe *)&rpl->data[0]);
3645 break;
3646 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
3647 req = (struct cpl_fw6_msg_ofld_connection_wr_rpl *)rpl->data;
3648 switch (req->t_state) {
3649 case TCP_SYN_SENT:
3650 active_ofld_conn_reply(dev, skb, req);
3651 break;
3652 case TCP_SYN_RECV:
3653 passive_ofld_conn_reply(dev, skb, req);
3654 break;
3655 default:
3656 pr_err("%s unexpected ofld conn wr state %d\n",
3657 __func__, req->t_state);
3658 break;
3659 }
3660 break;
3661 }
3662 return 0;
3663}
3664
3665static void build_cpl_pass_accept_req(struct sk_buff *skb, int stid , u8 tos)
3666{
Hariprasad S963cab52015-09-23 17:19:27 +05303667 __be32 l2info;
3668 __be16 hdr_len, vlantag, len;
3669 u16 eth_hdr_len;
3670 int tcp_hdr_len, ip_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003671 u8 intf;
3672 struct cpl_rx_pkt *cpl = cplhdr(skb);
3673 struct cpl_pass_accept_req *req;
3674 struct tcp_options_received tmp_opt;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003675 struct c4iw_dev *dev;
Hariprasad S963cab52015-09-23 17:19:27 +05303676 enum chip_type type;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003677
Vipul Pandyaf079af72013-03-14 05:08:58 +00003678 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003679 /* Store values from cpl_rx_pkt in temporary location. */
Hariprasad S963cab52015-09-23 17:19:27 +05303680 vlantag = cpl->vlan;
3681 len = cpl->len;
3682 l2info = cpl->l2info;
3683 hdr_len = cpl->hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003684 intf = cpl->iff;
3685
3686 __skb_pull(skb, sizeof(*req) + sizeof(struct rss_header));
3687
3688 /*
3689 * We need to parse the TCP options from SYN packet.
3690 * to generate cpl_pass_accept_req.
3691 */
3692 memset(&tmp_opt, 0, sizeof(tmp_opt));
3693 tcp_clear_options(&tmp_opt);
Christoph Paasch1a2c6182013-03-17 08:23:34 +00003694 tcp_parse_options(skb, &tmp_opt, 0, NULL);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003695
3696 req = (struct cpl_pass_accept_req *)__skb_push(skb, sizeof(*req));
3697 memset(req, 0, sizeof(*req));
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303698 req->l2info = cpu_to_be16(SYN_INTF_V(intf) |
3699 SYN_MAC_IDX_V(RX_MACIDX_G(
Hariprasad S963cab52015-09-23 17:19:27 +05303700 be32_to_cpu(l2info))) |
Hariprasad Shenaicf7fe642015-01-16 09:24:48 +05303701 SYN_XACT_MATCH_F);
Hariprasad S963cab52015-09-23 17:19:27 +05303702 type = dev->rdev.lldi.adapter_type;
3703 tcp_hdr_len = RX_TCPHDR_LEN_G(be16_to_cpu(hdr_len));
3704 ip_hdr_len = RX_IPHDR_LEN_G(be16_to_cpu(hdr_len));
3705 req->hdr_len =
3706 cpu_to_be32(SYN_RX_CHAN_V(RX_CHAN_G(be32_to_cpu(l2info))));
3707 if (CHELSIO_CHIP_VERSION(type) <= CHELSIO_T5) {
3708 eth_hdr_len = is_t4(type) ?
3709 RX_ETHHDR_LEN_G(be32_to_cpu(l2info)) :
3710 RX_T5_ETHHDR_LEN_G(be32_to_cpu(l2info));
3711 req->hdr_len |= cpu_to_be32(TCP_HDR_LEN_V(tcp_hdr_len) |
3712 IP_HDR_LEN_V(ip_hdr_len) |
3713 ETH_HDR_LEN_V(eth_hdr_len));
3714 } else { /* T6 and later */
3715 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(l2info));
3716 req->hdr_len |= cpu_to_be32(T6_TCP_HDR_LEN_V(tcp_hdr_len) |
3717 T6_IP_HDR_LEN_V(ip_hdr_len) |
3718 T6_ETH_HDR_LEN_V(eth_hdr_len));
3719 }
3720 req->vlan = vlantag;
3721 req->len = len;
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003722 req->tos_stid = cpu_to_be32(PASS_OPEN_TID_V(stid) |
3723 PASS_OPEN_TOS_V(tos));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003724 req->tcpopt.mss = htons(tmp_opt.mss_clamp);
3725 if (tmp_opt.wscale_ok)
3726 req->tcpopt.wsf = tmp_opt.snd_wscale;
3727 req->tcpopt.tstamp = tmp_opt.saw_tstamp;
3728 if (tmp_opt.sack_ok)
3729 req->tcpopt.sack = 1;
3730 OPCODE_TID(req) = htonl(MK_OPCODE_TID(CPL_PASS_ACCEPT_REQ, 0));
3731 return;
3732}
3733
3734static void send_fw_pass_open_req(struct c4iw_dev *dev, struct sk_buff *skb,
3735 __be32 laddr, __be16 lport,
3736 __be32 raddr, __be16 rport,
3737 u32 rcv_isn, u32 filter, u16 window,
3738 u32 rss_qid, u8 port_id)
3739{
3740 struct sk_buff *req_skb;
3741 struct fw_ofld_connection_wr *req;
3742 struct cpl_pass_accept_req *cpl = cplhdr(skb);
Steve Wise1ce1d472014-03-21 20:40:31 +05303743 int ret;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003744
3745 req_skb = alloc_skb(sizeof(struct fw_ofld_connection_wr), GFP_KERNEL);
3746 req = (struct fw_ofld_connection_wr *)__skb_put(req_skb, sizeof(*req));
3747 memset(req, 0, sizeof(*req));
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003748 req->op_compl = htonl(WR_OP_V(FW_OFLD_CONNECTION_WR) | FW_WR_COMPL_F);
Hariprasad Shenaie2ac9622014-11-07 09:35:25 +05303749 req->len16_pkd = htonl(FW_WR_LEN16_V(DIV_ROUND_UP(sizeof(*req), 16)));
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303750 req->le.version_cpl = htonl(FW_OFLD_CONNECTION_WR_CPL_F);
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003751 req->le.filter = (__force __be32) filter;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003752 req->le.lport = lport;
3753 req->le.pport = rport;
3754 req->le.u.ipv4.lip = laddr;
3755 req->le.u.ipv4.pip = raddr;
3756 req->tcb.rcv_nxt = htonl(rcv_isn + 1);
3757 req->tcb.rcv_adv = htons(window);
3758 req->tcb.t_state_to_astid =
Hariprasad Shenai77a80e22014-11-21 12:52:01 +05303759 htonl(FW_OFLD_CONNECTION_WR_T_STATE_V(TCP_SYN_RECV) |
3760 FW_OFLD_CONNECTION_WR_RCV_SCALE_V(cpl->tcpopt.wsf) |
3761 FW_OFLD_CONNECTION_WR_ASTID_V(
Hariprasad Shenai6c53e932015-01-08 21:38:15 -08003762 PASS_OPEN_TID_G(ntohl(cpl->tos_stid))));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003763
3764 /*
3765 * We store the qid in opt2 which will be used by the firmware
3766 * to send us the wr response.
3767 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003768 req->tcb.opt2 = htonl(RSS_QUEUE_V(rss_qid));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003769
3770 /*
3771 * We initialize the MSS index in TCB to 0xF.
3772 * So that when driver sends cpl_pass_accept_rpl
3773 * TCB picks up the correct value. If this was 0
3774 * TP will ignore any value > 0 for MSS index.
3775 */
Anish Bhattd7990b02014-11-12 17:15:57 -08003776 req->tcb.opt0 = cpu_to_be64(MSS_IDX_V(0xF));
Hariprasad S6198dd82015-04-22 01:44:59 +05303777 req->cookie = (uintptr_t)skb;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003778
3779 set_wr_txq(req_skb, CPL_PRIORITY_CONTROL, port_id);
Steve Wise1ce1d472014-03-21 20:40:31 +05303780 ret = cxgb4_ofld_send(dev->rdev.lldi.ports[0], req_skb);
3781 if (ret < 0) {
3782 pr_err("%s - cxgb4_ofld_send error %d - dropping\n", __func__,
3783 ret);
3784 kfree_skb(skb);
3785 kfree_skb(req_skb);
3786 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003787}
3788
3789/*
3790 * Handler for CPL_RX_PKT message. Need to handle cpl_rx_pkt
3791 * messages when a filter is being used instead of server to
3792 * redirect a syn packet. When packets hit filter they are redirected
3793 * to the offload queue and driver tries to establish the connection
3794 * using firmware work request.
3795 */
3796static int rx_pkt(struct c4iw_dev *dev, struct sk_buff *skb)
3797{
3798 int stid;
3799 unsigned int filter;
3800 struct ethhdr *eh = NULL;
3801 struct vlan_ethhdr *vlan_eh = NULL;
3802 struct iphdr *iph;
3803 struct tcphdr *tcph;
3804 struct rss_header *rss = (void *)skb->data;
3805 struct cpl_rx_pkt *cpl = (void *)skb->data;
3806 struct cpl_pass_accept_req *req = (void *)(rss + 1);
3807 struct l2t_entry *e;
3808 struct dst_entry *dst;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003809 struct c4iw_ep *lep;
3810 u16 window;
3811 struct port_info *pi;
3812 struct net_device *pdev;
Vipul Pandyaf079af72013-03-14 05:08:58 +00003813 u16 rss_qid, eth_hdr_len;
Vipul Pandya1cab7752012-12-10 09:30:55 +00003814 int step;
3815 u32 tx_chan;
3816 struct neighbour *neigh;
3817
3818 /* Drop all non-SYN packets */
Hariprasad Shenaibdc590b2015-01-08 21:38:16 -08003819 if (!(cpl->l2info & cpu_to_be32(RXF_SYN_F)))
Vipul Pandya1cab7752012-12-10 09:30:55 +00003820 goto reject;
3821
3822 /*
3823 * Drop all packets which did not hit the filter.
3824 * Unlikely to happen.
3825 */
3826 if (!(rss->filter_hit && rss->filter_tid))
3827 goto reject;
3828
3829 /*
3830 * Calculate the server tid from filter hit index from cpl_rx_pkt.
3831 */
Kumar Sanghvia4ea0252013-12-18 16:38:24 +05303832 stid = (__force int) cpu_to_be32((__force u32) rss->hash_val);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003833
3834 lep = (struct c4iw_ep *)lookup_stid(dev->rdev.lldi.tids, stid);
3835 if (!lep) {
3836 PDBG("%s connect request on invalid stid %d\n", __func__, stid);
3837 goto reject;
3838 }
3839
Hariprasad S963cab52015-09-23 17:19:27 +05303840 switch (CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type)) {
3841 case CHELSIO_T4:
3842 eth_hdr_len = RX_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3843 break;
3844 case CHELSIO_T5:
3845 eth_hdr_len = RX_T5_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3846 break;
3847 case CHELSIO_T6:
3848 eth_hdr_len = RX_T6_ETHHDR_LEN_G(be32_to_cpu(cpl->l2info));
3849 break;
3850 default:
3851 pr_err("T%d Chip is not supported\n",
3852 CHELSIO_CHIP_VERSION(dev->rdev.lldi.adapter_type));
3853 goto reject;
3854 }
3855
Vipul Pandyaf079af72013-03-14 05:08:58 +00003856 if (eth_hdr_len == ETH_HLEN) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003857 eh = (struct ethhdr *)(req + 1);
3858 iph = (struct iphdr *)(eh + 1);
3859 } else {
3860 vlan_eh = (struct vlan_ethhdr *)(req + 1);
3861 iph = (struct iphdr *)(vlan_eh + 1);
3862 skb->vlan_tci = ntohs(cpl->vlan);
3863 }
3864
3865 if (iph->version != 0x4)
3866 goto reject;
3867
3868 tcph = (struct tcphdr *)(iph + 1);
3869 skb_set_network_header(skb, (void *)iph - (void *)rss);
3870 skb_set_transport_header(skb, (void *)tcph - (void *)rss);
3871 skb_get(skb);
3872
3873 PDBG("%s lip 0x%x lport %u pip 0x%x pport %u tos %d\n", __func__,
3874 ntohl(iph->daddr), ntohs(tcph->dest), ntohl(iph->saddr),
3875 ntohs(tcph->source), iph->tos);
3876
Vipul Pandya830662f2013-07-04 16:10:47 +05303877 dst = find_route(dev, iph->daddr, iph->saddr, tcph->dest, tcph->source,
3878 iph->tos);
3879 if (!dst) {
Vipul Pandya1cab7752012-12-10 09:30:55 +00003880 pr_err("%s - failed to find dst entry!\n",
3881 __func__);
3882 goto reject;
3883 }
Vipul Pandya1cab7752012-12-10 09:30:55 +00003884 neigh = dst_neigh_lookup_skb(dst, skb);
3885
Zhouyi Zhouaaa0c232013-03-14 17:21:50 +00003886 if (!neigh) {
3887 pr_err("%s - failed to allocate neigh!\n",
3888 __func__);
3889 goto free_dst;
3890 }
3891
Vipul Pandya1cab7752012-12-10 09:30:55 +00003892 if (neigh->dev->flags & IFF_LOOPBACK) {
3893 pdev = ip_dev_find(&init_net, iph->daddr);
3894 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
3895 pdev, 0);
3896 pi = (struct port_info *)netdev_priv(pdev);
3897 tx_chan = cxgb4_port_chan(pdev);
3898 dev_put(pdev);
3899 } else {
Vipul Pandya830662f2013-07-04 16:10:47 +05303900 pdev = get_real_dev(neigh->dev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003901 e = cxgb4_l2t_get(dev->rdev.lldi.l2t, neigh,
Vipul Pandya830662f2013-07-04 16:10:47 +05303902 pdev, 0);
3903 pi = (struct port_info *)netdev_priv(pdev);
3904 tx_chan = cxgb4_port_chan(pdev);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003905 }
Steve Wiseebf00062014-03-19 17:44:40 +05303906 neigh_release(neigh);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003907 if (!e) {
3908 pr_err("%s - failed to allocate l2t entry!\n",
3909 __func__);
3910 goto free_dst;
3911 }
3912
3913 step = dev->rdev.lldi.nrxq / dev->rdev.lldi.nchan;
3914 rss_qid = dev->rdev.lldi.rxq_ids[pi->port_id * step];
Vipul Pandyaef5d6352013-01-07 13:12:00 +00003915 window = (__force u16) htons((__force u16)tcph->window);
Vipul Pandya1cab7752012-12-10 09:30:55 +00003916
3917 /* Calcuate filter portion for LE region. */
Kumar Sanghvi41b4f862013-12-18 16:38:26 +05303918 filter = (__force unsigned int) cpu_to_be32(cxgb4_select_ntuple(
3919 dev->rdev.lldi.ports[0],
3920 e));
Vipul Pandya1cab7752012-12-10 09:30:55 +00003921
3922 /*
3923 * Synthesize the cpl_pass_accept_req. We have everything except the
3924 * TID. Once firmware sends a reply with TID we update the TID field
3925 * in cpl and pass it through the regular cpl_pass_accept_req path.
3926 */
3927 build_cpl_pass_accept_req(skb, stid, iph->tos);
3928 send_fw_pass_open_req(dev, skb, iph->daddr, tcph->dest, iph->saddr,
3929 tcph->source, ntohl(tcph->seq), filter, window,
3930 rss_qid, pi->port_id);
3931 cxgb4_l2t_release(e);
3932free_dst:
3933 dst_release(dst);
3934reject:
Steve Wise2f5b48c2010-09-10 11:15:36 -05003935 return 0;
3936}
3937
Steve Wisecfdda9d2010-04-21 15:30:06 -07003938/*
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003939 * These are the real handlers that are called from a
3940 * work queue.
3941 */
Hariprasad S9dec9002016-05-05 01:27:29 +05303942static c4iw_handler_func work_handlers[NUM_CPL_CMDS + NUM_FAKE_CPLS] = {
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003943 [CPL_ACT_ESTABLISH] = act_establish,
3944 [CPL_ACT_OPEN_RPL] = act_open_rpl,
3945 [CPL_RX_DATA] = rx_data,
3946 [CPL_ABORT_RPL_RSS] = abort_rpl,
3947 [CPL_ABORT_RPL] = abort_rpl,
3948 [CPL_PASS_OPEN_RPL] = pass_open_rpl,
3949 [CPL_CLOSE_LISTSRV_RPL] = close_listsrv_rpl,
3950 [CPL_PASS_ACCEPT_REQ] = pass_accept_req,
3951 [CPL_PASS_ESTABLISH] = pass_establish,
3952 [CPL_PEER_CLOSE] = peer_close,
3953 [CPL_ABORT_REQ_RSS] = peer_abort,
3954 [CPL_CLOSE_CON_RPL] = close_con_rpl,
3955 [CPL_RDMA_TERMINATE] = terminate,
Steve Wise2f5b48c2010-09-10 11:15:36 -05003956 [CPL_FW4_ACK] = fw4_ack,
Vipul Pandya1cab7752012-12-10 09:30:55 +00003957 [CPL_FW6_MSG] = deferred_fw6_msg,
Hariprasad S9dec9002016-05-05 01:27:29 +05303958 [CPL_RX_PKT] = rx_pkt,
Hariprasad S8d1f1a62016-05-06 22:17:57 +05303959 [FAKE_CPL_PUT_EP_SAFE] = _put_ep_safe,
3960 [FAKE_CPL_PASS_PUT_EP_SAFE] = _put_pass_ep_safe
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003961};
3962
3963static void process_timeout(struct c4iw_ep *ep)
3964{
3965 struct c4iw_qp_attributes attrs;
3966 int abort = 1;
3967
Steve Wise2f5b48c2010-09-10 11:15:36 -05003968 mutex_lock(&ep->com.mutex);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003969 PDBG("%s ep %p tid %u state %d\n", __func__, ep, ep->hwtid,
3970 ep->com.state);
Vipul Pandya793dad92012-12-10 09:30:56 +00003971 set_bit(TIMEDOUT, &ep->com.history);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003972 switch (ep->com.state) {
3973 case MPA_REQ_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003974 connect_reply_upcall(ep, -ETIMEDOUT);
3975 break;
3976 case MPA_REQ_WAIT:
Hariprasad Se4b76a22016-05-06 22:17:59 +05303977 case MPA_REP_SENT:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003978 break;
3979 case CLOSING:
3980 case MORIBUND:
3981 if (ep->com.cm_id && ep->com.qp) {
3982 attrs.next_state = C4IW_QP_STATE_ERROR;
3983 c4iw_modify_qp(ep->com.qp->rhp,
3984 ep->com.qp, C4IW_QP_ATTR_NEXT_STATE,
3985 &attrs, 1);
3986 }
Steve Wisebe13b2d2014-03-21 20:40:33 +05303987 close_complete_upcall(ep, -ETIMEDOUT);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003988 break;
Steve Wiseb33bd0c2014-04-09 09:38:25 -05003989 case ABORTING:
3990 case DEAD:
3991
3992 /*
3993 * These states are expected if the ep timed out at the same
3994 * time as another thread was calling stop_ep_timer().
3995 * So we silently do nothing for these states.
3996 */
3997 abort = 0;
3998 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07003999 default:
Julia Lawall76f267b2012-11-03 10:58:27 +00004000 WARN(1, "%s unexpected state ep %p tid %u state %u\n",
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004001 __func__, ep, ep->hwtid, ep->com.state);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004002 abort = 0;
4003 }
Steve Wisecc18b932014-04-24 14:31:53 -05004004 mutex_unlock(&ep->com.mutex);
Hariprasad S69736272016-05-05 01:27:37 +05304005 if (abort)
4006 c4iw_ep_disconnect(ep, 1, GFP_KERNEL);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004007 c4iw_put_ep(&ep->com);
4008}
4009
4010static void process_timedout_eps(void)
4011{
4012 struct c4iw_ep *ep;
4013
4014 spin_lock_irq(&timeout_lock);
4015 while (!list_empty(&timeout_list)) {
4016 struct list_head *tmp;
4017
4018 tmp = timeout_list.next;
4019 list_del(tmp);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004020 tmp->next = NULL;
4021 tmp->prev = NULL;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004022 spin_unlock_irq(&timeout_lock);
4023 ep = list_entry(tmp, struct c4iw_ep, entry);
4024 process_timeout(ep);
4025 spin_lock_irq(&timeout_lock);
4026 }
4027 spin_unlock_irq(&timeout_lock);
4028}
4029
4030static void process_work(struct work_struct *work)
4031{
4032 struct sk_buff *skb = NULL;
4033 struct c4iw_dev *dev;
Dan Carpenterc1d73562010-05-31 14:00:53 +00004034 struct cpl_act_establish *rpl;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004035 unsigned int opcode;
4036 int ret;
4037
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004038 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004039 while ((skb = skb_dequeue(&rxq))) {
4040 rpl = cplhdr(skb);
4041 dev = *((struct c4iw_dev **) (skb->cb + sizeof(void *)));
4042 opcode = rpl->ot.opcode;
4043
4044 BUG_ON(!work_handlers[opcode]);
4045 ret = work_handlers[opcode](dev, skb);
4046 if (!ret)
4047 kfree_skb(skb);
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004048 process_timedout_eps();
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004049 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004050}
4051
4052static DECLARE_WORK(skb_work, process_work);
4053
4054static void ep_timeout(unsigned long arg)
4055{
4056 struct c4iw_ep *ep = (struct c4iw_ep *)arg;
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004057 int kickit = 0;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004058
4059 spin_lock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004060 if (!test_and_set_bit(TIMEOUT, &ep->com.flags)) {
Steve Wiseb33bd0c2014-04-09 09:38:25 -05004061 /*
4062 * Only insert if it is not already on the list.
4063 */
4064 if (!ep->entry.next) {
4065 list_add_tail(&ep->entry, &timeout_list);
4066 kickit = 1;
4067 }
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004068 }
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004069 spin_unlock(&timeout_lock);
Vipul Pandya1ec779c2013-01-07 13:11:56 +00004070 if (kickit)
4071 queue_work(workq, &skb_work);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004072}
4073
4074/*
Steve Wisecfdda9d2010-04-21 15:30:06 -07004075 * All the CM events are handled on a work queue to have a safe context.
4076 */
4077static int sched(struct c4iw_dev *dev, struct sk_buff *skb)
4078{
4079
4080 /*
4081 * Save dev in the skb->cb area.
4082 */
4083 *((struct c4iw_dev **) (skb->cb + sizeof(void *))) = dev;
4084
4085 /*
4086 * Queue the skb and schedule the worker thread.
4087 */
4088 skb_queue_tail(&rxq, skb);
4089 queue_work(workq, &skb_work);
4090 return 0;
4091}
4092
4093static int set_tcb_rpl(struct c4iw_dev *dev, struct sk_buff *skb)
4094{
4095 struct cpl_set_tcb_rpl *rpl = cplhdr(skb);
4096
4097 if (rpl->status != CPL_ERR_NONE) {
4098 printk(KERN_ERR MOD "Unexpected SET_TCB_RPL status %u "
4099 "for tid %u\n", rpl->status, GET_TID(rpl));
4100 }
Steve Wise2f5b48c2010-09-10 11:15:36 -05004101 kfree_skb(skb);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004102 return 0;
4103}
4104
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004105static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb)
4106{
4107 struct cpl_fw6_msg *rpl = cplhdr(skb);
4108 struct c4iw_wr_wait *wr_waitp;
4109 int ret;
4110
4111 PDBG("%s type %u\n", __func__, rpl->type);
4112
4113 switch (rpl->type) {
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004114 case FW6_TYPE_WR_RPL:
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004115 ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff);
Roland Dreierc8e081a2010-09-27 17:51:04 -07004116 wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1];
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004117 PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret);
Steve Wised9594d92011-05-09 22:06:22 -07004118 if (wr_waitp)
4119 c4iw_wake_up(wr_waitp, ret ? -ret : 0);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004120 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004121 break;
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004122 case FW6_TYPE_CQE:
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004123 case FW6_TYPE_OFLD_CONNECTION_WR_RPL:
Vipul Pandya1cab7752012-12-10 09:30:55 +00004124 sched(dev, skb);
Vipul Pandya5be78ee2012-12-10 09:30:54 +00004125 break;
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004126 default:
4127 printk(KERN_ERR MOD "%s unexpected fw6 msg type %u\n", __func__,
4128 rpl->type);
Steve Wise2f5b48c2010-09-10 11:15:36 -05004129 kfree_skb(skb);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004130 break;
4131 }
4132 return 0;
4133}
4134
Steve Wise8da7e7a2011-06-14 20:59:27 +00004135static int peer_abort_intr(struct c4iw_dev *dev, struct sk_buff *skb)
4136{
4137 struct cpl_abort_req_rss *req = cplhdr(skb);
4138 struct c4iw_ep *ep;
4139 struct tid_info *t = dev->rdev.lldi.tids;
4140 unsigned int tid = GET_TID(req);
4141
4142 ep = lookup_tid(t, tid);
Steve Wise14b92222012-04-30 15:31:29 -05004143 if (!ep) {
4144 printk(KERN_WARNING MOD
4145 "Abort on non-existent endpoint, tid %d\n", tid);
4146 kfree_skb(skb);
4147 return 0;
4148 }
Steve Wise7a2cea22014-03-14 21:52:07 +05304149 if (is_neg_adv(req->status)) {
Hariprasad S179d03b2015-05-05 03:55:24 +05304150 PDBG("%s Negative advice on abort- tid %u status %d (%s)\n",
4151 __func__, ep->hwtid, req->status,
4152 neg_adv_str(req->status));
4153 ep->stats.abort_neg_adv++;
4154 dev->rdev.stats.neg_adv++;
Steve Wise8da7e7a2011-06-14 20:59:27 +00004155 kfree_skb(skb);
4156 return 0;
4157 }
4158 PDBG("%s ep %p tid %u state %u\n", __func__, ep, ep->hwtid,
4159 ep->com.state);
4160
4161 /*
4162 * Wake up any threads in rdma_init() or rdma_fini().
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004163 * However, if we are on MPAv2 and want to retry with MPAv1
4164 * then, don't wake up yet.
Steve Wise8da7e7a2011-06-14 20:59:27 +00004165 */
Vipul Pandya7c0a33d2013-01-07 13:11:58 +00004166 if (mpa_rev == 2 && !ep->tried_with_mpa_v1) {
4167 if (ep->com.state != MPA_REQ_SENT)
4168 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
4169 } else
4170 c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET);
Steve Wise8da7e7a2011-06-14 20:59:27 +00004171 sched(dev, skb);
4172 return 0;
4173}
4174
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004175/*
4176 * Most upcalls from the T4 Core go to sched() to
4177 * schedule the processing on a work queue.
4178 */
4179c4iw_handler_func c4iw_handlers[NUM_CPL_CMDS] = {
4180 [CPL_ACT_ESTABLISH] = sched,
4181 [CPL_ACT_OPEN_RPL] = sched,
4182 [CPL_RX_DATA] = sched,
4183 [CPL_ABORT_RPL_RSS] = sched,
4184 [CPL_ABORT_RPL] = sched,
4185 [CPL_PASS_OPEN_RPL] = sched,
4186 [CPL_CLOSE_LISTSRV_RPL] = sched,
4187 [CPL_PASS_ACCEPT_REQ] = sched,
4188 [CPL_PASS_ESTABLISH] = sched,
4189 [CPL_PEER_CLOSE] = sched,
4190 [CPL_CLOSE_CON_RPL] = sched,
Steve Wise8da7e7a2011-06-14 20:59:27 +00004191 [CPL_ABORT_REQ_RSS] = peer_abort_intr,
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004192 [CPL_RDMA_TERMINATE] = sched,
4193 [CPL_FW4_ACK] = sched,
4194 [CPL_SET_TCB_RPL] = set_tcb_rpl,
Vipul Pandya1cab7752012-12-10 09:30:55 +00004195 [CPL_FW6_MSG] = fw6_msg,
4196 [CPL_RX_PKT] = sched
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004197};
4198
Steve Wisecfdda9d2010-04-21 15:30:06 -07004199int __init c4iw_cm_init(void)
4200{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004201 spin_lock_init(&timeout_lock);
Steve Wisecfdda9d2010-04-21 15:30:06 -07004202 skb_queue_head_init(&rxq);
4203
4204 workq = create_singlethread_workqueue("iw_cxgb4");
4205 if (!workq)
4206 return -ENOMEM;
4207
Steve Wisecfdda9d2010-04-21 15:30:06 -07004208 return 0;
4209}
4210
Steve Wise46c13762014-06-20 14:26:25 -05004211void c4iw_cm_term(void)
Steve Wisecfdda9d2010-04-21 15:30:06 -07004212{
Roland Dreierbe4c9ba2010-05-05 14:45:40 -07004213 WARN_ON(!list_empty(&timeout_list));
Steve Wisecfdda9d2010-04-21 15:30:06 -07004214 flush_workqueue(workq);
4215 destroy_workqueue(workq);
4216}